Skip to content

Commit c5ea1cb

Browse files
committed
lint
1 parent 668b636 commit c5ea1cb

File tree

10 files changed

+121
-131
lines changed

10 files changed

+121
-131
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![Discord](https://img.shields.io/badge/chat-on%20discord-brightgreen.svg)](https://discord.gg/h6DQzDx2G7)
44
[![Try it on gitpod](https://img.shields.io/badge/try-on%20gitpod-brightgreen.svg)](https://gitpod.io/#https://github.com/michaljaz/web-minecraft)
55
[![Build and Deploy](https://github.com/michaljaz/web-minecraft/actions/workflows/github-pages.yaml/badge.svg)](https://github.com/michaljaz/web-minecraft/actions/workflows/github-pages.yaml)
6+
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
67
## About
78

89
**Webmc is minecraft client written in Javascript.** From web browser this client connects to websocket proxy and then to real minecraft server, so you can play minecraft in the browser.

lib/postinstall.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
try{
2-
const decompress = require('decompress')
3-
const path = require('path')
1+
try {
2+
const decompress = require('decompress')
3+
const path = require('path')
44

5-
decompress(
6-
path.join(__dirname, '../assets/pack.zip'),
7-
path.join(__dirname, '../assets/pack')
8-
)
9-
}catch(e){}
5+
decompress(
6+
path.join(__dirname, '../assets/pack.zip'),
7+
path.join(__dirname, '../assets/pack')
8+
)
9+
} catch (e) {}

lib/server.js

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,47 @@ const app = express()
33
const netApi = require('./proxy.js')
44
const port = process.env.PORT || 8080
55
const cors = require('cors')
6-
const axios = require('axios');
7-
const atob = require('atob');
6+
const axios = require('axios')
7+
const atob = require('atob')
88

99
app.use(cors())
1010
app.use(netApi({ allowOrigin: '*' }))
1111

12-
app.use("/proxyCheck",(req,res,next)=>{
13-
res.send("OK")
12+
app.use('/proxyCheck', (req, res, next) => {
13+
res.send('OK')
1414
})
1515

16-
app.get("/getId",(req,res,next)=>{
17-
axios.get(`https://api.mojang.com/users/profiles/minecraft/${req.query.nick}`,{responseType: 'json'})
18-
.then(function (response) {
19-
if(response.status==204){
20-
res.send('ERR')
21-
}else{
22-
res.send(response.data.id)
23-
}
24-
})
25-
.catch(function (error) {
26-
res.send("ERR")
27-
})
16+
app.get('/getId', (req, res, next) => {
17+
axios.get(`https://api.mojang.com/users/profiles/minecraft/${req.query.nick}`, { responseType: 'json' })
18+
.then(function (response) {
19+
if (response.status === 204) {
20+
res.send('ERR')
21+
} else {
22+
res.send(response.data.id)
23+
}
24+
})
25+
.catch(function () {
26+
res.send('ERR')
27+
})
2828
})
2929

30-
app.get("/getSkin",(req,res,next)=>{
31-
axios.get(`https://sessionserver.mojang.com/session/minecraft/profile/${req.query.id}?legacy=true`,{responseType: 'json'})
32-
.then(function (response) {
33-
var url=JSON.parse(atob(response.data.properties[0].value)).textures.SKIN.url
34-
axios.get(url,{responseType: 'arraybuffer'})
35-
.then(function (response) {
36-
var headers = {'Content-Type': 'image/jpeg'};
37-
res.writeHead(200, headers);
38-
res.end(response.data, 'binary');
39-
})
40-
.catch(function (error) {
41-
res.send("ERR")
42-
})
43-
})
44-
.catch(function (error) {
45-
res.send("ERR")
46-
})
30+
app.get('/getSkin', (req, res, next) => {
31+
axios.get(`https://sessionserver.mojang.com/session/minecraft/profile/${req.query.id}?legacy=true`, { responseType: 'json' })
32+
.then(function (response) {
33+
const url = JSON.parse(atob(response.data.properties[0].value)).textures.SKIN.url
34+
axios.get(url, { responseType: 'arraybuffer' })
35+
.then(function (response) {
36+
const headers = { 'Content-Type': 'image/jpeg' }
37+
res.writeHead(200, headers)
38+
res.end(response.data, 'binary')
39+
})
40+
.catch(function () {
41+
res.send('ERR')
42+
})
43+
})
44+
.catch(function () {
45+
res.send('ERR')
46+
})
4747
})
4848

4949
app.listen(port, () => {

package-lock.json

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@
1212
"postinstall": "node lib/postinstall.js",
1313
"proxy": "node lib/server.js"
1414
},
15+
"standard": {
16+
"ignore": [
17+
"/src/vendor"
18+
]
19+
},
1520
"license": "MIT",
1621
"repository": {
1722
"type": "git",
1823
"url": "git://github.com/michaljaz/webmc.git"
1924
},
20-
"keywords": [
21-
"minecraft",
22-
"game",
23-
"browser",
24-
"web",
25-
"client"
26-
],
2725
"engines": {
2826
"node": "14.x"
2927
},
@@ -42,12 +40,13 @@
4240
"bootstrap": "^4.6.0",
4341
"browserify-zlib": "^0.2.0",
4442
"canvas": "^2.8.0",
45-
"child_process": "^1.0.2",
4643
"compression": "^1.7.4",
4744
"constants-browserify": "^1.0.0",
4845
"copy-webpack-plugin": "^6.3.1",
4946
"crypto-browserify": "^3.12.0",
5047
"css-loader": "^5.0.1",
48+
"decompress": "^4.2.1",
49+
"decompress-tarxz": "^3.0.0",
5150
"eslint": "^7.22.0",
5251
"file-loader": "^6.2.0",
5352
"helmet": "^4.4.1",
@@ -78,8 +77,6 @@
7877
"webpack-cli": "^4.2.0",
7978
"webpack-dev-server": "^3.11.1",
8079
"webpack-merge": "^5.7.3",
81-
"worker-loader": "^3.0.7",
82-
"decompress": "^4.2.1",
83-
"decompress-tarxz": "^3.0.0"
80+
"worker-loader": "^3.0.7"
8481
}
8582
}

src/scripts/EventHandler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ class EventHandler {
236236
$('.chat').addClass('blur')
237237
$('.com_i').blur()
238238
$('.com').hide()
239-
this.game.chat.hide()
239+
this.game.chat.hide()
240240
return $('.inv_window').hide()
241241
}
242242

@@ -258,7 +258,7 @@ class EventHandler {
258258
break
259259
case 'chat':
260260
if (this.gameState === 'gameLock') {
261-
this.game.chat.show()
261+
this.game.chat.show()
262262
$('.chat').addClass('focus')
263263
$('.chat').removeClass('blur')
264264
$('.gameMenu').hide()

src/scripts/Setup.js

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function Setup (game) {
4545
UrlParams(game)
4646
console.warn(gpuInfo())
4747
game.socket = new Socket(game)
48-
game.pii = new PlayerInInventory(game)
48+
game.pii = new PlayerInInventory(game)
4949
game.bb = new BlockBreak(game)
5050
game.bp = new BlockPlace(game)
5151
game.world = new World(game)
@@ -54,46 +54,45 @@ function Setup (game) {
5454
game.inv_bar = new InventoryBar(game)
5555
game.tl = new TabList(game)
5656
game.ls = new LoadingScreen(game)
57-
game.ls.show(`Waiting for proxy...`)
58-
let hostname, port, pars
59-
if (game.proxy === 'local') {
60-
hostname = document.location.hostname
61-
port = document.location.port
62-
} else if (game.proxy === 'production') {
63-
pars = game.al.get('config').proxy.split(':')
64-
hostname = pars[0]
65-
port = pars[1]
66-
} else {
67-
pars = game.proxy.split(':')
68-
hostname = pars[0]
69-
port = pars[1]
70-
}
71-
fetch(`${document.location.protocol}//${hostname}:${port}/proxyCheck`)
72-
.then(response => response.text())
73-
.then(data => {
74-
if(data=="OK"){
75-
game.ls.show(`Connecting to ${game.server}...`)
76-
77-
//PLAYER UUID
78-
fetch(`${document.location.protocol}//${hostname}:${port}/getId?nick=${game.nick}`)
79-
.then(response => response.text())
80-
.then(id => {
81-
if(id!=="ERR"){
82-
console.log(`UUID: ${id}`)
83-
//SKIN
84-
game.skinUrl=`${document.location.protocol}//${hostname}:${port}/getSkin?id=${id}`
85-
console.log(game.skinUrl)
86-
new TextureLoader().load(game.skinUrl, (texture) => {
87-
game.pii.setup(texture)
88-
})
57+
game.ls.show('Waiting for proxy...')
58+
let hostname, port, pars
59+
if (game.proxy === 'local') {
60+
hostname = document.location.hostname
61+
port = document.location.port
62+
} else if (game.proxy === 'production') {
63+
pars = game.al.get('config').proxy.split(':')
64+
hostname = pars[0]
65+
port = pars[1]
66+
} else {
67+
pars = game.proxy.split(':')
68+
hostname = pars[0]
69+
port = pars[1]
70+
}
71+
window.fetch(`${document.location.protocol}//${hostname}:${port}/proxyCheck`)
72+
.then(response => response.text())
73+
.then(data => {
74+
if (data === 'OK') {
75+
game.ls.show(`Connecting to ${game.server}...`)
8976

90-
}else{
91-
console.log("UUID not found!")
92-
game.pii.setup(game.al.get('playerTex'))
93-
}
94-
});
95-
}
96-
});
77+
// PLAYER UUID
78+
window.fetch(`${document.location.protocol}//${hostname}:${port}/getId?nick=${game.nick}`)
79+
.then(response => response.text())
80+
.then(id => {
81+
if (id !== 'ERR') {
82+
console.log(`UUID: ${id}`)
83+
// SKIN
84+
game.skinUrl = `${document.location.protocol}//${hostname}:${port}/getSkin?id=${id}`
85+
console.log(game.skinUrl)
86+
new TextureLoader().load(game.skinUrl, (texture) => {
87+
game.pii.setup(texture)
88+
})
89+
} else {
90+
console.log('UUID not found!')
91+
game.pii.setup(game.al.get('playerTex'))
92+
}
93+
})
94+
}
95+
})
9796

9897
game.distanceBasedFog.addShaderToMaterials([
9998
game.world.material,

src/scripts/gui/Chat.js

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Chat {
77
this.listen()
88
this.history = ['']
99
this.histState = 0
10-
this.fadeTimeout=10000
10+
this.fadeTimeout = 10000
1111
}
1212

1313
chatGoBack () {
@@ -55,35 +55,34 @@ class Chat {
5555
elem.innerHTML = message + '<br>'
5656
this.chatDiv.append(elem)
5757
this.scrollToBottom(this.chatDiv)
58-
setTimeout(()=>{
59-
if(this.game.eh.gameState=="chat"){
60-
elem.hidd=true;
61-
}else{
62-
$(elem).fadeOut(1000,()=>{
63-
elem.hidd=true;
64-
this.scrollToBottom(this.chatDiv)
65-
})
66-
}
67-
68-
},this.fadeTimeout)
58+
setTimeout(() => {
59+
if (this.game.eh.gameState === 'chat') {
60+
elem.hidd = true
61+
} else {
62+
$(elem).fadeOut(1000, () => {
63+
elem.hidd = true
64+
this.scrollToBottom(this.chatDiv)
65+
})
66+
}
67+
}, this.fadeTimeout)
6968
}
7069

71-
show (){
72-
const children=[].slice.call(this.chatDiv.children)
73-
for(var i=0;i<children.length;i++){
74-
$(children[i]).show()
75-
}
76-
this.scrollToBottom(this.chatDiv)
77-
}
70+
show () {
71+
const children = [].slice.call(this.chatDiv.children)
72+
for (let i = 0; i < children.length; i++) {
73+
$(children[i]).show()
74+
}
75+
this.scrollToBottom(this.chatDiv)
76+
}
7877

79-
hide (){
80-
const children=[].slice.call(this.chatDiv.children)
81-
for(var i=0;i<children.length;i++){
82-
if(children[i].hidd){
83-
$(children[i]).hide()
84-
}
85-
}
86-
}
78+
hide () {
79+
const children = [].slice.call(this.chatDiv.children)
80+
for (let i = 0; i < children.length; i++) {
81+
if (children[i].hidd) {
82+
$(children[i]).hide()
83+
}
84+
}
85+
}
8786

8887
command (com) {
8988
if (com !== '') {

src/scripts/gui/PlayerInInventory.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class PlayerInInventory {
2121
this.scene.add(light)
2222
}
2323

24-
setup (texture) {
25-
const player = this.game.al.get('player')
24+
setup (texture) {
25+
const player = this.game.al.get('player')
2626
texture.magFilter = NearestFilter
2727
player.children[0].material.map = texture
2828
this.scene.add(player)
@@ -52,7 +52,7 @@ class PlayerInInventory {
5252
wychX * top)
5353
}
5454
})
55-
}
55+
}
5656

5757
render () {
5858
return this.renderer.render(this.scene, this.camera)

src/scripts/rendering/DistanceBasedFog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class DistanceBasedFog {
1010
}
1111

1212
updateDistance (val) {
13-
this.farnear.x = (Math.sqrt(val-1.5)) * 16
13+
this.farnear.x = (Math.sqrt(val - 1.5)) * 16
1414
this.farnear.y = (val - 1) * 16
1515
}
1616

0 commit comments

Comments
 (0)