mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-28 21:52:17 -04:00
Move onConnect/set_protocol to client/setProtocol
This commit is contained in:
parent
821227d73e
commit
b37dcc4d08
21
src/client/setProtocol.js
Normal file
21
src/client/setProtocol.js
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
var states = require("../states");
|
||||
|
||||
module.exports = function(client, options) {
|
||||
client.on('connect', onConnect);
|
||||
|
||||
function onConnect() {
|
||||
client.write('set_protocol', {
|
||||
protocolVersion: options.protocolVersion,
|
||||
serverHost: options.host,
|
||||
serverPort: options.port,
|
||||
nextState: 2
|
||||
});
|
||||
client.state = states.LOGIN;
|
||||
client.write('login_start', {
|
||||
username: client.username
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -10,6 +10,7 @@ var encrypt = require('./client/encrypt');
|
||||
var keepalive = require('./client/keepalive');
|
||||
var compress = require('./client/compress');
|
||||
var caseCorrect = require('./client/caseCorrect');
|
||||
var setProtocol = require('./client/setProtocol');
|
||||
|
||||
module.exports=createClient;
|
||||
|
||||
@ -38,10 +39,12 @@ function createClient(options) {
|
||||
var optVersion = options.version || require("./version").defaultVersion;
|
||||
var mcData=require("minecraft-data")(optVersion);
|
||||
var version = mcData.version;
|
||||
options.majorVersion = version.majorVersion;
|
||||
options.protocolVersion = version.version;
|
||||
|
||||
|
||||
var client = new Client(false,version.majorVersion);
|
||||
client.on('connect', onConnect);
|
||||
var client = new Client(false, options.majorVersion);
|
||||
setProtocol(client, options);
|
||||
keepalive(client, options);
|
||||
encrypt(client);
|
||||
client.once('success', onLogin);
|
||||
@ -50,19 +53,6 @@ function createClient(options) {
|
||||
|
||||
return client;
|
||||
|
||||
function onConnect() {
|
||||
client.write('set_protocol', {
|
||||
protocolVersion: version.version,
|
||||
serverHost: options.host,
|
||||
serverPort: options.port,
|
||||
nextState: 2
|
||||
});
|
||||
client.state = states.LOGIN;
|
||||
client.write('login_start', {
|
||||
username: client.username
|
||||
});
|
||||
}
|
||||
|
||||
function onLogin(packet) {
|
||||
client.state = states.PLAY;
|
||||
client.uuid = packet.uuid;
|
||||
|
Loading…
x
Reference in New Issue
Block a user