From 482a4ecffd8ce6c62598c8877974863bfa969deb Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Mon, 1 Jan 2018 21:01:23 +0100 Subject: [PATCH 1/3] 17w50a support --- README.md | 2 +- package.json | 4 ++-- src/client.js | 2 +- src/version.js | 4 ++-- test/clientTest.js | 6 +++--- test/packetTest.js | 18 +++++++++++++----- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index b46512f..818110d 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Parse and serialize minecraft packets, plus authentication and encryption. ## Features * Supports Minecraft PC version 1.7.10, 1.8.8, 1.9 (15w40b, 1.9, 1.9.1-pre2, 1.9.2, 1.9.4), - 1.10 (16w20a, 1.10-pre1, 1.10, 1.10.1, 1.10.2), 1.11 (16w35a, 1.11, 1.11.2), and 1.12 (17w15a, 17w18b, 1.12-pre4, 1.12, 1.12.1) + 1.10 (16w20a, 1.10-pre1, 1.10, 1.10.1, 1.10.2), 1.11 (16w35a, 1.11, 1.11.2), 1.12 (17w15a, 17w18b, 1.12-pre4, 1.12, 1.12.1, 1.12.2), and 1.13 (17w50a) * Parses all packets and emits events with packet fields as JavaScript objects. * Send a packet by supplying fields as a JavaScript object. diff --git a/package.json b/package.json index b05988c..1a8f51c 100644 --- a/package.json +++ b/package.json @@ -41,9 +41,9 @@ "endian-toggle": "^0.0.0", "lodash.get": "^4.1.2", "lodash.merge": "^4.3.0", - "minecraft-data": "^2.20.0", + "minecraft-data": "^2.24.0", "node-rsa": "^0.4.2", - "prismarine-nbt": "^1.0.0", + "prismarine-nbt": "^1.2.0", "protodef": "^1.5.1", "readable-stream": "^2.0.5", "uuid-1345": "^0.99.6", diff --git a/src/client.js b/src/client.js index 929b851..1c1151e 100644 --- a/src/client.js +++ b/src/client.js @@ -97,7 +97,7 @@ class Client extends EventEmitter parsed.data=parsed.data.params; parsed.metadata.state=state; debug("read packet " + state + "." + parsed.metadata.name); - debug(parsed.data); + debug(JSON.stringify(parsed.data,null,2)); this.emit('packet', parsed.data, parsed.metadata); this.emit(parsed.metadata.name, parsed.data, parsed.metadata); this.emit('raw.' + parsed.metadata.name, parsed.buffer, parsed.metadata); diff --git a/src/version.js b/src/version.js index ad2d717..1c96a2f 100644 --- a/src/version.js +++ b/src/version.js @@ -1,6 +1,6 @@ 'use strict'; module.exports={ - defaultVersion:'1.12.1', - supportedVersions:['1.7','1.8','1.9','1.10','1.11.2','1.12.1'] + defaultVersion:'1.12.2', + supportedVersions:['1.7','1.8','1.9','1.10','1.11.2','1.12.2','17w50a'] }; diff --git a/test/clientTest.js b/test/clientTest.js index f3d57a3..8101fbf 100644 --- a/test/clientTest.js +++ b/test/clientTest.js @@ -117,15 +117,15 @@ mc.supportedVersions.forEach(function(supportedVersion,i) { assert.strictEqual(message.translate, "chat.type.text"); assert.deepEqual(message["with"][0].clickEvent, { action: "suggest_command", - value: "/msg Player " + value: mcData.version.version>340 ? "/tell Player " : "/msg Player " }); assert.deepEqual(message["with"][0].text, "Player"); assert.strictEqual(message["with"][1], "hello everyone; I have logged in."); } else if (chatCount === 2) { assert.strictEqual(message.translate, "chat.type.announcement"); assert.strictEqual(message["with"][0].text ? message["with"][0].text : message["with"][0], "Server"); - assert.deepEqual(message["with"][1].extra[0].text ? - message["with"][1].extra[0].text : message["with"][1].extra[0], "hello"); + assert.deepEqual(message["with"][1].extra ? (message["with"][1].extra[0].text ? + message["with"][1].extra[0].text : message["with"][1].extra[0]) : message["with"][1].text, "hello"); wrap.removeListener('line', lineListener); client.end(); done(); diff --git a/test/packetTest.js b/test/packetTest.js index 8b87c46..bc9012b 100644 --- a/test/packetTest.js +++ b/test/packetTest.js @@ -42,7 +42,7 @@ const values = { "..": context }; Object.keys(typeArgs).forEach(function(index){ - const v=getValue(typeArgs[index].type, results); + const v=typeArgs[index].name==="type" && typeArgs[index].type==="string" ? "crafting_shapeless" : getValue(typeArgs[index].type, results); if(typeArgs[index].anon) { Object.keys(v).forEach(key => { results[key]=v[key]; @@ -130,24 +130,30 @@ const values = { 'restBuffer': new Buffer(0), 'switch': function(typeArgs, context) { const i = typeArgs.fields[getField(typeArgs.compareTo, context)]; - if (typeof i === "undefined") + if (typeof i === "undefined") { + if(typeArgs.default === undefined) + throw new Error("couldn't find the field "+typeArgs.compareTo+" of the compareTo and the default is not defined"); return getValue(typeArgs.default, context); + } else return getValue(i, context); }, 'option': function(typeArgs, context) { return getValue(typeArgs, context); }, - 'bitfield': function(typeArgs) { + 'bitfield': function(typeArgs, context) { const results={}; Object.keys(typeArgs).forEach(function(index){ results[typeArgs[index].name] = 1; + context[typeArgs[index].name] = 1; }); return results; - } + }, + 'tags':[{'tagName':'hi','entries':[1,2,3,4,5]}] }; function getValue(_type, packet) { + console.log(_type); const fieldInfo = getFieldInfo(_type); if (typeof values[fieldInfo.type] === "function") return values[fieldInfo.type](fieldInfo.typeArgs, packet); @@ -192,7 +198,9 @@ mc.supportedVersions.forEach(function(supportedVersion,i){ let packetInfo, field; Object.keys(packets).filter(function(state){return state!=="types"}).forEach(function(state){ Object.keys(packets[state]).forEach(function(direction){ - Object.keys(packets[state][direction].types).filter(function(packetName){return packetName!=="packet"}).forEach(function(packetName){ + Object.keys(packets[state][direction].types) + .filter(function(packetName){return packetName!=="packet" && packetName.startsWith("packet_")}) + .forEach(function(packetName){ packetInfo = packets[state][direction].types[packetName]; packetInfo=packetInfo ? packetInfo : null; it(state + ","+(direction==="toServer" ? "Server" : "Client")+"Bound," + packetName, From 947f6bf2eacf6cffb31d95cac1ad4fe7d897d6e9 Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Mon, 1 Jan 2018 22:28:25 +0100 Subject: [PATCH 2/3] update mcdata for this in 17w50a protocol --- package.json | 2 +- src/client.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1a8f51c..f5a088e 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "endian-toggle": "^0.0.0", "lodash.get": "^4.1.2", "lodash.merge": "^4.3.0", - "minecraft-data": "^2.24.0", + "minecraft-data": "^2.25.0", "node-rsa": "^0.4.2", "prismarine-nbt": "^1.2.0", "protodef": "^1.5.1", diff --git a/src/client.js b/src/client.js index 1c1151e..4e51912 100644 --- a/src/client.js +++ b/src/client.js @@ -97,7 +97,8 @@ class Client extends EventEmitter parsed.data=parsed.data.params; parsed.metadata.state=state; debug("read packet " + state + "." + parsed.metadata.name); - debug(JSON.stringify(parsed.data,null,2)); + const s=JSON.stringify(parsed.data,null,2); + debug(s.length > 10000 ? parsed.data : s); this.emit('packet', parsed.data, parsed.metadata); this.emit(parsed.metadata.name, parsed.data, parsed.metadata); this.emit('raw.' + parsed.metadata.name, parsed.buffer, parsed.metadata); From ad0c76dd723ac891873e6e7b8e22bd39ee196f26 Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Mon, 1 Jan 2018 22:48:13 +0100 Subject: [PATCH 3/3] remove console.log --- test/packetTest.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/packetTest.js b/test/packetTest.js index bc9012b..afbd90e 100644 --- a/test/packetTest.js +++ b/test/packetTest.js @@ -153,7 +153,6 @@ const values = { }; function getValue(_type, packet) { - console.log(_type); const fieldInfo = getFieldInfo(_type); if (typeof values[fieldInfo.type] === "function") return values[fieldInfo.type](fieldInfo.typeArgs, packet);