Skip to content

Commit 58eb5f3

Browse files
t4imparamat
authored andcommitted
Builtin: Fix check for a player object in core.check_player_privs
core.check_player_privs accepts as first argument a name or player object, but just tested for a string. This caused crashes inside builtin, when being passed any unexpected types. This provides a better (duck-typing like) test, better error reporting.
1 parent f833159 commit 58eb5f3

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

builtin/game/misc.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ function core.after(after, func, ...)
4848
}
4949
end
5050

51-
function core.check_player_privs(player_or_name, ...)
52-
local name = player_or_name
53-
-- Check if we have been provided with a Player object.
54-
if type(name) ~= "string" then
51+
function core.check_player_privs(name, ...)
52+
local arg_type = type(name)
53+
if (arg_type == "userdata" or arg_type == "table") and
54+
name.get_player_name then -- If it quacks like a Player...
5555
name = name:get_player_name()
56+
elseif arg_type ~= "string" then
57+
error("Invalid core.check_player_privs argument type: " .. arg_type, 2)
5658
end
5759

5860
local requested_privs = {...}

0 commit comments

Comments
 (0)