Support SRV record unfurling for PC networks

This commit is contained in:
theminecoder
2016-06-09 13:26:32 +10:00
parent 41a6a25854
commit 0034d7fc03
2 changed files with 22 additions and 1 deletions

View File

@ -1,4 +1,5 @@
var logger = require('./logger');
var dns = require('dns');
var config = require('../config.json');
var servers = require('../servers.json');
@ -148,4 +149,21 @@ exports.getBootTime = function() {
}
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);
})
};