From d9111d982f6d18f93e53e0066732941aee073287 Mon Sep 17 00:00:00 2001 From: Romain Beaumont Date: Thu, 13 Jul 2017 14:27:44 +0200 Subject: [PATCH] add debug in plugin channels, fix #433 --- src/client/pluginChannels.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/client/pluginChannels.js b/src/client/pluginChannels.js index 4b8b87a..a3a945d 100644 --- a/src/client/pluginChannels.js +++ b/src/client/pluginChannels.js @@ -1,10 +1,11 @@ -var ProtoDef = require('protodef').ProtoDef; -var minecraft = require('../datatypes/minecraft'); +const ProtoDef = require('protodef').ProtoDef; +const minecraft = require('../datatypes/minecraft'); +const debug = require('debug')('minecraft-protocol'); module.exports = function(client, options) { - var mcdata = require('minecraft-data')(options.version || require("../version").defaultVersion); - var channels = []; - var proto = new ProtoDef(); + const mcdata = require('minecraft-data')(options.version || require("../version").defaultVersion); + const channels = []; + const proto = new ProtoDef(); proto.addTypes(mcdata.protocol.types); proto.addTypes(minecraft); proto.addType('registerarr',[readDumbArr, writeDumbArr, sizeOfDumbArr]); @@ -31,7 +32,7 @@ module.exports = function(client, options) { if(custom) { client.writeChannel("UNREGISTER",channel); } - var index = channels.find(function(name) { + const index = channels.find(function(name) { return channel === name; }); if (index) { @@ -43,17 +44,19 @@ module.exports = function(client, options) { } function onCustomPayload(packet) { - var channel = channels.find(function(channel) { + const channel = channels.find(function(channel) { return channel === packet.channel; }); if (channel) { if (proto.types[channel]) packet.data = proto.parsePacketBuffer(channel, packet.data).data; + debug("read custom payload "+channel+" "+packet.data); client.emit(channel, packet.data); } } function writeChannel(channel,params) { + debug("write custom payload "+channel+" "+params); client.write("custom_payload",{ channel:channel, data:proto.createPacketBuffer(channel,params) @@ -61,13 +64,13 @@ module.exports = function(client, options) { } function readDumbArr(buf, offset) { - var ret = { + const ret = { value: [], size: 0 }; let results; while (offset < buf.length) { - if (buf.indexOf(0x0, offset) == -1) + if (buf.indexOf(0x0, offset) === -1) results = this.read(buf, offset, "restBuffer", {}); else results = this.read(buf, offset, "cstring", {});