Builtin: Allow to revoke unknown privileges

This commit is contained in:
SmallJoker 2022-04-24 21:08:33 +02:00 committed by GitHub
parent 4558793caf
commit 1c8614ac9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -310,12 +310,7 @@ local function handle_revoke_command(caller, revokename, revokeprivstr)
and revokename == core.settings:get("name") and revokename == core.settings:get("name")
and revokename ~= "" and revokename ~= ""
if revokeprivstr == "all" then if revokeprivstr == "all" then
revokeprivs = privs revokeprivs = table.copy(privs)
privs = {}
else
for priv, _ in pairs(revokeprivs) do
privs[priv] = nil
end
end end
local privs_unknown = "" local privs_unknown = ""
@ -332,7 +327,10 @@ local function handle_revoke_command(caller, revokename, revokeprivstr)
end end
local def = core.registered_privileges[priv] local def = core.registered_privileges[priv]
if not def then 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 elseif is_singleplayer and def.give_to_singleplayer then
irrevokable[priv] = true irrevokable[priv] = true
elseif is_admin and def.give_to_admin then elseif is_admin and def.give_to_admin then
@ -359,19 +357,22 @@ local function handle_revoke_command(caller, revokename, revokeprivstr)
end end
local revokecount = 0 local revokecount = 0
for priv, _ in pairs(revokeprivs) do
privs[priv] = nil
revokecount = revokecount + 1
end
if revokecount == 0 then
return false, S("No privileges were revoked.")
end
core.set_player_privs(revokename, privs) core.set_player_privs(revokename, privs)
for priv, _ in pairs(revokeprivs) do for priv, _ in pairs(revokeprivs) do
-- call the on_revoke callbacks -- call the on_revoke callbacks
core.run_priv_callbacks(revokename, priv, caller, "revoke") core.run_priv_callbacks(revokename, priv, caller, "revoke")
revokecount = revokecount + 1
end end
local new_privs = core.get_player_privs(revokename) local new_privs = core.get_player_privs(revokename)
if revokecount == 0 then
return false, S("No privileges were revoked.")
end
core.log("action", caller..' revoked (' core.log("action", caller..' revoked ('
..core.privs_to_string(revokeprivs, ', ') ..core.privs_to_string(revokeprivs, ', ')
..') privileges from '..revokename) ..') privileges from '..revokename)