Add canafk priv
This commit is contained in:
parent
31ae819d0b
commit
105d824de5
1 changed files with 9 additions and 7 deletions
|
@ -14,6 +14,8 @@ local WARN_TIME = 20
|
||||||
local players = {}
|
local players = {}
|
||||||
local checkTimer = 0
|
local checkTimer = 0
|
||||||
|
|
||||||
|
minetest.register_privilege("canafk")
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
local playerName = player:get_player_name()
|
local playerName = player:get_player_name()
|
||||||
players[playerName] = {
|
players[playerName] = {
|
||||||
|
@ -32,28 +34,28 @@ end)
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
local currGameTime = minetest.get_gametime()
|
local currGameTime = minetest.get_gametime()
|
||||||
|
|
||||||
--Loop through each player in players
|
--Loop through each player in players
|
||||||
for playerName,_ in pairs(players) do
|
for playerName,_ in pairs(players) do
|
||||||
local player = minetest.get_player_by_name(playerName)
|
local player = minetest.get_player_by_name(playerName)
|
||||||
if player then
|
if player then
|
||||||
|
|
||||||
--Check for inactivity once every CHECK_INTERVAL seconds
|
--Check for inactivity once every CHECK_INTERVAL seconds
|
||||||
checkTimer = checkTimer + dtime
|
checkTimer = checkTimer + dtime
|
||||||
if checkTimer > CHECK_INTERVAL then
|
if checkTimer > CHECK_INTERVAL and not minetest.check_player_privs({ canafk = true }) then
|
||||||
checkTimer = 0
|
checkTimer = 0
|
||||||
|
|
||||||
--Kick player if he/she has been inactive for longer than MAX_INACTIVE_TIME seconds
|
--Kick player if he/she has been inactive for longer than MAX_INACTIVE_TIME seconds
|
||||||
if players[playerName]["lastAction"] + MAX_INACTIVE_TIME < currGameTime then
|
if players[playerName]["lastAction"] + MAX_INACTIVE_TIME < currGameTime then
|
||||||
minetest.kick_player(playerName, "Kicked for inactivity")
|
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
|
--Warn player if he/she has less than WARN_TIME seconds to move or be kicked
|
||||||
if players[playerName]["lastAction"] + MAX_INACTIVE_TIME - WARN_TIME < currGameTime then
|
if players[playerName]["lastAction"] + MAX_INACTIVE_TIME - WARN_TIME < currGameTime then
|
||||||
minetest.chat_send_player(playerName, "Warning, you have " .. tostring(players[playerName]["lastAction"] + MAX_INACTIVE_TIME - currGameTime) .. " seconds to move or be kicked")
|
minetest.chat_send_player(playerName, "Warning, you have " .. tostring(players[playerName]["lastAction"] + MAX_INACTIVE_TIME - currGameTime) .. " seconds to move or be kicked")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--Check if this player is doing an action
|
--Check if this player is doing an action
|
||||||
for _,keyPressed in pairs(player:get_player_control()) do
|
for _,keyPressed in pairs(player:get_player_control()) do
|
||||||
if keyPressed then
|
if keyPressed then
|
||||||
|
|
Loading…
Reference in a new issue