Skip to content

Commit

Permalink
Builtin: Allow to revoke unknown privileges
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallJoker committed Apr 24, 2022
1 parent 4558793 commit 1c8614a
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions builtin/game/chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 1c8614a

Please sign in to comment.