From cee1b81099cacbe301de40ed8de47b7858f80cd4 Mon Sep 17 00:00:00 2001 From: roblabla Date: Mon, 16 Mar 2015 17:45:09 +0000 Subject: [PATCH 01/15] Add circleci support --- circle.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 circle.yml diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..0570c63 --- /dev/null +++ b/circle.yml @@ -0,0 +1,9 @@ +machine: + node: + version: 0.10.22 +dependencies: + override: + - npm install --dev +test: + override: + - npm test From bceea2f89651be9b83a369a908bc454b2f2c1f26 Mon Sep 17 00:00:00 2001 From: Josh Wolfe Date: Wed, 18 Mar 2015 03:58:20 -0700 Subject: [PATCH 02/15] adding command line switches to examples/proxy.js for dumping messages --- examples/proxy.js | 76 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 11 deletions(-) diff --git a/examples/proxy.js b/examples/proxy.js index 37c729f..01b0629 100644 --- a/examples/proxy.js +++ b/examples/proxy.js @@ -1,27 +1,66 @@ var mc = require('../'); var states = mc.protocol.states; -function print_help() { - console.log("usage: node proxy.js []"); +function printHelpAndExit(exitCode) { + console.log("usage: node proxy.js [...] []"); + console.log("options:"); + console.log(" --dump ID"); + console.log(" print to stdout messages with the specified ID."); + console.log(" --dump-all"); + console.log(" print to stdout all messages, except those specified with -x."); + console.log(" -x ID"); + console.log(" do not print messages with this ID."); + console.log("examples:"); + console.log(" node proxy.js --dump-all -x 0x0 -x 0x3 -x 0x12 -x 0x015 -x 0x16 -x 0x17 -x 0x18 -x 0x19 localhost Player"); + console.log(" print all messages except for some of the most prolific."); + + process.exit(exitCode); } if (process.argv.length < 4) { console.log("Too few arguments!"); - print_help(); - process.exit(1); + printHelpAndExit(1); } process.argv.forEach(function(val, index, array) { if (val == "-h") { - print_help(); - process.exit(0); + printHelpAndExit(0); } }); -var host = process.argv[2]; +var args = process.argv.slice(2); +var host; var port = 25565; -var user = process.argv[3]; -var passwd = process.argv[4]; +var user; +var passwd; + +var printAllIds = false; +var printIdWhitelist = {}; +var printIdBlacklist = {}; +(function() { + for (var i = 0; i < args.length; i++) { + var option = args[i]; + if (!/^-/.test(option)) break; + if (option == "--dump-all") { + printAllIds = true; + continue; + } + i++; + var arg = parseInt(args[i]); + if (isNaN(arg)) printHelpAndExit(1); + if (option == "--dump") { + printIdWhitelist[arg] = true; + } else if (option == "-x") { + printIdBlacklist[arg] = true; + } else { + printHelpAndExit(1); + } + } + if (!(i + 2 <= args.length && args.length <= i + 3)) printHelpAndExit(1); + host = args[i++]; + user = args[i++]; + passwd = args[i++]; +})(); if (host.indexOf(':') != -1) { port = host.substring(host.indexOf(':')+1); @@ -59,7 +98,11 @@ srv.on('login', function (client) { var brokenPackets = [/*0x04, 0x2f, 0x30*/]; client.on('packet', function(packet) { if (targetClient.state == states.PLAY && packet.state == states.PLAY) { - //console.log(`client->server: ${client.state}.${packet.id} : ${JSON.stringify(packet)}`); + if (shouldDump(packet.id)) { + console.log("client->server:", + client.state + ".0x" + packet.id.toString(16) + " :", + JSON.stringify(packet)); + } if (!endedTargetClient) targetClient.write(packet.id, packet); } @@ -68,7 +111,11 @@ srv.on('login', function (client) { if (packet.state == states.PLAY && client.state == states.PLAY && brokenPackets.indexOf(packet.id) === -1) { - //console.log(`client<-server: ${targetClient.state}.${packet.id} : ${packet.id != 38 ? JSON.stringify(packet) : "Packet too big"}`); + if (shouldDump(packet.id)) { + console.log("client<-server:", + targetClient.state + ".0x" + packet.id.toString(16) + " :", + (packet.id != 38 ? JSON.stringify(packet) : "Packet too big")); + } if (!endedClient) client.write(packet.id, packet); } @@ -120,3 +167,10 @@ srv.on('login', function (client) { client.end("Error"); }); }); + +function shouldDump(id) { + if (printIdBlacklist[id]) return false; + if (printAllIds) return true; + if (printIdWhitelist[id]) return true; + return false; +} From 187f6bccd75f2046ae60ec0fe766dd1c238c16cb Mon Sep 17 00:00:00 2001 From: Robin Lambertz Date: Wed, 18 Mar 2015 19:12:18 +0100 Subject: [PATCH 03/15] Circle-CI : Only test packets and server Client tests require a minecraft server for now. Until we move on to a better way to test the protocol, this will disable the client tests. --- circle.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 0570c63..8cdb96e 100644 --- a/circle.yml +++ b/circle.yml @@ -6,4 +6,5 @@ dependencies: - npm install --dev test: override: - - npm test + - node_modules/.bin/mocha -g "packets" + - node_modules/.bin/mocha -g "mc-server" From 478140364a84bdd302654b499148c82aa3d42eae Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Sun, 22 Mar 2015 02:11:52 +0100 Subject: [PATCH 04/15] Fix bed package (see http://wiki.vg/Protocol#Use_Bed) --- src/protocol.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/protocol.js b/src/protocol.js index eb9b2f4..3a249dc 100644 --- a/src/protocol.js +++ b/src/protocol.js @@ -131,7 +131,7 @@ var packets = { { name: "slot", type: "byte" } ]}, bed: {id: 0x0a, fields: [ - { name: "entityId", type: "int" }, + { name: "entityId", type: "varint" }, { name: "location", type: "position" } ]}, animation: {id: 0x0b, fields: [ From f48b0ed15961381e498f24befb288f002ec27ead Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Sun, 22 Mar 2015 02:17:49 +0100 Subject: [PATCH 05/15] Fix animation (see http://wiki.vg/Protocol#Animation) --- src/protocol.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/protocol.js b/src/protocol.js index 3a249dc..80de4ee 100644 --- a/src/protocol.js +++ b/src/protocol.js @@ -136,7 +136,7 @@ var packets = { ]}, animation: {id: 0x0b, fields: [ { name: "entityId", type: "varint" }, - { name: "animation", type: "byte" } + { name: "animation", type: "ubyte" } ]}, named_entity_spawn: {id: 0x0c, fields: [ { name: "entityId", type: "varint" }, From a7dd89953d855ceaaf5cd017103e9a15aeb86661 Mon Sep 17 00:00:00 2001 From: roblabla Date: Sun, 22 Mar 2015 02:39:42 +0000 Subject: [PATCH 06/15] Release 0.13.1 --- README.md | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4a62ee9..2be4281 100644 --- a/README.md +++ b/README.md @@ -379,6 +379,11 @@ NODE_DEBUG="minecraft-protocol" node [...] ## History +### 0.13.1 + + * Externalized rsa-wrap library to its own npm module, named ursa-native + * Fixed broken bed-related packets (thanks [rom1504](https://github.com/rom1504)) + ### 0.13.0 * Updated protocol version to support 1.8.1 (thanks [wtfaremyinitials](https://github.com/wtfaremyinitials)) diff --git a/package.json b/package.json index 55c7a92..9eaff08 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minecraft-protocol", - "version": "0.13.0", + "version": "0.13.1", "description": "Parse and serialize minecraft packets, plus authentication and encryption.", "main": "index.js", "repository": { From 0d04e573309bc7fe2b1a4588fddcfe35cf1510be Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Mon, 23 Mar 2015 03:09:38 +0100 Subject: [PATCH 07/15] Add circle ci badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2be4281..2ecc68b 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ [![Join the chat at https://gitter.im/PrismarineJS/node-minecraft-protocol](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/PrismarineJS/node-minecraft-protocol?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Build Status](https://circleci.com/gh/PrismarineJS/node-minecraft-protocol.png?style=shield)](https://circleci.com/gh/PrismarineJS/node-minecraft-protocol) + Parse and serialize minecraft packets, plus authentication and encryption. ## Features From 7416ea7e4c21b362ea93d7bbd90c6d60aef7f074 Mon Sep 17 00:00:00 2001 From: roblabla Date: Mon, 23 Mar 2015 02:41:49 +0000 Subject: [PATCH 08/15] Add npmignore --- .npmignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .npmignore diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..be85d62 --- /dev/null +++ b/.npmignore @@ -0,0 +1,3 @@ +node_modules +test/npm-debug.log +test/server From ea62fdc67033697083a7fd166ebbc400fcbeaf4b Mon Sep 17 00:00:00 2001 From: roblabla Date: Mon, 23 Mar 2015 12:38:31 +0000 Subject: [PATCH 09/15] Fix particle packet --- src/protocol.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/protocol.js b/src/protocol.js index 80de4ee..48c2c0c 100644 --- a/src/protocol.js +++ b/src/protocol.js @@ -379,8 +379,15 @@ var packets = { { name: "offsetY", type: "float" }, { name: "offsetZ", type: "float" }, { name: "particleData", type: "float" }, - { name: "particles", type: "count", typeArgs: { countFor: "data", type: "int" } }, - { name: "data", type: "array", typeArgs: { count: "particles", type: "varint" } } + { name: "particles", type: "int" }, + { name: "data", type: "array", typeArgs: { count: function(fields) { + if (fields.particleId === 36) + return 2; + else if (fields.particleId === 37 || fields.particleId === 38) + return 1; + else + return 0; + }, type: "varint" } } ]}, game_state_change: {id: 0x2b, fields: [ { name: "reason", type: "ubyte" }, @@ -1348,7 +1355,11 @@ function readArray(buffer, offset, typeArgs, rootNode) { value: [], size: 0 } - var count = getField(typeArgs.count, rootNode); + var count; + if (typeof typeArgs.count === "function") + count = typeArgs.count(rootNode); + else + count = getField(typeArgs.count, rootNode); for (var i = 0; i < count; i++) { var readResults = read(buffer, offset, { type: typeArgs.type, typeArgs: typeArgs.typeArgs }, rootNode); results.size += readResults.size; From cbdf8adb05fc13c337ba17dac73421e6e28dd3f9 Mon Sep 17 00:00:00 2001 From: roblabla Date: Mon, 23 Mar 2015 13:11:25 +0000 Subject: [PATCH 10/15] Release 0.13.2 --- README.md | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2ecc68b..8887694 100644 --- a/README.md +++ b/README.md @@ -381,6 +381,11 @@ NODE_DEBUG="minecraft-protocol" node [...] ## History +### 0.13.2 + + * Fixed particle packet. + * Fixed release. 0.13.1 release was missing an entire folder. + ### 0.13.1 * Externalized rsa-wrap library to its own npm module, named ursa-native diff --git a/package.json b/package.json index 9eaff08..f630ea3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minecraft-protocol", - "version": "0.13.1", + "version": "0.13.2", "description": "Parse and serialize minecraft packets, plus authentication and encryption.", "main": "index.js", "repository": { From 254223d9c7593c600957ff6bd7b3a91899cc57c1 Mon Sep 17 00:00:00 2001 From: roblabla Date: Mon, 23 Mar 2015 16:20:50 +0000 Subject: [PATCH 11/15] Wrong context when grabbing username --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 0201dd6..3889c43 100644 --- a/src/index.js +++ b/src/index.js @@ -320,7 +320,7 @@ function createClient(options) { hash.update(packet.publicKey); var digest = mcHexDigest(hash); - joinServer(this.username, digest, accessToken, client.session.selectedProfile.id, cb); + joinServer(client.username, digest, accessToken, client.session.selectedProfile.id, cb); } function sendEncryptionKeyResponse() { From 3c7abf7b4a863795dac38aa869fc7d820ad9592e Mon Sep 17 00:00:00 2001 From: roblabla Date: Mon, 23 Mar 2015 16:55:47 +0000 Subject: [PATCH 12/15] Bump circleci node version. Now tests pass. This is ugly --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 8cdb96e..46fcd27 100644 --- a/circle.yml +++ b/circle.yml @@ -1,6 +1,6 @@ machine: node: - version: 0.10.22 + version: 0.10.28 dependencies: override: - npm install --dev From a43e1af1d585cc1fffe2c75c48c2e75cd6b59b5c Mon Sep 17 00:00:00 2001 From: Josh Wolfe Date: Tue, 24 Mar 2015 16:43:38 -0700 Subject: [PATCH 13/15] adding incoming and outgoing filters for proxy.js --dump arguments. --- examples/proxy.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/examples/proxy.js b/examples/proxy.js index 01b0629..a6ab416 100644 --- a/examples/proxy.js +++ b/examples/proxy.js @@ -10,9 +10,14 @@ function printHelpAndExit(exitCode) { console.log(" print to stdout all messages, except those specified with -x."); console.log(" -x ID"); console.log(" do not print messages with this ID."); + console.log(" ID"); + console.log(" an integer in decimal or hex (given to JavaScript's parseInt())"); + console.log(" optionally prefixed with o for client->server or i for client<-server."); console.log("examples:"); console.log(" node proxy.js --dump-all -x 0x0 -x 0x3 -x 0x12 -x 0x015 -x 0x16 -x 0x17 -x 0x18 -x 0x19 localhost Player"); console.log(" print all messages except for some of the most prolific."); + console.log(" node examples/proxy.js --dump i0x2d --dump i0x2e --dump i0x2f dump i0x30 --dump i0x31 --dump i0x32 --dump o0x0d --dump o0x0e --dump o0x0f --dump o0x10 --dump o0x11 localhost Player"); + console.log(" print messages relating to inventory management."); process.exit(exitCode); } @@ -46,12 +51,15 @@ var printIdBlacklist = {}; continue; } i++; - var arg = parseInt(args[i]); - if (isNaN(arg)) printHelpAndExit(1); + var match = /^([io]?)(.*)/.exec(args[i]); + var prefix = match[1]; + if (prefix === "") prefix = "io"; + var number = parseInt(match[2]); + if (isNaN(number)) printHelpAndExit(1); if (option == "--dump") { - printIdWhitelist[arg] = true; + printIdWhitelist[number] = prefix; } else if (option == "-x") { - printIdBlacklist[arg] = true; + printIdBlacklist[number] = prefix; } else { printHelpAndExit(1); } @@ -98,7 +106,7 @@ srv.on('login', function (client) { var brokenPackets = [/*0x04, 0x2f, 0x30*/]; client.on('packet', function(packet) { if (targetClient.state == states.PLAY && packet.state == states.PLAY) { - if (shouldDump(packet.id)) { + if (shouldDump(packet.id, "o")) { console.log("client->server:", client.state + ".0x" + packet.id.toString(16) + " :", JSON.stringify(packet)); @@ -111,7 +119,7 @@ srv.on('login', function (client) { if (packet.state == states.PLAY && client.state == states.PLAY && brokenPackets.indexOf(packet.id) === -1) { - if (shouldDump(packet.id)) { + if (shouldDump(packet.id, "i")) { console.log("client<-server:", targetClient.state + ".0x" + packet.id.toString(16) + " :", (packet.id != 38 ? JSON.stringify(packet) : "Packet too big")); @@ -168,9 +176,12 @@ srv.on('login', function (client) { }); }); -function shouldDump(id) { - if (printIdBlacklist[id]) return false; +function shouldDump(id, direction) { + if (matches(printIdBlacklist[id])) return false; if (printAllIds) return true; - if (printIdWhitelist[id]) return true; + if (matches(printIdWhitelist[id])) return true; return false; + function matches(result) { + return result != null && result.indexOf(direction) !== -1; + } } From 456331b952f4e0d60eef8f5b36c69dcfbb71ae2c Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Wed, 25 Mar 2015 04:09:36 +0100 Subject: [PATCH 14/15] fix readPosition (see http://wiki.vg/index.php?title=Data_Types&diff=6529&oldid=6491) thanks Fenhl --- src/protocol.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/protocol.js b/src/protocol.js index 48c2c0c..5d14349 100644 --- a/src/protocol.js +++ b/src/protocol.js @@ -1095,14 +1095,17 @@ function readBool(buffer, offset) { } function readPosition(buffer, offset) { - var longVal = readLong(buffer, offset).value; // I wish I could do destructuring... - var x = longVal[0] >> 6; - var y = ((longVal[0] & 0x3F) << 6) | ((longVal[1] >> 26) & 0x3f); - var z = longVal[1] & 0x3FFFFFF; - return { - value: { x: x, y: y, z: z }, - size: 8 - }; + var longVal = readLong(buffer, offset).value; // I wish I could do destructuring... + var x = longVal[0] >> 6; + if(x>33554432) x-=67108864; + var y = ((longVal[0] & 0x3F) << 6) | ((longVal[1] >> 26) & 0x3f); + if(y>2048) y-=4096; + var z = longVal[1] & 0x3FFFFFF; + if(z>33554432) z-=67108864; + return { + value: { x: x, y: y, z: z }, + size: 8 + }; } function readSlot(buffer, offset) { From 88b8653b4d6354b543b9b3ab00356b3c28b00736 Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Wed, 25 Mar 2015 04:12:58 +0100 Subject: [PATCH 15/15] fix indentation --- src/protocol.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/protocol.js b/src/protocol.js index 5d14349..2729ecc 100644 --- a/src/protocol.js +++ b/src/protocol.js @@ -1095,17 +1095,17 @@ function readBool(buffer, offset) { } function readPosition(buffer, offset) { - var longVal = readLong(buffer, offset).value; // I wish I could do destructuring... - var x = longVal[0] >> 6; - if(x>33554432) x-=67108864; - var y = ((longVal[0] & 0x3F) << 6) | ((longVal[1] >> 26) & 0x3f); - if(y>2048) y-=4096; - var z = longVal[1] & 0x3FFFFFF; - if(z>33554432) z-=67108864; - return { - value: { x: x, y: y, z: z }, - size: 8 - }; + var longVal = readLong(buffer, offset).value; // I wish I could do destructuring... + var x = longVal[0] >> 6; + if(x>33554432) x-=67108864; + var y = ((longVal[0] & 0x3F) << 6) | ((longVal[1] >> 26) & 0x3f); + if(y>2048) y-=4096; + var z = longVal[1] & 0x3FFFFFF; + if(z>33554432) z-=67108864; + return { + value: { x: x, y: y, z: z }, + size: 8 + }; } function readSlot(buffer, offset) {