Merge pull request #50 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') , protocol = require('./protocol')
, createPacketBuffer = protocol.createPacketBuffer , createPacketBuffer = protocol.createPacketBuffer
, parsePacket = protocol.parsePacket , parsePacket = protocol.parsePacket
, debug = protocol.debug
module.exports = Client; module.exports = Client;
@ -78,6 +79,7 @@ Client.prototype.end = function(reason) {
Client.prototype.write = function(packetId, params) { Client.prototype.write = function(packetId, params) {
var buffer = createPacketBuffer(packetId, params, this.isServer); 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; var out = this.encryptionEnabled ? new Buffer(this.cipher.update(buffer), 'binary') : buffer;
this.socket.write(out); this.socket.write(out);
}; };

View File

@ -1,4 +1,5 @@
var assert = require('assert'); var assert = require('assert');
var util = require('util');
var STRING_MAX_LENGTH = 240; var STRING_MAX_LENGTH = 240;
@ -307,6 +308,14 @@ var packets = {
{ name: "global", type: "bool" } { name: "global", type: "bool" }
], ],
0x3e: [ 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: "particleName", type: "string" },
{ name: "x", type: "float" }, { name: "x", type: "float" },
{ name: "y", type: "float" }, { name: "y", type: "float" },
@ -317,14 +326,6 @@ var packets = {
{ name: "particleSpeed", type: "float" }, { name: "particleSpeed", type: "float" },
{ name: "particles", type: "int" } { 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: [ 0x46: [
{ name: "reason", type: "byte" }, { name: "reason", type: "byte" },
{ name: "gameMode", type: "byte" } { name: "gameMode", type: "byte" }
@ -450,7 +451,7 @@ var packets = {
{ name: "name", type: "string" }, { name: "name", type: "string" },
{ name: "prefix", type: "string" }, { name: "prefix", type: "string" },
{ name: "suffix", type: "string" }, { name: "suffix", type: "string" },
{ name: "friendlyFire", type: "bool" }, { name: "friendlyFire", type: "byte" },
{ name: "players", type: "stringArray" } { name: "players", type: "stringArray" }
], ],
0xfa: [ 0xfa: [
@ -500,6 +501,20 @@ var types = {
'stringArray': [readStringArray, writeStringArray, sizeOfStringArray], '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) { function sizeOfByteArray32(value) {
return 4 + value.length; return 4 + value.length;
} }
@ -1239,8 +1254,10 @@ function parsePacket(buffer, isServer) {
var packetInfo = get(packetId, isServer); var packetInfo = get(packetId, isServer);
if (packetInfo == null) { if (packetInfo == null) {
return { 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; var i, fieldInfo, read, readResults;
for (i = 0; i < packetInfo.length; ++i) { for (i = 0; i < packetInfo.length; ++i) {
@ -1266,11 +1283,12 @@ function parsePacket(buffer, isServer) {
module.exports = { module.exports = {
version: 60, version: 60,
minecraftVersion: '1.5', minecraftVersion: '1.5.1',
sessionVersion: 13, sessionVersion: 13,
parsePacket: parsePacket, parsePacket: parsePacket,
createPacketBuffer: createPacketBuffer, createPacketBuffer: createPacketBuffer,
STRING_MAX_LENGTH: STRING_MAX_LENGTH, STRING_MAX_LENGTH: STRING_MAX_LENGTH,
packets: packets, packets: packets,
get: get, get: get,
debug: debug,
}; };