mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-29 06:03:33 -04:00
Move FML|HS listener to forge_client example, reduce changes in createClient
This commit is contained in:
parent
93c5c7315a
commit
bd72488bf3
@ -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.
|
||||
|
@ -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 <host> <port> [<name>] [<password>]");
|
||||
@ -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);
|
||||
});
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user