mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-30 14:41:27 -04:00
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`.
This commit is contained in:
parent
89198c62ff
commit
ea3b306988
@ -1,7 +1,8 @@
|
|||||||
var yggdrasil = require('yggdrasil')({});
|
var yggdrasil = require('yggdrasil')({});
|
||||||
var UUID = require('uuid-1345');
|
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();
|
var clientToken = options.clientToken || UUID.v4().toString();
|
||||||
options.accessToken = null;
|
options.accessToken = null;
|
||||||
options.haveCredentials = options.password != null || (clientToken != null && options.session != null);
|
options.haveCredentials = options.password != null || (clientToken != null && options.session != null);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module.exports = function(client, options) {
|
module.exports = function(client) {
|
||||||
client.once("compress", onCompressionRequest);
|
client.once("compress", onCompressionRequest);
|
||||||
client.on("set_compression", onCompressionRequest);
|
client.on("set_compression", onCompressionRequest);
|
||||||
|
|
||||||
|
@ -3,7 +3,8 @@ var yggserver = require('yggdrasil').server({});
|
|||||||
var ursa=require("../ursa");
|
var ursa=require("../ursa");
|
||||||
var debug = require("../debug");
|
var debug = require("../debug");
|
||||||
|
|
||||||
module.exports = function(client, options) {
|
module.exports = function(client) {
|
||||||
|
var options = client.options;
|
||||||
client.once('encryption_begin', onEncryptionKeyRequest);
|
client.once('encryption_begin', onEncryptionKeyRequest);
|
||||||
|
|
||||||
function onEncryptionKeyRequest(packet) {
|
function onEncryptionKeyRequest(packet) {
|
||||||
|
@ -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;
|
var keepAlive = options.keepAlive == null ? true : options.keepAlive;
|
||||||
if (!keepAlive) return;
|
if (!keepAlive) return;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
var states = require("../states");
|
var states = require("../states");
|
||||||
|
|
||||||
module.exports = function(client, options) {
|
module.exports = function(client) {
|
||||||
client.once('success', onLogin);
|
client.once('success', onLogin);
|
||||||
|
|
||||||
function onLogin(packet) {
|
function onLogin(packet) {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
|
|
||||||
var states = require("../states");
|
var states = require("../states");
|
||||||
|
|
||||||
module.exports = function(client, options) {
|
module.exports = function(client) {
|
||||||
|
var options = client.options;
|
||||||
client.on('connect', onConnect);
|
client.on('connect', onConnect);
|
||||||
|
|
||||||
function onConnect() {
|
function onConnect() {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
var net = require('net');
|
var net = require('net');
|
||||||
var dns = require('dns');
|
var dns = require('dns');
|
||||||
|
|
||||||
module.exports = function(client, options) {
|
module.exports = function(client) {
|
||||||
|
var options = client.options;
|
||||||
options.port = options.port || 25565;
|
options.port = options.port || 25565;
|
||||||
options.host = options.host || 'localhost';
|
options.host = options.host || 'localhost';
|
||||||
|
|
||||||
|
@ -22,14 +22,15 @@ function createClient(options) {
|
|||||||
options.protocolVersion = version.version;
|
options.protocolVersion = version.version;
|
||||||
|
|
||||||
var client = new Client(false, options.majorVersion);
|
var client = new Client(false, options.majorVersion);
|
||||||
|
client.options = options;
|
||||||
|
|
||||||
tcp_dns(client, options);
|
tcp_dns(client);
|
||||||
setProtocol(client, options);
|
setProtocol(client);
|
||||||
keepalive(client, options);
|
keepalive(client);
|
||||||
encrypt(client, options);
|
encrypt(client);
|
||||||
play(client, options);
|
play(client);
|
||||||
compress(client, options);
|
compress(client);
|
||||||
caseCorrect(client, options);
|
caseCorrect(client);
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
@ -47,13 +47,11 @@ function createClientAuto(options) {
|
|||||||
// 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
|
client.options.version = protocolVersion2MinecraftVersion(protocolVersion);
|
||||||
options.version = protocolVersion2MinecraftVersion(protocolVersion);
|
|
||||||
|
|
||||||
// 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
|
client.options.protocolVersion = protocolVersion;
|
||||||
options.protocolVersion = protocolVersion;
|
|
||||||
|
|
||||||
if (response.modinfo && response.modinfo.type === 'FML') {
|
if (response.modinfo && response.modinfo.type === 'FML') {
|
||||||
// Use the list of Forge mods from the server ping, so client will match server
|
// Use the list of Forge mods from the server ping, so client will match server
|
||||||
|
@ -15,6 +15,7 @@ function ping(options, cb) {
|
|||||||
options.protocolVersion = version.version;
|
options.protocolVersion = version.version;
|
||||||
|
|
||||||
var client = new Client(false,options.majorVersion);
|
var client = new Client(false,options.majorVersion);
|
||||||
|
client.options = options;
|
||||||
client.on('error', function(err) {
|
client.on('error', function(err) {
|
||||||
cb(err);
|
cb(err);
|
||||||
});
|
});
|
||||||
@ -46,6 +47,6 @@ function ping(options, cb) {
|
|||||||
client.state = states.STATUS;
|
client.state = states.STATUS;
|
||||||
});
|
});
|
||||||
|
|
||||||
tcp_dns(client, options);
|
tcp_dns(client);
|
||||||
options.connect(client);
|
options.connect(client);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user