Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ var states = require("./states");
var createSerializer=require("./transforms/serializer").createSerializer;
var createDeserializer=require("./transforms/serializer").createDeserializer;

var protocolSpecs = require('./protocol');
var protocolVersions = require('./protocol/protocolVersions');

class Client extends EventEmitter
{
constructor(isServer,version) {
Expand Down Expand Up @@ -42,6 +45,30 @@ class Client extends EventEmitter
});
}

set version(newVersion) {
let versionInfo;
if (typeof newVersion === 'string') {
if (newVersion === '1.9') newVersion = '15w40b'; // TODO: remove hack, should call it 15w40b instead of 1.9? no such 'release version' of 1.9 yet (ambiguous)
versionInfo = protocolVersions.versionsByMinecraftVersion[newVersion];
} else if (typeof newVersion === 'number') {
versionInfo = protocolVersions.latestVersionsByProtocolVersionCode[newVersion];
}
if (!versionInfo) throw new Error(`unrecognized release or protocol version: ${newVersion}, update minecraft-data?`);

this.protocolVersion = versionInfo.version;

// currently, datasets are indexed by major version TODO: generalize
let dataVersion = versionInfo.majorVersion;

if (!protocolSpecs[dataVersion]) throw new Error(`no protocol specification for version: ${newVersion}`);

this._version = dataVersion;
}

get version() {
return this._version;
}

get state(){
return this.protocolState;
}
Expand Down
8 changes: 1 addition & 7 deletions src/client/autoVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var ping = require('../ping');
var debug = require('../debug');
var states = require('../states');
var assert = require('assert');
var minecraft_data = require('minecraft-data');
var forgeHandshake = require('./forgeHandshake');

module.exports = function(client, options) {
Expand All @@ -29,14 +28,9 @@ module.exports = function(client, options) {
// 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.
// 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
options.version = versionInfo.minecraftVersion;
options.protocolVersion = protocolVersion;

// Reinitialize client object with new version TODO: move out of its constructor?
client.version = versionInfo.majorVersion;
client.version = protocolVersion;
client.state = states.HANDSHAKING;

if (response.modinfo && response.modinfo.type === 'FML') {
Expand Down
2 changes: 1 addition & 1 deletion src/client/setProtocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = function(client, options) {
if (options.tagHost) taggedHost += options.tagHost;

client.write('set_protocol', {
protocolVersion: options.protocolVersion,
protocolVersion: client.protocolVersion,
serverHost: taggedHost,
serverPort: options.port,
nextState: 2
Expand Down
7 changes: 1 addition & 6 deletions src/createClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@ function createClient(options) {

// 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;

var client = new Client(false, options.majorVersion);
var client = new Client(false, optVersion);

tcp_dns(client, options);
if (options.forgeMods) forgeHandshake(client, options);
Expand Down
6 changes: 1 addition & 5 deletions src/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ function ping(options, cb) {
options.host = options.host || 'localhost';
options.port = options.port || 25565;
var optVersion = options.version || require("./version").defaultVersion;
var mcData=require("minecraft-data")(optVersion);
var version = mcData.version;
options.majorVersion = version.majorVersion;
options.protocolVersion = version.version;

var client = new Client(false,options.majorVersion);
var client = new Client(false, optVersion);
client.on('error', function(err) {
cb(err);
});
Expand Down
Loading