Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2004:
[Freeciv-Dev] (PR#7405) list cleanup
Home

[Freeciv-Dev] (PR#7405) list cleanup

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#7405) list cleanup
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Mon, 9 Feb 2004 15:31:09 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=7405 >

This patch fixes a problem with lack of deinitialization of players and
double initialization of players in the server. It also makes sure that
connection, city and unit lists are properly deinitialized.

  - Per

Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.174
diff -u -r1.174 game.c
--- common/game.c       2004/01/29 15:04:00     1.174
+++ common/game.c       2004/02/09 23:23:16
@@ -311,14 +311,17 @@
 }
 
 /***************************************************************
-...
+  Remove all initialized players. This is all player slots, 
+  since we initialize them all on game initialization.
 ***************************************************************/
 static void game_remove_all_players(void)
 {
-  players_iterate(pplayer) {
-    game_remove_player(pplayer);
-  } players_iterate_end;
+  int i;
 
+  for (i = 0; i < MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS; i++) {
+    game_remove_player(&game.players[i]);
+  }
+
   game.nplayers=0;
   game.nbarbarians=0;
 }
@@ -442,13 +445,20 @@
     pplayer->island_improv = NULL;
   }
 
+  assert(conn_list_size(&pplayer->connections) == 0);
+  conn_list_unlink_all(&pplayer->connections);
+
   unit_list_iterate(pplayer->units, punit) 
     game_remove_unit(punit);
   unit_list_iterate_end;
+  assert(unit_list_size(&pplayer->units) == 0);
+  unit_list_unlink_all(&pplayer->units);
 
   city_list_iterate(pplayer->cities, pcity) 
     game_remove_city(pcity);
   city_list_iterate_end;
+  assert(city_list_size(&pplayer->cities) == 0);
+  city_list_unlink_all(&pplayer->cities);
 
   if (is_barbarian(pplayer)) game.nbarbarians--;
 }
Index: server/sernet.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sernet.c,v
retrieving revision 1.113
diff -u -r1.113 sernet.c
--- server/sernet.c     2004/01/25 13:55:14     1.113
+++ server/sernet.c     2004/02/09 23:23:16
@@ -210,7 +210,17 @@
     if(connections[i].used) {
       close_connection(&connections[i]);
     }
+    conn_list_unlink_all(&connections[i].self);
   }
+
+  /* Remove the game connection lists and make sure they are empty. */
+  assert(conn_list_size(&game.all_connections) == 0);
+  conn_list_unlink_all(&game.all_connections);
+  assert(conn_list_size(&game.est_connections) == 0);
+  conn_list_unlink_all(&game.est_connections);
+  assert(conn_list_size(&game.game_connections) == 0);
+  conn_list_unlink_all(&game.game_connections);
+
   my_closesocket(sock);
   my_closesocket(socklan);
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#7405) list cleanup, Per I. Mathisen <=