added support for new secure.enable_security feature

master
Sokomine 2015-07-01 22:02:24 +02:00
parent cf2511739c
commit 5148658ff9
4 changed files with 34 additions and 9 deletions

View File

@ -40,7 +40,7 @@ handle_schematics.analyze_mts_file = function( path )
local size = { x = 0, y = 0, z = 0, version = 0 }
local version = 0;
local file = io.open(path..'.mts', "rb")
local file, err = save_restore.file_access(path..'.mts', "rb")
if (file == nil) then
return nil
end
@ -175,7 +175,7 @@ handle_schematics.store_mts_file = function( path, data )
data.nodenames[ #data.nodenames+1 ] = 'air';
local file = io.open(path..'.mts', "wb")
local file, err = save_restore.file_access(path..'.mts', "wb")
if (file == nil) then
return nil
end

View File

@ -6,9 +6,9 @@ handle_schematics.analyze_we_file = function(scm, we_origin)
-- check if it is a worldedit file
-- (no idea why reading that is done in such a complicated way; a simple deserialize and iteration over all nodes ought to do as well)
local f, err = io.open( scm..".we", "r")
local f, err = save_restore.file_access( scm..".we", "r")
if not f then
f, err = io.open( scm..".wem", "r")
f, err = save_restore.file_access( scm..".wem", "r")
if not f then
error("Could not open schematic '" .. scm .. ".we': " .. err)
return nil;

View File

@ -1,7 +1,7 @@
build_chest.add_files_to_menu = function( path, add_path )
local file,error = io.open( path, "rb")
local file,err = io.open( path, "rb")
if (file == nil) then
return;
end

View File

@ -21,9 +21,7 @@ end
save_restore.restore_data = function( filename )
local path = minetest.get_worldpath()..'/'..filename;
local file = io.open( path, 'r' );
if( file ) then
local data = file:read("*all");
@ -41,7 +39,7 @@ save_restore.file_exists = function( filename )
local path = minetest.get_worldpath()..'/'..filename;
local file = io.open( path, 'r' );
local file = save_restore.file_access( path, 'r' );
if( file ) then
file:close();
return true;
@ -56,9 +54,36 @@ save_restore.create_directory = function( filename )
if( not( save_restore.file_exists( filename ))) then
if( minetest.mkdir ) then
minetest.mkdir( minetest.get_worldpath().."/schems".. "\"");
minetest.mkdir( minetest.get_worldpath().."/schems");
else
os.execute("mkdir \""..minetest.get_worldpath().."/schems".. "\"");
end
end
end
-- we only need the function io.open in a version that can read schematic files from diffrent places,
-- even if a secure environment is enforced; this does require an exception for the mod
local ie_io_open = io.open;
if( minetest.request_insecure_environment ) then
local ie, req_ie = _G, minetest.request_insecure_environment
if req_ie then ie = req_ie() end
if ie then
ie_io_open = ie.io.open;
end
end
-- only a certain type of files can be read and written
save_restore.file_access = function( path, params )
if( (params=='r' or params=='rb')
and ( string.find( path, '.mts', -4 )
or string.find( path, '.we', -3 )
or string.find( path, '.wem', -4 ) )) then
return ie_io_open( path, params );
elseif( (params=='w' or params=='wb')
and ( string.find( path, '.mts', -4 )
or string.find( path, '.we', -3 )
or string.find( path, '.wem', -4 ) )) then
return ie_io_open( path, params );
end
end