mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2025-05-23 19:41:47 -04:00
Connect to a server's SRV record if they specify one
This commit is contained in:
parent
8760ff55bc
commit
d0664f37b4
1 changed files with 8 additions and 1 deletions
|
@ -2,6 +2,7 @@ var net = require('net')
|
||||||
, EventEmitter = require('events').EventEmitter
|
, EventEmitter = require('events').EventEmitter
|
||||||
, util = require('util')
|
, util = require('util')
|
||||||
, protocol = require('./protocol')
|
, protocol = require('./protocol')
|
||||||
|
, dns = require('dns')
|
||||||
, createPacketBuffer = protocol.createPacketBuffer
|
, createPacketBuffer = protocol.createPacketBuffer
|
||||||
, parsePacket = protocol.parsePacket
|
, parsePacket = protocol.parsePacket
|
||||||
, debug = protocol.debug
|
, debug = protocol.debug
|
||||||
|
@ -69,7 +70,13 @@ Client.prototype.setSocket = function(socket) {
|
||||||
|
|
||||||
Client.prototype.connect = function(port, host) {
|
Client.prototype.connect = function(port, host) {
|
||||||
var self = this;
|
var self = this;
|
||||||
self.setSocket(net.connect(port, host));
|
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));
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Client.prototype.end = function(reason) {
|
Client.prototype.end = function(reason) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue