mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-14 19:04:59 -05:00
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:
parent
9cff34efc0
commit
68e6400e30
3 changed files with 15 additions and 7 deletions
|
@ -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
2
src/index.d.ts
vendored
|
@ -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
|
||||
|
|
|
@ -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 () {
|
||||
const response = {
|
||||
version: {
|
||||
// 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: responseVersion,
|
||||
players: {
|
||||
max: server.maxPlayers,
|
||||
online: server.playerCount,
|
||||
|
|
Loading…
Reference in a new issue