fix: cross version ping (#976)

* docs: explain version parameter

Explain version parameter more explicitly. Remove reference to outdated versions. Describe dynamic cross version support with parameter value `false`.

* fix(types): allow `false` for version parameter

Allow value `false` for version parameter. This makes dynamic cross version support usable in typescript projects.

* fix: enable cross version support for ping

Enable dynamic cross version support for ping by responding with the client version and protocol version if dynamic cross version support is enabled.
This commit is contained in:
jojomatik 2022-04-10 14:45:04 +02:00 committed by GitHub
parent 9cff34efc0
commit 68e6400e30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 7 deletions

View file

@ -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.

2
src/index.d.ts vendored
View file

@ -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

View file

@ -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,