Skip to content

Commit

Permalink
Builtin: Fix check for a player object in core.check_player_privs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
t4im authored and paramat committed Jul 26, 2016
1 parent f833159 commit 58eb5f3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions builtin/game/misc.lua
Expand Up @@ -48,11 +48,13 @@ function core.after(after, func, ...)
}
end

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

local requested_privs = {...}
Expand Down

0 comments on commit 58eb5f3

Please sign in to comment.