Show supported versions for PC servers

The Minetrack daemon will send a different protocol version each time
it pings a server. If a server responds with the same protocol version,
it is assumed that the version is supported, and it is shown on the
page above the server's player count.

The list of versions to be tried is stored in config.json.
At the moment, 4 versions are checked:
- 4 (Minecraft 1.7.2)
- 5 (Minecraft 1.7.10)
- 47 (Minecraft 1.8)
- 107 (Minecraft 1.9)
This commit is contained in:
Devin Ryan
2016-03-01 21:09:38 -06:00
parent df72b98d53
commit 43c284aa8a
6 changed files with 111 additions and 23 deletions

69
app.js
View File

@ -11,6 +11,12 @@ var servers = require('./servers.json');
var networkHistory = [];
var connectedClients = 0;
var currentVersionIndex = {
'PC': 0,
'PE': 0
};
var networkVersions = [];
var graphData = [];
var lastGraphPush = [];
@ -18,6 +24,7 @@ function pingAll() {
for (var i = 0; i < servers.length; i++) {
// Make sure we lock our scope.
(function(network) {
var attemptedVersion = config.versions[network.type][currentVersionIndex[network.type]];
ping.ping(network.ip, network.port, network.type, config.rates.connectTimeout, function(err, res) {
// Handle our ping results, if it succeeded.
if (err) {
@ -29,20 +36,62 @@ function pingAll() {
res.favicon = config.faviconOverride[network.name];
}
handlePing(network, res, err);
});
handlePing(network, res, err, attemptedVersion);
}, attemptedVersion);
})(servers[i]);
}
currentVersionIndex['PC']++;
currentVersionIndex['PE']++;
if (currentVersionIndex['PC'] >= config.versions['PC'].length) {
// Loop around
currentVersionIndex['PC'] = 0;
}
if (currentVersionIndex['PE'] >= config.versions['PE'].length) {
// Loop around
currentVersionIndex['PE'] = 0;
}
}
// This is where the result of a ping is feed.
// This stores it and converts it to ship to the frontend.
function handlePing(network, res, err) {
function handlePing(network, res, err, attemptedVersion) {
// Log our response.
if (!networkHistory[network.name]) {
networkHistory[network.name] = [];
}
// Update the version list
if (!networkVersions[network.name]) {
networkVersions[network.name] = [];
}
// If the result version matches the attempted version, the version is supported
var _networkVersions = networkVersions[network.name];
if (res) {
if (res.version == attemptedVersion) {
if (_networkVersions.indexOf(res.version) == -1) {
_networkVersions.push(res.version);
}
} else {
// Mismatch, so remove the version from the supported version list
var index = _networkVersions.indexOf(attemptedVersion);
if (index != -1) {
_networkVersions.splice(index, 1);
}
}
}
// Update the clients
var networkSnapshot = {
info: {
name: network.name,
timestamp: util.getCurrentTimeMs()
}
timestamp: util.getCurrentTimeMs(),
type: network.type
},
versions: _networkVersions
};
if (res) {
@ -53,11 +102,6 @@ function handlePing(network, res, err) {
server.io.sockets.emit('update', networkSnapshot);
// Log our response.
if (!networkHistory[network.name]) {
networkHistory[network.name] = [];
}
var _networkHistory = networkHistory[network.name];
// Remove our previous data that we don't need anymore.
@ -72,12 +116,13 @@ function handlePing(network, res, err) {
_networkHistory.push({
error: err,
result: res,
versions: _networkVersions,
timestamp: util.getCurrentTimeMs(),
info: {
ip: network.ip,
port: network.port,
type: network.type,
name: network.name
name: network.name,
}
});
@ -217,4 +262,4 @@ if (config.logToDatabase) {
logger.log('warn', 'Database logging is not enabled. You can enable it by setting "logToDatabase" to true in config.json. This requires sqlite3 to be installed.');
startServices();
}
}