mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-28 13:45:37 -04:00
Use minecraft-data for protocol version -> minecraft version
This commit is contained in:
parent
66e6f4dd0b
commit
89198c62ff
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user