mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-27 22:55:16 +01:00
The sandbox took io away from the scenery scripts; this gives them files
back the way the Lua screens have them. The screens have
eu07.read_file(path); the scenery state now gets it too, together with a
write function and one to read the written files back:
- eu07.read_file(path): a file of the scenery folder (scenery/), or nil.
The path rule of `lua <file>` and the screens (relative, no '..', no
drive, no leading separator), a regular file of at most 16 MB.
- eu07.write_file(path, text): writes the file in the scenery's data
folder, replacing it, and makes the folders of path. true, or nil and
the reason.
- eu07.read_data_file(path): a file of the data folder, or nil.
The data folder is per scenery and among the player's files, next to the
user eu07.ini and eu07_odometers.txt (user_config_path):
%APPDATA%/MaSzyna/scenery_data/<scenery without .scn>/, ~/.config/MaSzyna/
on Linux. Nothing is written into the game folder; with no user folder,
writes are refused. The log names the folder when the scenery loads its
first script.
Writes are limited to 1 MB a file, 256 files and 16 MB a data folder, and
to relative paths of at most 200 bytes and 8 folders, of portable names:
no '.', '..', empty names, :<>"|?* or control characters, no trailing dot
or space, no Windows device names (con, nul, com1, lpt1...). The parent
folder is checked with canonical paths, so a link in the data folder
doesn't lead a write out of it.
The code is in scripting/luasandbox.{h,cpp} (read_file, which
read_script_file now uses, is_safe_write_path, write_data_file,
scenery_data_folder, open_file_library); lua.cpp only opens the functions
and sets the folders in interpret(). The screens keep their own
read_screen_file, which #356 changes. Documented in the "Scenery scripts"
section of script_screens_doc.md; 8 new cases in test_lua_sandbox.cpp.
11 KiB
11 KiB