mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-12-01 19:46:58 -05:00
Loop should be recursive, otherwise messages disappear
This commit is contained in:
parent
8a81039e88
commit
43b29cf904
1 changed files with 12 additions and 9 deletions
|
@ -83,11 +83,11 @@ Client.prototype.setSocket = function(socket) {
|
|||
var self = this;
|
||||
function afterParse(err, parsed) {
|
||||
if (err || (parsed && parsed.error)) {
|
||||
this.emit('error', err || parser.error);
|
||||
this.emit('error', err || parsed.error);
|
||||
this.end("ProtocolError");
|
||||
return;
|
||||
}
|
||||
if (! parsed) { cont = false; return; }
|
||||
if (! parsed) { return; }
|
||||
packet = parsed.results;
|
||||
incomingBuffer = incomingBuffer.slice(parsed.size);
|
||||
|
||||
|
@ -96,8 +96,16 @@ Client.prototype.setSocket = function(socket) {
|
|||
self.emit('packet', packet);
|
||||
self.emit('raw.' + packetName, parsed.buffer);
|
||||
self.emit('raw', parsed.buffer);
|
||||
prepareParse();
|
||||
}
|
||||
var cont = true;
|
||||
|
||||
function prepareParse() {
|
||||
if(self.compressionThreshold == -2)
|
||||
afterParse(null, parsePacket(incomingBuffer, self.state, self.isServer, self.packetsToParse));
|
||||
else
|
||||
parseNewStylePacket(incomingBuffer, self.state, self.isServer, self.packetsToParse, afterParse);
|
||||
}
|
||||
|
||||
self.socket = socket;
|
||||
if (self.socket.setNoDelay)
|
||||
self.socket.setNoDelay(true);
|
||||
|
@ -105,12 +113,7 @@ Client.prototype.setSocket = function(socket) {
|
|||
self.socket.on('data', function(data) {
|
||||
if (self.encryptionEnabled) data = new Buffer(self.decipher.update(data), 'binary');
|
||||
incomingBuffer = Buffer.concat([incomingBuffer, data]);
|
||||
while (cont) {
|
||||
if(self.compressionThreshold == -2)
|
||||
afterParse(null, parsePacket(incomingBuffer, self.state, self.isServer, self.packetsToParse));
|
||||
else
|
||||
parseNewStylePacket(incomingBuffer, self.state, self.isServer, self.packetsToParse, afterParse);
|
||||
}
|
||||
prepareParse()
|
||||
});
|
||||
|
||||
self.socket.on('connect', function() {
|
||||
|
|
Loading…
Reference in a new issue