diff --git a/changelog b/changelog index 7353c72071b..0282ef0f1ca 100644 --- a/changelog +++ b/changelog @@ -50,6 +50,8 @@ Version 1.5.0+svn: collections, hotshot, psyco, Queue, sets, time, and the upcoming wail module Use of chr, hash, lambda, ord, and super (new style classes) are now allowed Control of safe_exec can now be toggled from the wesnoth binary (not implemented) + * Added new advanced option, "Only Run Safe Python AIs". When disabled, the safe_exec + environment is disabled for all running AIs. Use caution when disabling this option! * terrains: * Fixed city village not being alias of the village terrain type; this was causing a duplicate "Village" terrain being displayed in the defense ratios diff --git a/data/_main.cfg b/data/_main.cfg index ebc74be33bd..be7660ef7a0 100644 --- a/data/_main.cfg +++ b/data/_main.cfg @@ -101,6 +101,13 @@ # default=60 #[/advanced_preference] +[advanced_preference] + field=only_run_safe_python_ais + name=_"Only Run Safe Python AIs" + type=boolean + default=yes +[/advanced_preference] + [game_config] [server] name=_"Official Wesnoth Server" diff --git a/src/ai_python.cpp b/src/ai_python.cpp index 44ae8383a2c..3db412f2347 100644 --- a/src/ai_python.cpp +++ b/src/ai_python.cpp @@ -52,6 +52,7 @@ #include "game_events.hpp" #include "game_config.hpp" #include "settings.hpp" +#include "game_preferences.hpp" #include #include @@ -1985,6 +1986,7 @@ void python_ai::play_turn() // Run the python script. We actually execute a short inline python script, // which sets up the module search path to the data path, // runs the script, and then resets the path. + std::string runSafe = preferences::run_safe_python()?"True":"False" ; std::string python_code; python_code += "err = \"unknown error\"\n" @@ -2001,7 +2003,7 @@ void python_ai::play_turn() "\t\timport parse, safe\n" "\t\tparse.pathes = [\"" + path + "\"]\n" "\t\tcode, context = parse.parse(\"" + script + "\")\n" - "\t\tsafe.safe_exec(code, context)\n" + "\t\tsafe.safe_exec(code, context, " + runSafe + ")\n" "\texcept:\n" "\t\terr = str(traceback.format_exc())\n" "\t\traise\n" diff --git a/src/game_preferences.cpp b/src/game_preferences.cpp index 61a5f673d90..6571a8347e5 100644 --- a/src/game_preferences.cpp +++ b/src/game_preferences.cpp @@ -687,6 +687,11 @@ bool startup_effect() return utils::string_bool(preferences::get("startup_effect"), true); } +bool run_safe_python() +{ + return utils::string_bool(preferences::get("only_run_safe_python_ais"), true); +} + std::string get_chat_timestamp(const time_t& t) { if (chat_timestamping()) { return lg::get_timestamp(t, clock_format()) + " "; diff --git a/src/game_preferences.hpp b/src/game_preferences.hpp index 145cbc765ef..d4bf4d8ace9 100644 --- a/src/game_preferences.hpp +++ b/src/game_preferences.hpp @@ -176,6 +176,8 @@ namespace preferences { bool startup_effect(); + bool run_safe_python(); + std::set &encountered_units(); std::set &encountered_terrains();