generated from your-land/yl_template
Check configured privs on server start
This commit is contained in:
parent
33fb0990f3
commit
09f4becd21
@ -1,6 +1,7 @@
|
||||
local function run_each_serverstart()
|
||||
yl_scheduler.tasks = {}
|
||||
minetest.after(0.0, yl_scheduler.load_all_tasks)
|
||||
minetest.after(0.0, yl_scheduler.check_privs)
|
||||
end
|
||||
|
||||
run_each_serverstart()
|
||||
|
56
internal.lua
56
internal.lua
@ -31,6 +31,14 @@ local function sort_by_timestamp(tasks)
|
||||
return tasks
|
||||
end
|
||||
|
||||
local function split(str)
|
||||
local parts = {}
|
||||
for part in str:gmatch("[^,%s]+") do table.insert(parts, part) end
|
||||
return parts
|
||||
end
|
||||
|
||||
local function ends_with(str, suffix) return str:sub(-suffix:len()) == suffix end
|
||||
|
||||
-- Loading and Saving
|
||||
|
||||
local function get_savepath()
|
||||
@ -124,3 +132,51 @@ local function load_all_tasks()
|
||||
end
|
||||
|
||||
function yl_scheduler.load_all_tasks() return load_all_tasks() end
|
||||
|
||||
-- ### priv exists ###
|
||||
|
||||
local function priv_exists(priv)
|
||||
return (minetest.registered_privileges[priv] ~= nil) or false
|
||||
end
|
||||
|
||||
function yl_scheduler.priv_exists(priv) return priv_exists(priv) end
|
||||
|
||||
-- ### get_privs ###
|
||||
-- {[yl_scheduler.settings.admin_priv] = true}
|
||||
|
||||
local cmds = {}
|
||||
|
||||
cmds["scheduler_add"] = "taskadd_privs"
|
||||
cmds["scheduler_remove"] = "taskremove_privs"
|
||||
cmds["scheduler_list"] = "tasklist_privs"
|
||||
cmds["scheduler_clean"] = "taskclean_privs"
|
||||
|
||||
local function get_privs(chatcommand_cmd) -- scheduler_add -- taskadd_privs
|
||||
local privs = split(yl_scheduler.settings[cmds[chatcommand_cmd]])
|
||||
local ret = {}
|
||||
for _,priv in ipairs(privs) do
|
||||
ret[priv] = true
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
function yl_scheduler.get_privs(chatcommand_cmd)
|
||||
return get_privs(chatcommand_cmd)
|
||||
end
|
||||
|
||||
-- ### check privs ###
|
||||
|
||||
function check_privs()
|
||||
for key, value in pairs(yl_scheduler.settings) do
|
||||
if ends_with(key, "_privs") then
|
||||
local parts = split(value)
|
||||
for _, part in ipairs(parts) do
|
||||
assert(priv_exists(part), "yl_scheduler : configured priv " ..
|
||||
dump(part) .. " doesn not exist.")
|
||||
end
|
||||
end
|
||||
end
|
||||
say("PASS priv check")
|
||||
end
|
||||
|
||||
function yl_scheduler.check_privs() return check_privs() end
|
||||
|
Loading…
Reference in New Issue
Block a user