From df159efcee699c914a68549709dcd38da88ad47b Mon Sep 17 00:00:00 2001 From: khonkhortisan Date: Thu, 17 Apr 2014 10:37:24 -0700 Subject: [PATCH] Check privs not just during registration of chatcommands Creative mode could change while the server is running. --- worldedit_commands/depends.txt | 3 +- worldedit_commands/init.lua | 252 ++++++++++++++++----------------- worldedit_protection/init.lua | 42 ++++-- 3 files changed, 155 insertions(+), 142 deletions(-) diff --git a/worldedit_commands/depends.txt b/worldedit_commands/depends.txt index df8caff..3bdd90c 100644 --- a/worldedit_commands/depends.txt +++ b/worldedit_commands/depends.txt @@ -1 +1,2 @@ -worldedit \ No newline at end of file +worldedit +worldedit_protection diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index ad2b7fc..233cbba 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -82,8 +82,8 @@ minetest.register_chatcommand("/about", { minetest.register_chatcommand("/inspect", { params = "on/off/1/0/true/false/yes/no/enable/disable/", description = "Enable or disable node inspection", - privs = {worldedit=worldedit.priv()}, - func = function(name, param) + privs = {}, + func = worldedit.privs(function(name, param) if param == "on" or param == "1" or param == "true" or param == "yes" or param == "enable" or param == "" then worldedit.inspect[name] = true local axis, sign = worldedit.player_axis(name) @@ -95,7 +95,7 @@ minetest.register_chatcommand("/inspect", { else worldedit.player_notify(name, "invalid usage: " .. param) end - end, + end), }) minetest.register_on_punchnode(function(pos, node, puncher) @@ -115,33 +115,33 @@ end) minetest.register_chatcommand("/reset", { params = "", description = "Reset the region so that it is empty", - privs = {worldedit=worldedit.priv()}, - func = function(name, param) + privs = {}, + func = worldedit.privs(function(name, param) worldedit.pos1[name] = nil worldedit.pos2[name] = nil worldedit.mark_pos1(name) worldedit.mark_pos2(name) worldedit.set_pos[name] = nil worldedit.player_notify(name, "region reset") - end, + end), }) minetest.register_chatcommand("/mark", { params = "", description = "Show markers at the region positions", - privs = {worldedit=worldedit.priv()}, - func = function(name, param) + privs = {}, + func = worldedit.privs(function(name, param) worldedit.mark_pos1(name) worldedit.mark_pos2(name) worldedit.player_notify(name, "region marked") - end, + end), }) minetest.register_chatcommand("/unmark", { params = "", description = "Hide markers if currently shown", - privs = {worldedit=worldedit.priv()}, - func = function(name, param) + privs = {}, + func = worldedit.privs(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] worldedit.pos1[name] = nil worldedit.pos2[name] = nil @@ -150,40 +150,40 @@ minetest.register_chatcommand("/unmark", { worldedit.pos1[name] = pos1 worldedit.pos2[name] = pos2 worldedit.player_notify(name, "region unmarked") - end, + end), }) minetest.register_chatcommand("/pos1", { params = "", description = "Set WorldEdit region position 1 to the player's location", - privs = {worldedit=worldedit.priv()}, - func = function(name, param) + privs = {}, + func = worldedit.privs(function(name, param) local pos = minetest.get_player_by_name(name):getpos() pos.x, pos.y, pos.z = math.floor(pos.x + 0.5), math.floor(pos.y + 0.5), math.floor(pos.z + 0.5) worldedit.pos1[name] = pos worldedit.mark_pos1(name) worldedit.player_notify(name, "position 1 set to " .. minetest.pos_to_string(pos)) - end, + end), }) minetest.register_chatcommand("/pos2", { params = "", description = "Set WorldEdit region position 2 to the player's location", - privs = {worldedit=worldedit.priv()}, - func = function(name, param) + privs = {}, + func = worldedit.privs(function(name, param) local pos = minetest.get_player_by_name(name):getpos() pos.x, pos.y, pos.z = math.floor(pos.x + 0.5), math.floor(pos.y + 0.5), math.floor(pos.z + 0.5) worldedit.pos2[name] = pos worldedit.mark_pos2(name) worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos)) - end, + end), }) minetest.register_chatcommand("/p", { params = "set/set1/set2/get", description = "Set WorldEdit region, WorldEdit position 1, or WorldEdit position 2 by punching nodes, or display the current WorldEdit region", - privs = {worldedit=worldedit.priv()}, - func = function(name, param) + privs = {}, + func = worldedit.privs(function(name, param) if param == "set" then --set both WorldEdit positions worldedit.set_pos[name] = "pos1" worldedit.player_notify(name, "select positions by punching two nodes") @@ -207,14 +207,14 @@ minetest.register_chatcommand("/p", { else worldedit.player_notify(name, "unknown subcommand: " .. param) end - end, + end), }) minetest.register_chatcommand("/fixedpos", { params = "set1/set2 x y z", description = "Set a WorldEdit region position to the position at (, , )", - privs = {worldedit=worldedit.priv()}, - func = function(name, param) + privs = {}, + func = worldedit.privs(function(name, param) local found, _, flag, x, y, z = param:find("^(set[12])%s+([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)$") if found == nil then worldedit.player_notify(name, "invalid usage: " .. param) @@ -230,7 +230,7 @@ minetest.register_chatcommand("/fixedpos", { worldedit.mark_pos2(name) worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(pos)) end - end, + end), }) minetest.register_on_punchnode(function(pos, node, puncher) @@ -261,8 +261,8 @@ end) minetest.register_chatcommand("/volume", { params = "", description = "Display the volume of the current WorldEdit region", - privs = {worldedit=worldedit.priv()}, - func = function(name, param) + privs = {}, + func = worldedit.privs(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] if pos1 == nil or pos2 == nil then worldedit.player_notify(name, "no region selected") @@ -275,7 +275,7 @@ minetest.register_chatcommand("/volume", { .. abs(pos2.x - pos1.x) + 1 .. "*" .. abs(pos2.y - pos1.y) + 1 .. "*" .. abs(pos2.z - pos1.z) + 1 .. ")") - end, + end), }) local check_set = function(name, param) @@ -287,13 +287,13 @@ end minetest.register_chatcommand("/set", { params = "", description = "Set the current WorldEdit region to ", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local node = get_node(name, param) local count = worldedit.set(pos1, pos2, node) worldedit.player_notify(name, count .. " nodes set") - end, check_set), + end, check_set)), }) local check_replace = function(name, param) @@ -318,29 +318,29 @@ end minetest.register_chatcommand("/replace", { params = " ", description = "Replace all instances of with in the current WorldEdit region", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$") local newsearchnode = worldedit.normalize_nodename(searchnode) local newreplacenode = worldedit.normalize_nodename(replacenode) local count = worldedit.replace(pos1, pos2, newsearchnode, newreplacenode) worldedit.player_notify(name, count .. " nodes replaced") - end, check_replace), + end, check_replace)), }) minetest.register_chatcommand("/replaceinverse", { params = " ", description = "Replace all nodes other than with in the current WorldEdit region", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$") local newsearchnode = worldedit.normalize_nodename(searchnode) local newreplacenode = worldedit.normalize_nodename(replacenode) local count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode) worldedit.player_notify(name, count .. " nodes replaced") - end, check_replace), + end, check_replace)), }) local check_sphere = function(name, param) @@ -361,27 +361,27 @@ end minetest.register_chatcommand("/hollowsphere", { params = " ", description = "Add hollow sphere centered at WorldEdit position 1 with radius , composed of ", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos = worldedit.pos1[name] local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$") local node = get_node(name, nodename) local count = worldedit.hollow_sphere(pos, tonumber(radius), node) worldedit.player_notify(name, count .. " nodes added") - end, check_sphere), + end, check_sphere)), }) minetest.register_chatcommand("/sphere", { params = " ", description = "Add sphere centered at WorldEdit position 1 with radius , composed of ", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos = worldedit.pos1[name] local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$") local node = get_node(name, nodename) local count = worldedit.sphere(pos, tonumber(radius), node) worldedit.player_notify(name, count .. " nodes added") - end, check_sphere), + end, check_sphere)), }) local check_dome = function(name, param) @@ -402,27 +402,27 @@ end minetest.register_chatcommand("/hollowdome", { params = " ", description = "Add hollow dome centered at WorldEdit position 1 with radius , composed of ", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos = worldedit.pos1[name] local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$") local node = get_node(name, nodename) local count = worldedit.hollow_dome(pos, tonumber(radius), node) worldedit.player_notify(name, count .. " nodes added") - end, check_dome), + end, check_dome)), }) minetest.register_chatcommand("/dome", { params = " ", description = "Add dome centered at WorldEdit position 1 with radius , composed of ", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos = worldedit.pos1[name] local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$") local node = get_node(name, nodename) local count = worldedit.dome(pos, tonumber(radius), node) worldedit.player_notify(name, count .. " nodes added") - end, check_dome), + end, check_dome)), }) local check_cylinder = function(name, param) @@ -443,8 +443,8 @@ end minetest.register_chatcommand("/hollowcylinder", { params = "x/y/z/? ", description = "Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length and radius , composed of ", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos = worldedit.pos1[name] local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$") length = tonumber(length) @@ -455,14 +455,14 @@ minetest.register_chatcommand("/hollowcylinder", { local node = get_node(name, nodename) local count = worldedit.hollow_cylinder(pos, axis, length, tonumber(radius), node) worldedit.player_notify(name, count .. " nodes added") - end, check_cylinder), + end, check_cylinder)), }) minetest.register_chatcommand("/cylinder", { params = "x/y/z/? ", description = "Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length and radius , composed of ", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos = worldedit.pos1[name] local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$") length = tonumber(length) @@ -473,14 +473,14 @@ minetest.register_chatcommand("/cylinder", { local node = get_node(name, nodename) local count = worldedit.cylinder(pos, axis, length, tonumber(radius), node) worldedit.player_notify(name, count .. " nodes added") - end, check_cylinder), + end, check_cylinder)), }) minetest.register_chatcommand("/pyramid", { params = "x/y/z/? ", description = "Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height , composed of ", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos = get_position(name) local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$") height = tonumber(height) @@ -506,14 +506,14 @@ minetest.register_chatcommand("/pyramid", { if not node then return nil end height = tonumber(height) return math.ceil(((height * 2 + 1) ^ 2) * height / 3) - end), + end)), }) minetest.register_chatcommand("/spiral", { params = " ", description = "Add spiral centered at WorldEdit position 1 with side length , height , space between walls , composed of ", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos = worldedit.pos1[name] local found, _, length, height, space, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$") local node = get_node(name, nodename) @@ -533,14 +533,14 @@ minetest.register_chatcommand("/spiral", { local node = get_node(name, nodename) if not node then return nil end return check_region(name, param) - end), + end)), }) minetest.register_chatcommand("/copy", { params = "x/y/z/? ", description = "Copy the current WorldEdit region along the x/y/z/? axis by nodes", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$") if found == nil then @@ -559,14 +559,14 @@ minetest.register_chatcommand("/copy", { function(name, param) local volume = check_region(name, param) return volume and volume * 2 or volume - end), + end)), }) minetest.register_chatcommand("/move", { params = "x/y/z/? ", description = "Move the current WorldEdit region along the x/y/z/? axis by nodes", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$") if found == nil then @@ -586,14 +586,14 @@ minetest.register_chatcommand("/move", { worldedit.mark_pos1(name) worldedit.mark_pos2(name) worldedit.player_notify(name, count .. " nodes moved") - end, check_region), + end, check_region)), }) minetest.register_chatcommand("/stack", { params = "x/y/z/? ", description = "Stack the current WorldEdit region along the x/y/z/? axis times", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local found, _, axis, repetitions = param:find("^([xyz%?])%s+([+-]?%d+)$") repetitions = tonumber(repetitions) @@ -612,14 +612,14 @@ minetest.register_chatcommand("/stack", { local count = check_region(name, param) if count then return (tonumber(repetitions) + 1) * count end return nil - end), + end)), }) minetest.register_chatcommand("/stretch", { params = " ", description = "Scale the current WorldEdit positions and region by a factor of , , along the X, Y, and Z axes, repectively, with position 1 as the origin", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local found, _, stretchx, stretchy, stretchz = param:find("^(%d+)%s+(%d+)%s+(%d+)$") stretchx, stretchy, stretchz = tonumber(stretchx), tonumber(stretchy), tonumber(stretchz) @@ -646,14 +646,14 @@ minetest.register_chatcommand("/stretch", { local count = check_region(name, param) if count then return tonumber(stretchx) * tonumber(stretchy) * tonumber(stretchz) * count end return nil - end), + end)), }) minetest.register_chatcommand("/transpose", { params = "x/y/z/? x/y/z/?", description = "Transpose the current WorldEdit region along the x/y/z/? and x/y/z/? axes", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local found, _, axis1, axis2 = param:find("^([xyz%?])%s+([xyz%?])$") if axis1 == "?" then axis1 = worldedit.player_axis(name) end @@ -679,14 +679,14 @@ minetest.register_chatcommand("/transpose", { return nil end return check_region(name, param) - end), + end)), }) minetest.register_chatcommand("/flip", { params = "x/y/z/?", description = "Flip the current WorldEdit region along the x/y/z/? axis", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] if param == "?" then param = worldedit.player_axis(name) end local count = worldedit.flip(pos1, pos2, param) @@ -698,14 +698,14 @@ minetest.register_chatcommand("/flip", { return nil end return check_region(name, param) - end), + end)), }) minetest.register_chatcommand("/rotate", { params = " ", description = "Rotate the current WorldEdit region around the axis by angle (90 degree increment)", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local found, _, axis, angle = param:find("^([xyz%?])%s+([+-]?%d+)$") if axis == "?" then axis = worldedit.player_axis(name) end @@ -730,14 +730,14 @@ minetest.register_chatcommand("/rotate", { return nil end return check_region(name, param) - end), + end)), }) minetest.register_chatcommand("/orient", { params = "", description = "Rotate oriented nodes in the current WorldEdit region around the Y axis by angle (90 degree increment)", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local found, _, angle = param:find("^([+-]?%d+)$") local count = worldedit.orient(pos1, pos2, angle) @@ -754,71 +754,71 @@ minetest.register_chatcommand("/orient", { return nil end return check_region(name, param) - end), + end)), }) minetest.register_chatcommand("/fixlight", { params = "", description = "Fix the lighting in the current WorldEdit region", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local count = worldedit.fixlight(pos1, pos2) worldedit.player_notify(name, count .. " nodes updated") - end), + end)), }) minetest.register_chatcommand("/hide", { params = "", description = "Hide all nodes in the current WorldEdit region non-destructively", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local count = worldedit.hide(pos1, pos2) worldedit.player_notify(name, count .. " nodes hidden") - end), + end)), }) minetest.register_chatcommand("/suppress", { params = "", description = "Suppress all in the current WorldEdit region non-destructively", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local node = get_node(name, param) local count = worldedit.suppress(pos1, pos2, node) worldedit.player_notify(name, count .. " nodes suppressed") - end, check_set), + end, check_set)), }) minetest.register_chatcommand("/highlight", { params = "", description = "Highlight in the current WorldEdit region by hiding everything else non-destructively", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local node = get_node(name, param) local count = worldedit.highlight(pos1, pos2, node) worldedit.player_notify(name, count .. " nodes highlighted") - end, check_set), + end, check_set)), }) minetest.register_chatcommand("/restore", { params = "", description = "Restores nodes hidden with WorldEdit in the current WorldEdit region", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local count = worldedit.restore(pos1, pos2) worldedit.player_notify(name, count .. " nodes restored") - end), + end)), }) minetest.register_chatcommand("/save", { params = "", description = "Save the current WorldEdit region to \"(world folder)/schems/.we\"", - privs = {worldedit=worldedit.priv(), server=true}, - func = safe_region(function(name, param) + privs = {server=true}, + func = worldedit.privs(safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] if param == "" then worldedit.player_notify(name, "invalid usage: " .. param) @@ -845,14 +845,14 @@ minetest.register_chatcommand("/save", { file:close() worldedit.player_notify(name, count .. " nodes saved") - end), + end)), }) minetest.register_chatcommand("/allocate", { params = "", description = "Set the region defined by nodes from \"(world folder)/schems/.we\" as the current WorldEdit region", - privs = {worldedit=worldedit.priv()}, - func = function(name, param) + privs = {}, + func = worldedit.privs(function(name, param) local pos = get_position(name) if pos == nil then return end @@ -886,14 +886,14 @@ minetest.register_chatcommand("/allocate", { worldedit.mark_pos2(name) worldedit.player_notify(name, count .. " nodes allocated") - end, + end), }) minetest.register_chatcommand("/load", { params = "", description = "Load nodes from \"(world folder)/schems/[.we[m]]\" with position 1 of the current WorldEdit region as the origin", - privs = {worldedit=worldedit.priv()}, - func = function(name, param) + privs = {}, + func = worldedit.privs(function(name, param) local pos = get_position(name) if pos == nil then return end @@ -934,14 +934,14 @@ minetest.register_chatcommand("/load", { local count = worldedit.deserialize(pos, value) worldedit.player_notify(name, count .. " nodes loaded") - end, + end), }) minetest.register_chatcommand("/lua", { params = "", description = "Executes as a Lua chunk in the global namespace", - privs = {worldedit=worldedit.priv(), server=true}, - func = function(name, param) + privs = {server=true}, + func = worldedit.privs(function(name, param) local admin = minetest.setting_get("name") if not admin or not name == admin then worldedit.player_notify(name, "this command can only be run by the server administrator") @@ -953,14 +953,14 @@ minetest.register_chatcommand("/lua", { else worldedit.player_notify(name, "code successfully executed", false) end - end, + end), }) minetest.register_chatcommand("/luatransform", { params = "", description = "Executes as a Lua chunk in the global namespace with the variable pos available, for each node in the current WorldEdit region", - privs = {worldedit=worldedit.priv(), server=true}, - func = safe_region(function(name, param) + privs = {server=true}, + func = worldedit.privs(safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local admin = minetest.setting_get("name") if not admin or not name == admin then @@ -974,14 +974,14 @@ minetest.register_chatcommand("/luatransform", { else worldedit.player_notify(name, "code successfully executed", false) end - end), + end)), }) minetest.register_chatcommand("/mtschemcreate", { params = "", description = "Save the current WorldEdit region using the Minetest Schematic format to \"(world folder)/schems/.mts\"", - privs = {worldedit=worldedit.priv(), server=true}, - func = safe_region(function(name, param) + privs = {server=true}, + func = worldedit.privs(safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] if param == nil then worldedit.player_notify(name, "No filename specified") @@ -1000,14 +1000,14 @@ minetest.register_chatcommand("/mtschemcreate", { worldedit.player_notify(name, "saved Minetest schematic to " .. param, false) end worldedit.prob_list[name] = {} - end), + end)), }) minetest.register_chatcommand("/mtschemplace", { params = "", description = "Load nodes from \"(world folder)/schems/.mts\" with position 1 of the current WorldEdit region as the origin", - privs = {worldedit=worldedit.priv()}, - func = function(name, param) + privs = {}, + func = worldedit.privs(function(name, param) if param == nil then worldedit.player_notify(name, "no filename specified") return @@ -1023,14 +1023,14 @@ minetest.register_chatcommand("/mtschemplace", { worldedit.player_notify(name, "placed Minetest schematic " .. param .. " at " .. minetest.pos_to_string(pos), false) end - end, + end), }) minetest.register_chatcommand("/mtschemprob", { params = "start/finish/get", description = "Begins node probability entry for Minetest schematics, gets the nodes that have probabilities set, or ends node probability entry", - privs = {worldedit=worldedit.priv()}, - func = function(name, param) + privs = {}, + func = worldedit.privs(function(name, param) if param == "start" then --start probability setting worldedit.set_pos[name] = "prob" worldedit.prob_list[name] = {} @@ -1053,7 +1053,7 @@ minetest.register_chatcommand("/mtschemprob", { else worldedit.player_notify(name, "unknown subcommand: " .. param) end - end, + end), }) minetest.register_on_player_receive_fields( @@ -1070,10 +1070,10 @@ minetest.register_on_player_receive_fields( minetest.register_chatcommand("/clearobjects", { params = "", description = "Clears all objects within the WorldEdit region", - privs = {worldedit=worldedit.priv()}, - func = safe_region(function(name, param) + privs = {}, + func = worldedit.privs(safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local count = worldedit.clearobjects(pos1, pos2) worldedit.player_notify(name, count .. " objects cleared") - end), + end)), }) diff --git a/worldedit_protection/init.lua b/worldedit_protection/init.lua index 86bcb13..cb9eb62 100644 --- a/worldedit_protection/init.lua +++ b/worldedit_protection/init.lua @@ -9,20 +9,30 @@ minetest.after(0, function() --worldedit privilege is permission to edit everything end) ---this is privs={worldedit=this()} within chatcommands that actually change land ---(should be the same functions as safe_region) -function worldedit.priv() - if not PROTECTION_MOD_EXISTS or not minetest.setting_getbool("creative_mode") then +--I wanted this function to directly choose the privileges for the chat command, but it only applies once. +--privs={worldedit=true [, server=true]} +--privs={worldedit=worldedit.priv() [, server=true]} +--instead, I had to wrap the rest of func = . +function worldedit.privs(func) + if not minetest.setting_getbool("creative_mode") or not PROTECTION_MOD_EXISTS then --no protection mod, or not the kind of world where people can just create nodes out of thin air, --worldedit privilege means editing anywhere - return true + if minetest.check_player_privs(name, {worldedit=true}) then + func(name, param) + else + return + end + else + --protection mod, can edit inside your area without worldedit privilege + --(worldedit and areas let you edit in no-man's land and other-owned area) + func(name, param) end - --protection mod, can edit inside your area without worldedit privilege - --(worldedit and areas let you edit in no-man's land and other-owned area) - return false end -function worldedit.can_edit_volume(name) +--this is... within chatcommands that actually change land +--(should be the same functions as safe_region) +--also check for permission when region is set? +function worldedit.can_edit_volume(name, pos1, pos2) --old you-can-worldedit-everything behaviour if not PROTECTION_MOD_EXISTS then --then if you were able to run this command, then you have the worldedit privilege. @@ -35,18 +45,20 @@ function worldedit.can_edit_volume(name) return true end + --[[I need to use a special per-command region (think /stack, or even worse, /move), the same one safe_region uses, but corner points instead of count... instead of a for loop interpolating between pos1 and pos2]]-- + --all-or-nothing here local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] --pos1, pos2 = worldedit.sort_pos(pos1, pos2) --does this matter? for i in area:iterp(pos1, pos2) do +--[[ + THIS SECTION IGNORES the distinction of area that is owned by someone else, but still editable + this is treated as area owned by the editor, or no-man's land depending on if it's shared with one person or everyone - --THIS SECTION IGNORES the distinction of area that is owned by someone else, but still editable - --this is treated as area owned by the editor, or no-man's land depending on if it's shared with one person or everyone - -- - --If it was treated differently (it's not), then single edits would not be able to cross the border between someone else's editable land, and no-man's land, to prevent accidental writes. It may cross the border between multiple people's editable land (or should it?), such as to create a bridge between two skyscrapers that were previously built separately. - -- - --This needs testing for the other changes first. + If it was treated differently (it's not), then single edits would not be able to cross the border between someone else's editable land, and no-man's land, to prevent accidental writes. It may cross the border between multiple people's editable land (or should it?), such as to create a bridge between two skyscrapers that were previously built separately. + This needs testing for the other changes first. +--]] --Is it owned? if minetest.is_protected(i) then --Is it someone else's?