diff --git a/doc/README.md b/doc/README.md index d7deebf..912a172 100644 --- a/doc/README.md +++ b/doc/README.md @@ -18,7 +18,7 @@ automatically logged in and validated against mojang's auth. * maxPlayers : default to 20 * keepAlive : send keep alive packets : default to true * version : 1.8 or 1.9 : default to 1.8 - * customPackets (optional) : an object index by state/direction/name, see client_custom_packet for an example + * customPackets (optional) : an object index by version/state/direction/name, see client_custom_packet for an example ## mc.Server(version,[customPackets]) @@ -75,7 +75,7 @@ Returns a `Client` instance and perform login. * keepAlive : send keep alive packets : default to true * checkTimeoutInterval : default to `10*1000` (10s), check if keepalive received at that period, disconnect otherwise. * version : 1.8 or 1.9 or false (to auto-negotiate): default to 1.8 - * customPackets (optional) : an object index by state/direction/name, see client_custom_packet for an example + * customPackets (optional) : an object index by version/state/direction/name, see client_custom_packet for an example ## mc.Client(isServer,version,[customPackets]) diff --git a/examples/client_custom_packets/client_custom_packets.js b/examples/client_custom_packets/client_custom_packets.js index a7fa7c1..991d660 100644 --- a/examples/client_custom_packets/client_custom_packets.js +++ b/examples/client_custom_packets/client_custom_packets.js @@ -6,20 +6,22 @@ if(process.argv.length < 4 || process.argv.length > 6) { } var customPackets={ - "play":{ - "toClient":{ - "my_custom_packet": { - "id": "0x7A", - "fields": [ - { - "name": "age", - "type": "i64" - }, - { - "name": "time", - "type": "i64" - } - ] + "1.8": { + "play": { + "toClient": { + "my_custom_packet": { + "id": "0x7A", + "fields": [ + { + "name": "age", + "type": "i64" + }, + { + "name": "time", + "type": "i64" + } + ] + } } } } diff --git a/src/transforms/serializer.js b/src/transforms/serializer.js index 9eb1f1c..98fdb30 100644 --- a/src/transforms/serializer.js +++ b/src/transforms/serializer.js @@ -41,7 +41,8 @@ function createSerializer({ state = states.HANDSHAKING, isServer = false , versi const mcData=require("minecraft-data")(version); const direction = !isServer ? 'toServer' : 'toClient'; const packets = mcData.protocol.states[state][direction]; - if(customPackets && customPackets[state] && customPackets[state][direction]) Object.keys(customPackets[state][direction]).forEach(name => packets[name]=customPackets[state][direction][name]); + const v=mcData.version.majorVersion; + if(customPackets && customPackets[v] && customPackets[v][state] && customPackets[v][state][direction]) Object.keys(customPackets[v][state][direction]).forEach(name => packets[name]=customPackets[v][state][direction][name]); const proto=createProtocol(mcData.protocol.types,packets); return new Serializer(proto,"packet"); } @@ -52,7 +53,8 @@ function createDeserializer({ state = states.HANDSHAKING, isServer = false, const mcData=require("minecraft-data")(version); const direction = isServer ? "toServer" : "toClient"; const packets = mcData.protocol.states[state][direction]; - if(customPackets && customPackets[state] && customPackets[state][direction]) Object.keys(customPackets[state][direction]).forEach(name => packets[name]=customPackets[state][direction][name]); + const v=mcData.version.majorVersion; + if(customPackets && customPackets[v][state] && customPackets[v][state][direction]) Object.keys(customPackets[v][state][direction]).forEach(name => packets[name]=customPackets[v][state][direction][name]); const proto=createProtocol(mcData.protocol.types,packets); return new Parser(proto,"packet"); }