mirror of
https://github.com/WorldEditAxe/eaglerproxy.git
synced 2024-11-09 15:26:04 -08:00
eaglerproxy 1.0.7, eagpaas 1.0.1, smart compile
This commit is contained in:
parent
82f28aa8d0
commit
d5d0b4a6a5
|
@ -5,7 +5,7 @@ npm install
|
||||||
|
|
||||||
echo "compiling eaglerproxy, please wait... "
|
echo "compiling eaglerproxy, please wait... "
|
||||||
echo "this may take a while when you first compile the proxy, or when the proxy has to be recompiled (usually due to modification of anything in the src folder, including config.ts)"
|
echo "this may take a while when you first compile the proxy, or when the proxy has to be recompiled (usually due to modification of anything in the src folder, including config.ts)"
|
||||||
echo "after the initial compile, startups will be a lot more faster and snappier"
|
echo "after the initial compile, consequent startups will be a lot more faster and snappier"
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
|
|
||||||
|
|
|
@ -253,6 +253,7 @@ export async function onConnect(client: ClientState) {
|
||||||
skipValidation: true,
|
skipValidation: true,
|
||||||
hideErrors: true
|
hideErrors: true
|
||||||
})
|
})
|
||||||
|
break
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!client.gameClient.ended) {
|
if (!client.gameClient.ended) {
|
||||||
sendMessage(client.gameClient, `Something went wrong whilst switching servers: ${err.message}.`, { color: "red" })
|
sendMessage(client.gameClient, `Something went wrong whilst switching servers: ${err.message}.`, { color: "red" })
|
||||||
|
@ -261,7 +262,6 @@ export async function onConnect(client: ClientState) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
@ -141,39 +141,51 @@ export class Player extends EventEmitter {
|
||||||
await this._bindListenersMineClient(this.serverConnection)
|
await this._bindListenersMineClient(this.serverConnection)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async switchServers(options: ClientOptions) {
|
public switchServers(options: ClientOptions) {
|
||||||
if (!this._alreadyConnected)
|
if (!this._alreadyConnected)
|
||||||
throw new Error(`Invalid state: Player hasn't already been connected to a server, and .switchServers() has been called. Please use .connect() when initially connecting to a server, and only use .switchServers() if you want to switch servers.`)
|
throw new Error(`Invalid state: Player hasn't already been connected to a server, and .switchServers() has been called. Please use .connect() when initially connecting to a server, and only use .switchServers() if you want to switch servers.`)
|
||||||
this._switchingServers = true
|
return new Promise<void | never>(async (res, rej) => {
|
||||||
this.ws.send(this._serializer.createPacketBuffer({
|
const oldConnection = this.serverConnection
|
||||||
name: 'chat',
|
this._switchingServers = true
|
||||||
params: {
|
|
||||||
message: `${Enums.ChatColor.GRAY}Switching servers...`,
|
this.ws.send(this._serializer.createPacketBuffer({
|
||||||
position: 1
|
name: 'chat',
|
||||||
}
|
params: {
|
||||||
}))
|
message: `${Enums.ChatColor.GRAY}Switching servers...`,
|
||||||
this.ws.send(this._serializer.createPacketBuffer({
|
position: 1
|
||||||
name: 'playerlist_header',
|
}
|
||||||
params: {
|
}))
|
||||||
header: JSON.stringify({
|
this.ws.send(this._serializer.createPacketBuffer({
|
||||||
text: ""
|
name: 'playerlist_header',
|
||||||
}),
|
params: {
|
||||||
footer: JSON.stringify({
|
header: JSON.stringify({
|
||||||
text: ""
|
text: ""
|
||||||
|
}),
|
||||||
|
footer: JSON.stringify({
|
||||||
|
text: ""
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
|
this.serverConnection = createClient(Object.assign({
|
||||||
|
version: '1.8.9',
|
||||||
|
keepAlive: false,
|
||||||
|
hideErrors: false
|
||||||
|
}, options))
|
||||||
|
|
||||||
|
await this._bindListenersMineClient(this.serverConnection, true, () => oldConnection.end())
|
||||||
|
.then(() => {
|
||||||
|
this.emit('switchServer', this.serverConnection, this)
|
||||||
|
res()
|
||||||
})
|
})
|
||||||
}
|
.catch(err => {
|
||||||
}))
|
this.serverConnection = oldConnection
|
||||||
this.serverConnection.end()
|
rej(err)
|
||||||
this.serverConnection = createClient(Object.assign({
|
})
|
||||||
version: '1.8.9',
|
})
|
||||||
keepAlive: false,
|
|
||||||
hideErrors: false
|
|
||||||
}, options))
|
|
||||||
await this._bindListenersMineClient(this.serverConnection, true)
|
|
||||||
this.emit('switchServer', this.serverConnection, this)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _bindListenersMineClient(client: Client, switchingServers?: boolean) {
|
private async _bindListenersMineClient(client: Client, switchingServers?: boolean, onSwitch?: Function) {
|
||||||
return new Promise((res, rej) => {
|
return new Promise((res, rej) => {
|
||||||
let stream = false, uuid
|
let stream = false, uuid
|
||||||
const listener = msg => {
|
const listener = msg => {
|
||||||
|
@ -214,6 +226,7 @@ export class Player extends EventEmitter {
|
||||||
}))
|
}))
|
||||||
pckSeq.forEach(p => this.ws.send(p))
|
pckSeq.forEach(p => this.ws.send(p))
|
||||||
stream = true
|
stream = true
|
||||||
|
if (onSwitch) onSwitch()
|
||||||
res(null)
|
res(null)
|
||||||
} else if (meta.name == 'success' && meta.state == states.LOGIN && !uuid) {
|
} else if (meta.name == 'success' && meta.state == states.LOGIN && !uuid) {
|
||||||
uuid = packet.uuid
|
uuid = packet.uuid
|
||||||
|
@ -225,6 +238,7 @@ export class Player extends EventEmitter {
|
||||||
params: packet
|
params: packet
|
||||||
}))
|
}))
|
||||||
stream = true
|
stream = true
|
||||||
|
if (onSwitch) onSwitch()
|
||||||
res(null)
|
res(null)
|
||||||
} else if (meta.name == 'success' && meta.state == states.LOGIN && !uuid) {
|
} else if (meta.name == 'success' && meta.state == states.LOGIN && !uuid) {
|
||||||
uuid = packet.uuid
|
uuid = packet.uuid
|
||||||
|
|
Loading…
Reference in New Issue
Block a user