From 096ea031de5bdb3e51d2ceb12e6b7e2f2053081e Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 26 Aug 2017 07:17:05 +0100 Subject: Add on_grant and on_revoke callbacks (#4713) * Add register_on_priv_grant/revoke, and on_grant/revoke to privs. Call from /grant and /revoke * Call on_grant and on_revoke callbacks from set_privs --- builtin/game/register.lua | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'builtin/game/register.lua') diff --git a/builtin/game/register.lua b/builtin/game/register.lua index ec6f28097..87d1c5659 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -65,14 +65,14 @@ local function check_modname_prefix(name) error("Name " .. name .. " does not follow naming conventions: " .. "\"" .. expected_prefix .. "\" or \":\" prefix required") end - + -- Enforce that the name only contains letters, numbers and underscores. local subname = name:sub(#expected_prefix+1) if subname:find("[^%w_]") then error("Name " .. name .. " does not follow naming conventions: " .. "contains unallowed characters") end - + return name end end @@ -435,6 +435,17 @@ function core.run_callbacks(callbacks, mode, ...) return ret end +function core.run_priv_callbacks(name, priv, caller, method) + if not core.registered_privileges[priv]["on_" .. method] or + core.registered_privileges[priv]["on_" .. method](name, caller) then + for _, func in ipairs(core["registered_on_priv_" .. method]) do + if not func(name, caller) then + break + end + end + end +end + -- -- Callback registration -- @@ -553,10 +564,11 @@ core.registered_craft_predicts, core.register_craft_predict = make_registration( core.registered_on_protection_violation, core.register_on_protection_violation = make_registration() core.registered_on_item_eats, core.register_on_item_eat = make_registration() core.registered_on_punchplayers, core.register_on_punchplayer = make_registration() +core.registered_on_priv_grant, core.register_on_priv_grant = make_registration() +core.registered_on_priv_revoke, core.register_on_priv_revoke = make_registration() -- -- Compatibility for on_mapgen_init() -- core.register_on_mapgen_init = function(func) func(core.get_mapgen_params()) end - -- cgit v1.2.3