Skip to content

Commit 8b99ed6

Browse files
committed
use proxy in url
1 parent 5134919 commit 8b99ed6

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/scripts/UrlParams.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ function UrlParams (game) {
88
game.server = new URL(document.location).searchParams.get('server')
99
game.serverPort = new URL(document.location).searchParams.get('port')
1010
game.premium = new URL(document.location).searchParams.get('premium')
11+
game.proxy = {
12+
hostname: new URL(document.location).searchParams.get('proxyHost'),
13+
port: new URL(document.location).searchParams.get('proxyPort')
14+
}
1115
let reload = false
1216
if (game.nick === '' || game.nick === null) {
1317
reload = true
@@ -29,8 +33,16 @@ function UrlParams (game) {
2933
reload = true
3034
game.premium = 'false'
3135
}
36+
if (game.proxy.hostname === '' || game.proxy.hostname === null) {
37+
reload = true
38+
game.proxy.hostname = game.production ? 'web-minecraft-proxy.herokuapp.com' : 'local'
39+
}
40+
if (game.proxy.port === '' || game.proxy.port === null) {
41+
reload = true
42+
game.proxy.port = game.production ? '80' : 'local'
43+
}
3244
if (reload) {
33-
document.location.href = `?server=${game.server}&port=${game.serverPort}&nick=${game.nick}&premium=${game.premium}`
45+
document.location.href = `?server=${game.server}&port=${game.serverPort}&nick=${game.nick}&premium=${game.premium}&proxyHost=${game.proxy.hostname}&proxyPort=${game.proxy.port}`
3446
} else {
3547
if (game.premium === 'true') {
3648
swal({

src/scripts/proxy/Proxy.worker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ addEventListener('message', function (e) {
1919
switch (type) {
2020
case 'init':
2121
data = data[0]
22+
console.log(data)
2223
bot = self.mineflayer(data.hostname, data.port, {
2324
host: data.server,
2425
port: data.serverPort,

src/scripts/proxy/Socket.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ class Socket {
55
this.game = game
66
this.worker = new Proxy()
77
this.handlers = new Map()
8+
const hostname = this.game.proxy.hostname === 'local' ? document.location.hostname : this.game.proxy.hostname
9+
const port = this.game.proxy.port === 'local' ? document.location.port : this.game.proxy.port
810
this.emit('init', {
9-
hostname: document.location.hostname,
10-
port: document.location.port,
11+
hostname: hostname,
12+
port: port,
1113
nick: this.game.nick,
1214
server: this.game.server,
1315
serverPort: this.game.serverPort,

0 commit comments

Comments
 (0)