Compare commits
5 Commits
43c7258936
...
e8effb87b3
Author | SHA1 | Date |
---|---|---|
|
e8effb87b3 | |
|
91895fc1a9 | |
|
23d4ade140 | |
|
4a815cd04e | |
|
83d48fe2cb |
55
init.lua
55
init.lua
|
@ -1,5 +1,5 @@
|
||||||
--[[
|
--[[
|
||||||
Afk Kick mod for Minetest by GunshipPenguin
|
Afk tag mod for Minetest by Dargod, fork of GunshipPenguin afkkick mod.
|
||||||
|
|
||||||
To the extent possible under law, the author(s)
|
To the extent possible under law, the author(s)
|
||||||
have dedicated all copyright and related and neighboring rights
|
have dedicated all copyright and related and neighboring rights
|
||||||
|
@ -7,9 +7,8 @@ to this software to the public domain worldwide. This software is
|
||||||
distributed without any warranty.
|
distributed without any warranty.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local MAX_INACTIVE_TIME = 300
|
local MAX_INACTIVE_TIME = 120
|
||||||
local CHECK_INTERVAL = 1
|
local CHECK_INTERVAL = 1
|
||||||
local WARN_TIME = 20
|
|
||||||
|
|
||||||
local players = {}
|
local players = {}
|
||||||
local checkTimer = 0
|
local checkTimer = 0
|
||||||
|
@ -26,36 +25,44 @@ minetest.register_on_leaveplayer(function(player)
|
||||||
players[playerName] = nil
|
players[playerName] = nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_chat_message(function(playerName, message)
|
||||||
|
players[playerName]["lastAction"] = minetest.get_gametime()
|
||||||
|
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
|
||||||
|
|
||||||
--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 then
|
||||||
checkTimer = 0
|
checkTimer = 0
|
||||||
|
|
||||||
--Kick player if he/she has been inactive for longer than MAX_INACTIVE_TIME seconds
|
--Change tag of player if he/she has been inactive for longer than MAX_INACTIVE_TIME seconds
|
||||||
if players[playerName]["lastAction"] + MAX_INACTIVE_TIME < currGameTime then
|
if minetest.get_modpath("rank") then
|
||||||
print(dump(players[playerName]["lastAction"]))
|
if players[playerName]["lastAction"] + MAX_INACTIVE_TIME < currGameTime then
|
||||||
print(dump(currGameTime))
|
minetest.get_player_by_name(playerName):set_nametag_attributes({text = "[AFK] " ..rank.getRankName(playerName).. " " ..playerName})
|
||||||
print(dump(MAX_INACTIVE_TIME))
|
else minetest.get_player_by_name(playerName):set_nametag_attributes({text = "" ..rank.getRankName(playerName).. " " ..playerName})
|
||||||
minetest.kick_player(playerName, "Kicked for inactivity")
|
end
|
||||||
|
else
|
||||||
|
if players[playerName]["lastAction"] + MAX_INACTIVE_TIME < currGameTime then
|
||||||
|
minetest.get_player_by_name(playerName):set_nametag_attributes({text = "[AFK] " ..playerName})
|
||||||
|
--minetest.chat_send_player(playerName, "You have been marked as AFK")
|
||||||
|
else minetest.get_player_by_name(playerName):set_nametag_attributes({text = "" ..playerName})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--Warn player if he/she has less than WARN_TIME seconds to move or be kicked
|
--Check if this player is doing an action
|
||||||
if players[playerName]["lastAction"] + MAX_INACTIVE_TIME - WARN_TIME < currGameTime then
|
for _,keyPressed in pairs(player:get_player_control()) do
|
||||||
minetest.chat_send_player(playerName, "Warning, you have " .. tostring(players[playerName]["lastAction"] + MAX_INACTIVE_TIME - currGameTime) .. " seconds to move or be kicked")
|
if keyPressed then
|
||||||
end
|
players[playerName]["lastAction"] = currGameTime
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue