The safe execution of python AIs can now be enabled/disabled...

...from the advanced preferences menu. By default, all python AIs are
executed under safe.py's full control.
This commit is contained in:
Greg Copeland 2008-06-19 21:41:26 +00:00
parent 7cb9fa8110
commit 6b4e207e37
5 changed files with 19 additions and 1 deletions

View file

@ -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

View file

@ -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"

View file

@ -52,6 +52,7 @@
#include "game_events.hpp"
#include "game_config.hpp"
#include "settings.hpp"
#include "game_preferences.hpp"
#include <cassert>
#include <fstream>
@ -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"

View file

@ -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()) + " ";

View file

@ -176,6 +176,8 @@ namespace preferences {
bool startup_effect();
bool run_safe_python();
std::set<std::string> &encountered_units();
std::set<t_translation::t_terrain> &encountered_terrains();