new! helpful errors on custom channels payloads!
This commit is contained in:
parent
4a5f2e799c
commit
72e9e656cc
2 changed files with 43 additions and 0 deletions
|
|
@ -73,6 +73,19 @@ index 63cc2bd9615100bd2fd63dfe14c094aa6b8cd1c9..36df57d1196af9761d920fa285ac48f8
|
|||
}
|
||||
|
||||
function onJoinServerResponse (err) {
|
||||
diff --git a/src/client/pluginChannels.js b/src/client/pluginChannels.js
|
||||
index 671eb452f31e6b5fcd57d715f1009d010160c65f..7f69f511c8fb97d431ec5125c851b49be8e2ab76 100644
|
||||
--- a/src/client/pluginChannels.js
|
||||
+++ b/src/client/pluginChannels.js
|
||||
@@ -57,7 +57,7 @@ module.exports = function (client, options) {
|
||||
try {
|
||||
packet.data = proto.parsePacketBuffer(channel, packet.data).data
|
||||
} catch (error) {
|
||||
- client.emit('error', error)
|
||||
+ client.emit('error', error, { customPayload: packet })
|
||||
return
|
||||
}
|
||||
}
|
||||
diff --git a/src/client.js b/src/client.js
|
||||
index e369e77d055ba919e8f9da7b8e8b5dc879c74cf4..54bb9e6644388e9b6bd42b3012951875989cdf0c 100644
|
||||
--- a/src/client.js
|
||||
|
|
|
|||
|
|
@ -11,6 +11,36 @@ import { getWebsocketStream } from './websocket-core'
|
|||
|
||||
let lastPacketTime = 0
|
||||
customEvents.on('mineflayerBotCreated', () => {
|
||||
// const oldParsePacketBuffer = bot._client.deserializer.parsePacketBuffer
|
||||
// try {
|
||||
// const parsed = oldParsePacketBuffer(buffer)
|
||||
// } catch (err) {
|
||||
// debugger
|
||||
// reportError(new Error(`Error parsing packet ${buffer.subarray(0, 30).toString('hex')}`, { cause: err }))
|
||||
// throw err
|
||||
// }
|
||||
// }
|
||||
class MinecraftProtocolError extends Error {
|
||||
constructor (message: string, cause?: Error, public data?: any) {
|
||||
if (data?.customPayload) {
|
||||
message += ` (Custom payload: ${data.customPayload.channel})`
|
||||
}
|
||||
super(message, { cause })
|
||||
this.name = 'MinecraftProtocolError'
|
||||
}
|
||||
}
|
||||
|
||||
const onClientError = (err, data) => {
|
||||
const error = new MinecraftProtocolError(`Minecraft protocol client error: ${err.message}`, err, data)
|
||||
reportError(error)
|
||||
}
|
||||
if (typeof bot._client['_events'].error === 'function') {
|
||||
// dont report to bot for more explicit error
|
||||
bot._client['_events'].error = onClientError
|
||||
} else {
|
||||
bot._client.on('error' as any, onClientError)
|
||||
}
|
||||
|
||||
// todo move more code here
|
||||
if (!appQueryParams.noPacketsValidation) {
|
||||
(bot._client as unknown as Client).on('packet', (data, packetMeta, buffer, fullBuffer) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue