Skip to content

Commit 8cc04e0

Browse files
authoredJun 30, 2021
Run on_grant and on_revoke callbacks after privs change (#11387)
Callbacks were run too early. This changes the order to call after the privs are updated.
1 parent f2fd443 commit 8cc04e0

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed
 

‎builtin/game/auth.lua

+4-3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ core.builtin_auth_handler = {
8787
core.settings:get("default_password")))
8888
end
8989

90+
auth_entry.privileges = privileges
91+
92+
core_auth.save(auth_entry)
93+
9094
-- Run grant callbacks
9195
for priv, _ in pairs(privileges) do
9296
if not auth_entry.privileges[priv] then
@@ -100,9 +104,6 @@ core.builtin_auth_handler = {
100104
core.run_priv_callbacks(name, priv, nil, "revoke")
101105
end
102106
end
103-
104-
auth_entry.privileges = privileges
105-
core_auth.save(auth_entry)
106107
core.notify_authentication_modified(name)
107108
end,
108109
reload = function()

‎builtin/game/chat.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,11 @@ local function handle_grant_command(caller, grantname, grantprivstr)
255255
if privs_unknown ~= "" then
256256
return false, privs_unknown
257257
end
258+
core.set_player_privs(grantname, privs)
258259
for priv, _ in pairs(grantprivs) do
259260
-- call the on_grant callbacks
260261
core.run_priv_callbacks(grantname, priv, caller, "grant")
261262
end
262-
core.set_player_privs(grantname, privs)
263263
core.log("action", caller..' granted ('..core.privs_to_string(grantprivs, ', ')..') privileges to '..grantname)
264264
if grantname ~= caller then
265265
core.chat_send_player(grantname,
@@ -359,13 +359,13 @@ local function handle_revoke_command(caller, revokename, revokeprivstr)
359359
end
360360

361361
local revokecount = 0
362+
363+
core.set_player_privs(revokename, privs)
362364
for priv, _ in pairs(revokeprivs) do
363365
-- call the on_revoke callbacks
364366
core.run_priv_callbacks(revokename, priv, caller, "revoke")
365367
revokecount = revokecount + 1
366368
end
367-
368-
core.set_player_privs(revokename, privs)
369369
local new_privs = core.get_player_privs(revokename)
370370

371371
if revokecount == 0 then

0 commit comments

Comments
 (0)
Please sign in to comment.