diff --git a/docs/API.md b/docs/API.md index 8945e83..1feccae 100644 --- a/docs/API.md +++ b/docs/API.md @@ -20,7 +20,7 @@ automatically logged in and validated against mojang's auth. * motd : default to "A Minecraft server" * maxPlayers : default to 20 * keepAlive : send keep alive packets : default to true - * version : 1.8 or 1.9 : default to 1.8 + * version : the version of the server, defaults to the latest version. Set version to `false` to enable dynamic cross version support. * favicon (optional) : the favicon to set, base64 encoded * customPackets (optional) : an object index by version/state/direction/name, see client_custom_packet for an example * errorHandler : A way to override the default error handler for client errors. A function that takes a Client and an error. diff --git a/src/index.d.ts b/src/index.d.ts index 8a9adfe..77f60c1 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -142,7 +142,7 @@ declare module 'minecraft-protocol' { motd?: string maxPlayers?: number keepAlive?: boolean - version?: string + version?: string | false favicon?: string customPackets?: any errorHandler?: (client: Client, error: Error) => void diff --git a/src/server/ping.js b/src/server/ping.js index f72fca5..38205d4 100644 --- a/src/server/ping.js +++ b/src/server/ping.js @@ -1,15 +1,23 @@ const endianToggle = require('endian-toggle') -module.exports = function (client, server, { beforePing = null }) { +module.exports = function (client, server, { beforePing = null, version }) { client.once('ping_start', onPing) client.once('legacy_server_list_ping', onLegacyPing) function onPing () { + // Use client version if dynamic cross version support is enabled. + const responseVersion = (version === false) + ? { + name: client.version, + protocol: client.protocolVersion + } + : { + name: server.mcversion.minecraftVersion, + protocol: server.mcversion.version + } + const response = { - version: { - name: server.mcversion.minecraftVersion, - protocol: server.mcversion.version - }, + version: responseVersion, players: { max: server.maxPlayers, online: server.playerCount,