Fix player loop early bailout, standardize kickability logic
This commit is contained in:
parent
906cf51cbb
commit
f2b930f783
@ -17,6 +17,10 @@ minetest.register_privilege(modname, {
|
||||
give_to_admin = false
|
||||
})
|
||||
|
||||
local function kickable(pname)
|
||||
return (not minetest.check_player_privs(pname, modname)) == (not invert)
|
||||
end
|
||||
|
||||
local function now() return minetest.get_us_time() / 1000000 end
|
||||
|
||||
local times = {}
|
||||
@ -26,17 +30,21 @@ minetest.register_chatcommand(modname, {
|
||||
description = "Check player idle time and last action",
|
||||
privs = {server = true},
|
||||
func = function(_, param)
|
||||
local time = times[param]
|
||||
if not time then
|
||||
if not minetest.get_player_by_name(param) then
|
||||
return true, string_format("Player %q not found", param)
|
||||
end
|
||||
local active = (not minetest.check_player_privs(param, modname))
|
||||
== (not invert)
|
||||
if not kickable(param) then
|
||||
return true, string_format("Player %q exempt", param)
|
||||
end
|
||||
local time = times[param]
|
||||
if not time then
|
||||
return true, string_format("Player %q no data", param)
|
||||
end
|
||||
return true, string_format(
|
||||
"Player %q idle %0.2f/%s last action %q",
|
||||
"Player %q idle %0.2f/%0.2f last action %q",
|
||||
param,
|
||||
now() - time,
|
||||
active and string_format("%.2f", timeout) or "never",
|
||||
timeout,
|
||||
actions[param] or "unknown")
|
||||
end
|
||||
})
|
||||
@ -85,11 +93,12 @@ local function checkplayer(player, pname)
|
||||
end
|
||||
minetest.register_globalstep(function()
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
if (not minetest.check_player_privs(player, modname)) ~= (not invert) then return end
|
||||
local pname = player:get_player_name()
|
||||
if kickable(pname) then
|
||||
checkplayer(player, pname)
|
||||
if now() - times[pname] >= timeout then
|
||||
minetest.kick_player(pname, reason)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
Loading…
x
Reference in New Issue
Block a user