mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-30 06:30:39 -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 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);
|
||||
|
@ -1,4 +1,4 @@
|
||||
module.exports = function(client, options) {
|
||||
module.exports = function(client) {
|
||||
client.once("compress", onCompressionRequest);
|
||||
client.on("set_compression", onCompressionRequest);
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
var states = require("../states");
|
||||
|
||||
module.exports = function(client, options) {
|
||||
module.exports = function(client) {
|
||||
client.once('success', onLogin);
|
||||
|
||||
function onLogin(packet) {
|
||||
|
@ -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() {
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user