Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
23eb466487 | |||
ed50232075 | |||
|
86e0699d52 |
58
init.lua
58
init.lua
@ -11,34 +11,36 @@ local time_afk = { }
|
|||||||
local last_pos = { }
|
local last_pos = { }
|
||||||
|
|
||||||
local function check_moved()
|
local function check_moved()
|
||||||
for _, p in ipairs(minetest.get_connected_players()) do
|
for _, p in ipairs(minetest.get_connected_players()) do
|
||||||
local plname = p:get_player_name()
|
local plname = p:get_player_name()
|
||||||
local pos = p:getpos()
|
local pos = p:get_pos()
|
||||||
local kicked
|
local kicked
|
||||||
if last_pos[plname] then
|
if last_pos[plname] then
|
||||||
local d = vector.distance(last_pos[plname], pos)
|
local d = vector.distance(last_pos[plname], pos)
|
||||||
--print("Player: "..plname..", Dist: "..d)
|
--print("Player: "..plname..", Dist: "..d)
|
||||||
if d < MINDIST then
|
if d < MINDIST then
|
||||||
time_afk[plname] = (time_afk[plname] or 0) + INTERVAL
|
time_afk[plname] = (time_afk[plname] or 0) + INTERVAL
|
||||||
if time_afk[plname] >= TIMEOUT then
|
if time_afk[plname] >= TIMEOUT then
|
||||||
minetest.kick_player(plname,
|
minetest.kick_player(plname, "Inactive for "..TIMEOUT.." seconds.")
|
||||||
"Inactive for "..TIMEOUT.." seconds.")
|
kicked = true
|
||||||
kicked = true
|
end
|
||||||
end
|
else
|
||||||
else
|
time_afk[plname] = 0
|
||||||
time_afk[plname] = 0
|
end
|
||||||
end
|
end
|
||||||
end
|
if not kicked then
|
||||||
if not kicked then
|
last_pos[plname] = pos
|
||||||
last_pos[plname] = pos
|
end
|
||||||
end
|
end
|
||||||
end
|
minetest.after(INTERVAL, check_moved)
|
||||||
minetest.after(INTERVAL, check_moved)
|
|
||||||
end
|
end
|
||||||
minetest.after(INTERVAL, check_moved)
|
minetest.after(INTERVAL, check_moved)
|
||||||
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
minetest.register_on_leaveplayer(
|
||||||
local plname = player:get_player_name()
|
function(player)
|
||||||
time_afk[plname] = nil
|
local plname = player:get_player_name()
|
||||||
last_pos[plname] = nil
|
time_afk[plname] = nil
|
||||||
end)
|
last_pos[plname] = nil
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.log("action", "[player_inactive] loaded.")
|
||||||
|
Loading…
Reference in New Issue
Block a user