From be26987feea6c3d79425b0172386c740a4fdefc8 Mon Sep 17 00:00:00 2001 From: ssdaniel24 <107036969+ssdaniel24@users.noreply.github.com> Date: Mon, 27 May 2024 23:04:05 +0300 Subject: [PATCH] Kick inactive players from clans (lord-server/lord#1385). Closes lord-server/lord#1324. * Kick inactive players from clans on startup * Check last login clan players every day --- .../AuthenticationHandlerDefinition.lua | 51 +++++++++++++++++++ minetest_types.lua | 5 ++ 2 files changed, 56 insertions(+) create mode 100644 definitions/AuthenticationHandlerDefinition.lua diff --git a/definitions/AuthenticationHandlerDefinition.lua b/definitions/AuthenticationHandlerDefinition.lua new file mode 100644 index 0000000..5ccfd67 --- /dev/null +++ b/definitions/AuthenticationHandlerDefinition.lua @@ -0,0 +1,51 @@ +---@class AuthenticationHandlerGetAuth +---@field password string +---@field priveleges table +---@field last_login number|nil + +-- Used by `minetest.register_authentication_handler`. +---@class AuthenticationHandlerDefinition +local AuthenticationHandlerDefinition = { + --- Get authentication data for existing player `name` (`nil` if player + --- doesn't exist). + --- Returns following structure: + --- `{password=, privileges=, last_login=}` + ---@type fun(name:string):AuthenticationHandlerGetAuth + get_auth = function(name) end, + + --- Create new auth data for player `name`. + --- Note that `password` is not plain-text but an arbitrary + --- representation decided by the engine. + ---@type fun(name:string, password:string) + create_auth = function(name, password) end, + + --- Delete auth data of player `name`. + --- Returns boolean indicating success (false if player is nonexistent). + ---@type fun(name:string) + delete_auth = function(name) end, + + --- Set password of player `name` to `password`. + --- Auth data should be created if not present. + ---@type fun(name:string, password:string) + set_password = function(name, password) end, + + --- Set privileges of player `name`. + --- `privileges` is in table form, auth data should be created if not + --- present. + ---@type fun(name:string, priveleges:table) + set_privileges = function(name, privileges) end, + + --- Reload authentication data from the storage location. + --- Returns boolean indicating success. + ---@type fun():boolean + reload = function() end, + + --- Called when player joins, used for keeping track of last_login + ---@type fun(name:string) + record_login = function(name) end, + + --- Returns an iterator (use with `for` loops) for all player names + --- currently in the auth database + ---@type fun():fun() + iterate = function() end, +} diff --git a/minetest_types.lua b/minetest_types.lua index 5aa24e3..9743a57 100644 --- a/minetest_types.lua +++ b/minetest_types.lua @@ -150,6 +150,7 @@ function minetest.is_nan(arg) end --- * This value might overflow on certain 32-bit systems! --- --- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L3269-L3271) +---@return number function minetest.get_us_time() end --- returns a position. --- * returns the exact position on the surface of a pointed node @@ -839,6 +840,7 @@ function minetest.get_player_ip(name) end --- `local auth_data = minetest.get_auth_handler().get_auth(playername)` --- --- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L4807-L4810) +---@return AuthenticationHandlerDefinition function minetest.get_auth_handler() end --- * Must be called by the authentication handler for privilege changes. --- * `name`: string; if omitted, all auth data should be considered modified @@ -1703,6 +1705,9 @@ function minetest.sound_fade(handle, step, gain) end --- * Optional: Variable number of arguments that are passed to `func` --- --- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L5420-L5422) +---@param time number @in seconds +---@param func fun() +---@return table @job (job:cancel() to stop) function minetest.after(time, func, ...) end --- * Cancels the job function from being called function job:cancel() end