mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-30 03:05:37 -05:00
Move network-specific code out of client.js
This commit is contained in:
parent
c968cbefe5
commit
bbbd022f33
2 changed files with 18 additions and 18 deletions
|
@ -1,8 +1,6 @@
|
|||
var net = require('net')
|
||||
, EventEmitter = require('events').EventEmitter
|
||||
var EventEmitter = require('events').EventEmitter
|
||||
, util = require('util')
|
||||
, protocol = require('./protocol')
|
||||
, dns = require('dns')
|
||||
, createPacketBuffer = protocol.createPacketBuffer
|
||||
, compressPacketBuffer = protocol.compressPacketBuffer
|
||||
, oldStylePacket = protocol.oldStylePacket
|
||||
|
@ -152,21 +150,6 @@ Client.prototype.setSocket = function(socket) {
|
|||
}
|
||||
};
|
||||
|
||||
Client.prototype.connect = function(port, host) {
|
||||
var self = this;
|
||||
if (port == 25565 && net.isIP(host) === 0) {
|
||||
dns.resolveSrv("_minecraft._tcp." + host, function(err, addresses) {
|
||||
if (addresses && addresses.length > 0) {
|
||||
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) {
|
||||
this._endReason = reason;
|
||||
this.socket.end();
|
||||
|
|
17
src/index.js
17
src/index.js
|
@ -6,6 +6,8 @@ var EventEmitter = require('events').EventEmitter
|
|||
, superagent = require('superagent')
|
||||
, protocol = require('./protocol')
|
||||
, Client = require('./client')
|
||||
, dns = require('dns')
|
||||
, net = require('net')
|
||||
, Server = require('./server')
|
||||
, Yggdrasil = require('./yggdrasil.js')
|
||||
, getSession = Yggdrasil.getSession
|
||||
|
@ -228,6 +230,21 @@ function createServer(options) {
|
|||
return server;
|
||||
}
|
||||
|
||||
Client.prototype.connect = function(port, host) {
|
||||
var self = this;
|
||||
if (port == 25565 && net.isIP(host) === 0) {
|
||||
dns.resolveSrv("_minecraft._tcp." + host, function(err, addresses) {
|
||||
if (addresses && addresses.length > 0) {
|
||||
self.setSocket(net.connect(addresses[0].port, addresses[0].name));
|
||||
} else {
|
||||
self.setSocket(net.connect(port, host));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
self.setSocket(net.connect(port, host));
|
||||
}
|
||||
};
|
||||
|
||||
function createClient(options) {
|
||||
assert.ok(options, "options is required");
|
||||
var port = options.port || 25565;
|
||||
|
|
Loading…
Reference in a new issue