From 3d3916bb937424ae1c55eca8da32fbf351e60e0a Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Sun, 26 Feb 2017 19:46:17 +0100 Subject: [PATCH] some fixes for last protodef --- package.json | 2 +- src/client/pluginChannels.js | 2 +- src/transforms/serializer.js | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0ace9ce..15fc393 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "lodash.merge": "^4.3.0", "minecraft-data": "^2.11.0", "prismarine-nbt": "^1.0.0", - "protodef": "^1.2.3", + "protodef": "^1.3.0", "readable-stream": "^2.0.5", "ursa-purejs": "^0.0.3", "uuid-1345": "^0.99.6", diff --git a/src/client/pluginChannels.js b/src/client/pluginChannels.js index 92500ae..4b8b87a 100644 --- a/src/client/pluginChannels.js +++ b/src/client/pluginChannels.js @@ -7,7 +7,7 @@ module.exports = function(client, options) { var proto = new ProtoDef(); proto.addTypes(mcdata.protocol.types); proto.addTypes(minecraft); - proto.addTypes({'registerarr': [readDumbArr, writeDumbArr, sizeOfDumbArr]}); + proto.addType('registerarr',[readDumbArr, writeDumbArr, sizeOfDumbArr]); client.registerChannel = registerChannel; client.unregisterChannel = unregisterChannel; diff --git a/src/transforms/serializer.js b/src/transforms/serializer.js index d5dcafa..5f8e9be 100644 --- a/src/transforms/serializer.js +++ b/src/transforms/serializer.js @@ -18,12 +18,18 @@ function recursiveAddTypes(protocol,protocolData,path) recursiveAddTypes(protocol,get(protocolData,path.shift()),path); } +const protocols={}; + function createProtocol(state,direction,version,customPackets) { + const key=state+";"+direction+";"+version; + if(protocols[key]) + return protocols[key]; const proto = new ProtoDef(); proto.addTypes(minecraft); const mcData=require("minecraft-data")(version); recursiveAddTypes(proto,merge(mcData.protocol,get(customPackets,[mcData.version.majorVersion])),[state,direction]); + protocols[key]=proto; return proto; }