Author: oracle
Date: Thu Jun 19 23:41:26 2008
New Revision: 27329

URL: http://svn.gna.org/viewcvs/wesnoth?rev=27329&view=rev
Log:
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.


Modified:
    trunk/changelog
    trunk/data/_main.cfg
    trunk/src/ai_python.cpp
    trunk/src/game_preferences.cpp
    trunk/src/game_preferences.hpp

Modified: trunk/changelog
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=27329&r1=27328&r2=27329&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Thu Jun 19 23:41:26 2008
@@ -50,6 +50,8 @@
        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

Modified: trunk/data/_main.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/_main.cfg?rev=27329&r1=27328&r2=27329&view=diff
==============================================================================
--- trunk/data/_main.cfg (original)
+++ trunk/data/_main.cfg Thu Jun 19 23:41:26 2008
@@ -100,6 +100,13 @@
 #    type=int
 #    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]

Modified: trunk/src/ai_python.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai_python.cpp?rev=27329&r1=27328&r2=27329&view=diff
==============================================================================
--- trunk/src/ai_python.cpp (original)
+++ trunk/src/ai_python.cpp Thu Jun 19 23:41:26 2008
@@ -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 @@
        // 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 @@
                "\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"

Modified: trunk/src/game_preferences.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_preferences.cpp?rev=27329&r1=27328&r2=27329&view=diff
==============================================================================
--- trunk/src/game_preferences.cpp (original)
+++ trunk/src/game_preferences.cpp Thu Jun 19 23:41:26 2008
@@ -687,6 +687,11 @@
        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()) + " ";

Modified: trunk/src/game_preferences.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_preferences.hpp?rev=27329&r1=27328&r2=27329&view=diff
==============================================================================
--- trunk/src/game_preferences.hpp (original)
+++ trunk/src/game_preferences.hpp Thu Jun 19 23:41:26 2008
@@ -176,6 +176,8 @@
 
        bool startup_effect();
 
+       bool run_safe_python();
+
        std::set<std::string> &encountered_units();
        std::set<t_translation::t_terrain> &encountered_terrains();
 


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to