mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-10-02 23:52:07 -04:00
produce a decent error when connecting with the wrong version
This commit is contained in:
parent
5126b96954
commit
a55d2bc42c
11
src/client/versionChecking.js
Normal file
11
src/client/versionChecking.js
Normal 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."))
|
||||
})
|
||||
};
|
@ -12,6 +12,7 @@ const play = require('./client/play');
|
||||
const tcp_dns = require('./client/tcp_dns');
|
||||
const autoVersion = require('./client/autoVersion');
|
||||
const pluginChannels = require('./client/pluginChannels');
|
||||
const versionChecking = require('./client/versionChecking');
|
||||
|
||||
module.exports=createClient;
|
||||
|
||||
@ -38,6 +39,7 @@ function createClient(options) {
|
||||
play(client, options);
|
||||
compress(client, options);
|
||||
pluginChannels(client, options);
|
||||
versionChecking(client,options);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user