mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2025-05-13 23:00:25 -04:00
Merge pull request #55 from stith/patch-1
Connect to a server's SRV record if they specify one
This commit is contained in:
commit
a48d6dcdd8
1 changed files with 12 additions and 1 deletions
|
@ -2,6 +2,7 @@ var net = require('net')
|
|||
, EventEmitter = require('events').EventEmitter
|
||||
, util = require('util')
|
||||
, protocol = require('./protocol')
|
||||
, dns = require('dns')
|
||||
, createPacketBuffer = protocol.createPacketBuffer
|
||||
, parsePacket = protocol.parsePacket
|
||||
, debug = protocol.debug
|
||||
|
@ -69,7 +70,17 @@ Client.prototype.setSocket = function(socket) {
|
|||
|
||||
Client.prototype.connect = function(port, host) {
|
||||
var self = this;
|
||||
self.setSocket(net.connect(port, host));
|
||||
if (port == 25565) {
|
||||
dns.resolveSrv("_minecraft._tcp." + host, function(err, addresses) {
|
||||
if (addresses) {
|
||||
self.setSocket(net.connect(addresses[0].port, addresses[0].name));
|
||||
} else {
|
||||
self.setSocket(net.connect(port, host));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
self.setSocket(net.connect(port, host));
|
||||
}
|
||||
};
|
||||
|
||||
Client.prototype.end = function(reason) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue