mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-30 14:41:27 -04:00
woops, add back the 'packet' event
This commit is contained in:
parent
b7dd1ba04e
commit
c1a5b8294b
@ -33,14 +33,14 @@ function Client(isServer) {
|
|||||||
this.packetsToParse = {};
|
this.packetsToParse = {};
|
||||||
this.on('newListener', function(event, listener) {
|
this.on('newListener', function(event, listener) {
|
||||||
var direction = this.isServer ? 'toServer' : 'toClient';
|
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;
|
if (typeof this.packetsToParse[event] === "undefined") this.packetsToParse[event] = 1;
|
||||||
else this.packetsToParse[event] += 1;
|
else this.packetsToParse[event] += 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.on('removeListener', function(event, listener) {
|
this.on('removeListener', function(event, listener) {
|
||||||
var direction = this.isServer ? 'toServer' : 'toClient';
|
var direction = this.isServer ? 'toServer' : 'toClient';
|
||||||
if (protocol.packetStates[direction].hasOwnProperty(event)) {
|
if (protocol.packetStates[direction].hasOwnProperty(event) || event === "packet") {
|
||||||
this.packetsToParse[event] -= 1;
|
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];
|
var packetName = protocol.packetNames[self.state][self.isServer ? 'toServer' : 'toClient'][packet.id];
|
||||||
self.emit(packetName, packet);
|
self.emit(packetName, packet);
|
||||||
|
self.emit('packet', packet);
|
||||||
self.emit('raw.' + packetName, parsed.buffer);
|
self.emit('raw.' + packetName, parsed.buffer);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1287,7 +1287,9 @@ function parsePacket(buffer, state, isServer, packetsToParse) {
|
|||||||
var results = { id: packetId };
|
var results = { id: packetId };
|
||||||
// Only parse the packet if there is a need for it, AKA if there is a listener attached to it
|
// 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];
|
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 {
|
return {
|
||||||
size: length + lengthField.size,
|
size: length + lengthField.size,
|
||||||
buffer: buffer,
|
buffer: buffer,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user