From 2802ac9d2b511eace768e41e9d09c90591074ee0 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 23 Jan 2016 20:54:43 -0800 Subject: [PATCH] fml console.log -> debug --- examples/client_forge/client_forge.js | 3 +++ src/createClient.js | 1 + src/fml.js | 32 ++++++--------------------- 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/examples/client_forge/client_forge.js b/examples/client_forge/client_forge.js index fa19c10..c079c42 100644 --- a/examples/client_forge/client_forge.js +++ b/examples/client_forge/client_forge.js @@ -55,4 +55,7 @@ mc.ping({host, port}, function(err, response) { client.write('chat', {message: msg}); } }); + client.on('forgeMods', function(mods) { + console.log('Received forgeMods event:',mods); + }); }); diff --git a/src/createClient.js b/src/createClient.js index 3d8ceef..59ff455 100644 --- a/src/createClient.js +++ b/src/createClient.js @@ -56,6 +56,7 @@ function createClient(options) { client.on("set_compression", onCompressionRequest); if(client.forge) { client.on('custom_payload', function(packet) { + // TODO: channel registration tracking in NMP if (packet.channel === 'FML|HS') { fml.fmlHandshakeStep(client, packet.data); } diff --git a/src/fml.js b/src/fml.js index 418b3de..38b6686 100644 --- a/src/fml.js +++ b/src/fml.js @@ -1,5 +1,6 @@ var ProtoDef = require('protodef').ProtoDef; var assert = require('assert'); +var debug = require('./debug'); var proto = new ProtoDef(); // copied from ../../dist/transforms/serializer.js TODO: refactor @@ -174,7 +175,7 @@ var FMLHandshakeClientState = { function fmlHandshakeStep(client, data) { var parsed = proto.parsePacketBuffer('FML|HS', data); - console.log('FML|HS',parsed); + debug('FML|HS',parsed); var fmlHandshakeState = client.fmlHandshakeState || FMLHandshakeClientState.START; @@ -201,7 +202,7 @@ function fmlHandshakeStep(client, data) data: clientHello }); - console.log('Sending client modlist'); + debug('Sending client modlist'); var modList = proto.createPacketBuffer('FML|HS', { discriminator: 'ModList', mods: client.forgeMods || [] @@ -218,7 +219,7 @@ function fmlHandshakeStep(client, data) case FMLHandshakeClientState.WAITINGSERVERDATA: { assert.ok(parsed.data.discriminator === 'ModList', `expected ModList in WAITINGSERVERDATA state, got ${parsed.data.discriminator}`); - console.log('Server ModList:',parsed.data.mods); + debug('Server ModList:',parsed.data.mods); // TODO: client/server check if mods compatible client.fmlHandshakeState = FMLHandshakeClientState.WAITINGSERVERCOMPLETE; break; @@ -227,10 +228,10 @@ function fmlHandshakeStep(client, data) case FMLHandshakeClientState.WAITINGSERVERCOMPLETE: { assert.ok(parsed.data.discriminator === 'RegistryData', `expected RegistryData in WAITINGSERVERCOMPLETE, got ${parsed.data.discriminator}`); - console.log('RegistryData',parsed.data); + debug('RegistryData',parsed.data); // TODO: support <=1.7.10 single registry, https://github.com/ORelio/Minecraft-Console-Client/pull/100/files#diff-65b97c02a9736311374109e22d30ca9cR297 if (parsed.data.hasMore === false) { - console.log('LAST RegistryData'); + debug('LAST RegistryData'); writeAck(client, FMLHandshakeClientState.WAITINGSERVERCOMPLETE); client.fmlHandshakeState = FMLHandshakeClientState.PENDINGCOMPLETE; @@ -252,7 +253,7 @@ function fmlHandshakeStep(client, data) assert.ok(parsed.data.phase === 3, `expected HandshakeAck phase COMPLETE, got ${parsed.data.phase}`); writeAck(client, FMLHandshakeClientState.COMPLETE); - console.log('HandshakeAck Complete!'); + debug('HandshakeAck Complete!'); break; } @@ -261,25 +262,6 @@ function fmlHandshakeStep(client, data) } } -//var forgeMods; // = [ {modid:'IronChest', version:'6.0.121.768'} ]; -/* -function injectForge(client) { - client.on('custom_payload', function(packet) { - var channel = packet.channel; - var data = packet.data; - - if (channel === 'REGISTER') { - var channels = data.toString().split('\0'); - console.log('Server-side registered channels:',channels); - // TODO: do something? - // expect: [ 'FML|HS', 'FML', 'FML|MP', 'FML', 'FORGE' ] - } else if (channel === 'FML|HS') { - fmlHandshakeStep(client, data); - } - }); -} -*/ - module.exports = { fmlHandshakeStep };