From 479d183a2fba51a0e63c5e9e391b5b36a12c8d2b Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 24 Mar 2021 22:44:46 +0200 Subject: [PATCH 22/22] Wait until city is in sane state before sending info packets Don't send city info packets to client in the middle of the city processing when city might be in inconsistent state. See osdn #41851 Signed-off-by: Marko Lindqvist --- server/citytools.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/server/citytools.c b/server/citytools.c index 58cc822f63..5969be1d28 100644 --- a/server/citytools.c +++ b/server/citytools.c @@ -2086,10 +2086,16 @@ static void broadcast_city_info(struct city *pcity) struct player *powner = city_owner(pcity); /* Send to everyone who can see the city. */ - package_city(pcity, &packet, FALSE); + if (!pcity->server.needs_arrange) { + /* Send city only when it's in sane state. + * If it's not, it will be sent to everyone once + * rearrangement has been finished. */ + package_city(pcity, &packet, FALSE); + } players_iterate(pplayer) { if (can_player_see_city_internals(pplayer, pcity)) { - if (!send_city_suppressed || pplayer != powner) { + if ((!send_city_suppressed || pplayer != powner) + && !pcity->server.needs_arrange) { update_dumb_city(powner, pcity); lsend_packet_city_info(powner->connections, &packet, FALSE); } @@ -2104,11 +2110,13 @@ static void broadcast_city_info(struct city *pcity) } players_iterate_end; /* Send to global observers. */ - conn_list_iterate(game.est_connections, pconn) { - if (conn_is_global_observer(pconn)) { - send_packet_city_info(pconn, &packet, FALSE); - } - } conn_list_iterate_end; + if (!pcity->server.needs_arrange) { + conn_list_iterate(game.est_connections, pconn) { + if (conn_is_global_observer(pconn)) { + send_packet_city_info(pconn, &packet, FALSE); + } + } conn_list_iterate_end; + } } /************************************************************************** @@ -2223,8 +2231,11 @@ void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, if (powner && powner == pviewer) { /* send info to owner */ /* This case implies powner non-NULL which means pcity non-NULL */ - if (!send_city_suppressed) { - /* send all info to the owner */ + if (!send_city_suppressed && !pcity->server.needs_arrange) { + /* Send all info to the owner. + * Wait that city has been rearranged, if it's currently + * not in sane state. + */ update_dumb_city(powner, pcity); package_city(pcity, &packet, FALSE); lsend_packet_city_info(dest, &packet, FALSE); @@ -2240,7 +2251,7 @@ void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, } else { /* send info to non-owner */ if (!pviewer) { /* observer */ - if (pcity) { + if (pcity && !pcity->server.needs_arrange) { package_city(pcity, &packet, FALSE); /* should be dumb_city info? */ lsend_packet_city_info(dest, &packet, FALSE); } @@ -2274,6 +2285,8 @@ void package_city(struct city *pcity, struct packet_city_info *packet, int i; int ppl = 0; + fc_assert(!pcity->server.needs_arrange); + packet->id=pcity->id; packet->owner = player_number(city_owner(pcity)); packet->tile = tile_index(city_tile(pcity)); -- 2.30.2