aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorRobert Zenz <Robert.Zenz@bonsaimind.org>2015-09-03 21:28:38 +0200
committerest31 <MTest31@outlook.com>2015-10-22 19:55:48 +0200
commitc32847838d72c327031520c48b76607b63da4ccc (patch)
tree9b5d7f9015dda039264652d23f8a38f4a09e3b74 /builtin
parent37c1e2012724a5d74aa0b720ab91953a2cf2bf05 (diff)
downloadminetest-c32847838d72c327031520c48b76607b63da4ccc.tar.gz
minetest-c32847838d72c327031520c48b76607b63da4ccc.tar.bz2
minetest-c32847838d72c327031520c48b76607b63da4ccc.zip
Add more ways to pass data to check_player_privs
The callback can now be invoked with either the player object or name as the first parameter, and with either a table or a list of strings, like this: minetest.check_player_privs(player_name, { shout = true, fly = true }) minetest.check_player_privs(player_name, "shout", "fly") minetest.check_player_privs(player, { shout = true, fly = true }) minetest.check_player_privs(player, "shout", "fly")
Diffstat (limited to 'builtin')
-rw-r--r--builtin/game/misc.lua29
1 files changed, 24 insertions, 5 deletions
diff --git a/builtin/game/misc.lua b/builtin/game/misc.lua
index dee419767..efd0f8dc7 100644
--- a/builtin/game/misc.lua
+++ b/builtin/game/misc.lua
@@ -74,18 +74,37 @@ function core.after(time, func, ...)
}
end
-function core.check_player_privs(name, privs)
+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
+ name = name:get_player_name()
+ end
+
+ local requested_privs = {...}
local player_privs = core.get_player_privs(name)
local missing_privileges = {}
- for priv, val in pairs(privs) do
- if val
- and not player_privs[priv] then
- table.insert(missing_privileges, priv)
+
+ if type(requested_privs[1]) == "table" then
+ -- We were provided with a table like { privA = true, privB = true }.
+ for priv, value in pairs(requested_privs[1]) do
+ if value and not player_privs[priv] then
+ table.insert(missing_privileges, priv)
+ end
+ end
+ else
+ -- Only a list, we can process it directly.
+ for key, priv in pairs(requested_privs) do
+ if not player_privs[priv] then
+ table.insert(missing_privileges, priv)
+ end
end
end
+
if #missing_privileges > 0 then
return false, missing_privileges
end
+
return true, ""
end