Merge pull request #41 from theminecoder-me/srv-support
Support SRV record unfurling for PC networks
This commit is contained in:
commit
5f9d0d8207
@ -48,7 +48,10 @@ function pingMinecraftPE(host, port, timeout, callback) {
|
|||||||
|
|
||||||
exports.ping = function(host, port, type, timeout, callback, version) {
|
exports.ping = function(host, port, type, timeout, callback, version) {
|
||||||
if (type === 'PC') {
|
if (type === 'PC') {
|
||||||
pingMinecraftPC(host, port || 25565, timeout, callback, version);
|
util.unfurlSRV(host, port, function(host, port){
|
||||||
|
console.log('Pinging '+host+":"+port+"...")
|
||||||
|
pingMinecraftPC(host, port || 25565, timeout, callback, version);
|
||||||
|
})
|
||||||
} else if (type === 'PE') {
|
} else if (type === 'PE') {
|
||||||
pingMinecraftPE(host, port || 19132, timeout, callback);
|
pingMinecraftPE(host, port || 19132, timeout, callback);
|
||||||
} else {
|
} else {
|
||||||
|
18
lib/util.js
18
lib/util.js
@ -1,4 +1,5 @@
|
|||||||
var logger = require('./logger');
|
var logger = require('./logger');
|
||||||
|
var dns = require('dns');
|
||||||
|
|
||||||
var config = require('../config.json');
|
var config = require('../config.json');
|
||||||
var servers = require('../servers.json');
|
var servers = require('../servers.json');
|
||||||
@ -148,4 +149,21 @@ exports.getBootTime = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return bootTime;
|
return bootTime;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to resolve Minecraft PC SRV records from DNS, otherwise falling back to the old hostname.
|
||||||
|
*
|
||||||
|
* @param hostname hostname to check
|
||||||
|
* @param port port to pass to callback if required
|
||||||
|
* @param callback function with a hostname and port parameter
|
||||||
|
*/
|
||||||
|
exports.unfurlSRV = function(hostname, port, callback) {
|
||||||
|
dns.resolveSrv("_minecraft._tcp."+hostname, function (err, records) {
|
||||||
|
if(!records||records.length<=0) {
|
||||||
|
callback(hostname, port);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback(records[0].name, records[0].port);
|
||||||
|
})
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user