Skip to content

Commit 5b6fcee

Browse files
authored
connect using url params (#285)
* connect using url params * lint
1 parent dd0c3f2 commit 5b6fcee

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<pmui-playscreen id="play-screen" style="display: none;"></pmui-playscreen>
2525
<pmui-keybindsscreen id="keybinds-screen" style="display: none;"></pmui-keybindsscreen>
2626
<pmui-optionsscreen id="options-screen" style="display: none;"></pmui-optionsscreen>
27-
<pmui-titlescreen id="title-screen" style="display: block;"></pmui-titlescreen>
27+
<pmui-titlescreen id="title-screen" style="display: none;"></pmui-titlescreen>
2828
</div>
2929
</body>
3030
</html>

index.js

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,4 +401,53 @@ async function connect (options) {
401401
}, 2500)
402402
})
403403
}
404-
main()
404+
405+
/**
406+
* @param {URLSearchParams} params
407+
*/
408+
async function fromTheOutside (params, addr) {
409+
const opts = {}
410+
const dfltConfig = await (await window.fetch('config.json')).json()
411+
412+
let server, port, proxy, proxyPort
413+
414+
if (address.includes(':')) {
415+
const s = address.split(':')
416+
server = s[0]
417+
port = Number(s[1]) || 25565
418+
} else {
419+
server = address
420+
port = Number(params.get('port')) || 25565
421+
}
422+
423+
const proxyAddr = params.get('proxy')
424+
if (proxyAddr) {
425+
const s = proxyAddr.split(':')
426+
proxy = s[0]
427+
proxyPort = Number(s[1] ?? 'NaN') || 22
428+
} else {
429+
proxy = dfltConfig.defaultProxy
430+
proxyPort = !dfltConfig.defaultProxy && !dfltConfig.defaultProxyPort ? '' : dfltConfig.defaultProxyPort ?? 443
431+
}
432+
433+
opts.server = `${server}:${port}`
434+
opts.proxy = `${proxy}:${proxyPort}`
435+
opts.username = params.get('username') ?? `pviewer${Math.floor(Math.random() * 1000)}`
436+
opts.password = params.get('password') ?? ''
437+
opts.botVersion = params.get('version') ?? false
438+
439+
console.log(opts)
440+
441+
showEl('loading-screen')
442+
removePanorama()
443+
connect(opts)
444+
}
445+
446+
const params = new URLSearchParams(window.location.search)
447+
let address
448+
if ((address = params.get('address'))) {
449+
fromTheOutside(params, address)
450+
} else {
451+
showEl('title-screen')
452+
main()
453+
}

0 commit comments

Comments
 (0)