mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-28 13:45:37 -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);
|
client.on('connect', onConnect);
|
||||||
|
|
||||||
function onConnect() {
|
function onConnect() {
|
||||||
|
if (options.wait_connect) {
|
||||||
|
client.on('connect_allowed', next);
|
||||||
|
} else {
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function next() {
|
||||||
client.write('set_protocol', {
|
client.write('set_protocol', {
|
||||||
protocolVersion: options.protocolVersion,
|
protocolVersion: options.protocolVersion,
|
||||||
serverHost: options.host,
|
serverHost: options.host,
|
||||||
@ -16,6 +24,4 @@ module.exports = function(client, options) {
|
|||||||
username: client.username
|
username: client.username
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,9 @@ function protocol2version(n) {
|
|||||||
function createClientAsync(options, cb) {
|
function createClientAsync(options, cb) {
|
||||||
assert.ok(options, 'options is required');
|
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);
|
debug('pinging',options.host);
|
||||||
// TODO: refactor with DNS SRV lookup in NMP
|
// TODO: refactor with DNS SRV lookup in NMP
|
||||||
// TODO: detect ping timeout, https://github.com/PrismarineJS/node-minecraft-protocol/issues/329
|
// 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
|
// 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,
|
// 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.
|
// even though it is in a format accepted by minecraft-data. Instead, translate the protocol.
|
||||||
|
//XXX TODO: modify client object
|
||||||
options.version = protocol2version(versionProtocol);
|
options.version = protocol2version(versionProtocol);
|
||||||
|
|
||||||
// Use the exact same protocol version
|
// Use the exact same protocol version
|
||||||
// Requires https://github.com/PrismarineJS/node-minecraft-protocol/pull/330
|
// Requires https://github.com/PrismarineJS/node-minecraft-protocol/pull/330
|
||||||
|
//XXX TODO: modify client objecti
|
||||||
options.protocolVersion = versionProtocol;
|
options.protocolVersion = versionProtocol;
|
||||||
|
|
||||||
if (response.modinfo && response.modinfo.type === 'FML') {
|
if (response.modinfo && response.modinfo.type === 'FML') {
|
||||||
@ -53,10 +58,13 @@ function createClientAsync(options, cb) {
|
|||||||
debug('Using forgeMods:',forgeMods);
|
debug('Using forgeMods:',forgeMods);
|
||||||
// TODO: https://github.com/PrismarineJS/node-minecraft-protocol/issues/114
|
// TODO: https://github.com/PrismarineJS/node-minecraft-protocol/issues/114
|
||||||
// https://github.com/PrismarineJS/node-minecraft-protocol/pull/326
|
// 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');
|
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);
|
cb(null, client);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user