From ae5a7376c0eb88d000f61a3d1bda8afe72512cb9 Mon Sep 17 00:00:00 2001 From: khonkhortisan Date: Wed, 16 Apr 2014 18:54:16 -0700 Subject: [PATCH] Require the "server" privilege for commands that write to files (but not for reads) Inconsistently require the "worldedit" privilege, based on creative mode and the existence of a land ownership mod. --- worldedit_commands/init.lua | 84 +++++++++++++++++------------------ worldedit_protection/init.lua | 8 ++-- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index 2bbfeed..ad2b7fc 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -82,7 +82,7 @@ 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=true}, + privs = {worldedit=worldedit.priv()}, func = 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 @@ -115,7 +115,7 @@ end) minetest.register_chatcommand("/reset", { params = "", description = "Reset the region so that it is empty", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = function(name, param) worldedit.pos1[name] = nil worldedit.pos2[name] = nil @@ -129,7 +129,7 @@ minetest.register_chatcommand("/reset", { minetest.register_chatcommand("/mark", { params = "", description = "Show markers at the region positions", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = function(name, param) worldedit.mark_pos1(name) worldedit.mark_pos2(name) @@ -140,7 +140,7 @@ minetest.register_chatcommand("/mark", { minetest.register_chatcommand("/unmark", { params = "", description = "Hide markers if currently shown", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] worldedit.pos1[name] = nil @@ -156,7 +156,7 @@ minetest.register_chatcommand("/unmark", { minetest.register_chatcommand("/pos1", { params = "", description = "Set WorldEdit region position 1 to the player's location", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = 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) @@ -169,7 +169,7 @@ minetest.register_chatcommand("/pos1", { minetest.register_chatcommand("/pos2", { params = "", description = "Set WorldEdit region position 2 to the player's location", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = 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) @@ -182,7 +182,7 @@ minetest.register_chatcommand("/pos2", { 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=true}, + privs = {worldedit=worldedit.priv()}, func = function(name, param) if param == "set" then --set both WorldEdit positions worldedit.set_pos[name] = "pos1" @@ -213,7 +213,7 @@ minetest.register_chatcommand("/p", { minetest.register_chatcommand("/fixedpos", { params = "set1/set2 x y z", description = "Set a WorldEdit region position to the position at (, , )", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = function(name, param) local found, _, flag, x, y, z = param:find("^(set[12])%s+([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)$") if found == nil then @@ -261,7 +261,7 @@ end) minetest.register_chatcommand("/volume", { params = "", description = "Display the volume of the current WorldEdit region", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] if pos1 == nil or pos2 == nil then @@ -287,7 +287,7 @@ end minetest.register_chatcommand("/set", { params = "", description = "Set the current WorldEdit region to ", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local node = get_node(name, param) @@ -318,7 +318,7 @@ end minetest.register_chatcommand("/replace", { params = " ", description = "Replace all instances of with in the current WorldEdit region", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$") @@ -332,7 +332,7 @@ minetest.register_chatcommand("/replace", { minetest.register_chatcommand("/replaceinverse", { params = " ", description = "Replace all nodes other than with in the current WorldEdit region", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$") @@ -361,7 +361,7 @@ end minetest.register_chatcommand("/hollowsphere", { params = " ", description = "Add hollow sphere centered at WorldEdit position 1 with radius , composed of ", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos = worldedit.pos1[name] local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$") @@ -374,7 +374,7 @@ minetest.register_chatcommand("/hollowsphere", { minetest.register_chatcommand("/sphere", { params = " ", description = "Add sphere centered at WorldEdit position 1 with radius , composed of ", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos = worldedit.pos1[name] local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$") @@ -402,7 +402,7 @@ end minetest.register_chatcommand("/hollowdome", { params = " ", description = "Add hollow dome centered at WorldEdit position 1 with radius , composed of ", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos = worldedit.pos1[name] local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$") @@ -415,7 +415,7 @@ minetest.register_chatcommand("/hollowdome", { minetest.register_chatcommand("/dome", { params = " ", description = "Add dome centered at WorldEdit position 1 with radius , composed of ", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos = worldedit.pos1[name] local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$") @@ -443,7 +443,7 @@ 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=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos = worldedit.pos1[name] local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$") @@ -461,7 +461,7 @@ minetest.register_chatcommand("/hollowcylinder", { 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=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos = worldedit.pos1[name] local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$") @@ -479,7 +479,7 @@ minetest.register_chatcommand("/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=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos = get_position(name) local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$") @@ -512,7 +512,7 @@ minetest.register_chatcommand("/pyramid", { minetest.register_chatcommand("/spiral", { params = " ", description = "Add spiral centered at WorldEdit position 1 with side length , height , space between walls , composed of ", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos = worldedit.pos1[name] local found, _, length, height, space, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$") @@ -539,7 +539,7 @@ minetest.register_chatcommand("/spiral", { minetest.register_chatcommand("/copy", { params = "x/y/z/? ", description = "Copy the current WorldEdit region along the x/y/z/? axis by nodes", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$") @@ -565,7 +565,7 @@ minetest.register_chatcommand("/copy", { minetest.register_chatcommand("/move", { params = "x/y/z/? ", description = "Move the current WorldEdit region along the x/y/z/? axis by nodes", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local found, _, axis, amount = param:find("^([xyz%?])%s+([+-]?%d+)$") @@ -592,7 +592,7 @@ minetest.register_chatcommand("/move", { minetest.register_chatcommand("/stack", { params = "x/y/z/? ", description = "Stack the current WorldEdit region along the x/y/z/? axis times", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local found, _, axis, repetitions = param:find("^([xyz%?])%s+([+-]?%d+)$") @@ -618,7 +618,7 @@ minetest.register_chatcommand("/stack", { 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=true}, + privs = {worldedit=worldedit.priv()}, func = 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+)$") @@ -652,7 +652,7 @@ minetest.register_chatcommand("/stretch", { 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=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local found, _, axis1, axis2 = param:find("^([xyz%?])%s+([xyz%?])$") @@ -685,7 +685,7 @@ minetest.register_chatcommand("/transpose", { minetest.register_chatcommand("/flip", { params = "x/y/z/?", description = "Flip the current WorldEdit region along the x/y/z/? axis", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] if param == "?" then param = worldedit.player_axis(name) end @@ -704,7 +704,7 @@ minetest.register_chatcommand("/flip", { minetest.register_chatcommand("/rotate", { params = " ", description = "Rotate the current WorldEdit region around the axis by angle (90 degree increment)", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local found, _, axis, angle = param:find("^([xyz%?])%s+([+-]?%d+)$") @@ -736,7 +736,7 @@ minetest.register_chatcommand("/rotate", { 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=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local found, _, angle = param:find("^([+-]?%d+)$") @@ -760,7 +760,7 @@ minetest.register_chatcommand("/orient", { minetest.register_chatcommand("/fixlight", { params = "", description = "Fix the lighting in the current WorldEdit region", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local count = worldedit.fixlight(pos1, pos2) @@ -771,7 +771,7 @@ minetest.register_chatcommand("/fixlight", { minetest.register_chatcommand("/hide", { params = "", description = "Hide all nodes in the current WorldEdit region non-destructively", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local count = worldedit.hide(pos1, pos2) @@ -782,7 +782,7 @@ minetest.register_chatcommand("/hide", { minetest.register_chatcommand("/suppress", { params = "", description = "Suppress all in the current WorldEdit region non-destructively", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local node = get_node(name, param) @@ -794,7 +794,7 @@ minetest.register_chatcommand("/suppress", { minetest.register_chatcommand("/highlight", { params = "", description = "Highlight in the current WorldEdit region by hiding everything else non-destructively", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local node = get_node(name, param) @@ -806,7 +806,7 @@ minetest.register_chatcommand("/highlight", { minetest.register_chatcommand("/restore", { params = "", description = "Restores nodes hidden with WorldEdit in the current WorldEdit region", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local count = worldedit.restore(pos1, pos2) @@ -817,7 +817,7 @@ minetest.register_chatcommand("/restore", { minetest.register_chatcommand("/save", { params = "", description = "Save the current WorldEdit region to \"(world folder)/schems/.we\"", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv(), server=true}, func = safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] if param == "" then @@ -851,7 +851,7 @@ minetest.register_chatcommand("/save", { minetest.register_chatcommand("/allocate", { params = "", description = "Set the region defined by nodes from \"(world folder)/schems/.we\" as the current WorldEdit region", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = function(name, param) local pos = get_position(name) if pos == nil then return end @@ -892,7 +892,7 @@ minetest.register_chatcommand("/allocate", { 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=true}, + privs = {worldedit=worldedit.priv()}, func = function(name, param) local pos = get_position(name) if pos == nil then return end @@ -940,7 +940,7 @@ minetest.register_chatcommand("/load", { minetest.register_chatcommand("/lua", { params = "", description = "Executes as a Lua chunk in the global namespace", - privs = {worldedit=true, server=true}, + privs = {worldedit=worldedit.priv(), server=true}, func = function(name, param) local admin = minetest.setting_get("name") if not admin or not name == admin then @@ -959,7 +959,7 @@ minetest.register_chatcommand("/lua", { 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=true, server=true}, + privs = {worldedit=worldedit.priv(), server=true}, func = safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local admin = minetest.setting_get("name") @@ -980,7 +980,7 @@ minetest.register_chatcommand("/luatransform", { minetest.register_chatcommand("/mtschemcreate", { params = "", description = "Save the current WorldEdit region using the Minetest Schematic format to \"(world folder)/schems/.mts\"", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv(), server=true}, func = safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] if param == nil then @@ -1006,7 +1006,7 @@ minetest.register_chatcommand("/mtschemcreate", { 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=true}, + privs = {worldedit=worldedit.priv()}, func = function(name, param) if param == nil then worldedit.player_notify(name, "no filename specified") @@ -1029,7 +1029,7 @@ minetest.register_chatcommand("/mtschemplace", { 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=true}, + privs = {worldedit=worldedit.priv()}, func = function(name, param) if param == "start" then --start probability setting worldedit.set_pos[name] = "prob" @@ -1070,7 +1070,7 @@ minetest.register_on_player_receive_fields( minetest.register_chatcommand("/clearobjects", { params = "", description = "Clears all objects within the WorldEdit region", - privs = {worldedit=true}, + privs = {worldedit=worldedit.priv()}, func = safe_region(function(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] local count = worldedit.clearobjects(pos1, pos2) diff --git a/worldedit_protection/init.lua b/worldedit_protection/init.lua index 702b89c..86bcb13 100644 --- a/worldedit_protection/init.lua +++ b/worldedit_protection/init.lua @@ -9,17 +9,17 @@ minetest.after(0, function() --worldedit privilege is permission to edit everything end) ---this is privs= within chatcommands that actually change land +--this is privs={worldedit=this()} within chatcommands that actually change land --(should be the same functions as safe_region) -function worldedit.get_privs() +function worldedit.priv() if not PROTECTION_MOD_EXISTS or not minetest.setting_getbool("creative_mode") 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 {worldedit=true} + return true 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 {worldedit=false} -- this array could also be empty + return false end function worldedit.can_edit_volume(name)