mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-10-02 15:40:18 -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 keepalive = require('./client/keepalive');
|
||||||
var compress = require('./client/compress');
|
var compress = require('./client/compress');
|
||||||
var caseCorrect = require('./client/caseCorrect');
|
var caseCorrect = require('./client/caseCorrect');
|
||||||
|
var setProtocol = require('./client/setProtocol');
|
||||||
|
|
||||||
module.exports=createClient;
|
module.exports=createClient;
|
||||||
|
|
||||||
@ -38,10 +39,12 @@ function createClient(options) {
|
|||||||
var optVersion = options.version || require("./version").defaultVersion;
|
var optVersion = options.version || require("./version").defaultVersion;
|
||||||
var mcData=require("minecraft-data")(optVersion);
|
var mcData=require("minecraft-data")(optVersion);
|
||||||
var version = mcData.version;
|
var version = mcData.version;
|
||||||
|
options.majorVersion = version.majorVersion;
|
||||||
|
options.protocolVersion = version.version;
|
||||||
|
|
||||||
|
|
||||||
var client = new Client(false,version.majorVersion);
|
var client = new Client(false, options.majorVersion);
|
||||||
client.on('connect', onConnect);
|
setProtocol(client, options);
|
||||||
keepalive(client, options);
|
keepalive(client, options);
|
||||||
encrypt(client);
|
encrypt(client);
|
||||||
client.once('success', onLogin);
|
client.once('success', onLogin);
|
||||||
@ -50,19 +53,6 @@ function createClient(options) {
|
|||||||
|
|
||||||
return client;
|
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) {
|
function onLogin(packet) {
|
||||||
client.state = states.PLAY;
|
client.state = states.PLAY;
|
||||||
client.uuid = packet.uuid;
|
client.uuid = packet.uuid;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user