1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-18 08:10:38 +01:00
server-nalc/mods/player_inactive/init.lua

45 lines
1.3 KiB
Lua
Raw Normal View History

2014-10-28 18:01:32 +01:00
-- Interval between movement checks (in seconds).
local INTERVAL = 5
-- Minimum distance to move to register as not AFK (in blocks).
local MINDIST = 0.2
-- If player does not move within this time, kick player (in seconds).
2015-11-23 15:03:26 +01:00
local TIMEOUT = 3600 -- 60 minutes
2014-10-28 18:01:32 +01:00
local time_afk = { }
local last_pos = { }
local function check_moved()
for _, p in ipairs(minetest.get_connected_players()) do
local plname = p:get_player_name()
local pos = p:getpos()
local kicked
if last_pos[plname] then
local d = vector.distance(last_pos[plname], pos)
--print("Player: "..plname..", Dist: "..d)
if d < MINDIST then
time_afk[plname] = (time_afk[plname] or 0) + INTERVAL
if time_afk[plname] >= TIMEOUT then
minetest.kick_player(plname,
"Inactive for "..TIMEOUT.." seconds.")
kicked = true
end
else
time_afk[plname] = 0
end
end
if not kicked then
last_pos[plname] = pos
end
end
minetest.after(INTERVAL, check_moved)
end
minetest.after(INTERVAL, check_moved)
minetest.register_on_leaveplayer(function(player)
local plname = player:get_player_name()
time_afk[plname] = nil
last_pos[plname] = nil
end)