Configurable rates, handle ping exceptions, Mojang service tracking

This commit is contained in:
Cryptkeeper
2015-11-02 22:32:54 -06:00
parent 72172514b0
commit da5dd8b026
5 changed files with 150 additions and 38 deletions

View File

@ -5,42 +5,52 @@ var mcpc_ping = require('mc-ping-updated');
function pingMinecraftPC(host, port, timeout, callback) {
var milliseconds = (new Date).getTime();
mcpc_ping(host, port, function(err, res) {
if (err) {
callback(err, null);
} else {
// Remap our JSON into our custom structure.
callback(null, {
players: {
online: res.players.online,
max: res.players.max
},
version: res.version.protocol,
latency: (new Date).getTime() - milliseconds
});
}
}, timeout);
// Try catch incase the down stream module is bad at handling exceptions.
try {
mcpc_ping(host, port, function(err, res) {
if (err) {
callback(err, null);
} else {
// Remap our JSON into our custom structure.
callback(null, {
players: {
online: res.players.online,
max: res.players.max
},
version: res.version.protocol,
latency: (new Date).getTime() - milliseconds
});
}
}, timeout);
} catch (err) {
callback(err, null);
}
}
// This is a wrapper function for mcpe-ping, mainly used to convert the data structure of the result.
function pingMinecraftPE(host, port, timeout, callback) {
var milliseconds = (new Date).getTime();
mcpe_ping(host, port || 19132, function(err, res) {
if (err) {
callback(err, null);
} else {
// Remap our JSON into our custom structure.
callback(err, {
players: {
online: res.currentPlayers,
max: res.maxPlayers
},
version: res.version,
latency: (new Date).getTime() - milliseconds
});
}
}, timeout);
// Try catch incase the down stream module is bad at handling exceptions.
try {
mcpe_ping(host, port || 19132, function(err, res) {
if (err) {
callback(err, null);
} else {
// Remap our JSON into our custom structure.
callback(err, {
players: {
online: res.currentPlayers,
max: res.maxPlayers
},
version: res.version,
latency: (new Date).getTime() - milliseconds
});
}
}, timeout);
} catch (err) {
callback(err, null);
}
}
exports.ping = function(host, port, type, timeout, callback) {