node-minecraft-protocol icon indicating copy to clipboard operation
node-minecraft-protocol copied to clipboard

Cannot handle deserialization error for individual packets

Open Gjum opened this issue 5 years ago • 8 comments

Using createClient, when protodef fails to deserialize a packet, the whole client shuts down, and does not allow me to handle expected malformed packets.

I'm not sure if this should be fixed in protodef or nmp.

Versions: minecraft-protocol 1.11.0, protodef 1.6.10, minecraft-data 2.50.0

Gjum avatar May 06 '20 14:05 Gjum

If you listen to error event it should not crash

rom1504 avatar May 06 '20 19:05 rom1504

What emitter do I need to listen on? I'm listening on Client and the deserializer is already listened to in minecraft-protocol/src/client.js:66 (setSerializer).

Minimal example:
const mcProto = require('minecraft-protocol')

const client = mcProto.createClient({
  host: process.env.MC_HOST || "localhost",
  username: process.env.MC_USERNAME || "McProto",
  password: process.env.MC_PASSWORD,
})

process.on("unhandledRejection", err => {
  console.error(`[ERROR] process.unhandledRejection error=${err}`)
  console.error(err)
})
process.on("uncaughtException", err => {
  console.error(`[ERROR] process.uncaughtException error=${err}`)
  console.error(err)
})
process.on("warning", err => {
  console.error(`[WARNING] process.warning error=${err}`)
  console.error(err)
})

client.on('error', err => {
  console.error(`[ERROR] error error=${err}`)
  console.error(err)
})
client.on('kicked', packet => {
  console.error(`[ERROR] kicked reason=${packet.reason}`)
})
client.on('end', payload => {
  console.error(`[ERROR] end reason=${payload}`)
})
client.on('disconnect', packet => {
  console.error(`[ERROR] disconnected reason=${packet.reason}`)
})
client.on('close', () => {
  console.error(`[ERROR] connection closed`)
})
client.on('timeout', () => {
  console.error(`[ERROR] connection timeout`)
})

let pos
client.on('position', packet => {
  pos = packet
  if (packet.teleportId) {
    client.write('teleport_confirm', { teleportId: packet.teleportId })
  }
})

client.once('position', () => {
  this.tickInterval = setInterval(() => {
    client.write('position_look', { onGround: true, ...pos })
  }, 50)
})

Gjum avatar May 06 '20 22:05 Gjum

I got the following error trying to connect to a server using 1.14.4 as client version: https://paste.lucko.me/ROwYEVJ811 I used the example code in the README file.

sgdc3 avatar May 31 '20 00:05 sgdc3

Can you post the server too

On Sun, May 31, 2020, 02:39 Gabriele C. [email protected] wrote:

I got the following error trying to connect to a server using 1.14.4 as client version: https://paste.lucko.me/ROwYEVJ811 I used the example code in the README file.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/node-minecraft-protocol/issues/709#issuecomment-636403610, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR437SRUS4IVQUF7RXJBULRUGRLNANCNFSM4M2PW3KA .

rom1504 avatar May 31 '20 00:05 rom1504

The server was play.tecnocraft.net

sgdc3 avatar May 31 '20 12:05 sgdc3

client.on('error', () => {}) works fine for me

rom1504 avatar Jun 21 '20 16:06 rom1504

I'm having the same issue,client.on('error', () => {}) doesn't stop the process from crashing my server has fabric mods

Martinz64 avatar Jun 25 '20 13:06 Martinz64

https://github.com/PrismarineJS/node-minecraft-protocol/blob/master/src/client.js#L68 this shouldn't be a pb

rom1504 avatar Sep 05 '20 22:09 rom1504