Merge pull request from onddo/packetid-3e-3f-fix

Fixed parsing package IDs 0x3e and 0x3f
This commit is contained in:
Andrew Kelley 2013-04-06 07:43:53 -07:00
commit 1015a9787b
2 changed files with 31 additions and 11 deletions

View file

@ -4,6 +4,7 @@ var net = require('net')
, protocol = require('./protocol')
, createPacketBuffer = protocol.createPacketBuffer
, parsePacket = protocol.parsePacket
, debug = protocol.debug
module.exports = Client;
@ -78,6 +79,7 @@ Client.prototype.end = function(reason) {
Client.prototype.write = function(packetId, params) {
var buffer = createPacketBuffer(packetId, params, this.isServer);
debug("writing packetId " + packetId + " (0x" + packetId.toString(16) + ")");
var out = this.encryptionEnabled ? new Buffer(this.cipher.update(buffer), 'binary') : buffer;
this.socket.write(out);
};

View file

@ -1,4 +1,5 @@
var assert = require('assert');
var util = require('util');
var STRING_MAX_LENGTH = 240;
@ -307,6 +308,14 @@ var packets = {
{ name: "global", type: "bool" }
],
0x3e: [
{ name: "soundName", type: "string" },
{ name: "x", type: "int" },
{ name: "y", type: "int" },
{ name: "z", type: "int" },
{ name: "volume", type: "float" },
{ name: "pitch", type: "byte" }
],
0x3f: [
{ name: "particleName", type: "string" },
{ name: "x", type: "float" },
{ name: "y", type: "float" },
@ -317,14 +326,6 @@ var packets = {
{ name: "particleSpeed", type: "float" },
{ name: "particles", type: "int" }
],
0x3f: [
{ name: "soundName", type: "string" },
{ name: "x", type: "int" },
{ name: "y", type: "int" },
{ name: "z", type: "int" },
{ name: "volume", type: "float" },
{ name: "pitch", type: "byte" }
],
0x46: [
{ name: "reason", type: "byte" },
{ name: "gameMode", type: "byte" }
@ -450,7 +451,7 @@ var packets = {
{ name: "name", type: "string" },
{ name: "prefix", type: "string" },
{ name: "suffix", type: "string" },
{ name: "friendlyFire", type: "bool" },
{ name: "friendlyFire", type: "byte" },
{ name: "players", type: "stringArray" }
],
0xfa: [
@ -500,6 +501,20 @@ var types = {
'stringArray': [readStringArray, writeStringArray, sizeOfStringArray],
};
var debug;
if (process.env.NODE_DEBUG && /(minecraft-protocol|mc-proto)/.test(process.env.NODE_DEBUG)) {
var pid = process.pid;
debug = function(x) {
// if console is not set up yet, then skip this.
if (!console.error)
return;
console.error('MC-PROTO: %d', pid,
util.format.apply(util, arguments).slice(0, 500));
};
} else {
debug = function() { };
}
function sizeOfByteArray32(value) {
return 4 + value.length;
}
@ -1239,8 +1254,10 @@ function parsePacket(buffer, isServer) {
var packetInfo = get(packetId, isServer);
if (packetInfo == null) {
return {
error: new Error("Unrecognized packetId: " + packetId)
error: new Error("Unrecognized packetId: " + packetId + " (0x" + packetId.toString(16) + ")")
}
} else {
debug("read packetId " + packetId + " (0x" + packetId.toString(16) + ")");
}
var i, fieldInfo, read, readResults;
for (i = 0; i < packetInfo.length; ++i) {
@ -1266,11 +1283,12 @@ function parsePacket(buffer, isServer) {
module.exports = {
version: 60,
minecraftVersion: '1.5',
minecraftVersion: '1.5.1',
sessionVersion: 13,
parsePacket: parsePacket,
createPacketBuffer: createPacketBuffer,
STRING_MAX_LENGTH: STRING_MAX_LENGTH,
packets: packets,
get: get,
debug: debug,
};