From e4c5a652bac33a60bc753bd151ef78bcd3f44ebf Mon Sep 17 00:00:00 2001 From: tchncs Date: Thu, 31 Mar 2016 20:57:03 +0200 Subject: [PATCH] changed kick message and increase afk time to 45 minutes --- init.lua | 83 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/init.lua b/init.lua index 04fa94d..c676ead 100644 --- a/init.lua +++ b/init.lua @@ -7,59 +7,60 @@ to this software to the public domain worldwide. This software is distributed without any warranty. ]] -local MAX_INACTIVE_TIME = 300 -local CHECK_INTERVAL = 1 -local WARN_TIME = 20 +local MAX_INACTIVE_TIME = 2700 +local CHECK_INTERVAL = 10 +local WARN_TIME = 10 local players = {} local checkTimer = 0 minetest.register_on_joinplayer(function(player) - local playerName = player:get_player_name() - players[playerName] = { - lastAction = minetest.get_gametime() - } + local playerName = player:get_player_name() + players[playerName] = { + lastAction = minetest.get_gametime() + } end) minetest.register_on_leaveplayer(function(player) - local playerName = player:get_player_name() - players[playerName] = nil + local playerName = player:get_player_name() + players[playerName] = nil end) minetest.register_on_chat_message(function(playerName, message) - players[playerName]["lastAction"] = minetest.get_gametime() + players[playerName]["lastAction"] = minetest.get_gametime() end) minetest.register_globalstep(function(dtime) - local currGameTime = minetest.get_gametime() - - --Loop through each player in players - for playerName,_ in pairs(players) do - local player = minetest.get_player_by_name(playerName) - if player then - - --Check for inactivity once every CHECK_INTERVAL seconds - checkTimer = checkTimer + dtime - if checkTimer > CHECK_INTERVAL then - checkTimer = 0 - - --Kick player if he/she has been inactive for longer than MAX_INACTIVE_TIME seconds - if players[playerName]["lastAction"] + MAX_INACTIVE_TIME < currGameTime then - minetest.kick_player(playerName, "Kicked for inactivity") - end - - --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 - minetest.chat_send_player(playerName, "Warning, you have " .. tostring(players[playerName]["lastAction"] + MAX_INACTIVE_TIME - currGameTime) .. " seconds to move or be kicked") - end - end - - --Check if this player is doing an action - for _,keyPressed in pairs(player:get_player_control()) do - if keyPressed then - players[playerName]["lastAction"] = currGameTime - end - end - end - end + local currGameTime = minetest.get_gametime() + + --Loop through each player in players + for playerName,_ in pairs(players) do + local player = minetest.get_player_by_name(playerName) + if player then + + --Check for inactivity once every CHECK_INTERVAL seconds + checkTimer = checkTimer + dtime + if checkTimer > CHECK_INTERVAL then + checkTimer = 0 + + --Kick player if he/she has been inactive for longer than MAX_INACTIVE_TIME seconds + if players[playerName]["lastAction"] + MAX_INACTIVE_TIME < currGameTime then + minetest.kick_player(playerName, "The Server has kicked you for inactivity to save your life!") + core.chat_send_all("# Illuna: " .. playerName .. "'s avatar is doing something else now, because its master is not here.") + end + + --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 + minetest.chat_send_player(playerName, "# Illuna: **Warning**, you have " .. tostring(players[playerName]["lastAction"] + MAX_INACTIVE_TIME - currGameTime) .. " seconds to move or the server will kick you for inactivity") + end + end + + --Check if this player is doing an action + for _,keyPressed in pairs(player:get_player_control()) do + if keyPressed then + players[playerName]["lastAction"] = currGameTime + end + end + end + end end)