produce a decent error when connecting with the wrong version

This commit is contained in:
Romain Beaumont 2017-03-12 12:23:13 +01:00
parent 5126b96954
commit a55d2bc42c
No known key found for this signature in database
GPG Key ID: DB60E388B3BCF286
3 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,11 @@
module.exports = function(client,options) {
client.on("disconnect",message => {
if(!message.reason)
return;
const versionRequired=/Outdated client! Please use (.+)/.exec(JSON.parse(message.reason).text);
if(!versionRequired)
return;
client.emit("error",new Error("This server is version "+versionRequired[1]+
", you are using version "+client.version+", please specify the correct version in the options."))
})
};

View File

@ -12,6 +12,7 @@ const play = require('./client/play');
const tcp_dns = require('./client/tcp_dns'); const tcp_dns = require('./client/tcp_dns');
const autoVersion = require('./client/autoVersion'); const autoVersion = require('./client/autoVersion');
const pluginChannels = require('./client/pluginChannels'); const pluginChannels = require('./client/pluginChannels');
const versionChecking = require('./client/versionChecking');
module.exports=createClient; module.exports=createClient;
@ -38,6 +39,7 @@ function createClient(options) {
play(client, options); play(client, options);
compress(client, options); compress(client, options);
pluginChannels(client, options); pluginChannels(client, options);
versionChecking(client,options);
return client; return client;
} }

View File

@ -221,5 +221,29 @@ mc.supportedVersions.forEach(function(supportedVersion) {
}); });
}); });
}); });
it("produce a decent error when connecting with the wrong version",function(done) {
wrap.startServer({
'online-mode': 'false',
'server-port':PORT
}, function(err) {
if(err)
return done(err);
var client = mc.createClient({
username: 'Player',
version: version.minecraftVersion=="1.8.8" ? "1.11.2" : "1.8.8",
port:PORT
});
client.once("error",function(err) {
if(err.message.startsWith("This server is version")) {
console.log("Correctly got an error for wrong version : "+err.message);
done();
}
else {
done(err);
}
});
})
})
}); });
}); });