mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-12-02 03:56:54 -05:00
Fix crash when trying to write to socket
This commit is contained in:
parent
52078273fe
commit
00241c4044
1 changed files with 6 additions and 2 deletions
|
@ -155,13 +155,15 @@ Client.prototype.write = function(packetId, params) {
|
|||
packetId = packetId[1];
|
||||
}
|
||||
|
||||
var that = this;
|
||||
|
||||
// TODO: Which comes first, encryption or compression?
|
||||
|
||||
var finishWriting = function(buffer) {
|
||||
debug("writing packetId " + packetId + " (0x" + packetId.toString(16) + ")");
|
||||
debug(params);
|
||||
var out = this.encryptionEnabled ? new Buffer(this.cipher.update(buffer), 'binary') : buffer;
|
||||
this.socket.write(out);
|
||||
that.socket.write(out);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -179,9 +181,11 @@ Client.prototype.writeRaw = function(buffer, shouldEncrypt) {
|
|||
shouldEncrypt = true;
|
||||
}
|
||||
|
||||
var that = this;
|
||||
|
||||
var finishWriting = function(buffer) {
|
||||
var out = (shouldEncrypt && this.encryptionEnabled) ? new Buffer(this.cipher.update(buffer), 'binary') : buffer;
|
||||
this.socket.write(out);
|
||||
that.socket.write(out);
|
||||
};
|
||||
|
||||
if(this.compressionThreshold != -1 && buffer.length > this.compressionThreshold) {
|
||||
|
|
Loading…
Reference in a new issue