<URL: http://bugs.freeciv.org/Ticket/Display.html?id=11517 >

 This I wrote 14 Dec 2004:
  Meta messages given by user are handled exactly like ones made
automatically. /metamessage command simply calls set_meta_message_string().
This means that as soon as set_meta_message_string() is called for
some automatic metastring update, string set by user is forever lost.
Automatic string is even stored to savegames instead of one provided by
user. Also write_init_script() might put 'metamessage restarting for
lack of players' to generated script.


 Attached patch fixes this. It also replaces automatically generated
'restarting for lack of players' metamessage with another message
(either user supported, or default one) when new game starts.
 Showing that 'restarting for lack of players in xx seconds' message
when game is actually running and everything is ok is quite bad thing.
That for I will probably backport this patch to S2_0 too.


 - ML

diff -Nurd -X.diff_ignore freeciv/common/game.c freeciv/common/game.c
--- freeciv/common/game.c	2007-08-06 18:09:20.000000000 +0300
+++ freeciv/common/game.c	2007-08-10 04:21:02.000000000 +0300
@@ -354,6 +354,9 @@
   game.info.player_idx = 0;
   game.player_ptr=&game.players[0];
   terrain_control.river_help_text[0] = '\0';
+
+  game.meta_info.user_message_set = FALSE;
+  game.meta_info.user_message[0] = '\0';
 }
 
 /****************************************************************************
diff -Nurd -X.diff_ignore freeciv/common/game.h freeciv/common/game.h
--- freeciv/common/game.h	2007-08-04 18:38:32.000000000 +0300
+++ freeciv/common/game.h	2007-08-10 03:49:36.000000000 +0300
@@ -115,6 +115,11 @@
   int veteran_chance[MAX_VET_LEVELS];
 
   struct {
+    bool user_message_set;
+    char user_message[256];
+  } meta_info;
+
+  struct {
     /* Function to be called in game_remove_unit when a unit is deleted. */
     void (*unit_deallocate)(int unit_id);
   } callbacks;
diff -Nurd -X.diff_ignore freeciv/server/commands.c freeciv/server/commands.c
--- freeciv/server/commands.c	2007-08-04 18:36:24.000000000 +0300
+++ freeciv/server/commands.c	2007-08-10 05:04:46.000000000 +0300
@@ -148,7 +148,11 @@
   {"metamessage", ALLOW_CTRL,
    /* TRANS: translate text between <> only */
    N_("metainfo <meta-line>"),
-   N_("Set metaserver info line."), NULL
+   N_("Set metaserver info line."),
+   N_("Set user defined metaserver info line. If parameter is omitted,\n"
+      "previously set metamessage will be removed. For most of the time\n"
+      "user defined metamessage will be used instead of automatically\n"
+      "generated messages, if it is available.")
   },
   {"metapatches", ALLOW_HACK,
    /* TRANS: translate text between <> only */
diff -Nurd -X.diff_ignore freeciv/server/connecthand.c freeciv/server/connecthand.c
--- freeciv/server/connecthand.c	2007-08-04 18:36:24.000000000 +0300
+++ freeciv/server/connecthand.c	2007-08-10 04:48:25.000000000 +0300
@@ -73,6 +73,12 @@
   pconn->server.status = AS_ESTABLISHED;
 
   conn_list_append(game.est_connections, pconn);
+  if (conn_list_size(game.est_connections) == 1) {
+    /* First connection
+     * Replace "restarting in x seconds" meta message */
+    maybe_automatic_meta_message(default_meta_message_string());
+    (void) send_server_info_to_metaserver(META_INFO);
+  }
 
   /* introduce the server to the connection */
   if (my_gethostname(hostname, sizeof(hostname)) == 0) {
diff -Nurd -X.diff_ignore freeciv/server/meta.c freeciv/server/meta.c
--- freeciv/server/meta.c	2007-08-04 18:36:24.000000000 +0300
+++ freeciv/server/meta.c	2007-08-10 04:55:00.000000000 +0300
@@ -76,20 +76,18 @@
 
 /*************************************************************************
   Return static string with default info line to send to metaserver.
-  This is a function (instead of a define) to keep meta.h clean of
-  including config.h and version.h
 *************************************************************************/
 const char *default_meta_message_string(void)
 {
 #if IS_BETA_VERSION
   return "unstable pre-" NEXT_STABLE_VERSION ": beware";
-#else
+#else  /* IS_BETA_VERSION */
 #if IS_DEVEL_VERSION
   return "development version: beware";
-#else
+#else  /* IS_DEVEL_VERSION */
   return "(default)";
-#endif
-#endif
+#endif /* IS_DEVEL_VERSION */
+#endif /* IS_BETA_VERSION */
 }
 
 /*************************************************************************
@@ -109,6 +107,41 @@
 }
 
 /*************************************************************************
+ The metaserver message set by user
+*************************************************************************/
+const char *get_user_meta_message_string(void)
+{
+  if (game.meta_info.user_message_set) {
+    return game.meta_info.user_message;
+  }
+
+  return NULL;
+}
+
+/*************************************************************************
+  Update meta message. Set it to user meta message, if it is available.
+  Otherwise use provided message.
+  It is ok to call this with NULL message. Then it only replaces current
+  meta message with user meta message if available.
+*************************************************************************/
+void maybe_automatic_meta_message(const char *automatic)
+{
+  const char *user_message;
+
+  user_message = get_user_meta_message_string();
+
+  if (user_message == NULL) {
+    /* No user message */
+    if (automatic != NULL) {
+      set_meta_message_string(automatic);
+    }
+    return;
+  }
+
+  set_meta_message_string(user_message);
+}
+
+/*************************************************************************
  set the metaserver patches string
 *************************************************************************/
 void set_meta_patches_string(const char *string)
@@ -125,6 +158,23 @@
 }
 
 /*************************************************************************
+ set user defined metaserver message string
+*************************************************************************/
+void set_user_meta_message_string(const char *string)
+{
+  if (string != NULL && string[0] != '\0') {
+    sz_strlcpy(game.meta_info.user_message, string);
+    game.meta_info.user_message_set = TRUE;
+    set_meta_message_string(string);
+  } else {
+    /* Remove user meta message. We will use automatic messages instead */
+    game.meta_info.user_message[0] = '\0';
+    game.meta_info.user_message_set = FALSE;
+    set_meta_message_string(default_meta_message_string());    
+  }
+}
+
+/*************************************************************************
 ...
 *************************************************************************/
 char *meta_addr_port(void)
diff -Nurd -X.diff_ignore freeciv/server/meta.h freeciv/server/meta.h
--- freeciv/server/meta.h	2007-08-04 18:36:24.000000000 +0300
+++ freeciv/server/meta.h	2007-08-10 03:44:58.000000000 +0300
@@ -31,9 +31,13 @@
 
 const char *get_meta_patches_string(void);
 const char *get_meta_message_string(void);
+const char *get_user_meta_message_string(void);
+
+void maybe_automatic_meta_message(const char *automatic);
 
 void set_meta_patches_string(const char *string);
 void set_meta_message_string(const char *string);
+void set_user_meta_message_string(const char *string);
 
 char *meta_addr_port(void);
 
diff -Nurd -X.diff_ignore freeciv/server/savegame.c freeciv/server/savegame.c
--- freeciv/server/savegame.c	2007-08-09 17:37:29.000000000 +0300
+++ freeciv/server/savegame.c	2007-08-10 03:49:25.000000000 +0300
@@ -3596,9 +3596,17 @@
     set_meta_patches_string(secfile_lookup_str_default(file, 
                                                 default_meta_patches_string(),
                                                 "game.metapatches"));
-    set_meta_message_string(secfile_lookup_str_default(file, 
+    game.meta_info.user_message_set = secfile_lookup_bool_default(file,
+                                                                  FALSE,
+                                                "game.user_metamessage");
+    if (game.meta_info.user_message_set) {
+      set_user_meta_message_string(secfile_lookup_str_default(file, 
                                                 default_meta_message_string(),
                                                 "game.metamessage"));
+    } else {
+      /* To avoid warnings when loading pre-2.1 savegames */
+      secfile_lookup_str_default(file, "", "game.metamessage");
+    }
 
     sz_strlcpy(srvarg.metaserver_addr,
 	       secfile_lookup_str_default(file, DEFAULT_META_SERVER_ADDR,
@@ -4171,6 +4179,7 @@
   int version;
   char options[512];
   char temp[B_LAST+1];
+  const char *user_message;
 
   version = MAJOR_VERSION *10000 + MINOR_VERSION *100 + PATCH_VERSION; 
   secfile_insert_int(file, version, "game.version");
@@ -4183,7 +4192,12 @@
 				  RUN_GAME_STATE), "game.server_state");
   
   secfile_insert_str(file, get_meta_patches_string(), "game.metapatches");
-  secfile_insert_str(file, get_meta_message_string(), "game.metamessage");
+  secfile_insert_bool(file, game.meta_info.user_message_set,
+                      "game.user_metamessage");
+  user_message = get_user_meta_message_string();
+  if (user_message != NULL) {
+    secfile_insert_str(file, user_message, "game.metamessage");
+  }
   secfile_insert_str(file, meta_addr_port(), "game.metaserver");
   
   sz_strlcpy(options, SAVEFILE_OPTIONS);
diff -Nurd -X.diff_ignore freeciv/server/stdinhand.c freeciv/server/stdinhand.c
--- freeciv/server/stdinhand.c	2007-08-07 15:32:59.000000000 +0300
+++ freeciv/server/stdinhand.c	2007-08-10 03:09:41.000000000 +0300
@@ -618,7 +618,7 @@
     return TRUE;
   }
 
-  set_meta_message_string(arg);
+  set_user_meta_message_string(arg);
   if (is_metaserver_open()) {
     send_server_info_to_metaserver(META_INFO);
     notify_conn(NULL, NULL, E_SETTING,
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to