From 38f46998e392d329b909ced6f169097d62a91388 Mon Sep 17 00:00:00 2001 From: Xabier de Zuazo Date: Sat, 6 Apr 2013 04:45:32 +0200 Subject: [PATCH 1/5] Unrecognized packetId error printing id in hex --- lib/protocol.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protocol.js b/lib/protocol.js index e91df4a..0ef63ff 100644 --- a/lib/protocol.js +++ b/lib/protocol.js @@ -1239,7 +1239,7 @@ 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) + ")") } } var i, fieldInfo, read, readResults; From 0ff49078ff767566e17c8ae4de97523015c5518b Mon Sep 17 00:00:00 2001 From: Xabier de Zuazo Date: Sat, 6 Apr 2013 04:48:05 +0200 Subject: [PATCH 2/5] friendlyFire on 0xd1 package id changed from bool to byte type --- lib/protocol.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/protocol.js b/lib/protocol.js index 0ef63ff..e994a2c 100644 --- a/lib/protocol.js +++ b/lib/protocol.js @@ -307,6 +307,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 +325,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 +450,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: [ From b699d5506a3eccdf49ca399f681922dffb23e973 Mon Sep 17 00:00:00 2001 From: Xabier de Zuazo Date: Sat, 6 Apr 2013 05:02:36 +0200 Subject: [PATCH 3/5] added debug() method for NODE_DEBUG=mc-proto --- lib/client.js | 1 + lib/protocol.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/client.js b/lib/client.js index fb41c85..a89ba5b 100644 --- a/lib/client.js +++ b/lib/client.js @@ -4,6 +4,7 @@ var net = require('net') , protocol = require('./protocol') , createPacketBuffer = protocol.createPacketBuffer , parsePacket = protocol.parsePacket + , debug = protocol.debug module.exports = Client; diff --git a/lib/protocol.js b/lib/protocol.js index e994a2c..38459c6 100644 --- a/lib/protocol.js +++ b/lib/protocol.js @@ -1,4 +1,5 @@ var assert = require('assert'); +var util = require('util'); var STRING_MAX_LENGTH = 240; @@ -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; } @@ -1273,4 +1288,5 @@ module.exports = { STRING_MAX_LENGTH: STRING_MAX_LENGTH, packets: packets, get: get, + debug: debug, }; From 936ba5832d5061760f8893cc8a30b29f6a4dd2dc Mon Sep 17 00:00:00 2001 From: Xabier de Zuazo Date: Sat, 6 Apr 2013 05:04:47 +0200 Subject: [PATCH 4/5] added debug output for read/written packet ids --- lib/client.js | 1 + lib/protocol.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/lib/client.js b/lib/client.js index a89ba5b..2131496 100644 --- a/lib/client.js +++ b/lib/client.js @@ -79,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); }; diff --git a/lib/protocol.js b/lib/protocol.js index 38459c6..9554586 100644 --- a/lib/protocol.js +++ b/lib/protocol.js @@ -1256,6 +1256,8 @@ function parsePacket(buffer, isServer) { return { 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) { From e17693868242c955ab995393ab56ccb8a537dffb Mon Sep 17 00:00:00 2001 From: Xabier de Zuazo Date: Sat, 6 Apr 2013 05:41:40 +0200 Subject: [PATCH 5/5] Protocol version updated to 1.5.1 --- lib/protocol.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protocol.js b/lib/protocol.js index 9554586..21be784 100644 --- a/lib/protocol.js +++ b/lib/protocol.js @@ -1283,7 +1283,7 @@ function parsePacket(buffer, isServer) { module.exports = { version: 60, - minecraftVersion: '1.5', + minecraftVersion: '1.5.1', sessionVersion: 13, parsePacket: parsePacket, createPacketBuffer: createPacketBuffer,