mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-29 06:03:33 -04:00
Automatic compression of packet header in writeRaw
This commit is contained in:
parent
c45c4d3cf4
commit
a2b06f70a2
@ -211,21 +211,18 @@ Client.prototype.write = function(packetId, params) {
|
||||
// TODO : Perhaps this should only accept buffers without length, so we can
|
||||
// handle compression ourself ? Needs to ask peopl who actually use this feature
|
||||
// like @deathcap
|
||||
Client.prototype.writeRaw = function(buffer, shouldEncrypt) {
|
||||
if (shouldEncrypt === null) {
|
||||
shouldEncrypt = true;
|
||||
}
|
||||
|
||||
var that = this;
|
||||
Client.prototype.writeRaw = function(buffer) {
|
||||
var self = this;
|
||||
|
||||
var finishWriting = function(buffer) {
|
||||
var out = (shouldEncrypt && this.encryptionEnabled) ? new Buffer(this.cipher.update(buffer), 'binary') : buffer;
|
||||
var out = self.encryptionEnabled ? new Buffer(self.cipher.update(buffer), 'binary') : buffer;
|
||||
that.socket.write(out);
|
||||
};
|
||||
|
||||
if(this.compressionThreshold != -1 && buffer.length > this.compressionThreshold) {
|
||||
if (this.compressionThreshold >= 0 && buffer.length >= this.compressionThreshold) {
|
||||
compressPacketBuffer(buffer, finishWriting);
|
||||
} else if (this.compressionThreshold >= -1) {
|
||||
newStylePacket(buffer, finishWriting);
|
||||
} else {
|
||||
finishWriting(buffer);
|
||||
oldStylePacket(buffer, finishWriting);
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user