eaglerproxy 1.0.7, eagpaas 1.0.1, smart compile

This commit is contained in:
WorldEditAxe 2023-06-21 10:45:22 +00:00
parent 82f28aa8d0
commit d5d0b4a6a5
3 changed files with 44 additions and 30 deletions

View File

@ -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

View File

@ -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) {

View File

@ -141,10 +141,13 @@ 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.`)
return new Promise<void | never>(async (res, rej) => {
const oldConnection = this.serverConnection
this._switchingServers = true this._switchingServers = true
this.ws.send(this._serializer.createPacketBuffer({ this.ws.send(this._serializer.createPacketBuffer({
name: 'chat', name: 'chat',
params: { params: {
@ -163,17 +166,26 @@ export class Player extends EventEmitter {
}) })
} }
})) }))
this.serverConnection.end()
this.serverConnection = createClient(Object.assign({ this.serverConnection = createClient(Object.assign({
version: '1.8.9', version: '1.8.9',
keepAlive: false, keepAlive: false,
hideErrors: false hideErrors: false
}, options)) }, options))
await this._bindListenersMineClient(this.serverConnection, true)
await this._bindListenersMineClient(this.serverConnection, true, () => oldConnection.end())
.then(() => {
this.emit('switchServer', this.serverConnection, this) 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) => { 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