1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Address set_player_privs footgun (#14297)

---------

Co-authored-by: grorp <gregor.parzefall@posteo.de>
This commit is contained in:
Lars Müller 2024-01-22 20:06:03 +01:00 committed by GitHub
parent 5958714309
commit afc48cf224
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 6 deletions

View file

@ -92,8 +92,16 @@ core.builtin_auth_handler = {
core_auth.save(auth_entry)
-- Run grant callbacks
for priv, _ in pairs(privileges) do
for priv, value in pairs(privileges) do
-- Warnings for improper API usage
if value == false then
core.log('deprecated', "`false` value given to `minetest.set_player_privs`, "..
"this is almost certainly a bug, "..
"granting a privilege rather than revoking it")
elseif value ~= true then
core.log('deprecated', "non-`true` value given to `minetest.set_player_privs`")
end
-- Run grant callbacks
if not prev_privs[priv] then
core.run_priv_callbacks(name, priv, nil, "grant")
end
@ -180,6 +188,20 @@ core.set_player_privs = auth_pass("set_privileges")
core.remove_player_auth = auth_pass("delete_auth")
core.auth_reload = auth_pass("reload")
function core.change_player_privs(name, changes)
local privs = core.get_player_privs(name)
for priv, change in pairs(changes) do
if change == true then
privs[priv] = true
elseif change == false then
privs[priv] = nil
else
error("non-bool value given to `minetest.change_player_privs`")
end
end
core.set_player_privs(name, privs)
end
local record_login = auth_pass("record_login")
core.register_on_joinplayer(function(player)
record_login(player:get_player_name())