mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-29 22:23:21 -04:00
Splitter prepends length header to legacy ping for deserializer support
This commit is contained in:
parent
c24718f64c
commit
4840ffe7b1
@ -23,6 +23,8 @@ class Framer extends Transform {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const LEGACY_PING_PACKET_ID = 0xfe;
|
||||||
|
|
||||||
class Splitter extends Transform {
|
class Splitter extends Transform {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -31,9 +33,15 @@ class Splitter extends Transform {
|
|||||||
_transform(chunk, enc, cb) {
|
_transform(chunk, enc, cb) {
|
||||||
this.buffer = Buffer.concat([this.buffer, chunk]);
|
this.buffer = Buffer.concat([this.buffer, chunk]);
|
||||||
|
|
||||||
if (this.buffer[0] === 0xfe) {
|
// TODO: only decode if in handshake state! important since 254 is a valid varint (encodes as 0xfe 0x01), packet length
|
||||||
// legacy_server_list_ping packet follows a different protocol format, no varint length
|
if (this.buffer[0] === LEGACY_PING_PACKET_ID) {
|
||||||
this.push(this.buffer);
|
// legacy_server_list_ping packet follows a different protocol format
|
||||||
|
// prefix the encoded varint packet id for the deserializer
|
||||||
|
var header = new Buffer(sizeOfVarInt(LEGACY_PING_PACKET_ID));
|
||||||
|
writeVarInt(LEGACY_PING_PACKET_ID, header, 0);
|
||||||
|
var payload = this.buffer.slice(1); // remove 0xfe packet id
|
||||||
|
if (payload.length === 0) payload = new Buffer('\0'); // TODO: update minecraft-data to recognize a lone 0xfe, https://github.com/PrismarineJS/minecraft-data/issues/95
|
||||||
|
this.push(Buffer.concat([header, payload]));
|
||||||
return cb();
|
return cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user