local state = "passthrough" local dumpcalls = false local old_is_protected = minetest.is_protected minetest.register_chatcommand("isprot_override",{ params = "< prot | unprot | passthrough >", description = "Override minetest.is_protected() results. DANGER - 'unprot' option effectively disables area protection for the entire server!", privs = {server = true}, func = function(name,param) if param == "prot" or param == "protected" or param == "true" then minetest.chat_send_player(name,"minetest.is_protected() will now always return "..minetest.colorize("#55ffff","true")..".") state = "true" elseif param == "unprot" or param == "unprotected" or param == "false" then minetest.chat_send_player(name,"minetest.is_protected() will now always return "..minetest.colorize("#55ffff","false")..". This means that area protection is "..minetest.colorize("#ff5555","effectively disabled").."!") state = "false" elseif param == "passthrough" then minetest.chat_send_player(name,"minetest.is_protected() will now "..minetest.colorize("#55ffff","run the existing function")..".") state = "passthrough" elseif param == "" or not param then local states = { ["passthrough"] = "passing calls to the existing function", ["true"] = "always returning true", ["false"] = "always returning false", } minetest.chat_send_player(name,"minetest.is_protected() is currently "..states[state]) else minetest.chat_send_player(name,minetest.colorize("#ff5555","Error: ").."Unrecognized mode. Valid modes are: prot, unprot, passthrough") end end, }) minetest.register_chatcommand("isprot_dumpcalls",{ params = "< on | off >", description = "Enables/disables sending chat messages to the entire server every time minetest.is_protected() or minetest.record_protection_violation() is called.", privs = {server = true}, func = function(name,param) if param == "on" or param == "true" or param == "enable" then minetest.chat_send_player(name,"minetest.is_protected() / minetest.record_protection_violation() debugging "..minetest.colorize("#55ffff","enabled")..".") dumpcalls = true elseif param == "off" or param == "false" or param == "disable" then minetest.chat_send_player(name,"minetest.is_protected() / minetest.record_protection_violation() debugging "..minetest.colorize("#55ffff","disabled")..".") dumpcalls = false elseif param == "" or not param then minetest.chat_send_player(name,"minetest.is_protected() / minetest.record_protection_violation() debugging is currently "..(dumpcalls and "enabled" or "disabled")..".") else minetest.chat_send_player(name,minetest.colorize("#ff5555","Error: ").."Unrecognized mode. Valid options are: on, off") end end, }) minetest.is_protected = function(pos,name) if state == "true" then if dumpcalls then minetest.chat_send_all(string.format("minetest.is_protected() called for %s at %d,%d,%d. Returning true due to override.",name,pos.x,pos.y,pos.z)) end return true elseif state == "false" then if dumpcalls then minetest.chat_send_all(string.format("minetest.is_protected() called for %s at %d,%d,%d. Returning false due to override.",name,pos.x,pos.y,pos.z)) end return false elseif state == "passthrough" then local ret = old_is_protected(pos,name) if dumpcalls then minetest.chat_send_all(string.format("minetest.is_protected() called for %s at %d,%d,%d. Existing function returned %s.",name,pos.x,pos.y,pos.z,ret)) end return ret end end minetest.register_on_protection_violation(function(pos,name) if dumpcalls then minetest.chat_send_all(string.format("minetest.record_protection_violation() called for %s at %d,%d,%d.",name,pos.x,pos.y,pos.z)) end end)