From 069a79ba3ed8d2213aa307a6c111145e4f224ae9 Mon Sep 17 00:00:00 2001 From: deathcap Date: Wed, 27 Jan 2016 20:42:15 -0800 Subject: [PATCH] Update client/forgeHandshake.js to be installable as module --- examples/client_forge/client_forge.js | 18 +++--------------- src/client/forgeHandshake.js | 13 +++++++++---- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/examples/client_forge/client_forge.js b/examples/client_forge/client_forge.js index 6c3621a..43bb28b 100644 --- a/examples/client_forge/client_forge.js +++ b/examples/client_forge/client_forge.js @@ -1,5 +1,5 @@ var mc = require('minecraft-protocol'); -var fml = require('../../dist/client/forgeHandshake'); // TODO: separate module +var forgeHandshake = require('../../dist/client/forgeHandshake'); // TODO: what's with 'dist' here? if(process.argv.length < 4 || process.argv.length > 6) { console.log("Usage : node echo.js [] []"); @@ -25,18 +25,13 @@ mc.ping({host, port}, function(err, response) { console.log('Using forgeMods:',forgeMods); var client = mc.createClient({ - tagHost: '\0FML\0', // signifies client supports FML/Forge - // Client/server mods installed on the client - // if not specified, pings server and uses its list - /* - forgeMods: - */ + tagHost: '\0FML\0', // passed to src/client/setProtocol.js, signifies client supports FML/Forge TODO: refactor into src/client/forgeHandshake.js, let it set it, but earliest enough(pause) host: host, port: port, username: username, password: password }); - client.forgeMods = forgeMods; // for fmlHandshakeStep TODO: refactor + forgeHandshake(client, {forgeMods}); client.on('connect', function() { console.info('connected'); @@ -57,13 +52,6 @@ mc.ping({host, port}, function(err, response) { } }); - client.on('custom_payload', function(packet) { - // TODO: channel registration tracking in NMP, https://github.com/PrismarineJS/node-minecraft-protocol/pull/328 - if (packet.channel === 'FML|HS') { - fml.fmlHandshakeStep(client, packet.data); - } - }); - client.on('forgeMods', function(mods) { console.log('Received forgeMods event:',mods); }); diff --git a/src/client/forgeHandshake.js b/src/client/forgeHandshake.js index 8be1c4d..5767a1c 100644 --- a/src/client/forgeHandshake.js +++ b/src/client/forgeHandshake.js @@ -172,7 +172,7 @@ var FMLHandshakeClientState = { COMPLETE: 5, }; -function fmlHandshakeStep(client, data) +function fmlHandshakeStep(client, data, options) { var parsed = proto.parsePacketBuffer('FML|HS', data); debug('FML|HS',parsed); @@ -205,7 +205,7 @@ function fmlHandshakeStep(client, data) debug('Sending client modlist'); var modList = proto.createPacketBuffer('FML|HS', { discriminator: 'ModList', - mods: client.forgeMods || [] + mods: options.forgeMods || [] }); client.write('custom_payload', { channel: 'FML|HS', @@ -263,6 +263,11 @@ function fmlHandshakeStep(client, data) } } -module.exports = { - fmlHandshakeStep +module.exports = function(client, options) { + client.on('custom_payload', function(packet) { + // TODO: channel registration tracking in NMP, https://github.com/PrismarineJS/node-minecraft-protocol/pull/328 + if (packet.channel === 'FML|HS') { + fmlHandshakeStep(client, packet.data, options); + } + }); };