Author: cazfi Date: Fri Jun 24 10:21:45 2016 New Revision: 32993 URL: http://svn.gna.org/viewcvs/freeciv?rev=32993&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: branches/S2_5/server/civserver.c branches/S2_5/server/commands.c branches/S2_5/server/meta.c branches/S2_5/server/meta.h branches/S2_5/server/srv_main.c branches/S2_5/server/stdinhand.c Modified: branches/S2_5/server/civserver.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/civserver.c?rev=32993&r1=32992&r2=32993&view=diff ============================================================================== --- branches/S2_5/server/civserver.c (original) +++ branches/S2_5/server/civserver.c Fri Jun 24 10:21:45 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 @@ -233,12 +233,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: branches/S2_5/server/commands.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/commands.c?rev=32993&r1=32992&r2=32993&view=diff ============================================================================== --- branches/S2_5/server/commands.c (original) +++ branches/S2_5/server/commands.c Fri Jun 24 10:21:45 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: branches/S2_5/server/meta.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/meta.c?rev=32993&r1=32992&r2=32993&view=diff ============================================================================== --- branches/S2_5/server/meta.c (original) +++ branches/S2_5/server/meta.c Fri Jun 24 10:21:45 2016 @@ -70,6 +70,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] = ""; @@ -197,10 +199,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; + } } /**************************************************************************** @@ -424,12 +431,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()); @@ -439,12 +447,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) { @@ -461,6 +471,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: branches/S2_5/server/meta.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/meta.h?rev=32993&r1=32992&r2=32993&view=diff ============================================================================== --- branches/S2_5/server/meta.h (original) +++ branches/S2_5/server/meta.h Fri Jun 24 10:21:45 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 @@ -42,7 +42,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: branches/S2_5/server/srv_main.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/srv_main.c?rev=32993&r1=32992&r2=32993&view=diff ============================================================================== --- branches/S2_5/server/srv_main.c (original) +++ branches/S2_5/server/srv_main.c Fri Jun 24 10:21:45 2016 @@ -2574,7 +2574,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: branches/S2_5/server/stdinhand.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/stdinhand.c?rev=32993&r1=32992&r2=32993&view=diff ============================================================================== --- branches/S2_5/server/stdinhand.c (original) +++ branches/S2_5/server/stdinhand.c Fri Jun 24 10:21:45 2016 @@ -480,9 +480,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]."), @@ -509,8 +510,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.")); @@ -518,31 +521,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