From ae61ef1f2f2f114d3df3da38c280f8183f0a11c6 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 10 Apr 2021 02:12:02 +0300 Subject: [PATCH 52/52] Fix server crash when illness destroys a city See osdn #41959 Signed-off-by: Marko Lindqvist --- server/citytools.c | 19 ++++++++++++------- server/citytools.h | 2 +- server/cityturn.c | 5 ++++- server/diplomats.c | 10 +++++----- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/server/citytools.c b/server/citytools.c index 905f00a8fd..6bca8dbf56 100644 --- a/server/citytools.c +++ b/server/citytools.c @@ -2778,19 +2778,24 @@ struct trade_route *remove_trade_route(struct city *pc1, struct trade_route *pro /**********************************************************************//** Give the city a plague. **************************************************************************/ -void city_illness_strike(struct city *pcity) +bool city_illness_strike(struct city *pcity) { notify_player(city_owner(pcity), city_tile(pcity), E_CITY_PLAGUE, ftc_server, _("%s has been struck by a plague! Population lost!"), city_link(pcity)); - city_reduce_size(pcity, 1, NULL, "plague"); - pcity->turn_plague = game.info.turn; + if (city_reduce_size(pcity, 1, NULL, "plague")) { + pcity->turn_plague = game.info.turn; - /* recalculate illness */ - pcity->server.illness - = city_illness_calc(pcity, NULL, NULL, &(pcity->illness_trade), - NULL); + /* recalculate illness */ + pcity->server.illness + = city_illness_calc(pcity, NULL, NULL, &(pcity->illness_trade), + NULL); + + return TRUE; + } + + return FALSE; } /************************************************************************//** diff --git a/server/citytools.h b/server/citytools.h index 9d60166fbf..d57fb28fb7 100644 --- a/server/citytools.h +++ b/server/citytools.h @@ -71,7 +71,7 @@ struct trade_route *remove_trade_route(struct city *pc1, struct trade_route *proute, bool announce, bool source_gone); -void city_illness_strike(struct city *pcity); +bool city_illness_strike(struct city *pcity); void do_sell_building(struct player *pplayer, struct city *pcity, struct impr_type *pimprove, const char *reason); diff --git a/server/cityturn.c b/server/cityturn.c index e1aee9d729..21d23f2759 100644 --- a/server/cityturn.c +++ b/server/cityturn.c @@ -3207,7 +3207,10 @@ static void update_city_activity(struct city *pcity) = city_illness_calc(pcity, NULL, NULL, &(pcity->illness_trade), NULL); if (city_illness_check(pcity)) { - city_illness_strike(pcity); + if (!city_illness_strike(pcity)) { + /* Illness destroyed the city */ + return; + } } } diff --git a/server/diplomats.c b/server/diplomats.c index 048d3922e8..e7c1223ced 100644 --- a/server/diplomats.c +++ b/server/diplomats.c @@ -278,11 +278,11 @@ bool spy_spread_plague(struct player *act_player, struct unit *act_unit, log_debug("spread plague: succeeded"); /* Commit bio-terrorism. */ - city_illness_strike(tgt_city); - - /* Update the clients. */ - city_refresh(tgt_city); - send_city_info(NULL, tgt_city); + if (city_illness_strike(tgt_city)) { + /* Update the clients. */ + city_refresh(tgt_city); + send_city_info(NULL, tgt_city); + } /* Notify everyone involved. */ notify_player(act_player, tgt_tile, E_UNIT_ACTION_ACTOR_SUCCESS, -- 2.30.2