connect using url params (#285)

* connect using url params

* lint
This commit is contained in:
KalmeMarq 2022-03-08 14:46:50 +00:00 committed by GitHub
parent dd0c3f22d3
commit 5b6fcee7f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 2 deletions

View file

@ -24,7 +24,7 @@
<pmui-playscreen id="play-screen" style="display: none;"></pmui-playscreen>
<pmui-keybindsscreen id="keybinds-screen" style="display: none;"></pmui-keybindsscreen>
<pmui-optionsscreen id="options-screen" style="display: none;"></pmui-optionsscreen>
<pmui-titlescreen id="title-screen" style="display: block;"></pmui-titlescreen>
<pmui-titlescreen id="title-screen" style="display: none;"></pmui-titlescreen>
</div>
</body>
</html>

View file

@ -401,4 +401,53 @@ async function connect (options) {
}, 2500)
})
}
main()
/**
* @param {URLSearchParams} params
*/
async function fromTheOutside (params, addr) {
const opts = {}
const dfltConfig = await (await window.fetch('config.json')).json()
let server, port, proxy, proxyPort
if (address.includes(':')) {
const s = address.split(':')
server = s[0]
port = Number(s[1]) || 25565
} else {
server = address
port = Number(params.get('port')) || 25565
}
const proxyAddr = params.get('proxy')
if (proxyAddr) {
const s = proxyAddr.split(':')
proxy = s[0]
proxyPort = Number(s[1] ?? 'NaN') || 22
} else {
proxy = dfltConfig.defaultProxy
proxyPort = !dfltConfig.defaultProxy && !dfltConfig.defaultProxyPort ? '' : dfltConfig.defaultProxyPort ?? 443
}
opts.server = `${server}:${port}`
opts.proxy = `${proxy}:${proxyPort}`
opts.username = params.get('username') ?? `pviewer${Math.floor(Math.random() * 1000)}`
opts.password = params.get('password') ?? ''
opts.botVersion = params.get('version') ?? false
console.log(opts)
showEl('loading-screen')
removePanorama()
connect(opts)
}
const params = new URLSearchParams(window.location.search)
let address
if ((address = params.get('address'))) {
fromTheOutside(params, address)
} else {
showEl('title-screen')
main()
}