pushrax / node-rcon

A generic RCON protocol client for node.js
MIT License
134 stars 31 forks source link

Can't connect to server - buffer error #32

Closed zer0grand closed 3 years ago

zer0grand commented 3 years ago

The default example doesn't work when I use my own server credentials...


(node:9308) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use 'node --trace-deprecation ...' to show where the warning was created)
node:internal/buffer:86
  throw new ERR_OUT_OF_RANGE(type || 'offset',
  ^

RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 6. Received 8
    at new NodeError (node:internal/errors:329:5)
    at boundsError (node:internal/buffer:86:9)
    at Buffer.readInt32LE (node:internal/buffer:390:5)
    at Rcon._tcpSocketOnData (C:\node-rcon-master\node-rcon.js:144:21)
    at Socket.<anonymous> (C:\node-rcon-master\node-rcon.js:87:54)
    at Socket.emit (node:events:378:20)
    at addChunk (node:internal/streams/readable:313:12)
    at readableAddChunk (node:internal/streams/readable:288:9)
    at Socket.Readable.push (node:internal/streams/readable:227:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  code: 'ERR_OUT_OF_RANGE'
}
pushrax commented 3 years ago

Looks like the response was either too short or got split into several packets. The code doesn't seem to handle the case where the stream is split into less than 12 bytes, which I suppose is quite possible though unlikely.

This condition should be changed to while (data.length >= 12) https://github.com/pushrax/node-rcon/blob/9c05be51b0ee48d6877cf7b52e8bd6edf0a3f555/node-rcon.js#L139-L144

pushrax commented 3 years ago

Should be fixed in 5155353f3c359af80ddf2ed55edebebb6137b0b1, which I will release to npm today.

ZariZaryab commented 3 years ago

Should be fixed in 5155353, which I will release to npm today.

Still not working

pushrax commented 3 years ago

You'll need to be more specific. What problem are you running into? Is it just the deprecation notice you mentioned in #36?

ZariZaryab commented 3 years ago

You'll need to be more specific. What problem are you running into? Is it just the deprecation notice you mentioned in #36?

Yeah, That fixed Buffer issue