PrismarineJS / dazed-sheep

A Minecraft Classic server in JavaScript
MIT License
24 stars 5 forks source link

Out of range error when flying around with more than one client connected #25

Open ozzt opened 5 years ago

ozzt commented 5 years ago
RangeError [ERR_OUT_OF_RANGE]: Serialization error for toClient.position_update.change_in_y : Write error for params.position_update.change_in_y : The value of "value" is out of range. It must be >= -128 and <= 127. Received 136
    at writeU_Int8 (internal/buffer.js:559:11)
    at Buffer.writeInt8 (internal/buffer.js:690:10)
    at ProtoDef.writer (C:\Users\ozzt\Documents\test\dazed-sheep\node_modules\protodef\src\datatypes\numeric.js:69:25)
    at ProtoDef.write (C:\Users\ozzt\Documents\test\dazed-sheep\node_modules\protodef\src\protodef.js:117:29)
    at tryDoc (C:\Users\ozzt\Documents\test\dazed-sheep\node_modules\protodef\src\datatypes\structures.js:64:23)
    at tryCatch (C:\Users\ozzt\Documents\test\dazed-sheep\node_modules\protodef\src\utils.js:50:16)
    at tryDoc (C:\Users\ozzt\Documents\test\dazed-sheep\node_modules\protodef\src\utils.js:54:10)
    at typeArgs.reduce (C:\Users\ozzt\Documents\test\dazed-sheep\node_modules\protodef\src\datatypes\structures.js:64:5)
    at Array.reduce (<anonymous>)
    at ProtoDef.writeContainer (C:\Users\ozzt\Documents\test\dazed-sheep\node_modules\protodef\src\datatypes\structures.js:63:21)

How to reproduce

  1. Join local server with 2 clients
  2. Fly around
  3. Errors will be spammed in the console and the player will disappear from the other client

The error doesn't occur if there's only one client connected to the server. Reproduced on ClassiCube 1.0.3 beta and dazed-sheep 1b6fb0f node.js v10.15.0

Thanks.

ozzt commented 5 years ago

To work around this, I am currently using teleport_player which accepts an absolute position unlike position_update.

ghost commented 5 years ago

This is kind of wack, I don't understand how a movement packet could have a change that is greater than 128 in a single movement packet -- yet I think you can solve this by clamping the value from -127 to 128? Unless this is a more deeply rooted bug. I'm not currently maintaining this project but I'd be thankful if you'd send a pull request fixing this issue (if my aforementioned idea fixes the issue [make sure you do the same to the other values as well])

ghost commented 4 years ago

Following up: this is supposed to be solved by splitting the movement into movement packets that sum up to the total delta. For example, 136 would result in a packet of 128 being sent, then a packet of 8.