From bd72488bf34c4dbae3cd4934990fe55a176110d3 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 24 Jan 2016 11:19:19 -0800 Subject: [PATCH] Move FML|HS listener to forge_client example, reduce changes in createClient --- doc/README.md | 7 ------- examples/client_forge/client_forge.js | 12 ++++++++++-- src/createClient.js | 11 ----------- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/doc/README.md b/doc/README.md index bb60825..daca5a1 100644 --- a/doc/README.md +++ b/doc/README.md @@ -69,8 +69,6 @@ Returns a `Client` instance and perform login. * port : default to 25565 * password : can be omitted (if the tokens are also omitted then it tries to connect in offline mode) * host : default to localhost - * forge : if true, will attempt to negotiate a FML/Forge handshake - * forgeMods : array of objects with `modid` and `version` properties for the Forge mods the client supports * clientToken : generated if a password is given * accessToken : generated if a password is given * keepAlive : send keep alive packets : default to true @@ -133,11 +131,6 @@ and the packet metadata (name, state) Called when the protocol changes state. Takes the new state and old state as parameters. -### `forgeMods` event - -Called when the client receives the server's `ModList`, when connecting to an -FML/Forge server. - ### per-packet events Check out the [minecraft-data docs](https://prismarinejs.github.io/minecraft-data/?v=1.8&d=protocol) to know the event names and data field names. diff --git a/examples/client_forge/client_forge.js b/examples/client_forge/client_forge.js index 683cb72..d6b6c17 100644 --- a/examples/client_forge/client_forge.js +++ b/examples/client_forge/client_forge.js @@ -1,4 +1,5 @@ var mc = require('minecraft-protocol'); +var fml = require('../../dist/fml'); // TODO: separate module if(process.argv.length < 4 || process.argv.length > 6) { console.log("Usage : node echo.js [] []"); @@ -25,8 +26,6 @@ mc.ping({host, port}, function(err, response) { var client = mc.createClient({ tagHost: '\0FML\0', // signifies client supports FML/Forge - forge: true, - forgeMods: forgeMods, // Client/server mods installed on the client // if not specified, pings server and uses its list /* @@ -37,6 +36,7 @@ mc.ping({host, port}, function(err, response) { username: username, password: password }); + client.forgeMods = forgeMods; // for fmlHandshakeStep TODO: refactor client.on('connect', function() { console.info('connected'); @@ -56,6 +56,14 @@ mc.ping({host, port}, function(err, response) { client.write('chat', {message: msg}); } }); + + 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/createClient.js b/src/createClient.js index 5ed48e1..cbd833d 100644 --- a/src/createClient.js +++ b/src/createClient.js @@ -9,7 +9,6 @@ var yggserver = require('yggdrasil').server({}); var states = require("./states"); var debug = require("./debug"); var UUID = require('uuid-1345'); -var fml = require('./fml'); module.exports=createClient; @@ -46,22 +45,12 @@ function createClient(options) { var client = new Client(false,version.majorVersion); - client.forge = options.forge; - client.forgeMods = options.forgeMods; client.on('connect', onConnect); if(keepAlive) client.on('keep_alive', onKeepAlive); client.once('encryption_begin', onEncryptionKeyRequest); client.once('success', onLogin); client.once("compress", onCompressionRequest); 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); - } - }); - } if(haveCredentials) { // make a request to get the case-correct username before connecting. var cb = function(err, session) {