mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-27 21:24:25 -04:00
Add wait_connect option, to require 'connect_allowed' event before src/client/setProtocol proceeds
Intended to allow clients to configure the client object before any data is sent, specifically, before src/client/setProtocol sends the set_protocol packet.
This commit is contained in:
parent
a53a2977f2
commit
9ec6d876ba
@ -5,6 +5,14 @@ module.exports = function(client, options) {
|
||||
client.on('connect', onConnect);
|
||||
|
||||
function onConnect() {
|
||||
if (options.wait_connect) {
|
||||
client.on('connect_allowed', next);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
function next() {
|
||||
client.write('set_protocol', {
|
||||
protocolVersion: options.protocolVersion,
|
||||
serverHost: options.host,
|
||||
@ -16,6 +24,4 @@ module.exports = function(client, options) {
|
||||
username: client.username
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,9 @@ function protocol2version(n) {
|
||||
function createClientAsync(options, cb) {
|
||||
assert.ok(options, 'options is required');
|
||||
|
||||
debug('creating client');
|
||||
options.wait_connect = true; // don't let createClient / src/client/setProtocol proceed on socket 'connect' until 'connect_allowed'
|
||||
var client = createClient(options); // vanilla
|
||||
debug('pinging',options.host);
|
||||
// TODO: refactor with DNS SRV lookup in NMP
|
||||
// TODO: detect ping timeout, https://github.com/PrismarineJS/node-minecraft-protocol/issues/329
|
||||
@ -41,10 +44,12 @@ function createClientAsync(options, cb) {
|
||||
// Note that versionName is a descriptive version stirng like '1.8.9' on vailla, but other
|
||||
// servers add their own name (Spigot 1.8.8, Glowstone++ 1.8.9) so we cannot use it directly,
|
||||
// even though it is in a format accepted by minecraft-data. Instead, translate the protocol.
|
||||
//XXX TODO: modify client object
|
||||
options.version = protocol2version(versionProtocol);
|
||||
|
||||
// Use the exact same protocol version
|
||||
// Requires https://github.com/PrismarineJS/node-minecraft-protocol/pull/330
|
||||
//XXX TODO: modify client objecti
|
||||
options.protocolVersion = versionProtocol;
|
||||
|
||||
if (response.modinfo && response.modinfo.type === 'FML') {
|
||||
@ -53,10 +58,13 @@ function createClientAsync(options, cb) {
|
||||
debug('Using forgeMods:',forgeMods);
|
||||
// TODO: https://github.com/PrismarineJS/node-minecraft-protocol/issues/114
|
||||
// https://github.com/PrismarineJS/node-minecraft-protocol/pull/326
|
||||
// TODO: modify client object to set forgeMods and enable forgeHandshake
|
||||
throw new Error('FML/Forge not yet supported');
|
||||
} else {
|
||||
client = createClient(options); // vanilla
|
||||
}
|
||||
// done configuring client object, let connection proceed
|
||||
client.emit('connect_allowed');
|
||||
|
||||
|
||||
cb(null, client);
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user