make autoVersion use const

This commit is contained in:
Romain Beaumont 2016-02-02 09:24:01 +01:00
parent a222c4fd49
commit 8569b65594

View File

@ -1,36 +1,34 @@
'use strict'; const ping = require('../ping');
const debug = require('../debug');
var ping = require('../ping'); const states = require('../states');
var debug = require('../debug'); const assert = require('assert');
var states = require('../states'); const minecraft_data = require('minecraft-data');
var assert = require('assert');
var minecraft_data = require('minecraft-data');
module.exports = function(client, options) { module.exports = function(client, options) {
client.wait_connect = true; // don't let src/client/setProtocol proceed on socket 'connect' until 'connect_allowed' client.wait_connect = true; // don't let src/client/setProtocol proceed on socket 'connect' until 'connect_allowed'
debug('pinging',options.host); debug('pinging',options.host);
var pingOptions = {host: options.host, port: options.port}; const pingOptions = {host: options.host, port: options.port};
// TODO: use 0xfe ping instead for better compatibility/performance? https://github.com/deathcap/node-minecraft-ping // TODO: use 0xfe ping instead for better compatibility/performance? https://github.com/deathcap/node-minecraft-ping
ping(pingOptions, function(err, response) { ping(pingOptions, function(err, response) {
if (err) throw err; // hmm if (err) throw err; // hmm
debug('ping response',response); debug('ping response',response);
// TODO: could also use ping pre-connect to save description, type, max players, etc. // TODO: could also use ping pre-connect to save description, type, max players, etc.
var motd = response.description; const motd = response.description;
debug('Server description:',motd); // TODO: save debug('Server description:',motd); // TODO: save
// Pass server-reported version to protocol handler // Pass server-reported version to protocol handler
// The version string is interpereted by https://github.com/PrismarineJS/node-minecraft-data // The version string is interpereted by https://github.com/PrismarineJS/node-minecraft-data
var minecraftVersion = response.version.name; // 1.8.9, 1.7.10 const minecraftVersion = response.version.name; // 1.8.9, 1.7.10
var protocolVersion = response.version.protocol;// 47, 5 const protocolVersion = response.version.protocol;// 47, 5
debug(`Server version: ${minecraftVersion}, protocol: ${protocolVersion}`); debug(`Server version: ${minecraftVersion}, protocol: ${protocolVersion}`);
// 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.
// TODO: pre-Netty version support (uses overlapping version numbers, so would have to check versionName) // TODO: pre-Netty version support (uses overlapping version numbers, so would have to check versionName)
var versionInfos = minecraft_data.postNettyVersionsByProtocolVersion[protocolVersion]; const versionInfos = minecraft_data.postNettyVersionsByProtocolVersion[protocolVersion];
if (!versionInfos && versionInfos.length < 1) throw new Error(`unsupported/unknown protocol version: ${protocolVersion}, update minecraft-data`); if (!versionInfos && versionInfos.length < 1) throw new Error(`unsupported/unknown protocol version: ${protocolVersion}, update minecraft-data`);
var versionInfo = versionInfos[0]; // use newest const versionInfo = versionInfos[0]; // use newest
options.version = versionInfo.minecraftVersion; options.version = versionInfo.minecraftVersion;
options.protocolVersion = protocolVersion; options.protocolVersion = protocolVersion;
@ -40,7 +38,7 @@ module.exports = function(client, options) {
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
var forgeMods = response.modinfo.modList; const forgeMods = response.modinfo.modList;
debug('Using forgeMods:',forgeMods); debug('Using forgeMods:',forgeMods);
// TODO: https://github.com/PrismarineJS/node-minecraft-protocol/issues/114 // TODO: https://github.com/PrismarineJS/node-minecraft-protocol/issues/114
// https://github.com/PrismarineJS/node-minecraft-protocol/pull/326 // https://github.com/PrismarineJS/node-minecraft-protocol/pull/326
@ -51,4 +49,4 @@ module.exports = function(client, options) {
client.emit('connect_allowed'); client.emit('connect_allowed');
}); });
return client; return client;
} };