diff --git a/mods/WorldEdit/worldedit/init.lua b/mods/WorldEdit/worldedit/init.lua index 34c98200..ab7af21e 100755 --- a/mods/WorldEdit/worldedit/init.lua +++ b/mods/WorldEdit/worldedit/init.lua @@ -23,7 +23,7 @@ end local path = minetest.get_modpath(minetest.get_current_modname()) local function load_module(path) - local file = io.open(path) + local file = io.open(path,"r") if not file then return end file:close() return dofile(path) diff --git a/mods/WorldEdit/worldedit/manipulations.lua b/mods/WorldEdit/worldedit/manipulations.lua index e76cf701..e40a8829 100755 --- a/mods/WorldEdit/worldedit/manipulations.lua +++ b/mods/WorldEdit/worldedit/manipulations.lua @@ -503,8 +503,8 @@ function worldedit.orient(pos1, pos2, angle) worldedit.keep_loaded(pos1, pos2) local count = 0 - local get_node, get_meta, swap_node = minetest.get_node, - minetest.get_meta, minetest.swap_node + local set_node, get_node, get_meta, swap_node = minetest.get_node, + minetest.get_node minetest.get_meta, minetest.swap_node local pos = {x=pos1.x, y=0, z=0} while pos.x <= pos2.x do pos.y = pos1.y diff --git a/mods/WorldEdit/worldedit_commands/init.lua b/mods/WorldEdit/worldedit_commands/init.lua index 1522ecd0..0212bf09 100755 --- a/mods/WorldEdit/worldedit_commands/init.lua +++ b/mods/WorldEdit/worldedit_commands/init.lua @@ -11,9 +11,9 @@ if minetest.place_schematic then end dofile(minetest.get_modpath("worldedit_commands") .. "/mark.lua") -dofile(minetest.get_modpath("worldedit_commands") .. "/safe.lua"); safe_region = safe_region or function(callback) return callback end +local safe_region, check_region = dofile(minetest.get_modpath("worldedit_commands") .. "/safe.lua") -local get_position = function(name) --position 1 retrieval function for when not using `safe_region` +local function get_position(name) --position 1 retrieval function for when not using `safe_region` local pos1 = worldedit.pos1[name] if pos1 == nil then worldedit.player_notify(name, "no position 1 selected") @@ -21,7 +21,7 @@ local get_position = function(name) --position 1 retrieval function for when not return pos1 end -local get_node = function(name, nodename) +local function get_node(name, nodename) local node = worldedit.normalize_nodename(nodename) if not node then worldedit.player_notify(name, "invalid node name: " .. nodename) @@ -30,7 +30,7 @@ local get_node = function(name, nodename) return node end -worldedit.player_notify = function(name, message) +function worldedit.player_notify(name, message) minetest.chat_send_player(name, "WorldEdit -!- " .. message, false) end @@ -56,8 +56,8 @@ worldedit.normalize_nodename = function(nodename) return nil end ---determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1) -worldedit.player_axis = function(name) +-- Determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1) +function worldedit.player_axis(name) local dir = minetest.get_player_by_name(name):get_look_dir() local x, y, z = math.abs(dir.x), math.abs(dir.y), math.abs(dir.z) if x > y then @@ -70,6 +70,15 @@ worldedit.player_axis = function(name) return "z", dir.z > 0 and 1 or -1 end +function worldedit.mkdir(path) + if minetest.mkdir then + minetest.mkdir(path) + else + os.execute('mkdir "' .. path .. '"') + end +end + + minetest.register_chatcommand("/about", { params = "", description = "Get information about the mod", @@ -802,10 +811,6 @@ minetest.register_chatcommand("/orient", { worldedit.player_notify(name, count .. " nodes oriented") end, function(name, param) - if param == nil then - minetest.log("error","No parameters given to /orient WE's command!") - return - end local found, _, angle = param:find("^([+-]?%d+)$") if found == nil then worldedit.player_notify(name, "invalid usage: " .. param) @@ -880,20 +885,22 @@ minetest.register_chatcommand("/save", { worldedit.player_notify(name, "invalid usage: " .. param) return end - if not string.find(param, "^[%w \t.,+-_=!@#$%%^&*()%[%]{};'\"]+$") then - worldedit.player_notify(name, "invalid file name: " .. param) + if not param:find("^[a-zA-Z0-9_%-.]+$") then + worldedit.player_notify(name, "Disallowed file name: " .. param) return end - local result, count = worldedit.serialize(worldedit.pos1[name], worldedit.pos2[name]) + local result, count = worldedit.serialize(worldedit.pos1[name], + worldedit.pos2[name]) local path = minetest.get_worldpath() .. "/schems" + -- Create directory if it does not already exist + worldedit.mkdir(path) + local filename = path .. "/" .. param .. ".we" - filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\") --escape any nasty characters - os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist local file, err = io.open(filename, "wb") if err ~= nil then - worldedit.player_notify(name, "could not save file to \"" .. filename .. "\"") + worldedit.player_notify(name, "Could not save file to \"" .. filename .. "\"") return end file:write(result) @@ -1041,24 +1048,29 @@ 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\"", + description = "Save the current WorldEdit region using the Minetest ".. + "Schematic format to \"(world folder)/schems/.mts\"", privs = {worldedit=true}, func = safe_region(function(name, param) if param == nil then worldedit.player_notify(name, "No filename specified") return end + if not param:find("^[a-zA-Z0-9_%-.]+$") then + worldedit.player_notify(name, "Disallowed file name: " .. param) + return + end local path = minetest.get_worldpath() .. "/schems" - local filename = path .. "/" .. param .. ".mts" - filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\") --escape any nasty characters - os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist - local ret = minetest.create_schematic(worldedit.pos1[name], worldedit.pos2[name], worldedit.prob_list[name], filename) + local filename = path .. "/" .. param .. ".mts" + local ret = minetest.create_schematic(worldedit.pos1[name], + worldedit.pos2[name], worldedit.prob_list[name], + filename) if ret == nil then - worldedit.player_notify(name, "failed to create Minetest schematic", false) + worldedit.player_notify(name, "Failed to create Minetest schematic", false) else - worldedit.player_notify(name, "saved Minetest schematic to " .. param, false) + worldedit.player_notify(name, "Saved Minetest schematic to " .. param, false) end worldedit.prob_list[name] = {} end), diff --git a/mods/WorldEdit/worldedit_commands/safe.lua b/mods/WorldEdit/worldedit_commands/safe.lua index c6751c13..909554a9 100755 --- a/mods/WorldEdit/worldedit_commands/safe.lua +++ b/mods/WorldEdit/worldedit_commands/safe.lua @@ -1,7 +1,7 @@ local safe_region_callback = {} local safe_region_param = {} -check_region = function(name, param) +function check_region(name, param) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] --obtain positions if pos1 == nil or pos2 == nil then worldedit.player_notify(name, "no region selected") @@ -12,7 +12,7 @@ end --`callback` is a callback to run when the user confirms --`nodes_needed` is a function accepting `param`, `pos1`, and `pos2` to calculate the number of nodes needed -safe_region = function(callback, nodes_needed) +function safe_region(callback, nodes_needed) --default node volume calculation nodes_needed = nodes_needed or check_region @@ -63,3 +63,5 @@ minetest.register_chatcommand("/n", { safe_region_callback[name], safe_region_param[name] = nil, nil end, }) + +return safe_region, check_region