Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2005:
[Freeciv-Dev] (PR#11688) civserver still runs when client has stopped
Home

[Freeciv-Dev] (PR#11688) civserver still runs when client has stopped

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: benoithudson+freeciv@xxxxxxxxx, carllobo@xxxxxxxxx, chrisk@xxxxxxxxx, excellent.one@xxxxxxxxxxxx, superfli@xxxxxxxxx, vbpekez@xxxxxxxx
Subject: [Freeciv-Dev] (PR#11688) civserver still runs when client has stopped
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 13 Aug 2005 20:05:05 -0700
Reply-to: bugs@xxxxxxxxxxx

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

The problem happens because -e and -q don't work well together.

-q causes the server to end the game.  This happens by changing the
state to gameover.  However before the game can really end the game loop
must be exited and this advances the year.  Also when the game ends
there is a game-over autosave.  It's this autosave that causes all the
confusion since it occurrs after the map is revealed to everyone.

-e causes the server to exit when the game ends.  However this doesn't
take effect until after all of the above happens because the check
doesn't come until the end of the gameover handling.  This is
problematic since in this case we don't want any gameover handling.

This patch fixes all of these behaviors.

* End-turn and end-phase handling is skipped when the game is already
over (this should only apply with -q for now).
* A end-game savegame isn't done when there are no connections.
* When -q comes into play an autosave is done immediately (*before* the
game state is changed).  Thus when the client crashes now you should get
a useful autosave.
* When -q and -e are both in play then server_quit is called immediately
rather than going through end-game handling.  This isn't truly necessary
but does skip all of those calculations (they can be pretty long).

This patch is for the development version.  Most of these changes should
be backported (maybe just a minimal set).

-jason

Index: server/sernet.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sernet.c,v
retrieving revision 1.142
diff -p -u -r1.142 sernet.c
--- server/sernet.c     23 Jun 2005 20:35:45 -0000      1.142
+++ server/sernet.c     14 Aug 2005 02:58:57 -0000
@@ -467,6 +467,7 @@ int sniff_packets(void)
       if (conn_list_size(game.est_connections) == 0) {
        if (last_noplayers != 0) {
          if (time(NULL) > last_noplayers + srvarg.quitidle) {
+           save_game_auto("Lost all connections");
            set_meta_message_string("restarting for lack of players");
            freelog(LOG_NORMAL, get_meta_message_string());
            (void) send_server_info_to_metaserver(META_INFO);
@@ -477,6 +478,11 @@ int sniff_packets(void)
               lost_connection_to_client(pconn);
               close_connection(pconn);
             } conn_list_iterate_end;
+
+           if (srvarg.exit_on_end) {
+             /* No need for anything more; just quit. */
+             server_quit();
+           }
          }
        } else {
           char buf[256];
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.284
diff -p -u -r1.284 srv_main.c
--- server/srv_main.c   8 Aug 2005 16:30:24 -0000       1.284
+++ server/srv_main.c   14 Aug 2005 02:58:57 -0000
@@ -110,7 +110,6 @@
 
 
 static void end_turn(void);
-static void save_game_auto(const char *save_reason);
 static void announce_player(struct player *pplayer);
 static void srv_loop(void);
 
@@ -775,7 +774,7 @@ void save_game(char *orig_filename, cons
 /**************************************************************************
 Save game with autosave filename, and call gamelog_save().
 **************************************************************************/
-static void save_game_auto(const char *save_reason)
+void save_game_auto(const char *save_reason)
 {
   char filename[512];
 
@@ -1622,6 +1621,10 @@ static void main_loop(void)
       /* After sniff, re-zero the timer: (read-out above on next loop) */
       clear_timer_start(eot_timer);
 
+      if (server_state == GAME_OVER_STATE) {
+       break;
+      }
+
       conn_list_do_buffer(game.game_connections);
 
       sanity_check();
@@ -1635,6 +1638,9 @@ static void main_loop(void)
 
       conn_list_do_unbuffer(game.game_connections);
     }
+    if (server_state == GAME_OVER_STATE) {
+      break;
+    }
     end_turn();
     freelog(LOG_DEBUG, "Sendinfotometaserver");
     (void) send_server_info_to_metaserver(META_REFRESH);
@@ -1717,7 +1723,10 @@ void srv_main(void)
     notify_player(NULL, _("The game is over..."));
     gamelog(GAMELOG_JUDGE, GL_NONE);
     send_server_info_to_metaserver(META_INFO);
-    if (game.info.save_nturns > 0) {
+    if (game.info.save_nturns > 0
+       && conn_list_size(game.est_connections) > 0) {
+      /* Save game on game-over, but not when the gameover was caused by
+       * the -q parameter. */
       save_game_auto("Game over");
     }
     gamelog(GAMELOG_END);
Index: server/srv_main.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.h,v
retrieving revision 1.36
diff -p -u -r1.36 srv_main.h
--- server/srv_main.h   18 Jul 2005 22:46:29 -0000      1.36
+++ server/srv_main.h   14 Aug 2005 02:58:57 -0000
@@ -53,6 +53,7 @@ void init_game_seed(void);
 void srv_init(void);
 void srv_main(void);
 void server_quit(void);
+void save_game_auto(const char *save_reason);
 
 bool is_game_over(void);
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#11688) civserver still runs when client has stopped, Jason Short <=