mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-28 21:52:17 -04:00
Break client/caseCorrect dependence on TCP/IP host/port; generalize options.connect(client)
This commit is contained in:
parent
9c2112802a
commit
de36de8496
@ -16,7 +16,7 @@ module.exports = function(client, options) {
|
|||||||
client.username = session.selectedProfile.name;
|
client.username = session.selectedProfile.name;
|
||||||
accessToken = session.accessToken;
|
accessToken = session.accessToken;
|
||||||
client.emit('session');
|
client.emit('session');
|
||||||
client.connect(options.port, options.host);
|
options.connect(client);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -38,6 +38,6 @@ module.exports = function(client, options) {
|
|||||||
} else {
|
} else {
|
||||||
// assume the server is in offline mode and just go for it.
|
// assume the server is in offline mode and just go for it.
|
||||||
client.username = options.username;
|
client.username = options.username;
|
||||||
client.connect(options.port, options.host);
|
options.connect(client);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -12,26 +12,25 @@ var play = require('./client/play');
|
|||||||
|
|
||||||
module.exports=createClient;
|
module.exports=createClient;
|
||||||
|
|
||||||
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");
|
||||||
options.port = options.port || 25565;
|
options.port = options.port || 25565;
|
||||||
options.host = options.host || 'localhost';
|
options.host = options.host || 'localhost';
|
||||||
|
|
||||||
|
options.connect = (client) => {
|
||||||
|
if(options.port == 25565 && net.isIP(host) === 0) {
|
||||||
|
dns.resolveSrv("_minecraft._tcp." + options.host, function(err, addresses) {
|
||||||
|
if(addresses && addresses.length > 0) {
|
||||||
|
client.setSocket(net.connect(addresses[0].port, addresses[0].name));
|
||||||
|
} else {
|
||||||
|
client.setSocket(net.connect(options.port, options.host));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
client.setSocket(net.connect(options.port, options.host));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
assert.ok(options.username, "username is required");
|
assert.ok(options.username, "username is required");
|
||||||
|
|
||||||
var optVersion = options.version || require("./version").defaultVersion;
|
var optVersion = options.version || require("./version").defaultVersion;
|
||||||
|
@ -42,5 +42,6 @@ function ping(options, cb) {
|
|||||||
client.state = states.STATUS;
|
client.state = states.STATUS;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO: update
|
||||||
client.connect(port, host);
|
client.connect(port, host);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user