mirror of
https://github.com/tribufu/node-gamedig
synced 2026-05-18 09:35:50 +00:00
Resolve SRV records for minecraft servers
This commit is contained in:
parent
a0ba0d219c
commit
c4f66a72db
2 changed files with 52 additions and 9 deletions
|
|
@ -1,7 +1,33 @@
|
|||
var dns = require('dns');
|
||||
|
||||
module.exports = require('./gamespy3').extend({
|
||||
init: function() {
|
||||
this._super();
|
||||
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(self.options.host.match(/\d+\.\d+\.\d+\.\d+/)) {
|
||||
self.options.host = srvhost;
|
||||
c();
|
||||
} else {
|
||||
// resolve yet again
|
||||
fallback(srvhost);
|
||||
}
|
||||
return;
|
||||
}
|
||||
return fallback(host);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue