mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-14 19:04:59 -05:00
dynamic autoversion server
This commit is contained in:
parent
8c370d8011
commit
562c7ebec7
3 changed files with 17 additions and 9 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue