Drop the try catches, this might make it a bit unstable until we work out some bugs.
This commit is contained in:
parent
0150e3b30e
commit
82752767b9
74
lib/ping.js
74
lib/ping.js
@ -7,53 +7,43 @@ var util = require('./util');
|
||||
function pingMinecraftPC(host, port, timeout, callback) {
|
||||
var startTime = util.getCurrentTimeMs();
|
||||
|
||||
// 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: util.getCurrentTimeMs() - startTime,
|
||||
favicon: res.favicon
|
||||
});
|
||||
}
|
||||
}, timeout);
|
||||
} catch (err) {
|
||||
callback(err, null);
|
||||
}
|
||||
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: util.getCurrentTimeMs() - startTime,
|
||||
favicon: res.favicon
|
||||
});
|
||||
}
|
||||
}, timeout);
|
||||
}
|
||||
|
||||
// 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 startTime = util.getCurrentTimeMs();
|
||||
|
||||
// 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: parseInt(res.currentPlayers),
|
||||
max: parseInt(res.maxPlayers)
|
||||
},
|
||||
version: res.version,
|
||||
latency: util.getCurrentTimeMs() - startTime
|
||||
});
|
||||
}
|
||||
}, timeout);
|
||||
} catch (err) {
|
||||
callback(err, null);
|
||||
}
|
||||
|
||||
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: parseInt(res.currentPlayers),
|
||||
max: parseInt(res.maxPlayers)
|
||||
},
|
||||
version: res.version,
|
||||
latency: util.getCurrentTimeMs() - startTime
|
||||
});
|
||||
}
|
||||
}, timeout);
|
||||
}
|
||||
|
||||
exports.ping = function(host, port, type, timeout, callback) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user