generated from your-land/yl_template
Adds priv existence check
This commit is contained in:
parent
5385ac94d7
commit
493ef0fc92
30
internal.lua
30
internal.lua
@ -103,6 +103,36 @@ end
|
||||
|
||||
function yl_announcements.load_all_data() return load_all_data() end
|
||||
|
||||
-- check privs
|
||||
--
|
||||
|
||||
local function ends_with(str, suffix) return str:sub(-suffix:len()) == suffix end
|
||||
|
||||
local function split(str)
|
||||
local parts = {}
|
||||
for part in str:gmatch("[^,%s]+") do table.insert(parts, part) end
|
||||
return parts
|
||||
end
|
||||
|
||||
local function priv_exists(priv)
|
||||
return (minetest.registered_privileges[priv] ~= nil) or false
|
||||
end
|
||||
|
||||
function check_privs()
|
||||
for key, value in pairs(yl_announcements.settings) do
|
||||
if ends_with(key, "_privs") then
|
||||
local parts = split(value)
|
||||
for _, part in ipairs(parts) do
|
||||
assert(priv_exists(part), "yl_announcements : configured priv " ..
|
||||
dump(part) .. " does not exist.")
|
||||
end
|
||||
end
|
||||
end
|
||||
say("PASS priv check")
|
||||
end
|
||||
|
||||
function yl_announcements.check_privs() return check_privs() end
|
||||
|
||||
-- Chatcommands
|
||||
--
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user