mirror of
https://github.com/gamedig/node-gamedig.git
synced 2024-11-03 13:01:04 +01:00
35 lines
779 B
JavaScript
35 lines
779 B
JavaScript
var dns = require('dns');
|
|
|
|
module.exports = require('./gamespy3').extend({
|
|
init: function() {
|
|
this._super();
|
|
this.pretty = 'Minecraft';
|
|
this.maxAttempts = 2;
|
|
this.options.port = 25565;
|
|
},
|
|
parseDns: function(host,c) {
|
|
var self = this;
|
|
var _super = this._super;
|
|
function fallback(h) { _super.call(self,h,c); }
|
|
|
|
dns.resolve('_minecraft._tcp.'+host, 'SRV', function(err,addresses) {
|
|
if(err) return fallback(host);
|
|
if(addresses.length >= 1) {
|
|
var line = addresses[0];
|
|
self.options.port = line.port;
|
|
var srvhost = line.name;
|
|
|
|
if(srvhost.match(/\d+\.\d+\.\d+\.\d+/)) {
|
|
self.options.address = srvhost;
|
|
c();
|
|
} else {
|
|
// resolve yet again
|
|
fallback(srvhost);
|
|
}
|
|
return;
|
|
}
|
|
return fallback(host);
|
|
});
|
|
}
|
|
});
|