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

View File

@ -4,7 +4,7 @@ var mcpc_ping = require('mc-ping-updated');
var util = require('./util');
// This is a wrapper function for mc-ping-updated, mainly used to convert the data structure of the result.
function pingMinecraftPC(host, port, timeout, callback) {
function pingMinecraftPC(host, port, timeout, callback, version) {
var startTime = util.getCurrentTimeMs();
mcpc_ping(host, port, function(err, res) {
@ -22,7 +22,7 @@ function pingMinecraftPC(host, port, timeout, callback) {
favicon: res.favicon
});
}
}, timeout);
}, timeout, version);
}
// This is a wrapper function for mcpe-ping, mainly used to convert the data structure of the result.
@ -46,12 +46,12 @@ function pingMinecraftPE(host, port, timeout, callback) {
}, timeout);
}
exports.ping = function(host, port, type, timeout, callback) {
exports.ping = function(host, port, type, timeout, callback, version) {
if (type === 'PC') {
pingMinecraftPC(host, port || 25565, timeout, callback);
pingMinecraftPC(host, port || 25565, timeout, callback, version);
} else if (type === 'PE') {
pingMinecraftPE(host, port || 19132, timeout, callback);
} else {
throw new Error('Unsupported type: ' + type);
}
};
};