@@ -11,17 +11,18 @@ if minetest.place_schematic then
11
11
end
12
12
13
13
dofile (minetest .get_modpath (" worldedit_commands" ) .. " /mark.lua" )
14
- dofile (minetest .get_modpath (" worldedit_commands" ) .. " /safe.lua" ); safe_region = safe_region or function (callback ) return callback end
14
+ dofile (minetest .get_modpath (" worldedit_commands" ) .. " /safe.lua" )
15
+ safe_region = rawget (_G , " safe_region" ) or function (callback ) return callback end
15
16
16
- local get_position = function (name ) -- position 1 retrieval function for when not using `safe_region`
17
+ local function get_position (name ) -- position 1 retrieval function for when not using `safe_region`
17
18
local pos1 = worldedit .pos1 [name ]
18
19
if pos1 == nil then
19
20
worldedit .player_notify (name , " no position 1 selected" )
20
21
end
21
22
return pos1
22
23
end
23
24
24
- local get_node = function (name , nodename )
25
+ local function get_node (name , nodename )
25
26
local node = worldedit .normalize_nodename (nodename )
26
27
if not node then
27
28
worldedit .player_notify (name , " invalid node name: " .. nodename )
@@ -30,7 +31,7 @@ local get_node = function(name, nodename)
30
31
return node
31
32
end
32
33
33
- worldedit .player_notify = function (name , message )
34
+ function worldedit .player_notify (name , message )
34
35
minetest .chat_send_player (name , " WorldEdit -!- " .. message , false )
35
36
end
36
37
@@ -56,8 +57,8 @@ worldedit.normalize_nodename = function(nodename)
56
57
return nil
57
58
end
58
59
59
- -- determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)
60
- worldedit .player_axis = function (name )
60
+ -- Determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)
61
+ function worldedit .player_axis (name )
61
62
local dir = minetest .get_player_by_name (name ):get_look_dir ()
62
63
local x , y , z = math.abs (dir .x ), math.abs (dir .y ), math.abs (dir .z )
63
64
if x > y then
@@ -70,6 +71,15 @@ worldedit.player_axis = function(name)
70
71
return " z" , dir .z > 0 and 1 or - 1
71
72
end
72
73
74
+ function worldedit .mkdir (path )
75
+ if minetest .mkdir then
76
+ minetest .mkdir (path )
77
+ else
78
+ os.execute (' mkdir "' .. path .. ' "' )
79
+ end
80
+ end
81
+
82
+
73
83
minetest .register_chatcommand (" /about" , {
74
84
params = " " ,
75
85
description = " Get information about the mod" ,
@@ -876,20 +886,22 @@ minetest.register_chatcommand("/save", {
876
886
worldedit .player_notify (name , " invalid usage: " .. param )
877
887
return
878
888
end
879
- if not string. find (param , " ^[%w \t .,+-_=!@#$%%^&*()%[%]{};' \" ]+$" ) then
880
- worldedit .player_notify (name , " invalid file name: " .. param )
889
+ if not param : find (" ^[a-zA-Z0-9_%-. ]+$" ) then
890
+ worldedit .player_notify (name , " Disallowed file name: " .. param )
881
891
return
882
892
end
883
893
884
- local result , count = worldedit .serialize (worldedit .pos1 [name ], worldedit .pos2 [name ])
894
+ local result , count = worldedit .serialize (worldedit .pos1 [name ],
895
+ worldedit .pos2 [name ])
885
896
886
897
local path = minetest .get_worldpath () .. " /schems"
898
+ -- Create directory if it does not already exist
899
+ worldedit .mkdir (path )
900
+
887
901
local filename = path .. " /" .. param .. " .we"
888
- filename = filename :gsub (" \" " , " \\\" " ):gsub (" \\ " , " \\\\ " ) -- escape any nasty characters
889
- os.execute (" mkdir \" " .. path .. " \" " ) -- create directory if it does not already exist
890
902
local file , err = io.open (filename , " wb" )
891
903
if err ~= nil then
892
- worldedit .player_notify (name , " could not save file to \" " .. filename .. " \" " )
904
+ worldedit .player_notify (name , " Could not save file to \" " .. filename .. " \" " )
893
905
return
894
906
end
895
907
file :write (result )
@@ -1037,24 +1049,31 @@ minetest.register_chatcommand("/luatransform", {
1037
1049
1038
1050
minetest .register_chatcommand (" /mtschemcreate" , {
1039
1051
params = " <file>" ,
1040
- description = " Save the current WorldEdit region using the Minetest Schematic format to \" (world folder)/schems/<filename>.mts\" " ,
1052
+ description = " Save the current WorldEdit region using the Minetest " ..
1053
+ " Schematic format to \" (world folder)/schems/<filename>.mts\" " ,
1041
1054
privs = {worldedit = true },
1042
1055
func = safe_region (function (name , param )
1043
1056
if param == nil then
1044
1057
worldedit .player_notify (name , " No filename specified" )
1045
1058
return
1046
1059
end
1060
+ if not param :find (" ^[a-zA-Z0-9_%-.]+$" ) then
1061
+ worldedit .player_notify (name , " Disallowed file name: " .. param )
1062
+ return
1063
+ end
1047
1064
1048
1065
local path = minetest .get_worldpath () .. " /schems"
1049
- local filename = path .. " /" .. param .. " .mts"
1050
- filename = filename :gsub (" \" " , " \\\" " ):gsub (" \\ " , " \\\\ " ) -- escape any nasty characters
1051
- os.execute (" mkdir \" " .. path .. " \" " ) -- create directory if it does not already exist
1066
+ -- Create directory if it does not already exist
1067
+ worldedit .mkdir (path )
1052
1068
1053
- local ret = minetest .create_schematic (worldedit .pos1 [name ], worldedit .pos2 [name ], worldedit .prob_list [name ], filename )
1069
+ local filename = path .. " /" .. param .. " .mts"
1070
+ local ret = minetest .create_schematic (worldedit .pos1 [name ],
1071
+ worldedit .pos2 [name ], worldedit .prob_list [name ],
1072
+ filename )
1054
1073
if ret == nil then
1055
- worldedit .player_notify (name , " failed to create Minetest schematic" , false )
1074
+ worldedit .player_notify (name , " Failed to create Minetest schematic" , false )
1056
1075
else
1057
- worldedit .player_notify (name , " saved Minetest schematic to " .. param , false )
1076
+ worldedit .player_notify (name , " Saved Minetest schematic to " .. param , false )
1058
1077
end
1059
1078
worldedit .prob_list [name ] = {}
1060
1079
end ),
0 commit comments