mirror of
https://github.com/WorldEditAxe/eaglerproxy.git
synced 2024-11-22 21:46: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 "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
|
||||
|
||||
|
|
|
@ -253,6 +253,7 @@ export async function onConnect(client: ClientState) {
|
|||
skipValidation: true,
|
||||
hideErrors: true
|
||||
})
|
||||
break
|
||||
} catch (err) {
|
||||
if (!client.gameClient.ended) {
|
||||
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) {
|
||||
|
|
|
@ -141,10 +141,13 @@ export class Player extends EventEmitter {
|
|||
await this._bindListenersMineClient(this.serverConnection)
|
||||
}
|
||||
|
||||
public async switchServers(options: ClientOptions) {
|
||||
public switchServers(options: ClientOptions) {
|
||||
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.`)
|
||||
return new Promise<void | never>(async (res, rej) => {
|
||||
const oldConnection = this.serverConnection
|
||||
this._switchingServers = true
|
||||
|
||||
this.ws.send(this._serializer.createPacketBuffer({
|
||||
name: 'chat',
|
||||
params: {
|
||||
|
@ -163,17 +166,26 @@ export class Player extends EventEmitter {
|
|||
})
|
||||
}
|
||||
}))
|
||||
this.serverConnection.end()
|
||||
|
||||
this.serverConnection = createClient(Object.assign({
|
||||
version: '1.8.9',
|
||||
keepAlive: false,
|
||||
hideErrors: false
|
||||
}, options))
|
||||
await this._bindListenersMineClient(this.serverConnection, true)
|
||||
|
||||
await this._bindListenersMineClient(this.serverConnection, true, () => oldConnection.end())
|
||||
.then(() => {
|
||||
this.emit('switchServer', this.serverConnection, this)
|
||||
res()
|
||||
})
|
||||
.catch(err => {
|
||||
this.serverConnection = oldConnection
|
||||
rej(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
private async _bindListenersMineClient(client: Client, switchingServers?: boolean) {
|
||||
private async _bindListenersMineClient(client: Client, switchingServers?: boolean, onSwitch?: Function) {
|
||||
return new Promise((res, rej) => {
|
||||
let stream = false, uuid
|
||||
const listener = msg => {
|
||||
|
@ -214,6 +226,7 @@ export class Player extends EventEmitter {
|
|||
}))
|
||||
pckSeq.forEach(p => this.ws.send(p))
|
||||
stream = true
|
||||
if (onSwitch) onSwitch()
|
||||
res(null)
|
||||
} else if (meta.name == 'success' && meta.state == states.LOGIN && !uuid) {
|
||||
uuid = packet.uuid
|
||||
|
@ -225,6 +238,7 @@ export class Player extends EventEmitter {
|
|||
params: packet
|
||||
}))
|
||||
stream = true
|
||||
if (onSwitch) onSwitch()
|
||||
res(null)
|
||||
} else if (meta.name == 'success' && meta.state == states.LOGIN && !uuid) {
|
||||
uuid = packet.uuid
|
||||
|
|
Loading…
Reference in New Issue
Block a user