mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-12-02 03:56:54 -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;
|
var self = this;
|
||||||
function afterParse(err, parsed) {
|
function afterParse(err, parsed) {
|
||||||
if (err || (parsed && parsed.error)) {
|
if (err || (parsed && parsed.error)) {
|
||||||
this.emit('error', err || parser.error);
|
this.emit('error', err || parsed.error);
|
||||||
this.end("ProtocolError");
|
this.end("ProtocolError");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (! parsed) { cont = false; return; }
|
if (! parsed) { return; }
|
||||||
packet = parsed.results;
|
packet = parsed.results;
|
||||||
incomingBuffer = incomingBuffer.slice(parsed.size);
|
incomingBuffer = incomingBuffer.slice(parsed.size);
|
||||||
|
|
||||||
|
@ -96,8 +96,16 @@ Client.prototype.setSocket = function(socket) {
|
||||||
self.emit('packet', packet);
|
self.emit('packet', packet);
|
||||||
self.emit('raw.' + packetName, parsed.buffer);
|
self.emit('raw.' + packetName, parsed.buffer);
|
||||||
self.emit('raw', 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;
|
self.socket = socket;
|
||||||
if (self.socket.setNoDelay)
|
if (self.socket.setNoDelay)
|
||||||
self.socket.setNoDelay(true);
|
self.socket.setNoDelay(true);
|
||||||
|
@ -105,12 +113,7 @@ Client.prototype.setSocket = function(socket) {
|
||||||
self.socket.on('data', function(data) {
|
self.socket.on('data', function(data) {
|
||||||
if (self.encryptionEnabled) data = new Buffer(self.decipher.update(data), 'binary');
|
if (self.encryptionEnabled) data = new Buffer(self.decipher.update(data), 'binary');
|
||||||
incomingBuffer = Buffer.concat([incomingBuffer, data]);
|
incomingBuffer = Buffer.concat([incomingBuffer, data]);
|
||||||
while (cont) {
|
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.on('connect', function() {
|
self.socket.on('connect', function() {
|
||||||
|
|
Loading…
Reference in a new issue