From 6a3acff5de4bd931e05360fad496cb8a5a46563d Mon Sep 17 00:00:00 2001 From: plexigras Date: Wed, 14 Jun 2017 14:54:25 +0200 Subject: [PATCH 1/2] improved version getter --- src/client/autoVersion.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/client/autoVersion.js b/src/client/autoVersion.js index 710e12b..98ec4b5 100644 --- a/src/client/autoVersion.js +++ b/src/client/autoVersion.js @@ -22,19 +22,22 @@ module.exports = function(client, options) { // The version string is interpreted by https://github.com/PrismarineJS/node-minecraft-data const brandedMinecraftVersion = response.version.name; // 1.8.9, 1.7.10 const protocolVersion = response.version.protocol;// 47, 5 - - debug(`Server version: ${brandedMinecraftVersion}, protocol: ${protocolVersion}`); - - let minecraftVersion; - if (brandedMinecraftVersion.indexOf(' ') !== -1) { - // Spigot and Glowstone++ prepend their name; strip it off - minecraftVersion = brandedMinecraftVersion.split(' ')[1]; - } else { - minecraftVersion = brandedMinecraftVersion; + let versions = brandedMinecraftVersion.match(/((\d+\.)+\d+)/g).map(function (version) { + return minecraft_data.versionsByMinecraftVersion["pc"][version] + }).filter(function (info) { + return info + }).sort(function (a, b) { + return b.version - a.version + }) + if (versions.length === 0) { + versions = minecraft_data.postNettyVersionsByProtocolVersion["pc"][protocolVersion]; + if (!versions) { + throw new Error(`unsupported/unknown protocol version: ${protocolVersion}, update minecraft-data`); + } } + const minecraftVersion = versions[0].minecraftVersion; - const versionInfo = minecraft_data.versionsByMinecraftVersion["pc"][minecraftVersion]; - if (!versionInfo) throw new Error(`unsupported/unknown protocol version: ${protocolVersion}, update minecraft-data`); + debug(`Server version: ${minecraftVersion}, protocol: ${protocolVersion}`); options.version = minecraftVersion; options.protocolVersion = protocolVersion; From 2a6973ab42a8fd47fad7e1e1b7fb17bc9bbfa2b4 Mon Sep 17 00:00:00 2001 From: plexigras Date: Sat, 17 Jun 2017 20:17:52 +0200 Subject: [PATCH 2/2] simplified autoversion fallback --- src/client/autoVersion.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/client/autoVersion.js b/src/client/autoVersion.js index 98ec4b5..061e52b 100644 --- a/src/client/autoVersion.js +++ b/src/client/autoVersion.js @@ -22,18 +22,16 @@ module.exports = function(client, options) { // The version string is interpreted by https://github.com/PrismarineJS/node-minecraft-data const brandedMinecraftVersion = response.version.name; // 1.8.9, 1.7.10 const protocolVersion = response.version.protocol;// 47, 5 - let versions = brandedMinecraftVersion.match(/((\d+\.)+\d+)/g).map(function (version) { + let versions = [brandedMinecraftVersion] + .concat(brandedMinecraftVersion.match(/((\d+\.)+\d+)/g)||[]) + .map(function (version) { return minecraft_data.versionsByMinecraftVersion["pc"][version] - }).filter(function (info) { - return info - }).sort(function (a, b) { - return b.version - a.version }) + .filter(function (info) { return info }) + .sort(function (a, b) { return b.version - a.version }) + .concat(minecraft_data.postNettyVersionsByProtocolVersion["pc"][protocolVersion]||[]) if (versions.length === 0) { - versions = minecraft_data.postNettyVersionsByProtocolVersion["pc"][protocolVersion]; - if (!versions) { - throw new Error(`unsupported/unknown protocol version: ${protocolVersion}, update minecraft-data`); - } + throw new Error(`unsupported/unknown protocol version: ${protocolVersion}, update minecraft-data`); } const minecraftVersion = versions[0].minecraftVersion;