Merge pull request #500 from PrismarineJS/trying_to_fix_autoversion

trying to fix autoversion in online mode
This commit is contained in:
Romain Beaumont 2017-07-12 13:21:10 +02:00 committed by GitHub
commit 9c1925a1f2
4 changed files with 21 additions and 17 deletions

View File

@ -7,7 +7,8 @@ if(process.argv.length < 4 || process.argv.length > 6) {
process.exit(1); process.exit(1);
} }
var client = mc.createClient({version: false, var client = mc.createClient({
version: false,
host: process.argv[2], host: process.argv[2],
port: parseInt(process.argv[3]), port: parseInt(process.argv[3]),
username: process.argv[4] ? process.argv[4] : "echo", username: process.argv[4] ? process.argv[4] : "echo",

View File

@ -18,7 +18,6 @@ class Client extends EventEmitter
this.version=version; this.version=version;
this.isServer = !!isServer; this.isServer = !!isServer;
this.splitter=framing.createSplitter(); this.splitter=framing.createSplitter();
this.setSerializer(states.HANDSHAKING);
this.packetsToParse={}; this.packetsToParse={};
this.serializer; this.serializer;
this.compressor=null; this.compressor=null;
@ -28,7 +27,6 @@ class Client extends EventEmitter
this.decompressor=null; this.decompressor=null;
this.deserializer; this.deserializer;
this.isServer; this.isServer;
this.protocolState=states.HANDSHAKING;
this.ended=true; this.ended=true;
this.latency=0; this.latency=0;
@ -41,6 +39,8 @@ class Client extends EventEmitter
const direction = this.isServer ? 'toServer' : 'toClient'; const direction = this.isServer ? 'toServer' : 'toClient';
this.packetsToParse[event] -= 1; this.packetsToParse[event] -= 1;
}); });
this.state=states.HANDSHAKING;
} }
get state(){ get state(){
@ -109,19 +109,19 @@ class Client extends EventEmitter
const oldProperty = this.protocolState; const oldProperty = this.protocolState;
this.protocolState = newProperty; this.protocolState = newProperty;
if(!this.compressor) if(this.serializer) {
{ if (!this.compressor) {
this.serializer.unpipe(this.framer); this.serializer.unpipe();
this.splitter.unpipe(this.deserializer); this.splitter.unpipe(this.deserializer);
} }
else else {
{ this.serializer.unpipe(this.compressor);
this.serializer.unpipe(this.compressor); this.decompressor.unpipe(this.deserializer);
this.decompressor.unpipe(this.deserializer); }
}
this.serializer.removeAllListeners(); this.serializer.removeAllListeners();
this.deserializer.removeAllListeners(); this.deserializer.removeAllListeners();
}
this.setSerializer(this.protocolState); this.setSerializer(this.protocolState);
if(!this.compressor) if(!this.compressor)
@ -180,8 +180,8 @@ class Client extends EventEmitter
this.framer.on('error', onError); this.framer.on('error', onError);
this.splitter.on('error', onError); this.splitter.on('error', onError);
this.socket.pipe(this.splitter).pipe(this.deserializer); this.socket.pipe(this.splitter);
this.serializer.pipe(this.framer).pipe(this.socket); this.framer.pipe(this.socket);
} }
end(reason) { end(reason) {

View File

@ -53,6 +53,7 @@ module.exports = function(client, options) {
// Finished configuring client object, let connection proceed // Finished configuring client object, let connection proceed
client.emit('connect_allowed'); client.emit('connect_allowed');
client.wait_connect = false;
}); });
return client; return client;
}; };

View File

@ -19,6 +19,8 @@ module.exports=createClient;
function createClient(options) { function createClient(options) {
assert.ok(options, "options is required"); assert.ok(options, "options is required");
assert.ok(options.username, "username is required"); assert.ok(options.username, "username is required");
if(!options.version)
options.version=false;
// TODO: avoid setting default version if autoVersion is enabled // TODO: avoid setting default version if autoVersion is enabled
const optVersion = options.version || require("./version").defaultVersion; const optVersion = options.version || require("./version").defaultVersion;