aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2022-04-24 21:08:33 +0200
committerGitHub <noreply@github.com>2022-04-24 21:08:33 +0200
commit1c8614ac9ad591f8025712deae26b572cdede50d (patch)
tree6e43d1a79e8705890b075d98c793c57b6b8760b2
parent4558793caf48d63c74574ba740a96c92d0afcc2c (diff)
downloadminetest-1c8614ac9ad591f8025712deae26b572cdede50d.tar.gz
minetest-1c8614ac9ad591f8025712deae26b572cdede50d.tar.bz2
minetest-1c8614ac9ad591f8025712deae26b572cdede50d.zip
Builtin: Allow to revoke unknown privileges
-rw-r--r--builtin/game/chat.lua25
1 files changed, 13 insertions, 12 deletions
diff --git a/builtin/game/chat.lua b/builtin/game/chat.lua
index 78d6bef98..c4fb6314e 100644
--- a/builtin/game/chat.lua
+++ b/builtin/game/chat.lua
@@ -310,12 +310,7 @@ local function handle_revoke_command(caller, revokename, revokeprivstr)
and revokename == core.settings:get("name")
and revokename ~= ""
if revokeprivstr == "all" then
- revokeprivs = privs
- privs = {}
- else
- for priv, _ in pairs(revokeprivs) do
- privs[priv] = nil
- end
+ revokeprivs = table.copy(privs)
end
local privs_unknown = ""
@@ -332,7 +327,10 @@ local function handle_revoke_command(caller, revokename, revokeprivstr)
end
local def = core.registered_privileges[priv]
if not def then
- privs_unknown = privs_unknown .. S("Unknown privilege: @1", priv) .. "\n"
+ -- Old/removed privileges might still be granted to certain players
+ if not privs[priv] then
+ privs_unknown = privs_unknown .. S("Unknown privilege: @1", priv) .. "\n"
+ end
elseif is_singleplayer and def.give_to_singleplayer then
irrevokable[priv] = true
elseif is_admin and def.give_to_admin then
@@ -359,19 +357,22 @@ local function handle_revoke_command(caller, revokename, revokeprivstr)
end
local revokecount = 0
-
- core.set_player_privs(revokename, privs)
for priv, _ in pairs(revokeprivs) do
- -- call the on_revoke callbacks
- core.run_priv_callbacks(revokename, priv, caller, "revoke")
+ privs[priv] = nil
revokecount = revokecount + 1
end
- local new_privs = core.get_player_privs(revokename)
if revokecount == 0 then
return false, S("No privileges were revoked.")
end
+ core.set_player_privs(revokename, privs)
+ for priv, _ in pairs(revokeprivs) do
+ -- call the on_revoke callbacks
+ core.run_priv_callbacks(revokename, priv, caller, "revoke")
+ end
+ local new_privs = core.get_player_privs(revokename)
+
core.log("action", caller..' revoked ('
..core.privs_to_string(revokeprivs, ', ')
..') privileges from '..revokename)