allow false as beforePing callback result to ignore pings and terminate the connection (#986)

This commit is contained in:
Matthias Neid 2022-05-15 00:51:18 +02:00 committed by GitHub
parent 7a1d857602
commit 83f1e85480
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View file

@ -15,6 +15,7 @@ automatically logged in and validated against mojang's auth.
* beforePing : allow customisation of the answer to ping the server does.
It takes a function with argument response and client, response is the default json response, and client is client who sent a ping.
It can take as third argument a callback. If the callback is passed, the function should pass its result to the callback, if not it should return.
If the result is `false` instead of a response object then the connection is terminated and no ping is returned to the client.
* beforeLogin : allow customisation of client before the `success` packet is sent.
It takes a function with argument client and should be synchronous for the server to wait for completion before continuing execution.
* motd : default to "A Minecraft server"

View file

@ -41,7 +41,11 @@ module.exports = function (client, server, { beforePing = null, version, fallbac
function answerToPing (err, response) {
if (err) return
client.write('server_info', { response: JSON.stringify(response) })
if (response === false) {
client.socket.destroy()
} else {
client.write('server_info', { response: JSON.stringify(response) })
}
}
if (beforePing) {