Fix readRaw, writeRaw

This commit is contained in:
roblabla 2015-03-03 12:35:51 +00:00
parent a2b06f70a2
commit e37a820709

View file

@ -93,10 +93,11 @@ Client.prototype.setSocket = function(socket) {
//incomingBuffer = incomingBuffer.slice(parsed.size); TODO: Already removed in prepare
var packetName = protocol.packetNames[self.state][self.isServer ? 'toServer' : 'toClient'][packet.id];
var packetState = self.state;
self.emit(packetName, packet);
self.emit('packet', packet);
self.emit('raw.' + packetName, parsed.buffer);
self.emit('raw', parsed.buffer);
self.emit('raw.' + packetName, parsed.buffer, packetState);
self.emit('raw', parsed.buffer, packetState);
prepareParse();
}
@ -214,9 +215,11 @@ Client.prototype.write = function(packetId, params) {
Client.prototype.writeRaw = function(buffer) {
var self = this;
var finishWriting = function(buffer) {
var finishWriting = function(error, buffer) {
if (error)
throw error; // TODO : How do we handle this error ?
var out = self.encryptionEnabled ? new Buffer(self.cipher.update(buffer), 'binary') : buffer;
that.socket.write(out);
self.socket.write(out);
};
if (this.compressionThreshold >= 0 && buffer.length >= this.compressionThreshold) {
compressPacketBuffer(buffer, finishWriting);