18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-27 21:45:16 +01:00

fix(config): a scenery switches a script runtime off as before, only switching it on is refused

keep() put python.enabled, luascreens.enabled, wasm.enabled and lua.fulllibraries back in either
direction, so a scenery with config python.enabled no endconfig, which the release honoured, was
overridden and got an error in the log. They are put back now only when the scenery turned them
on; switched off they stay so, silently.
This commit is contained in:
jerrrrycho
2026-11-17 10:00:49 +01:00
parent 3ae8d4e72e
commit 68c704e513
4 changed files with 59 additions and 18 deletions

View File

@@ -264,7 +264,8 @@ again:
|---------------------|---------|------------------------------------------------------------------------------------------|
| `lua.fulllibraries` | no | yes: the scenery scripts get all of LuaJIT's libraries (`io`, `os`, `ffi`, `require`...), and with them the files and programs of the computer. The Lua screens stay sandboxed |
Only `eu07.ini` sets it: a `config` block of a scenery doesn't (the log says the key was ignored). Nor does it set
Only `eu07.ini` turns it on: a `config` block of a scenery doesn't (the log says the key was ignored). Nor does it set
the other keys that would take a scenery out of its sandbox or reach the computer: `execonexit`, `extcam.cmd`,
`extcam.rec`, `screenshotsdir`, `network.server`, `network.client`, `zmq.address`, `motiontelemetry`, `uart`,
`feedbackmode`, `feedbackport`, `python.enabled`, `luascreens.enabled` and `wasm.enabled`.
`feedbackmode`, `feedbackport`, nor does it switch on `python.enabled`, `luascreens.enabled` or `wasm.enabled` when
`eu07.ini` has them off. A scenery may still switch those three off, or `lua.fulllibraries` off, as it always could.

View File

@@ -11,6 +11,7 @@
#include <algorithm>
#include <memory>
#include <string_view>
#include <utility>
#include <vector>
namespace {
@@ -32,17 +33,43 @@ TEST_CASE("ini only settings: a scenery's config block doesn't give its scripts
CHECK(changed == std::vector<std::string_view>{"lua.fulllibraries"});
}
TEST_CASE("ini only settings: what eu07.ini turned on stays on") {
auto const settings{std::make_unique<global_settings>()};
settings->lua_fulllibraries = true;
settings->python_enabled = false;
ini_only_settings const ini{*settings};
settings->lua_fulllibraries = false;
settings->python_enabled = true;
auto const changed{ini.restore(*settings)};
CHECK(settings->lua_fulllibraries);
CHECK_FALSE(settings->python_enabled);
CHECK(changed.size() == 2);
TEST_CASE("ini only settings: a scenery switches a runtime off, but not on") {
auto const python{[](global_settings &Settings) -> bool & { return Settings.python_enabled; }};
auto const luascreens{[](global_settings &Settings) -> bool & { return Settings.luascreens_enabled; }};
auto const wasm{[](global_settings &Settings) -> bool & { return Settings.wasm_enabled; }};
auto const fulllibraries{[](global_settings &Settings) -> bool & { return Settings.lua_fulllibraries; }};
using setting = bool &(*)(global_settings &);
for (auto const &[key, switched] : {std::pair<std::string_view, setting>{"python.enabled", python}, {"luascreens.enabled", luascreens},
{"wasm.enabled", wasm}, {"lua.fulllibraries", fulllibraries}}) {
CAPTURE(key);
{
// on in eu07.ini, off in the scenery: off, and nothing in the log
auto const settings{std::make_unique<global_settings>()};
switched(*settings) = true;
ini_only_settings const ini{*settings};
// "config python.enabled no endconfig" in the .scn, as the release honoured it
switched(*settings) = false;
CHECK(ini.restore(*settings).empty());
CHECK_FALSE(switched(*settings));
}
{
// off in eu07.ini, on in the scenery: back off, and told
auto const settings{std::make_unique<global_settings>()};
switched(*settings) = false;
ini_only_settings const ini{*settings};
switched(*settings) = true;
CHECK(ini.restore(*settings) == std::vector<std::string_view>{key});
CHECK_FALSE(switched(*settings));
}
// as eu07.ini set it: kept, nothing told
for (auto const value : {false, true}) {
auto const settings{std::make_unique<global_settings>()};
switched(*settings) = value;
ini_only_settings const ini{*settings};
CHECK(ini.restore(*settings).empty());
CHECK(switched(*settings) == value);
}
}
}
TEST_CASE("ini only settings: a scenery runs no program, opens no connection and switches no runtime back on") {

View File

@@ -23,6 +23,17 @@ template <typename Type_> void keep(Type_ &Current, Type_ const &Kept, std::stri
}
}
// a switch a scenery may turn off but not on: puts Kept back into Current, and adds Key to Changed, only when the
// scenery turned it on. turned off it stays so, as before these keys were kept
void keep_off(bool &Current, bool const Kept, std::string_view const Key, std::vector<std::string_view> &Changed)
{
if (Current && false == Kept)
{
Current = false;
Changed.push_back(Key);
}
}
} // namespace
ini_only_settings::ini_only_settings(global_settings const &Settings)
@@ -74,9 +85,10 @@ std::vector<std::string_view> ini_only_settings::restore(global_settings &Settin
#endif
keep(Settings.iFeedbackMode, m_feedback_mode, "feedbackmode", changed);
keep(Settings.iFeedbackPort, m_feedback_port, "feedbackport", changed);
keep(Settings.python_enabled, m_python_enabled, "python.enabled", changed);
keep(Settings.luascreens_enabled, m_luascreens_enabled, "luascreens.enabled", changed);
keep(Settings.lua_fulllibraries, m_lua_fulllibraries, "lua.fulllibraries", changed);
keep(Settings.wasm_enabled, m_wasm_enabled, "wasm.enabled", changed);
// a scenery may switch a runtime off, and keep its scripts in the sandbox
keep_off(Settings.python_enabled, m_python_enabled, "python.enabled", changed);
keep_off(Settings.luascreens_enabled, m_luascreens_enabled, "luascreens.enabled", changed);
keep_off(Settings.lua_fulllibraries, m_lua_fulllibraries, "lua.fulllibraries", changed);
keep_off(Settings.wasm_enabled, m_wasm_enabled, "wasm.enabled", changed);
return changed;
}

View File

@@ -22,7 +22,8 @@ http://mozilla.org/MPL/2.0/.
// (execonexit, extcam.cmd, extcam.rec), write the screenshots elsewhere (screenshotsdir), open connections and ports
// (network.server, network.client, zmq.address, motiontelemetry, uart, feedbackmode, feedbackport), switch back on a
// script runtime the player switched off (python.enabled, luascreens.enabled, wasm.enabled) or take its own scripts
// out of the sandbox (lua.fulllibraries). they keep what eu07.ini set
// out of the sandbox (lua.fulllibraries). they keep what eu07.ini set; a scenery may still switch a runtime off, or
// keep its scripts in the sandbox when eu07.ini didn't, as it always could
class ini_only_settings
{
public: