Author: cazfi
Date: Mon Jan  5 21:38:36 2015
New Revision: 27543

URL: http://svn.gna.org/viewcvs/freeciv?rev=27543&view=rev
Log:
Do not parse lua scripts when loading rulesets for ruledit.

See bug #23099

Modified:
    trunk/server/ruleset.c
    trunk/server/ruleset.h
    trunk/server/scripting/script_server.c
    trunk/server/scripting/script_server.h
    trunk/server/stdinhand.c

Modified: trunk/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/ruleset.c?rev=27543&r1=27542&r2=27543&view=diff
==============================================================================
--- trunk/server/ruleset.c      (original)
+++ trunk/server/ruleset.c      Mon Jan  5 21:38:36 2015
@@ -117,7 +117,7 @@
 static char *road_sections = NULL;
 
 static bool load_rulesetdir(const char *rsdir, bool compat_mode,
-                            bool act, bool save_script);
+                            bool act, bool buffer_script);
 static struct section_file *openload_ruleset_file(const char *whichset,
                                                   const char *rsdir);
 static const char *check_ruleset_capabilities(struct section_file *file,
@@ -287,11 +287,15 @@
     return FALSE;
   }
 
-  if (!script_server_do_file(NULL, dfilename, buffer)) {
-    ruleset_error(LOG_ERROR, "\"%s\": could not load ruleset script.",
-                  dfilename);
-
-    return FALSE;
+  if (buffer == NULL) {
+    if (!script_server_do_file(NULL, dfilename)) {
+      ruleset_error(LOG_ERROR, "\"%s\": could not load ruleset script.",
+                    dfilename);
+
+      return FALSE;
+    }
+  } else {
+    script_server_load_file(dfilename, buffer);
   }
 
   return TRUE;
@@ -6531,15 +6535,15 @@
   Loads the rulesets.
 **************************************************************************/
 bool load_rulesets(const char *restore, bool compat_mode,
-                   bool act, bool save_script)
-{
-  if (load_rulesetdir(game.server.rulesetdir, compat_mode, act, save_script)) {
+                   bool act, bool buffer_script)
+{
+  if (load_rulesetdir(game.server.rulesetdir, compat_mode, act, 
buffer_script)) {
     return TRUE;
   }
 
   /* Fallback to previous one. */
   if (restore != NULL) {
-    if (load_rulesetdir(restore, compat_mode, act, save_script)) {
+    if (load_rulesetdir(restore, compat_mode, act, buffer_script)) {
       sz_strlcpy(game.server.rulesetdir, restore);
 
       notify_ruleset_fallback(_("Ruleset couldn't be loaded. Keeping previous 
one."));
@@ -6554,7 +6558,7 @@
   /* Fallback to default one, but not if that's what we tried already */
   if (strcmp(GAME_DEFAULT_RULESETDIR, game.server.rulesetdir)
       && (restore == NULL || strcmp(GAME_DEFAULT_RULESETDIR, restore))) {
-    if (load_rulesetdir(GAME_DEFAULT_RULESETDIR, FALSE, act, save_script)) {
+    if (load_rulesetdir(GAME_DEFAULT_RULESETDIR, FALSE, act, buffer_script)) {
       /* We're in sane state as fallback ruleset loading succeeded,
        * but return failure to indicate that this is not what caller
        * wanted. */
@@ -6590,7 +6594,7 @@
   This may be called more than once and it will free any stale data.
 **************************************************************************/
 static bool load_rulesetdir(const char *rsdir, bool compat_mode,
-                            bool act, bool save_script)
+                            bool act, bool buffer_script)
 {
   struct section_file *techfile, *unitfile, *buildfile, *govfile, *terrfile;
   struct section_file *stylefile, *cityfile, *nationfile, *effectfile, 
*gamefile;
@@ -6729,7 +6733,7 @@
   }
 
   if (ok) {
-    char **buffer = save_script ? &script_buffer : NULL;
+    char **buffer = buffer_script ? &script_buffer : NULL;
 
     script_server_free();
 
@@ -6738,7 +6742,7 @@
     ok = openload_script_file("script", rsdir, buffer);
   }
 
-  if (ok) {
+  if (ok && buffer_script) {
     ok = openload_script_file("default", rsdir, NULL);
   }
 

Modified: trunk/server/ruleset.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/ruleset.h?rev=27543&r1=27542&r2=27543&view=diff
==============================================================================
--- trunk/server/ruleset.h      (original)
+++ trunk/server/ruleset.h      Mon Jan  5 21:38:36 2015
@@ -32,7 +32,7 @@
 
 /* functions */
 bool load_rulesets(const char *restore, bool compat_mode,
-                   bool act, bool save_script);
+                   bool act, bool buffer_script);
 bool reload_rulesets_settings(void);
 void send_rulesets(struct conn_list *dest);
 

Modified: trunk/server/scripting/script_server.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/scripting/script_server.c?rev=27543&r1=27542&r2=27543&view=diff
==============================================================================
--- trunk/server/scripting/script_server.c      (original)
+++ trunk/server/scripting/script_server.c      Mon Jan  5 21:38:36 2015
@@ -103,10 +103,39 @@
 }
 
 /*****************************************************************************
+  Load script to a buffer
+*****************************************************************************/
+bool script_server_load_file(const char *filename, char **buf)
+{
+  FILE *ffile;
+  struct stat stats;
+  char *buffer;
+
+  fc_stat(filename, &stats);
+  ffile = fc_fopen(filename, "r");
+
+  if (ffile != NULL) {
+    int len;
+
+    buffer = fc_malloc(stats.st_size + 1);
+
+    len = fread(buffer, 1, stats.st_size, ffile);
+
+    if (len == stats.st_size) {
+      buffer[len] = '\0';
+
+      *buf = buffer;
+    }
+    fclose(ffile);
+  }
+
+  return 1;
+}  
+
+/*****************************************************************************
   Parse and execute the script at filename.
 *****************************************************************************/
-bool script_server_do_file(struct connection *caller, const char *filename,
-                           char **buf)
+bool script_server_do_file(struct connection *caller, const char *filename)
 {
   int status = 1;
   struct connection *save_caller;
@@ -119,32 +148,7 @@
   fcl->output_fct = script_server_cmd_reply;
   fcl->caller = caller;
 
-  if (buf == NULL) {
-    status = luascript_do_file(fcl, filename);
-  } else {
-    FILE *ffile;
-    struct stat stats;
-    char *buffer;
-
-    fc_stat(filename, &stats);
-    ffile = fc_fopen(filename, "r");
-
-    if (ffile != NULL) {
-      int len;
-
-      buffer = fc_malloc(stats.st_size + 1);
-
-      len = fread(buffer, 1, stats.st_size, ffile);
-
-      if (len == stats.st_size) {
-        buffer[len] = '\0';
-        status = luascript_do_string(fcl, buffer, filename);
-
-        *buf = buffer;
-      }
-      fclose(ffile);
-    }
-  }
+  status = luascript_do_file(fcl, filename);
 
   /* Reset the changes. */
   fcl->caller = save_caller;

Modified: trunk/server/scripting/script_server.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/scripting/script_server.h?rev=27543&r1=27542&r2=27543&view=diff
==============================================================================
--- trunk/server/scripting/script_server.h      (original)
+++ trunk/server/scripting/script_server.h      Mon Jan  5 21:38:36 2015
@@ -33,8 +33,8 @@
 bool script_server_init(void);
 void script_server_free(void);
 bool script_server_do_string(struct connection *caller, const char *str);
-bool script_server_do_file(struct connection *caller, const char *filename,
-                           char **buf);
+bool script_server_do_file(struct connection *caller, const char *filename);
+bool script_server_load_file(const char *filename, char **buf);
 
 /* Script state i/o. */
 void script_server_state_load(struct section_file *file);

Modified: trunk/server/stdinhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/stdinhand.c?rev=27543&r1=27542&r2=27543&view=diff
==============================================================================
--- trunk/server/stdinhand.c    (original)
+++ trunk/server/stdinhand.c    Mon Jan  5 21:38:36 2015
@@ -4633,7 +4633,7 @@
 
     if (is_reg_file_for_access(real_filename, FALSE)
         && (script_file = fc_fopen(real_filename, "r"))) {
-      ret = script_server_do_file(caller, real_filename, NULL);
+      ret = script_server_do_file(caller, real_filename);
       goto cleanup;
     } else {
       cmd_reply(CMD_LUA, caller, C_FAIL,


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to