From c1a5b8294bec3ed4164322a2cd8250b6037f041d Mon Sep 17 00:00:00 2001 From: roblabla Date: Fri, 11 Apr 2014 02:08:17 +0200 Subject: [PATCH] woops, add back the 'packet' event --- lib/client.js | 5 +++-- lib/protocol.js | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/client.js b/lib/client.js index eb88eb9..5dbe4b0 100644 --- a/lib/client.js +++ b/lib/client.js @@ -33,14 +33,14 @@ function Client(isServer) { this.packetsToParse = {}; this.on('newListener', function(event, listener) { var direction = this.isServer ? 'toServer' : 'toClient'; - if (protocol.packetStates[direction].hasOwnProperty(event)) { + if (protocol.packetStates[direction].hasOwnProperty(event) || event === "packet") { if (typeof this.packetsToParse[event] === "undefined") this.packetsToParse[event] = 1; else this.packetsToParse[event] += 1; } }); this.on('removeListener', function(event, listener) { var direction = this.isServer ? 'toServer' : 'toClient'; - if (protocol.packetStates[direction].hasOwnProperty(event)) { + if (protocol.packetStates[direction].hasOwnProperty(event) || event === "packet") { this.packetsToParse[event] -= 1; } }); @@ -93,6 +93,7 @@ Client.prototype.setSocket = function(socket) { var packetName = protocol.packetNames[self.state][self.isServer ? 'toServer' : 'toClient'][packet.id]; self.emit(packetName, packet); + self.emit('packet', packet); self.emit('raw.' + packetName, parsed.buffer); } }); diff --git a/lib/protocol.js b/lib/protocol.js index d20e85e..b2df675 100644 --- a/lib/protocol.js +++ b/lib/protocol.js @@ -1287,7 +1287,9 @@ function parsePacket(buffer, state, isServer, packetsToParse) { var results = { id: packetId }; // Only parse the packet if there is a need for it, AKA if there is a listener attached to it var name = packetNames[state][isServer ? "toServer" : "toClient"][packetId]; - if (!packetsToParse.hasOwnProperty(name) || packetsToParse[name] <= 0) { + var shouldParse = (!packetsToParse.hasOwnProperty(name) || packetsToParse[name] <= 0) + && (!packetsToParse.hasOwnProperty("packet") || packetsToParse["packet"] <= 0); + if (shouldParse) { return { size: length + lengthField.size, buffer: buffer,