forked from michaljaz/webmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUrlParams.js
More file actions
32 lines (31 loc) · 1.08 KB
/
UrlParams.js
File metadata and controls
32 lines (31 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function UrlParams (game) {
const nameList = game.al.get('nameList').split('\n')
const finalName = nameList[Math.floor(Math.random() * nameList.length)]
game.nick = new URL(document.location).searchParams.get('nick')
game.server = new URL(document.location).searchParams.get('server')
game.proxy = new URL(document.location).searchParams.get('proxy')
let reload = false
if (game.nick === '' || game.nick === null) {
reload = true
game.nick = finalName
}
if (game.server === '' || game.server === null) {
reload = true
game.server = game.production ? game.servers.production : game.servers.development
}
if (game.proxy === '' || game.proxy === null) {
reload = true
if (game.production) {
game.proxy = 'production'
} else {
game.proxy = 'local'
}
}
if (document.location.protocol !== 'https:' && game.proxy === 'production') {
console.error('Web-minecraft in production mode needs https!')
}
if (reload) {
document.location.href = `?server=${game.server}&nick=${game.nick}&proxy=${game.proxy}`
}
}
export { UrlParams }