Author: cazfi
Date: Fri Jun 24 10:21:34 2016
New Revision: 32991

URL: http://svn.gna.org/viewcvs/freeciv?rev=32991&view=rev
Log:
Added persistent mode of the metaserver connection, initiated by
'metaconnection persistent' server command.
It's not persistent as in keeping TCP connection alive, but
it does not stop attempts to send later updates when one send
fails.

See patch #7300

Modified:
    trunk/server/civserver.c
    trunk/server/commands.c
    trunk/server/meta.c
    trunk/server/meta.h
    trunk/server/srv_main.c
    trunk/server/stdinhand.c

Modified: trunk/server/civserver.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/civserver.c?rev=32991&r1=32990&r2=32991&view=diff
==============================================================================
--- trunk/server/civserver.c    (original)
+++ trunk/server/civserver.c    Fri Jun 24 10:21:34 2016
@@ -1,4 +1,4 @@
-/**********************************************************************
+/***********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -225,12 +225,12 @@
       srvarg.ranklog_filename = option; /* Never freed. */
     } else if (is_option("--nometa", argv[inx])) {
       fc_fprintf(stderr, _("Warning: the %s option is obsolete.  "
-                          "Use -m to enable the metaserver.\n"), argv[inx]);
+                           "Use -m to enable the metaserver.\n"), argv[inx]);
       showhelp = TRUE;
     } else if (is_option("--meta", argv[inx])) {
       srvarg.metaserver_no_send = FALSE;
     } else if ((option = get_option_malloc("--Metaserver",
-                                        argv, &inx, argc))) {
+                                           argv, &inx, argc))) {
       sz_strlcpy(srvarg.metaserver_addr, option);
       free(option);
       srvarg.metaserver_no_send = FALSE;      /* --Metaserver implies --meta */

Modified: trunk/server/commands.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/commands.c?rev=32991&r1=32990&r2=32991&view=diff
==============================================================================
--- trunk/server/commands.c     (original)
+++ trunk/server/commands.c     Fri Jun 24 10:21:34 2016
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/***********************************************************************
  Freeciv - Copyright (C) 1996-2004 - The Freeciv Project
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -266,7 +266,8 @@
    N_("Control metaserver connection."),
    N_("'metaconnection ?' reports on the status of the connection to 
metaserver. "
       "'metaconnection down' or 'metac d' brings the metaserver connection 
down. "
-      "'metaconnection up' or 'metac u' brings the metaserver connection up."),
+      "'metaconnection up' or 'metac u' brings the metaserver connection up. "
+      "'metaconnection persistent' or 'metac p' is like 'up', but keeps trying 
after failures. "),
    NULL,
    CMD_ECHO_ADMINS, VCF_NONE, 0
   },

Modified: trunk/server/meta.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/meta.c?rev=32991&r1=32990&r2=32991&view=diff
==============================================================================
--- trunk/server/meta.c (original)
+++ trunk/server/meta.c Fri Jun 24 10:21:34 2016
@@ -66,6 +66,8 @@
 #include "meta.h"
 
 static bool server_is_open = FALSE;
+static bool persistent_meta_connection = FALSE;
+static int meta_retry_wait = 0;
 
 static char meta_patches[256] = "";
 static char meta_message[256] = "";
@@ -203,10 +205,15 @@
 *************************************************************************/
 static void metaserver_failed(void)
 {
-  con_puts(C_METAERROR, _("Not reporting to the metaserver in this game."));
-  con_flush();
-
-  server_close_meta();
+  if (!persistent_meta_connection) {
+    con_puts(C_METAERROR, _("Not reporting to the metaserver in this game."));
+    con_flush();
+
+    server_close_meta();
+  } else {
+    con_puts(C_METAERROR, _("Metaserver connection currently failing."));
+    meta_retry_wait = 1;
+  }
 }
 
 /****************************************************************************
@@ -441,12 +448,13 @@
 void server_close_meta(void)
 {
   server_is_open = FALSE;
-}
-
-/*************************************************************************
- lookup the correct address for the metaserver.
-*************************************************************************/
-bool server_open_meta(void)
+  persistent_meta_connection = FALSE;
+}
+
+/*************************************************************************
+  Lookup the correct address for the metaserver.
+*************************************************************************/
+bool server_open_meta(bool persistent)
 {
   if (meta_patches[0] == '\0') {
     set_meta_patches_string(default_meta_patches_string());
@@ -456,12 +464,14 @@
   }
 
   server_is_open = TRUE;
+  persistent_meta_connection = persistent;
+  meta_retry_wait = 0;
 
   return TRUE;
 }
 
 /**************************************************************************
- are we sending info to the metaserver?
+  Are we sending info to the metaserver?
 **************************************************************************/
 bool is_metaserver_open(void)
 {
@@ -478,6 +488,15 @@
 
   if (!server_is_open) {
     return FALSE;
+  }
+
+  /* Persistent connection temporary failures handling */
+  if (meta_retry_wait > 0) {
+    if (meta_retry_wait++ > 5) {
+      meta_retry_wait = 0;
+    } else {
+      return FALSE;
+    }
   }
 
   /* if we're bidding farewell, ignore all timers */

Modified: trunk/server/meta.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/meta.h?rev=32991&r1=32990&r2=32991&view=diff
==============================================================================
--- trunk/server/meta.h (original)
+++ trunk/server/meta.h Fri Jun 24 10:21:34 2016
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/***********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -44,7 +44,7 @@
 char *meta_addr_port(void);
 
 void server_close_meta(void);
-bool server_open_meta(void);
+bool server_open_meta(bool persistent);
 bool is_metaserver_open(void);
 
 bool send_server_info_to_metaserver(enum meta_flag flag);

Modified: trunk/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/srv_main.c?rev=32991&r1=32990&r2=32991&view=diff
==============================================================================
--- trunk/server/srv_main.c     (original)
+++ trunk/server/srv_main.c     Fri Jun 24 10:21:34 2016
@@ -2735,7 +2735,7 @@
   if (!(srvarg.metaserver_no_send)) {
     log_normal(_("Sending info to metaserver <%s>."), meta_addr_port());
     /* Open socket for meta server */
-    if (!server_open_meta()
+    if (!server_open_meta(FALSE)
         || !send_server_info_to_metaserver(META_INFO)) {
       con_write(C_FAIL, _("Not starting without explicitly requested 
metaserver connection."));
       exit(EXIT_FAILURE);

Modified: trunk/server/stdinhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/stdinhand.c?rev=32991&r1=32990&r2=32991&view=diff
==============================================================================
--- trunk/server/stdinhand.c    (original)
+++ trunk/server/stdinhand.c    Fri Jun 24 10:21:34 2016
@@ -484,9 +484,10 @@
 /**************************************************************************
   Start sending game info to metaserver.
 **************************************************************************/
-static void open_metaserver_connection(struct connection *caller)
-{
-  server_open_meta();
+static void open_metaserver_connection(struct connection *caller,
+                                       bool persistent)
+{
+  server_open_meta(persistent);
   if (send_server_info_to_metaserver(META_INFO)) {
     cmd_reply(CMD_METACONN, caller, C_OK,
               _("Open metaserver connection to [%s]."),
@@ -513,8 +514,10 @@
 static bool metaconnection_command(struct connection *caller, char *arg, 
                                    bool check)
 {
-  if ((*arg == '\0') ||
-      (0 == strcmp (arg, "?"))) {
+  bool persistent = FALSE;
+
+  if ((*arg == '\0')
+      || (!strcmp(arg, "?"))) {
     if (is_metaserver_open()) {
       cmd_reply(CMD_METACONN, caller, C_COMMENT,
                 _("Metaserver connection is open."));
@@ -522,31 +525,40 @@
       cmd_reply(CMD_METACONN, caller, C_COMMENT,
                 _("Metaserver connection is closed."));
     }
-  } else if (0 == fc_strcasecmp(arg, "u")
-             || 0 == fc_strcasecmp(arg, "up")) {
+    return TRUE;
+  }
+
+  if (!fc_strcasecmp(arg, "p")
+      || !fc_strcasecmp(arg, "persistent")) {
+    persistent = TRUE;
+  }
+
+  if (persistent
+      || !fc_strcasecmp(arg, "u")
+      || !fc_strcasecmp(arg, "up")) {
     if (!is_metaserver_open()) {
       if (!check) {
-        open_metaserver_connection(caller);
+        open_metaserver_connection(caller, persistent);
       }
     } else {
       cmd_reply(CMD_METACONN, caller, C_METAERROR,
-               _("Metaserver connection is already open."));
+                _("Metaserver connection is already open."));
       return FALSE;
     }
-  } else if (0 == fc_strcasecmp(arg, "d")
-             || 0 == fc_strcasecmp(arg, "down")) {
+  } else if (!fc_strcasecmp(arg, "d")
+             || !fc_strcasecmp(arg, "down")) {
     if (is_metaserver_open()) {
       if (!check) {
         close_metaserver_connection(caller);
       }
     } else {
       cmd_reply(CMD_METACONN, caller, C_METAERROR,
-               _("Metaserver connection is already closed."));
+                _("Metaserver connection is already closed."));
       return FALSE;
     }
   } else {
     cmd_reply(CMD_METACONN, caller, C_METAERROR,
-             _("Argument must be 'u', 'up', 'd', 'down', or '?'."));
+              _("Argument must be 'u', 'up', 'd', 'down', 'p', 'persistent', 
or '?'."));
     return FALSE;
   }
   return TRUE;


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

Reply via email to