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
65 lines (62 loc) · 2.21 KB
/
UrlParams.js
File metadata and controls
65 lines (62 loc) · 2.21 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import swal from 'sweetalert'
function UrlParams (game) {
return new Promise((resolve) => {
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.serverPort = new URL(document.location).searchParams.get('port')
game.premium = new URL(document.location).searchParams.get('premium')
game.proxy = {
hostname: new URL(document.location).searchParams.get('proxyHost'),
port: new URL(document.location).searchParams.get('proxyPort')
}
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[0]
: game.servers.development[0]
}
if (game.serverPort === '' || game.serverPort === null) {
reload = true
game.serverPort = game.production
? game.servers.production[1]
: game.servers.development[1]
}
if (game.premium === '' || game.premium === null) {
reload = true
game.premium = 'false'
}
if (game.proxy.hostname === '' || game.proxy.hostname === null) {
reload = true
game.proxy.hostname = game.production ? 'web-minecraft-proxy.herokuapp.com' : 'local'
}
if (game.proxy.port === '' || game.proxy.port === null) {
reload = true
game.proxy.port = game.production ? (document.location.protocol === 'https:' ? '443' : '80') : 'local'
}
if (reload) {
document.location.href = `?server=${game.server}&port=${game.serverPort}&nick=${game.nick}&premium=${game.premium}&proxyHost=${game.proxy.hostname}&proxyPort=${game.proxy.port}`
} else {
if (game.premium === 'true') {
swal({
text: 'Enter password for premium account',
content: 'input',
button: {
text: 'Login'
}
}).then((password) => {
resolve(password)
})
} else {
resolve(null)
}
}
})
}
export { UrlParams }