mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-12-02 03:56:54 -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')
|
var 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
|
||||||
, compressPacketBuffer = protocol.compressPacketBuffer
|
, compressPacketBuffer = protocol.compressPacketBuffer
|
||||||
, oldStylePacket = protocol.oldStylePacket
|
, 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) {
|
Client.prototype.end = function(reason) {
|
||||||
this._endReason = reason;
|
this._endReason = reason;
|
||||||
this.socket.end();
|
this.socket.end();
|
||||||
|
|
17
src/index.js
17
src/index.js
|
@ -6,6 +6,8 @@ var EventEmitter = require('events').EventEmitter
|
||||||
, superagent = require('superagent')
|
, superagent = require('superagent')
|
||||||
, protocol = require('./protocol')
|
, protocol = require('./protocol')
|
||||||
, Client = require('./client')
|
, Client = require('./client')
|
||||||
|
, dns = require('dns')
|
||||||
|
, net = require('net')
|
||||||
, Server = require('./server')
|
, Server = require('./server')
|
||||||
, Yggdrasil = require('./yggdrasil.js')
|
, Yggdrasil = require('./yggdrasil.js')
|
||||||
, getSession = Yggdrasil.getSession
|
, getSession = Yggdrasil.getSession
|
||||||
|
@ -228,6 +230,21 @@ function createServer(options) {
|
||||||
return server;
|
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) {
|
function createClient(options) {
|
||||||
assert.ok(options, "options is required");
|
assert.ok(options, "options is required");
|
||||||
var port = options.port || 25565;
|
var port = options.port || 25565;
|
||||||
|
|
Loading…
Reference in a new issue