dynamic autoversion server

This commit is contained in:
Romain Beaumont 2017-07-21 22:15:50 +02:00
parent 8c370d8011
commit 562c7ebec7
No known key found for this signature in database
GPG key ID: DB60E388B3BCF286
3 changed files with 17 additions and 9 deletions

View file

@ -18,17 +18,19 @@ function createServer(options={}) {
port = serverPort || 25565,
motd = "A Minecraft server",
'max-players' : maxPlayers = 20,
version : optVersion = require("./version").defaultVersion,
version,
favicon,
customPackets
} = options;
const optVersion = version===undefined || version===false ? require("./version").defaultVersion : version;
const mcData=require("minecraft-data")(optVersion);
const version = mcData.version;
const mcversion = mcData.version;
const server = new Server(version.minecraftVersion,customPackets);
server.mcversion=version;
const server = new Server(mcversion.minecraftVersion,customPackets);
server.mcversion=mcversion;
server.motd = motd;
server.maxPlayers = maxPlayers;
server.playerCount = 0;

View file

@ -1,6 +1,6 @@
const states = require("../states");
module.exports=function(client,server) {
module.exports=function(client,server,{version}) {
client.once('set_protocol', onHandshake);
@ -8,14 +8,20 @@ module.exports=function(client,server) {
client.serverHost = packet.serverHost;
client.serverPort = packet.serverPort;
client.protocolVersion = packet.protocolVersion;
if(version === false || version === undefined) {
client.version=client.protocolVersion;
}
else if (client.protocolVersion !== server.mcversion.version) {
client.end("Wrong protocol version, expected: " + server.mcversion.version + " and you are using: " + client.protocolVersion);
}
if (packet.nextState === 1) {
client.state = states.STATUS;
} else if (packet.nextState === 2) {
client.state = states.LOGIN;
}
if (client.protocolVersion !== server.mcversion.version) {
client.end("Wrong protocol version, expected: " + server.mcversion.version + " and you are using: " + client.protocolVersion);
}
}
};

View file

@ -115,7 +115,7 @@ module.exports=function(client,server,options) {
if(onlineMode === false || isException) {
client.uuid = nameToMcOfflineUUID(client.username);
}
if (server.mcversion.version >= 27) { // 14w28a (27) added whole-protocol compression (http://wiki.vg/Protocol_History#14w28a), earlier versions per-packet compressed TODO: refactor into minecraft-data
if (client.protocolVersion >= 27) { // 14w28a (27) added whole-protocol compression (http://wiki.vg/Protocol_History#14w28a), earlier versions per-packet compressed TODO: refactor into minecraft-data
client.write('compress', { threshold: 256 }); // Default threshold is 256
client.compressionThreshold = 256;
}