added detection for afk players
parent
03662355d2
commit
275b7690ca
|
@ -6,6 +6,7 @@ To install, rename to "enhancements" and place in the mods/ directory.
|
||||||
* scale and override different tools
|
* scale and override different tools
|
||||||
* clean-up server - unknown nodes and entities
|
* clean-up server - unknown nodes and entities
|
||||||
* [external_cmd]server chat messages from outside Minetest game
|
* [external_cmd]server chat messages from outside Minetest game
|
||||||
|
* detect AFK player
|
||||||
* areas - control privilages
|
* areas - control privilages
|
||||||
|
|
||||||
External Commands
|
External Commands
|
||||||
|
@ -26,4 +27,9 @@ Manage players privileges in 'areas' mod if using the mod only for admin purpose
|
||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
* create tables from where you can read/write the privileges
|
* create tables from where you can read/write the privileges
|
||||||
* don't repeat grand/revoke on globalstep - only once when in/out of area - check within tables!
|
* don't repeat grand/revoke on globalstep - only once when in/out of area - check within tables!
|
||||||
|
|
||||||
|
Detect AFK player
|
||||||
|
------------------
|
||||||
|
|
||||||
|
AFK (away from keyboard) is detected when player doesn't move for certain time, player will sit down.
|
|
@ -0,0 +1,85 @@
|
||||||
|
-- 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, 'sit' player (in seconds).
|
||||||
|
local TIMEOUT = 600 -- 10 minutes
|
||||||
|
|
||||||
|
local time_afk = {}
|
||||||
|
local last_pos = {}
|
||||||
|
local chat_afk = {}
|
||||||
|
local chat_noafk = {}
|
||||||
|
|
||||||
|
local function check_moved()
|
||||||
|
|
||||||
|
for _, p in ipairs(minetest.get_connected_players()) do
|
||||||
|
local plname = p:get_player_name()
|
||||||
|
local pos = p:getpos()
|
||||||
|
local sit = false
|
||||||
|
|
||||||
|
if chat_noafk[plname] == nil then
|
||||||
|
chat_afk[plname] = false
|
||||||
|
chat_noafk[plname] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
default.player_attached[plname] = true
|
||||||
|
default.player_set_animation(p, "sit")
|
||||||
|
sit = true
|
||||||
|
|
||||||
|
chat_noafk[plname] = false
|
||||||
|
|
||||||
|
if chat_afk[plname] == false then
|
||||||
|
minetest.chat_send_all("* "..plname.." is AFK.")
|
||||||
|
chat_afk[plname] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
time_afk[plname] = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not sit then
|
||||||
|
|
||||||
|
last_pos[plname] = pos
|
||||||
|
default.player_attached[plname] = false
|
||||||
|
default.player_set_animation(p, "stand")
|
||||||
|
|
||||||
|
chat_afk[plname] = false
|
||||||
|
|
||||||
|
if chat_noafk[plname] == false then
|
||||||
|
minetest.chat_send_all("* "..plname.." came back from AFK.")
|
||||||
|
chat_noafk[plname] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if p:get_hp() == 0 and sit then
|
||||||
|
default.player_set_animation(p, "lay")
|
||||||
|
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
|
||||||
|
chat_afk[plname] = nil
|
||||||
|
chat_noafk[plname] = nil
|
||||||
|
end)
|
9
init.lua
9
init.lua
|
@ -1,4 +1,4 @@
|
||||||
-- main setings
|
-- main settings
|
||||||
dofile(minetest.get_modpath("enhancements").."/settings.txt")
|
dofile(minetest.get_modpath("enhancements").."/settings.txt")
|
||||||
|
|
||||||
-- tools enhancements
|
-- tools enhancements
|
||||||
|
@ -24,6 +24,13 @@ if EXTERNAL_CMD then
|
||||||
print("[Mod][enhancements] EXTERNAL_CMD enabled")
|
print("[Mod][enhancements] EXTERNAL_CMD enabled")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- detect AFK players
|
||||||
|
if PLAYER_AFK then
|
||||||
|
dofile(minetest.get_modpath("enhancements").."/afk.lua")
|
||||||
|
|
||||||
|
print("[Mod][enhancements] PLAYER_AFK enabled")
|
||||||
|
end
|
||||||
|
|
||||||
-- manage privileges i areas mod - if using areas mod only for admin purposes
|
-- manage privileges i areas mod - if using areas mod only for admin purposes
|
||||||
-- WIP DONT ENABLE!
|
-- WIP DONT ENABLE!
|
||||||
if AREAS_ENHANCE and minetest.get_modpath("areas") then
|
if AREAS_ENHANCE and minetest.get_modpath("areas") then
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
TOOLS_ENHANCE = true
|
TOOLS_ENHANCE = true
|
||||||
CLEAN_UNKNOWN = true
|
CLEAN_UNKNOWN = true
|
||||||
EXTERNAL_CMD = true
|
EXTERNAL_CMD = true
|
||||||
|
PLAYER_AFK = true
|
||||||
AREAS_ENHANCE = false
|
AREAS_ENHANCE = false
|
||||||
|
|
Loading…
Reference in New Issue