Added bypass_afk_kick priv

Those who have this priv will not be kicked for AFK.
master
david 2021-07-22 14:03:55 -04:00
parent 1ad2645823
commit 7145ac40d4
2 changed files with 21 additions and 3 deletions

View File

@ -1,4 +1,7 @@
Afk Kick mod for Minetest by GunshipPenguin
# Afk Kick
a mod for Minetest by GunshipPenguin
Kicks players after they are Afk for an amount of time. By default,
players are kicked after five minutes, although this can be configured.
@ -21,3 +24,8 @@ WARN_TIME (default 20)
Number of seconds remaining before being kicked that a player will
start to be warned via chat message.
## Changelog:
- 07/22/2021 Beanzilla added the priv bypass_afk_kick which prevents being kicked for an unlimited amount of time. (Default's
to being granted to server admin and if single player)

View File

@ -30,6 +30,12 @@ minetest.register_on_chat_message(function(playerName, message)
players[playerName]["lastAction"] = minetest.get_gametime()
end)
-- Provide a priv to prevent being kicked
minetest.register_privilege("bypass_afk_kick", {
description = "Don't get kicked for being AFK.",
give_to_singleplayer = true,
})
minetest.register_globalstep(function(dtime)
local currGameTime = minetest.get_gametime()
@ -55,11 +61,15 @@ minetest.register_globalstep(function(dtime)
if checkNow then
--Kick player if he/she has been inactive for longer than MAX_INACTIVE_TIME seconds
if info["lastAction"] + MAX_INACTIVE_TIME < currGameTime then
minetest.kick_player(playerName, "Kicked for inactivity")
-- Only kick the player if they don't have bypass_afk_kick
if not minetest.check_player_privs(playerName, {bypass_afk_kick = true}) then
minetest.kick_player(playerName, "Kicked for inactivity")
end
end
--Warn player if he/she has less than WARN_TIME seconds to move or be kicked
if info["lastAction"] + MAX_INACTIVE_TIME - WARN_TIME < currGameTime then
-- Only show this if they can be kicked
if info["lastAction"] + MAX_INACTIVE_TIME - WARN_TIME < currGameTime and not minetest.check_player_privs(playerName, {bypass_afk_kick = true}) then
minetest.chat_send_player(playerName,
minetest.colorize("#FF8C00", "Warning, you have " ..
tostring(info["lastAction"] + MAX_INACTIVE_TIME - currGameTime + 1) ..