Move FML|HS listener to forge_client example, reduce changes in createClient

This commit is contained in:
deathcap 2016-01-24 11:19:19 -08:00
parent 93c5c7315a
commit bd72488bf3
3 changed files with 10 additions and 20 deletions

View File

@ -69,8 +69,6 @@ Returns a `Client` instance and perform login.
* port : default to 25565 * port : default to 25565
* password : can be omitted (if the tokens are also omitted then it tries to connect in offline mode) * password : can be omitted (if the tokens are also omitted then it tries to connect in offline mode)
* host : default to localhost * 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 * clientToken : generated if a password is given
* accessToken : generated if a password is given * accessToken : generated if a password is given
* keepAlive : send keep alive packets : default to true * 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 Called when the protocol changes state. Takes the new state and old state as
parameters. parameters.
### `forgeMods` event
Called when the client receives the server's `ModList`, when connecting to an
FML/Forge server.
### per-packet events ### 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. 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.

View File

@ -1,4 +1,5 @@
var mc = require('minecraft-protocol'); var mc = require('minecraft-protocol');
var fml = require('../../dist/fml'); // TODO: separate module
if(process.argv.length < 4 || process.argv.length > 6) { if(process.argv.length < 4 || process.argv.length > 6) {
console.log("Usage : node echo.js <host> <port> [<name>] [<password>]"); console.log("Usage : node echo.js <host> <port> [<name>] [<password>]");
@ -25,8 +26,6 @@ mc.ping({host, port}, function(err, response) {
var client = mc.createClient({ var client = mc.createClient({
tagHost: '\0FML\0', // signifies client supports FML/Forge tagHost: '\0FML\0', // signifies client supports FML/Forge
forge: true,
forgeMods: forgeMods,
// Client/server mods installed on the client // Client/server mods installed on the client
// if not specified, pings server and uses its list // if not specified, pings server and uses its list
/* /*
@ -37,6 +36,7 @@ mc.ping({host, port}, function(err, response) {
username: username, username: username,
password: password password: password
}); });
client.forgeMods = forgeMods; // for fmlHandshakeStep TODO: refactor
client.on('connect', function() { client.on('connect', function() {
console.info('connected'); console.info('connected');
@ -56,6 +56,14 @@ mc.ping({host, port}, function(err, response) {
client.write('chat', {message: msg}); 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) { client.on('forgeMods', function(mods) {
console.log('Received forgeMods event:',mods); console.log('Received forgeMods event:',mods);
}); });

View File

@ -9,7 +9,6 @@ var yggserver = require('yggdrasil').server({});
var states = require("./states"); var states = require("./states");
var debug = require("./debug"); var debug = require("./debug");
var UUID = require('uuid-1345'); var UUID = require('uuid-1345');
var fml = require('./fml');
module.exports=createClient; module.exports=createClient;
@ -46,22 +45,12 @@ function createClient(options) {
var client = new Client(false,version.majorVersion); var client = new Client(false,version.majorVersion);
client.forge = options.forge;
client.forgeMods = options.forgeMods;
client.on('connect', onConnect); client.on('connect', onConnect);
if(keepAlive) client.on('keep_alive', onKeepAlive); if(keepAlive) client.on('keep_alive', onKeepAlive);
client.once('encryption_begin', onEncryptionKeyRequest); client.once('encryption_begin', onEncryptionKeyRequest);
client.once('success', onLogin); client.once('success', onLogin);
client.once("compress", onCompressionRequest); client.once("compress", onCompressionRequest);
client.on("set_compression", 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) { if(haveCredentials) {
// make a request to get the case-correct username before connecting. // make a request to get the case-correct username before connecting.
var cb = function(err, session) { var cb = function(err, session) {