diff options
-rw-r--r-- | init.lua | 68 | ||||
-rw-r--r-- | mod.conf | 3 |
2 files changed, 71 insertions, 0 deletions
diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..663c031 --- /dev/null +++ b/init.lua @@ -0,0 +1,68 @@ +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) diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..befd1b6 --- /dev/null +++ b/mod.conf @@ -0,0 +1,3 @@ +name = protectiontester +description = Debugging tool for area protection +optional_depends = areas |