From a53a2977f2cd458db86387b1e5016e8a877247bf Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 24 Jan 2016 18:53:34 -0800 Subject: [PATCH 01/22] Add dynamic cross-protocol support --- doc/README.md | 5 +++ examples/client_auto/client_auto.js | 31 ++++++++++++++ examples/client_auto/package.json | 8 ++++ src/createClientAuto.js | 64 +++++++++++++++++++++++++++++ src/index.js | 2 + 5 files changed, 110 insertions(+) create mode 100644 examples/client_auto/client_auto.js create mode 100644 examples/client_auto/package.json create mode 100644 src/createClientAuto.js diff --git a/doc/README.md b/doc/README.md index daca5a1..c109899 100644 --- a/doc/README.md +++ b/doc/README.md @@ -75,6 +75,11 @@ Returns a `Client` instance and perform login. * checkTimeoutInterval : default to `10*1000` (10s), check if keepalive received at that period, disconnect otherwise. * version : 1.8 or 1.9 : default to 1.8 +## mc.createClientAuto(options, cb) + +Pings the server and attempts to call `createClient(options)` with the appropriate protocol version. +When created, calls the callback `cb(err, client)`. + ## mc.Client(isServer,version) Create a new client, if `isServer` is true then it is a server-side client, otherwise it's a client-side client. diff --git a/examples/client_auto/client_auto.js b/examples/client_auto/client_auto.js new file mode 100644 index 0000000..0af381f --- /dev/null +++ b/examples/client_auto/client_auto.js @@ -0,0 +1,31 @@ +var mc = require('minecraft-protocol'); + +if(process.argv.length < 4 || process.argv.length > 6) { + console.log("Usage : node echo.js [] []"); + process.exit(1); +} + +mc.createClientAuto({ + host: process.argv[2], + port: parseInt(process.argv[3]), + username: process.argv[4] ? process.argv[4] : "echo", + password: process.argv[5] +}, function(err, client) { + if (err) throw err; + + client.on('connect', function() { + console.info('connected'); + }); + client.on('disconnect', function(packet) { + console.log('disconnected: '+ packet.reason); + }); + client.on('chat', function(packet) { + var jsonMsg = JSON.parse(packet.message); + if(jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') { + var username = jsonMsg.with[0].text; + var msg = jsonMsg.with[1]; + if(username === client.username) return; + client.write('chat', {message: msg}); + } + }); +}); diff --git a/examples/client_auto/package.json b/examples/client_auto/package.json new file mode 100644 index 0000000..56fcdf2 --- /dev/null +++ b/examples/client_auto/package.json @@ -0,0 +1,8 @@ +{ + "name": "node-minecraft-protocol-example", + "version": "0.0.0", + "private": true, + "dependencies": { + }, + "description": "A node-minecraft-protocol example" +} diff --git a/src/createClientAuto.js b/src/createClientAuto.js new file mode 100644 index 0000000..209fe36 --- /dev/null +++ b/src/createClientAuto.js @@ -0,0 +1,64 @@ +'use strict'; + +var ping = require('./ping'); +var assert = require('assert'); +var debug = require('./debug'); +var createClient = require('./createClient'); + +// see http://wiki.vg/Protocol_version_numbers +// Get the minecraft-data version string for a protocol version +// TODO: switch to using https://github.com/PrismarineJS/minecraft-data/pull/92 +function protocol2version(n) { + if (n >= 48) return '1.9'; // 1.9 snapshots (15w+), 16w03a is 96 + if (n >= 6 && n <= 47) return '1.8.9'; // including 1.8 snapshots (14w) + if (n >= 4 && n <= 5) return '1.7.10'; // including 1.7 prereleases + // TODO: earlier versions "Beginning with the 1.7.1 pre-release (and release 1.7.2), versioning was reset." + throw new Error(`unsupported/unknown protocol version: ${versionProtocol}, update protocol2version`); +} + +function createClientAsync(options, cb) { + assert.ok(options, 'options is required'); + + 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 + ping(options, function(err, response) { + var client; + + if (err) return cb(err, null); + debug('ping response',response); + // TODO: could also use ping pre-connect to save description, type, negotiate protocol etc. + // ^ see https://github.com/PrismarineJS/node-minecraft-protocol/issues/327 + var motd = response.description; + debug('Server description:',motd); // TODO: save + + // Pass server-reported version to protocol handler + // The version string is interpereted by https://github.com/PrismarineJS/node-minecraft-data + var versionName = response.version.name; // 1.8.9, 1.7.10 + var versionProtocol = response.version.protocol;// 47, 5 + + debug(`Server version: ${versionName}, protocol: ${versionProtocol}`); + // 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. + options.version = protocol2version(versionProtocol); + + // Use the exact same protocol version + // Requires https://github.com/PrismarineJS/node-minecraft-protocol/pull/330 + options.protocolVersion = versionProtocol; + + if (response.modinfo && response.modinfo.type === 'FML') { + // Use the list of Forge mods from the server ping, so client will match server + var forgeMods = response.modinfo.modList; + debug('Using forgeMods:',forgeMods); + // TODO: https://github.com/PrismarineJS/node-minecraft-protocol/issues/114 + // https://github.com/PrismarineJS/node-minecraft-protocol/pull/326 + throw new Error('FML/Forge not yet supported'); + } else { + client = createClient(options); // vanilla + } + cb(null, client); + }); +} + +module.exports = createClientAsync; diff --git a/src/index.js b/src/index.js index 8d90027..697c657 100644 --- a/src/index.js +++ b/src/index.js @@ -2,10 +2,12 @@ var Client = require('./client'); var Server = require('./server'); var serializer = require("./transforms/serializer"); var createClient = require("./createClient"); +var createClientAuto = require("./createClientAuto"); var createServer = require("./createServer"); module.exports = { createClient: createClient, + createClientAuto: createClientAuto, createServer: createServer, Client: Client, Server: Server, From 9ec6d876ba386c2a33ce197f54f6d900c0e80c97 Mon Sep 17 00:00:00 2001 From: deathcap Date: Thu, 28 Jan 2016 09:49:35 -0800 Subject: [PATCH 02/22] 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. --- src/client/setProtocol.js | 10 ++++++++-- src/createClientAuto.js | 12 ++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/client/setProtocol.js b/src/client/setProtocol.js index 865b44e..4948b1c 100644 --- a/src/client/setProtocol.js +++ b/src/client/setProtocol.js @@ -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 }); } - - } diff --git a/src/createClientAuto.js b/src/createClientAuto.js index 209fe36..62f7e29 100644 --- a/src/createClientAuto.js +++ b/src/createClientAuto.js @@ -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); }); } From 00bf6acea9452288e00714453a9918eaeaf4c068 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 30 Jan 2016 22:09:25 -0800 Subject: [PATCH 03/22] Fix unintentional var client declaration --- src/createClientAuto.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/createClientAuto.js b/src/createClientAuto.js index 62f7e29..dc9fbd1 100644 --- a/src/createClientAuto.js +++ b/src/createClientAuto.js @@ -26,8 +26,6 @@ function createClientAsync(options, cb) { // TODO: refactor with DNS SRV lookup in NMP // TODO: detect ping timeout, https://github.com/PrismarineJS/node-minecraft-protocol/issues/329 ping(options, function(err, response) { - var client; - if (err) return cb(err, null); debug('ping response',response); // TODO: could also use ping pre-connect to save description, type, negotiate protocol etc. From 66e6f4dd0b2549707398a2ea32675776ec5c330a Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 30 Jan 2016 22:14:13 -0800 Subject: [PATCH 04/22] Update to use compatible sync API (createClient) --- doc/README.md | 3 +-- examples/client_auto/client_auto.js | 36 ++++++++++++++--------------- src/createClientAuto.js | 10 ++++---- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/doc/README.md b/doc/README.md index c109899..68b54b7 100644 --- a/doc/README.md +++ b/doc/README.md @@ -75,10 +75,9 @@ Returns a `Client` instance and perform login. * checkTimeoutInterval : default to `10*1000` (10s), check if keepalive received at that period, disconnect otherwise. * version : 1.8 or 1.9 : default to 1.8 -## mc.createClientAuto(options, cb) +## mc.createClientAuto(options) Pings the server and attempts to call `createClient(options)` with the appropriate protocol version. -When created, calls the callback `cb(err, client)`. ## mc.Client(isServer,version) diff --git a/examples/client_auto/client_auto.js b/examples/client_auto/client_auto.js index 0af381f..99701ae 100644 --- a/examples/client_auto/client_auto.js +++ b/examples/client_auto/client_auto.js @@ -5,27 +5,25 @@ if(process.argv.length < 4 || process.argv.length > 6) { process.exit(1); } -mc.createClientAuto({ +var client = mc.createClientAuto({ host: process.argv[2], port: parseInt(process.argv[3]), username: process.argv[4] ? process.argv[4] : "echo", password: process.argv[5] -}, function(err, client) { - if (err) throw err; - - client.on('connect', function() { - console.info('connected'); - }); - client.on('disconnect', function(packet) { - console.log('disconnected: '+ packet.reason); - }); - client.on('chat', function(packet) { - var jsonMsg = JSON.parse(packet.message); - if(jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') { - var username = jsonMsg.with[0].text; - var msg = jsonMsg.with[1]; - if(username === client.username) return; - client.write('chat', {message: msg}); - } - }); +}); + +client.on('connect', function() { + console.info('connected'); +}); +client.on('disconnect', function(packet) { + console.log('disconnected: '+ packet.reason); +}); +client.on('chat', function(packet) { + var jsonMsg = JSON.parse(packet.message); + if(jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') { + var username = jsonMsg.with[0].text; + var msg = jsonMsg.with[1]; + if(username === client.username) return; + client.write('chat', {message: msg}); + } }); diff --git a/src/createClientAuto.js b/src/createClientAuto.js index dc9fbd1..95c5ab6 100644 --- a/src/createClientAuto.js +++ b/src/createClientAuto.js @@ -16,7 +16,7 @@ function protocol2version(n) { throw new Error(`unsupported/unknown protocol version: ${versionProtocol}, update protocol2version`); } -function createClientAsync(options, cb) { +function createClientAuto(options) { assert.ok(options, 'options is required'); debug('creating client'); @@ -26,7 +26,7 @@ function createClientAsync(options, cb) { // TODO: refactor with DNS SRV lookup in NMP // TODO: detect ping timeout, https://github.com/PrismarineJS/node-minecraft-protocol/issues/329 ping(options, function(err, response) { - if (err) return cb(err, null); + if (err) throw err; // hmm debug('ping response',response); // TODO: could also use ping pre-connect to save description, type, negotiate protocol etc. // ^ see https://github.com/PrismarineJS/node-minecraft-protocol/issues/327 @@ -61,10 +61,8 @@ function createClientAsync(options, cb) { } // done configuring client object, let connection proceed client.emit('connect_allowed'); - - - cb(null, client); }); + return client; } -module.exports = createClientAsync; +module.exports = createClientAuto; From 89198c62ff2826057fda8858d814117e1b305e98 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 30 Jan 2016 22:27:36 -0800 Subject: [PATCH 05/22] Use minecraft-data for protocol version -> minecraft version --- src/createClientAuto.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/createClientAuto.js b/src/createClientAuto.js index 95c5ab6..509d72c 100644 --- a/src/createClientAuto.js +++ b/src/createClientAuto.js @@ -4,16 +4,21 @@ var ping = require('./ping'); var assert = require('assert'); var debug = require('./debug'); var createClient = require('./createClient'); +var minecraft_data = require('minecraft-data'); -// see http://wiki.vg/Protocol_version_numbers // Get the minecraft-data version string for a protocol version -// TODO: switch to using https://github.com/PrismarineJS/minecraft-data/pull/92 -function protocol2version(n) { - if (n >= 48) return '1.9'; // 1.9 snapshots (15w+), 16w03a is 96 - if (n >= 6 && n <= 47) return '1.8.9'; // including 1.8 snapshots (14w) - if (n >= 4 && n <= 5) return '1.7.10'; // including 1.7 prereleases - // TODO: earlier versions "Beginning with the 1.7.1 pre-release (and release 1.7.2), versioning was reset." - throw new Error(`unsupported/unknown protocol version: ${versionProtocol}, update protocol2version`); +// TODO: add to node-minecraft-data index (protocol to newest release, if multiple) +function protocolVersion2MinecraftVersion(n) { + var usesNetty = n > 0; + for (var i = 0; i < minecraft_data.versions.length; ++i) { + var version = minecraft_data.versions[i]; + if (version.version === Math.abs(n) && version.usesNetty === usesNetty) { + console.log(version); + return version.minecraftVersion; + } + } + + throw new Error(`unsupported/unknown protocol version: ${n}, update minecraft-data`); } function createClientAuto(options) { @@ -35,20 +40,20 @@ function createClientAuto(options) { // Pass server-reported version to protocol handler // The version string is interpereted by https://github.com/PrismarineJS/node-minecraft-data - var versionName = response.version.name; // 1.8.9, 1.7.10 - var versionProtocol = response.version.protocol;// 47, 5 + var minecraftVersion = response.version.name; // 1.8.9, 1.7.10 + var protocolVersion = response.version.protocol;// 47, 5 - debug(`Server version: ${versionName}, protocol: ${versionProtocol}`); + debug(`Server version: ${minecraftVersion}, protocol: ${protocolVersion}`); // 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); + options.version = protocolVersion2MinecraftVersion(protocolVersion); // Use the exact same protocol version // Requires https://github.com/PrismarineJS/node-minecraft-protocol/pull/330 //XXX TODO: modify client objecti - options.protocolVersion = versionProtocol; + options.protocolVersion = protocolVersion; if (response.modinfo && response.modinfo.type === 'FML') { // Use the list of Forge mods from the server ping, so client will match server From ea3b306988e1ab9995013e48f4e384fc00a0a001 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 30 Jan 2016 22:31:10 -0800 Subject: [PATCH 06/22] Move options to client object This allows client plugins to change the options on the client object, and have it reflected in other plugins. Previously, had to rely on the options being the same object, and hold a reference to it. Now it is always accessible as `client.options`. --- src/client/caseCorrect.js | 3 ++- src/client/compress.js | 2 +- src/client/encrypt.js | 3 ++- src/client/keepalive.js | 3 ++- src/client/play.js | 2 +- src/client/setProtocol.js | 3 ++- src/client/tcp_dns.js | 3 ++- src/createClient.js | 15 ++++++++------- src/createClientAuto.js | 6 ++---- src/ping.js | 3 ++- 10 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/client/caseCorrect.js b/src/client/caseCorrect.js index 2eb634a..e8a42d8 100644 --- a/src/client/caseCorrect.js +++ b/src/client/caseCorrect.js @@ -1,7 +1,8 @@ var yggdrasil = require('yggdrasil')({}); var UUID = require('uuid-1345'); -module.exports = function(client, options) { +module.exports = function(client) { + var options = client.options; var clientToken = options.clientToken || UUID.v4().toString(); options.accessToken = null; options.haveCredentials = options.password != null || (clientToken != null && options.session != null); diff --git a/src/client/compress.js b/src/client/compress.js index cebe34f..40d092f 100644 --- a/src/client/compress.js +++ b/src/client/compress.js @@ -1,4 +1,4 @@ -module.exports = function(client, options) { +module.exports = function(client) { client.once("compress", onCompressionRequest); client.on("set_compression", onCompressionRequest); diff --git a/src/client/encrypt.js b/src/client/encrypt.js index 696ddfc..10b391c 100644 --- a/src/client/encrypt.js +++ b/src/client/encrypt.js @@ -3,7 +3,8 @@ var yggserver = require('yggdrasil').server({}); var ursa=require("../ursa"); var debug = require("../debug"); -module.exports = function(client, options) { +module.exports = function(client) { + var options = client.options; client.once('encryption_begin', onEncryptionKeyRequest); function onEncryptionKeyRequest(packet) { diff --git a/src/client/keepalive.js b/src/client/keepalive.js index 3fc817b..5b206cf 100644 --- a/src/client/keepalive.js +++ b/src/client/keepalive.js @@ -1,4 +1,5 @@ -module.exports = function(client, options) { +module.exports = function(client) { + var options = client.options; var keepAlive = options.keepAlive == null ? true : options.keepAlive; if (!keepAlive) return; diff --git a/src/client/play.js b/src/client/play.js index ebc491e..efcf84b 100644 --- a/src/client/play.js +++ b/src/client/play.js @@ -1,6 +1,6 @@ var states = require("../states"); -module.exports = function(client, options) { +module.exports = function(client) { client.once('success', onLogin); function onLogin(packet) { diff --git a/src/client/setProtocol.js b/src/client/setProtocol.js index 4948b1c..0c5b7db 100644 --- a/src/client/setProtocol.js +++ b/src/client/setProtocol.js @@ -1,7 +1,8 @@ var states = require("../states"); -module.exports = function(client, options) { +module.exports = function(client) { + var options = client.options; client.on('connect', onConnect); function onConnect() { diff --git a/src/client/tcp_dns.js b/src/client/tcp_dns.js index a8e3060..2863962 100644 --- a/src/client/tcp_dns.js +++ b/src/client/tcp_dns.js @@ -1,7 +1,8 @@ var net = require('net'); var dns = require('dns'); -module.exports = function(client, options) { +module.exports = function(client) { + var options = client.options; options.port = options.port || 25565; options.host = options.host || 'localhost'; diff --git a/src/createClient.js b/src/createClient.js index 40a3d13..5d7c342 100644 --- a/src/createClient.js +++ b/src/createClient.js @@ -22,14 +22,15 @@ function createClient(options) { options.protocolVersion = version.version; var client = new Client(false, options.majorVersion); + client.options = options; - tcp_dns(client, options); - setProtocol(client, options); - keepalive(client, options); - encrypt(client, options); - play(client, options); - compress(client, options); - caseCorrect(client, options); + tcp_dns(client); + setProtocol(client); + keepalive(client); + encrypt(client); + play(client); + compress(client); + caseCorrect(client); return client; } diff --git a/src/createClientAuto.js b/src/createClientAuto.js index 509d72c..b307157 100644 --- a/src/createClientAuto.js +++ b/src/createClientAuto.js @@ -47,13 +47,11 @@ function createClientAuto(options) { // 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 = protocolVersion2MinecraftVersion(protocolVersion); + client.options.version = protocolVersion2MinecraftVersion(protocolVersion); // Use the exact same protocol version // Requires https://github.com/PrismarineJS/node-minecraft-protocol/pull/330 - //XXX TODO: modify client objecti - options.protocolVersion = protocolVersion; + client.options.protocolVersion = protocolVersion; if (response.modinfo && response.modinfo.type === 'FML') { // Use the list of Forge mods from the server ping, so client will match server diff --git a/src/ping.js b/src/ping.js index 4a58353..1e6adcb 100644 --- a/src/ping.js +++ b/src/ping.js @@ -15,6 +15,7 @@ function ping(options, cb) { options.protocolVersion = version.version; var client = new Client(false,options.majorVersion); + client.options = options; client.on('error', function(err) { cb(err); }); @@ -46,6 +47,6 @@ function ping(options, cb) { client.state = states.STATUS; }); - tcp_dns(client, options); + tcp_dns(client); options.connect(client); } From af62189e19791808f737ba4322c26f999bf792ac Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 30 Jan 2016 22:34:26 -0800 Subject: [PATCH 07/22] Rename src/createClientAuto.js -> src/client/autoVersion.js --- src/{createClientAuto.js => client/autoVersion.js} | 1 - 1 file changed, 1 deletion(-) rename src/{createClientAuto.js => client/autoVersion.js} (98%) diff --git a/src/createClientAuto.js b/src/client/autoVersion.js similarity index 98% rename from src/createClientAuto.js rename to src/client/autoVersion.js index b307157..b88463f 100644 --- a/src/createClientAuto.js +++ b/src/client/autoVersion.js @@ -28,7 +28,6 @@ function createClientAuto(options) { 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 ping(options, function(err, response) { if (err) throw err; // hmm From 163e2157fc6d0d513396a877164c1dff9b6c82e9 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 30 Jan 2016 22:49:57 -0800 Subject: [PATCH 08/22] Remove useless statement --- src/client.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/client.js b/src/client.js index 8a0a129..356ab53 100644 --- a/src/client.js +++ b/src/client.js @@ -25,7 +25,6 @@ class Client extends EventEmitter this.decompressor=null; this.deserializer; this.isServer; - this.version; this.protocolState=states.HANDSHAKING; this.ended=true; this.latency=0; From 9a68fd6c34fc99f3dcf20f8582fe482609d28dba Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 30 Jan 2016 22:50:24 -0800 Subject: [PATCH 09/22] Support options.version==false in createClient() to auto-detect version --- examples/client_auto/client_auto.js | 2 +- src/client/autoVersion.js | 24 +++++++++++++----------- src/createClient.js | 6 +++++- src/index.js | 2 -- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/examples/client_auto/client_auto.js b/examples/client_auto/client_auto.js index 99701ae..fdc586d 100644 --- a/examples/client_auto/client_auto.js +++ b/examples/client_auto/client_auto.js @@ -5,7 +5,7 @@ if(process.argv.length < 4 || process.argv.length > 6) { process.exit(1); } -var client = mc.createClientAuto({ +var client = mc.createClient({version: false, host: process.argv[2], port: parseInt(process.argv[3]), username: process.argv[4] ? process.argv[4] : "echo", diff --git a/src/client/autoVersion.js b/src/client/autoVersion.js index b88463f..83cae2c 100644 --- a/src/client/autoVersion.js +++ b/src/client/autoVersion.js @@ -1,9 +1,9 @@ 'use strict'; -var ping = require('./ping'); +var ping = require('../ping'); +var debug = require('../debug'); +var states = require('../states'); var assert = require('assert'); -var debug = require('./debug'); -var createClient = require('./createClient'); var minecraft_data = require('minecraft-data'); // Get the minecraft-data version string for a protocol version @@ -14,19 +14,18 @@ function protocolVersion2MinecraftVersion(n) { var version = minecraft_data.versions[i]; if (version.version === Math.abs(n) && version.usesNetty === usesNetty) { console.log(version); - return version.minecraftVersion; + return [version.minecraftVersion, version.majorVersion]; } } throw new Error(`unsupported/unknown protocol version: ${n}, update minecraft-data`); } -function createClientAuto(options) { - assert.ok(options, 'options is required'); +module.exports = function(client) { + var options = client.options; 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 + options.wait_connect = true; // don't let src/client/setProtocol proceed on socket 'connect' until 'connect_allowed' debug('pinging',options.host); // TODO: detect ping timeout, https://github.com/PrismarineJS/node-minecraft-protocol/issues/329 ping(options, function(err, response) { @@ -46,12 +45,17 @@ function createClientAuto(options) { // 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. - client.options.version = protocolVersion2MinecraftVersion(protocolVersion); + var [minecraftVersion, majorVersion] = protocolVersion2MinecraftVersion(protocolVersion); + client.options.version = minecraftVersion; // Use the exact same protocol version // Requires https://github.com/PrismarineJS/node-minecraft-protocol/pull/330 client.options.protocolVersion = protocolVersion; + // reinitialize client object with new version TODO: move out of its constructor + client.version = majorVersion; + client.setSerializer(states.HANDSHAKING); + if (response.modinfo && response.modinfo.type === 'FML') { // Use the list of Forge mods from the server ping, so client will match server var forgeMods = response.modinfo.modList; @@ -66,5 +70,3 @@ function createClientAuto(options) { }); return client; } - -module.exports = createClientAuto; diff --git a/src/createClient.js b/src/createClient.js index 5d7c342..0a68c7c 100644 --- a/src/createClient.js +++ b/src/createClient.js @@ -8,6 +8,7 @@ var caseCorrect = require('./client/caseCorrect'); var setProtocol = require('./client/setProtocol'); var play = require('./client/play'); var tcp_dns = require('./client/tcp_dns'); +var autoVersion = require('./client/autoVersion'); module.exports=createClient; @@ -15,8 +16,10 @@ function createClient(options) { assert.ok(options, "options is required"); assert.ok(options.username, "username is required"); + // TODO: avoid setting default version if autoVersion is enabled var optVersion = options.version || require("./version").defaultVersion; var mcData=require("minecraft-data")(optVersion); + if (!mcData) throw new Error(`unsupported protocol version: ${optVersion}`); var version = mcData.version; options.majorVersion = version.majorVersion; options.protocolVersion = version.version; @@ -25,12 +28,13 @@ function createClient(options) { client.options = options; tcp_dns(client); + caseCorrect(client); + if (options.version === false) autoVersion(client); setProtocol(client); keepalive(client); encrypt(client); play(client); compress(client); - caseCorrect(client); return client; } diff --git a/src/index.js b/src/index.js index 697c657..8d90027 100644 --- a/src/index.js +++ b/src/index.js @@ -2,12 +2,10 @@ var Client = require('./client'); var Server = require('./server'); var serializer = require("./transforms/serializer"); var createClient = require("./createClient"); -var createClientAuto = require("./createClientAuto"); var createServer = require("./createServer"); module.exports = { createClient: createClient, - createClientAuto: createClientAuto, createServer: createServer, Client: Client, Server: Server, From d0f64e9c65c9d03ab13d2cb33d17e5f4f61b9816 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 31 Jan 2016 12:20:51 -0800 Subject: [PATCH 10/22] Set state property instead of setSerializer() to ensure serializers are properly piped --- src/client/autoVersion.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/autoVersion.js b/src/client/autoVersion.js index 83cae2c..86e3d6a 100644 --- a/src/client/autoVersion.js +++ b/src/client/autoVersion.js @@ -54,7 +54,7 @@ module.exports = function(client) { // reinitialize client object with new version TODO: move out of its constructor client.version = majorVersion; - client.setSerializer(states.HANDSHAKING); + client.state = states.HANDSHAKING; if (response.modinfo && response.modinfo.type === 'FML') { // Use the list of Forge mods from the server ping, so client will match server From f17de6410b34b6f6bd8bbea7953130e9eee26c97 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 31 Jan 2016 12:26:03 -0800 Subject: [PATCH 11/22] Use new object for ping() to avoid potential cross-contamination --- src/client/autoVersion.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/autoVersion.js b/src/client/autoVersion.js index 86e3d6a..5a41b2b 100644 --- a/src/client/autoVersion.js +++ b/src/client/autoVersion.js @@ -24,11 +24,11 @@ function protocolVersion2MinecraftVersion(n) { module.exports = function(client) { var options = client.options; - debug('creating client'); options.wait_connect = true; // don't let src/client/setProtocol proceed on socket 'connect' until 'connect_allowed' debug('pinging',options.host); - // TODO: detect ping timeout, https://github.com/PrismarineJS/node-minecraft-protocol/issues/329 - ping(options, function(err, response) { + var pingOptions = {host: options.host, port: options.port}; + // TODO: use 0xfe ping instead for better compatibility/performance? https://github.com/deathcap/node-minecraft-ping + ping(pingOptions, function(err, response) { if (err) throw err; // hmm debug('ping response',response); // TODO: could also use ping pre-connect to save description, type, negotiate protocol etc. From 2e2a213076e284d2ce7e76578b75843936077f69 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 31 Jan 2016 12:28:25 -0800 Subject: [PATCH 12/22] Update client connect() for options move compatibility --- src/client.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/client.js b/src/client.js index 356ab53..8668f62 100644 --- a/src/client.js +++ b/src/client.js @@ -218,6 +218,7 @@ class Client extends EventEmitter // TCP/IP-specific (not generic Stream) method for backwards-compatibility connect(port, host) { var options = {port, host}; + if (!this.options) this.options = options; require('./client/tcp_dns')(this, options); options.connect(this); } From 88e8374ad43955905143a54e7a54e91099067528 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 31 Jan 2016 12:44:06 -0800 Subject: [PATCH 13/22] Update documentation for version:false option --- doc/README.md | 6 +----- src/client/autoVersion.js | 10 +++------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/doc/README.md b/doc/README.md index 68b54b7..f87a864 100644 --- a/doc/README.md +++ b/doc/README.md @@ -73,11 +73,7 @@ Returns a `Client` instance and perform login. * accessToken : generated if a password is given * keepAlive : send keep alive packets : default to true * checkTimeoutInterval : default to `10*1000` (10s), check if keepalive received at that period, disconnect otherwise. - * version : 1.8 or 1.9 : default to 1.8 - -## mc.createClientAuto(options) - -Pings the server and attempts to call `createClient(options)` with the appropriate protocol version. + * version : 1.8 or 1.9 or false (to auto-negotiate): default to 1.8 ## mc.Client(isServer,version) diff --git a/src/client/autoVersion.js b/src/client/autoVersion.js index 5a41b2b..6d58a87 100644 --- a/src/client/autoVersion.js +++ b/src/client/autoVersion.js @@ -31,8 +31,7 @@ module.exports = function(client) { ping(pingOptions, function(err, response) { if (err) throw err; // hmm debug('ping response',response); - // TODO: could also use ping pre-connect to save description, type, negotiate protocol etc. - // ^ see https://github.com/PrismarineJS/node-minecraft-protocol/issues/327 + // TODO: could also use ping pre-connect to save description, type, max players, etc. var motd = response.description; debug('Server description:',motd); // TODO: save @@ -47,12 +46,9 @@ module.exports = function(client) { // even though it is in a format accepted by minecraft-data. Instead, translate the protocol. var [minecraftVersion, majorVersion] = protocolVersion2MinecraftVersion(protocolVersion); client.options.version = minecraftVersion; - - // Use the exact same protocol version - // Requires https://github.com/PrismarineJS/node-minecraft-protocol/pull/330 client.options.protocolVersion = protocolVersion; - // reinitialize client object with new version TODO: move out of its constructor + // Reinitialize client object with new version TODO: move out of its constructor? client.version = majorVersion; client.state = states.HANDSHAKING; @@ -65,7 +61,7 @@ module.exports = function(client) { // TODO: modify client object to set forgeMods and enable forgeHandshake throw new Error('FML/Forge not yet supported'); } - // done configuring client object, let connection proceed + // Finished configuring client object, let connection proceed client.emit('connect_allowed'); }); return client; From ddcca012efc5e4c44b9a05ec2eb1e339f4f7f981 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 31 Jan 2016 12:48:39 -0800 Subject: [PATCH 14/22] Pre-Netty protocol versions are not supported yet --- src/client/autoVersion.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/client/autoVersion.js b/src/client/autoVersion.js index 6d58a87..57c76ea 100644 --- a/src/client/autoVersion.js +++ b/src/client/autoVersion.js @@ -9,11 +9,10 @@ var minecraft_data = require('minecraft-data'); // Get the minecraft-data version string for a protocol version // TODO: add to node-minecraft-data index (protocol to newest release, if multiple) function protocolVersion2MinecraftVersion(n) { - var usesNetty = n > 0; + var usesNetty = true; // for now, only Netty protocols are supported TODO: pre-Netty (beware, colliding protocol version numbers) for (var i = 0; i < minecraft_data.versions.length; ++i) { var version = minecraft_data.versions[i]; - if (version.version === Math.abs(n) && version.usesNetty === usesNetty) { - console.log(version); + if (version.version === n && version.usesNetty === usesNetty) { return [version.minecraftVersion, version.majorVersion]; } } From 84c4c26503e544f542c5e114c80c1a85e2c5e688 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 31 Jan 2016 20:11:15 -0800 Subject: [PATCH 15/22] Update to minecraft-data ^0.19.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fd3abd5..8f07055 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ }, "dependencies": { "buffer-equal": "0.0.1", - "minecraft-data": "^0.16.1", + "minecraft-data": "^0.19.0", "prismarine-nbt": "0.1.0", "protodef": "0.2.5", "readable-stream": "^1.1.0", From 4b3f8b5b0924eb82cb7e89fb30883a81e3f20623 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 31 Jan 2016 20:39:01 -0800 Subject: [PATCH 16/22] Update minecraft-data to use GitHub dependency on PrismarineJS/node-minecraft-data --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8f07055..d3a14e2 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ }, "dependencies": { "buffer-equal": "0.0.1", - "minecraft-data": "^0.19.0", + "minecraft-data": "PrismarineJS/node-minecraft-data", "prismarine-nbt": "0.1.0", "protodef": "0.2.5", "readable-stream": "^1.1.0", From aa3ae329758eed114c382e56459a552a489b5a2c Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 31 Jan 2016 20:50:57 -0800 Subject: [PATCH 17/22] Try using git commit hash to node-minecraft-data --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d3a14e2..1ad175d 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ }, "dependencies": { "buffer-equal": "0.0.1", - "minecraft-data": "PrismarineJS/node-minecraft-data", + "minecraft-data": "git://github.com/prismarinejs/node-minecraft-data.git#4e7f910e62ea30c641a9df2170275d49bbd1edad", "prismarine-nbt": "0.1.0", "protodef": "0.2.5", "readable-stream": "^1.1.0", From 070a046eea4beb5280a12015828b4393ecb7e850 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sun, 31 Jan 2016 21:07:14 -0800 Subject: [PATCH 18/22] Try to clone minecraft-data to workaround https://github.com/PrismarineJS/node-minecraft-data/issues/16 --- circle.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/circle.yml b/circle.yml index 824c958..6a35cba 100644 --- a/circle.yml +++ b/circle.yml @@ -8,3 +8,4 @@ machine: dependencies: pre: - mkdir minecraft-server + - git clone https://github.com/PrismarineJS/minecraft-data node_modules/minecraft-data/minecraft-data || true From c2913daae023196bc8d14c54fbd35c2608006ad0 Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 1 Feb 2016 09:48:12 -0800 Subject: [PATCH 19/22] Update to minecraft-data ^0.19.1 --- circle.yml | 1 - package.json | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/circle.yml b/circle.yml index 6a35cba..824c958 100644 --- a/circle.yml +++ b/circle.yml @@ -8,4 +8,3 @@ machine: dependencies: pre: - mkdir minecraft-server - - git clone https://github.com/PrismarineJS/minecraft-data node_modules/minecraft-data/minecraft-data || true diff --git a/package.json b/package.json index 1ad175d..55de5fd 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ }, "dependencies": { "buffer-equal": "0.0.1", - "minecraft-data": "git://github.com/prismarinejs/node-minecraft-data.git#4e7f910e62ea30c641a9df2170275d49bbd1edad", + "minecraft-data": "^0.19.1", "prismarine-nbt": "0.1.0", "protodef": "0.2.5", "readable-stream": "^1.1.0", From 58fd1eab35ff9e7afd221d4afb3c263c953f82df Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 1 Feb 2016 21:02:42 -0800 Subject: [PATCH 20/22] Lookup version using minecraft-data postNettyVersionsByProtocolVersion --- src/client/autoVersion.js | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/client/autoVersion.js b/src/client/autoVersion.js index 57c76ea..8cdf0e4 100644 --- a/src/client/autoVersion.js +++ b/src/client/autoVersion.js @@ -6,20 +6,6 @@ var states = require('../states'); var assert = require('assert'); var minecraft_data = require('minecraft-data'); -// Get the minecraft-data version string for a protocol version -// TODO: add to node-minecraft-data index (protocol to newest release, if multiple) -function protocolVersion2MinecraftVersion(n) { - var usesNetty = true; // for now, only Netty protocols are supported TODO: pre-Netty (beware, colliding protocol version numbers) - for (var i = 0; i < minecraft_data.versions.length; ++i) { - var version = minecraft_data.versions[i]; - if (version.version === n && version.usesNetty === usesNetty) { - return [version.minecraftVersion, version.majorVersion]; - } - } - - throw new Error(`unsupported/unknown protocol version: ${n}, update minecraft-data`); -} - module.exports = function(client) { var options = client.options; @@ -43,12 +29,15 @@ module.exports = function(client) { // 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. - var [minecraftVersion, majorVersion] = protocolVersion2MinecraftVersion(protocolVersion); - client.options.version = minecraftVersion; + // TODO: pre-Netty version support (uses overlapping version numbers, so would have to check versionName) + var versionInfos = minecraft_data.postNettyVersionsByProtocolVersion[protocolVersion]; + if (!versionInfos && versionInfos.length < 1) throw new Error(`unsupported/unknown protocol version: ${protocolVersion}, update minecraft-data`); + var versionInfo = versionInfos[0]; // use newest + client.options.version = versionInfo.minecraftVersion; client.options.protocolVersion = protocolVersion; // Reinitialize client object with new version TODO: move out of its constructor? - client.version = majorVersion; + client.version = versionInfo.majorVersion; client.state = states.HANDSHAKING; if (response.modinfo && response.modinfo.type === 'FML') { From a8bc7d134365e1aa26226c165b6642fc87b76644 Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 1 Feb 2016 21:07:32 -0800 Subject: [PATCH 21/22] Move options back to client parameters --- src/client/autoVersion.js | 8 +++----- src/client/caseCorrect.js | 3 +-- src/client/compress.js | 2 +- src/client/encrypt.js | 3 +-- src/client/keepalive.js | 3 +-- src/client/play.js | 2 +- src/client/setProtocol.js | 3 +-- src/client/tcp_dns.js | 3 +-- src/createClient.js | 17 ++++++++--------- src/ping.js | 3 +-- 10 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/client/autoVersion.js b/src/client/autoVersion.js index 8cdf0e4..3051403 100644 --- a/src/client/autoVersion.js +++ b/src/client/autoVersion.js @@ -6,9 +6,7 @@ var states = require('../states'); var assert = require('assert'); var minecraft_data = require('minecraft-data'); -module.exports = function(client) { - var options = client.options; - +module.exports = function(client, options) { options.wait_connect = true; // don't let src/client/setProtocol proceed on socket 'connect' until 'connect_allowed' debug('pinging',options.host); var pingOptions = {host: options.host, port: options.port}; @@ -33,8 +31,8 @@ module.exports = function(client) { var versionInfos = minecraft_data.postNettyVersionsByProtocolVersion[protocolVersion]; if (!versionInfos && versionInfos.length < 1) throw new Error(`unsupported/unknown protocol version: ${protocolVersion}, update minecraft-data`); var versionInfo = versionInfos[0]; // use newest - client.options.version = versionInfo.minecraftVersion; - client.options.protocolVersion = protocolVersion; + options.version = versionInfo.minecraftVersion; + options.protocolVersion = protocolVersion; // Reinitialize client object with new version TODO: move out of its constructor? client.version = versionInfo.majorVersion; diff --git a/src/client/caseCorrect.js b/src/client/caseCorrect.js index e8a42d8..2eb634a 100644 --- a/src/client/caseCorrect.js +++ b/src/client/caseCorrect.js @@ -1,8 +1,7 @@ var yggdrasil = require('yggdrasil')({}); var UUID = require('uuid-1345'); -module.exports = function(client) { - var options = client.options; +module.exports = function(client, options) { var clientToken = options.clientToken || UUID.v4().toString(); options.accessToken = null; options.haveCredentials = options.password != null || (clientToken != null && options.session != null); diff --git a/src/client/compress.js b/src/client/compress.js index 40d092f..cebe34f 100644 --- a/src/client/compress.js +++ b/src/client/compress.js @@ -1,4 +1,4 @@ -module.exports = function(client) { +module.exports = function(client, options) { client.once("compress", onCompressionRequest); client.on("set_compression", onCompressionRequest); diff --git a/src/client/encrypt.js b/src/client/encrypt.js index 10b391c..696ddfc 100644 --- a/src/client/encrypt.js +++ b/src/client/encrypt.js @@ -3,8 +3,7 @@ var yggserver = require('yggdrasil').server({}); var ursa=require("../ursa"); var debug = require("../debug"); -module.exports = function(client) { - var options = client.options; +module.exports = function(client, options) { client.once('encryption_begin', onEncryptionKeyRequest); function onEncryptionKeyRequest(packet) { diff --git a/src/client/keepalive.js b/src/client/keepalive.js index 5b206cf..3fc817b 100644 --- a/src/client/keepalive.js +++ b/src/client/keepalive.js @@ -1,5 +1,4 @@ -module.exports = function(client) { - var options = client.options; +module.exports = function(client, options) { var keepAlive = options.keepAlive == null ? true : options.keepAlive; if (!keepAlive) return; diff --git a/src/client/play.js b/src/client/play.js index efcf84b..ebc491e 100644 --- a/src/client/play.js +++ b/src/client/play.js @@ -1,6 +1,6 @@ var states = require("../states"); -module.exports = function(client) { +module.exports = function(client, options) { client.once('success', onLogin); function onLogin(packet) { diff --git a/src/client/setProtocol.js b/src/client/setProtocol.js index 0c5b7db..4948b1c 100644 --- a/src/client/setProtocol.js +++ b/src/client/setProtocol.js @@ -1,8 +1,7 @@ var states = require("../states"); -module.exports = function(client) { - var options = client.options; +module.exports = function(client, options) { client.on('connect', onConnect); function onConnect() { diff --git a/src/client/tcp_dns.js b/src/client/tcp_dns.js index 2863962..a8e3060 100644 --- a/src/client/tcp_dns.js +++ b/src/client/tcp_dns.js @@ -1,8 +1,7 @@ var net = require('net'); var dns = require('dns'); -module.exports = function(client) { - var options = client.options; +module.exports = function(client, options) { options.port = options.port || 25565; options.host = options.host || 'localhost'; diff --git a/src/createClient.js b/src/createClient.js index 0a68c7c..f702353 100644 --- a/src/createClient.js +++ b/src/createClient.js @@ -25,16 +25,15 @@ function createClient(options) { options.protocolVersion = version.version; var client = new Client(false, options.majorVersion); - client.options = options; - tcp_dns(client); - caseCorrect(client); - if (options.version === false) autoVersion(client); - setProtocol(client); - keepalive(client); - encrypt(client); - play(client); - compress(client); + tcp_dns(client, options); + caseCorrect(client, options); + if (options.version === false) autoVersion(client, options); + setProtocol(client, options); + keepalive(client, options); + encrypt(client, options); + play(client, options); + compress(client, options); return client; } diff --git a/src/ping.js b/src/ping.js index 1e6adcb..4a58353 100644 --- a/src/ping.js +++ b/src/ping.js @@ -15,7 +15,6 @@ function ping(options, cb) { options.protocolVersion = version.version; var client = new Client(false,options.majorVersion); - client.options = options; client.on('error', function(err) { cb(err); }); @@ -47,6 +46,6 @@ function ping(options, cb) { client.state = states.STATUS; }); - tcp_dns(client); + tcp_dns(client, options); options.connect(client); } From a3a2d3d6f1ba389cfa4a3e06f8d8975d33b1b290 Mon Sep 17 00:00:00 2001 From: deathcap Date: Mon, 1 Feb 2016 21:42:53 -0800 Subject: [PATCH 22/22] Move wait_connect to client object --- src/client/autoVersion.js | 2 +- src/client/setProtocol.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/autoVersion.js b/src/client/autoVersion.js index 3051403..1e09e0a 100644 --- a/src/client/autoVersion.js +++ b/src/client/autoVersion.js @@ -7,7 +7,7 @@ var assert = require('assert'); var minecraft_data = require('minecraft-data'); module.exports = function(client, options) { - options.wait_connect = true; // don't let src/client/setProtocol proceed on socket 'connect' until 'connect_allowed' + client.wait_connect = true; // don't let src/client/setProtocol proceed on socket 'connect' until 'connect_allowed' debug('pinging',options.host); var pingOptions = {host: options.host, port: options.port}; // TODO: use 0xfe ping instead for better compatibility/performance? https://github.com/deathcap/node-minecraft-ping diff --git a/src/client/setProtocol.js b/src/client/setProtocol.js index 4948b1c..ae1b519 100644 --- a/src/client/setProtocol.js +++ b/src/client/setProtocol.js @@ -5,7 +5,7 @@ module.exports = function(client, options) { client.on('connect', onConnect); function onConnect() { - if (options.wait_connect) { + if (client.wait_connect) { client.on('connect_allowed', next); } else { next();