woops, add back the 'packet' event

This commit is contained in:
roblabla 2014-04-11 02:08:17 +02:00
parent b7dd1ba04e
commit c1a5b8294b
2 changed files with 6 additions and 3 deletions

View File

@ -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);
}
});

View File

@ -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,