[Freeciv-Dev] Re: (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] Re: (PR#7405) list cleanup |
From: |
"Per I. Mathisen" <per@xxxxxxxxxxx> |
Date: |
Tue, 10 Feb 2004 08:21:28 -0800 |
Reply-to: |
rt@xxxxxxxxxxx |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=7405 >
On Mon, 9 Feb 2004, Per I. Mathisen wrote:
> 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.
static void game_remove_all_players(void)
...
+ assert(conn_list_size(&pplayer->connections) == 0);
+ conn_list_unlink_all(&pplayer->connections);
The assert will not hold for some ways of quitting, most notably when one
player has been connected ;)
Also, missed one list in sernet.c:
void close_connection(struct connection *pconn)
{
while (timer_list_size(pconn->server.ping_timers) > 0) {
struct timer *timer = timer_list_get(pconn->server.ping_timers, 0);
timer_list_unlink(pconn->server.ping_timers, timer);
free_timer(timer);
}
+ assert(timer_list_size(pconn->server.ping_timers) == 0);
+ timer_list_unlink_all(pconn->server.ping_timers);
And one in diplhand.c (static treaties list).
New patch attached.
- 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/10 16:17:10
@@ -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,19 @@
pplayer->island_improv = NULL;
}
+ 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/10 16:17:11
@@ -187,6 +187,8 @@
timer_list_unlink(pconn->server.ping_timers, timer);
free_timer(timer);
}
+ assert(timer_list_size(pconn->server.ping_timers) == 0);
+ timer_list_unlink_all(pconn->server.ping_timers);
/* safe to do these even if not in lists: */
conn_list_unlink(&game.all_connections, pconn);
@@ -210,7 +212,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);
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.302
diff -u -r1.302 plrhand.c
--- server/plrhand.c 2004/01/31 17:52:42 1.302
+++ server/plrhand.c 2004/02/10 16:17:12
@@ -1469,7 +1469,6 @@
if (initmap) {
player_map_allocate(pplayer);
}
- player_init(pplayer);
ai_data_init(pplayer);
}
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.153
diff -u -r1.153 srv_main.c
--- server/srv_main.c 2004/01/31 17:52:42 1.153
+++ server/srv_main.c 2004/02/10 16:17:13
@@ -1446,6 +1453,7 @@
con_flush();
game_init();
+ diplhand_init();
/* init network */
init_connections();
@@ -1709,6 +1717,6 @@
players_iterate(pplayer) {
player_map_free(pplayer);
} players_iterate_end;
-
+ diplhand_free();
game_free();
}
Index: server/diplhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/diplhand.c,v
retrieving revision 1.78
diff -u -r1.78 diplhand.c
--- server/diplhand.c 2004/01/31 17:52:41 1.78
+++ server/diplhand.c 2004/02/10 16:19:32
@@ -54,18 +54,28 @@
#define treaty_list_iterate_end LIST_ITERATE_END
static struct treaty_list treaties;
-static bool did_init_treaties;
/**************************************************************************
...
**************************************************************************/
-struct Treaty *find_treaty(struct player *plr0, struct player *plr1)
+void diplhand_init()
+{
+ treaty_list_init(&treaties);
+}
+
+/**************************************************************************
+...
+**************************************************************************/
+void diplhand_free()
{
- if (!did_init_treaties) {
- treaty_list_init(&treaties);
- did_init_treaties = TRUE;
- }
+ treaty_list_unlink_all(&treaties);
+}
+/**************************************************************************
+...
+**************************************************************************/
+struct Treaty *find_treaty(struct player *plr0, struct player *plr1)
+{
treaty_list_iterate(treaties, ptreaty) {
if ((ptreaty->plr0 == plr0 && ptreaty->plr1 == plr1) ||
(ptreaty->plr0 == plr1 && ptreaty->plr1 == plr0)) {
Index: server/diplhand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/diplhand.h,v
retrieving revision 1.7
diff -u -r1.7 diplhand.h
--- server/diplhand.h 2003/11/28 17:37:22 1.7
+++ server/diplhand.h 2004/02/10 16:19:52
@@ -22,6 +22,9 @@
void establish_embassy(struct player *pplayer, struct player *aplayer);
+void diplhand_init(void);
+void diplhand_free(void);
+
struct Treaty *find_treaty(struct player *plr0, struct player *plr1);
void send_diplomatic_meetings(struct connection *dest);
- [Freeciv-Dev] Re: (PR#7405) list cleanup, Raimar Falke, 2004/02/10
- [Freeciv-Dev] Re: (PR#7405) list cleanup, Per I. Mathisen, 2004/02/10
- [Freeciv-Dev] Re: (PR#7405) list cleanup,
Per I. Mathisen <=
- [Freeciv-Dev] Re: (PR#7405) list cleanup, Raimar Falke, 2004/02/10
- [Freeciv-Dev] Re: (PR#7405) list cleanup, Raimar Falke, 2004/02/10
- [Freeciv-Dev] Re: (PR#7405) list cleanup, Per I. Mathisen, 2004/02/10
- [Freeciv-Dev] Re: (PR#7405) list cleanup, Jason Short, 2004/02/11
- [Freeciv-Dev] Re: (PR#7405) list cleanup, Raimar Falke, 2004/02/11
- [Freeciv-Dev] Re: (PR#7405) list cleanup, Raimar Falke, 2004/02/11
- [Freeciv-Dev] Re: (PR#7405) list cleanup, Per I. Mathisen, 2004/02/13
|
|