From 13096e63b6b5fbd8a240d347406d2c6b1ee1197a Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 10 May 2023 06:18:13 +0300 Subject: [PATCH 29/29] Keep observes in sync with city investigation See osdn #46186 Signed-off-by: Marko Lindqvist --- client/packhand.c | 55 +++++++++++++++++++++++------------ common/networking/packets.def | 10 +++++++ server/diplomats.c | 8 +++-- 3 files changed, 53 insertions(+), 20 deletions(-) diff --git a/client/packhand.c b/client/packhand.c index 4f8d844d0f..a6387ca27f 100644 --- a/client/packhand.c +++ b/client/packhand.c @@ -1065,12 +1065,12 @@ static void city_packet_common(struct city *pcity, struct tile *pcenter, unit_list_destroy(pcity->client.info_units_present); pcity->client.info_units_present = - pcity->client.collecting_info_units_present; + pcity->client.collecting_info_units_present; pcity->client.collecting_info_units_present = NULL; unit_list_destroy(pcity->client.info_units_supported); pcity->client.info_units_supported = - pcity->client.collecting_info_units_supported; + pcity->client.collecting_info_units_supported; pcity->client.collecting_info_units_supported = NULL; } else { /* We didn't get any unit, let's clear the unit lists. */ @@ -2103,6 +2103,40 @@ static bool handle_unit_packet_common(struct unit *packet_unit) return ret; } +/************************************************************************//** + Receive an investigate_started packet + + Can't rely on generic packet_processing_started, as that works for + the requesting connection only, and not for observers. +****************************************************************************/ +void handle_investigate_started(const struct packet_investigate_started *packet) +{ + struct city *pcity = game_city_by_number(packet->city_id); + + if (!pcity) { + log_error("Investigate city: unknown city id %d!", + packet->city_id); + return; + } + + /* Start collecting supported and present units. */ + + /* Ensure we are not already in an investigate cycle. */ + fc_assert(pcity->client.collecting_info_units_supported == NULL); + fc_assert(pcity->client.collecting_info_units_present == NULL); + pcity->client.collecting_info_units_supported = + unit_list_new_full(unit_virtual_destroy); + pcity->client.collecting_info_units_present = + unit_list_new_full(unit_virtual_destroy); +} + +/************************************************************************//** + Receive an investigate_finished packet +****************************************************************************/ +void handle_investigate_finished(const struct packet_investigate_finished *packet) +{ +} + /************************************************************************//** Receive a short_unit info packet. ****************************************************************************/ @@ -2117,7 +2151,6 @@ void handle_unit_short_info(const struct packet_unit_short_info *packet) * info. */ if (packet->packet_use == UNIT_INFO_CITY_SUPPORTED || packet->packet_use == UNIT_INFO_CITY_PRESENT) { - static int last_serial_num = 0; pcity = game_city_by_number(packet->info_city_id); if (!pcity) { @@ -2126,21 +2159,7 @@ void handle_unit_short_info(const struct packet_unit_short_info *packet) return; } - /* New serial number: start collecting supported and present units. */ - if (last_serial_num - != client.conn.client.request_id_of_currently_handled_packet) { - last_serial_num = - client.conn.client.request_id_of_currently_handled_packet; - /* Ensure we are not already in an investigate cycle. */ - fc_assert(pcity->client.collecting_info_units_supported == NULL); - fc_assert(pcity->client.collecting_info_units_present == NULL); - pcity->client.collecting_info_units_supported = - unit_list_new_full(unit_virtual_destroy); - pcity->client.collecting_info_units_present = - unit_list_new_full(unit_virtual_destroy); - } - - /* Okay, append a unit struct to the proper list. */ + /* Append a unit struct to the proper list. */ punit = unpackage_short_unit(packet); if (packet->packet_use == UNIT_INFO_CITY_SUPPORTED) { fc_assert(pcity->client.collecting_info_units_supported != NULL); diff --git a/common/networking/packets.def b/common/networking/packets.def index d0229eed44..e74f2dd6f1 100644 --- a/common/networking/packets.def +++ b/common/networking/packets.def @@ -375,6 +375,16 @@ end PACKET_PROCESSING_FINISHED = 1; sc end +PACKET_INVESTIGATE_STARTED = 21; sc, lsend, dsend + UNIT unit_id; + CITY city_id; +end + +PACKET_INVESTIGATE_FINISHED = 22; sc, lsend, dsend + UNIT unit_id; + CITY city_id; +end + /************** Login/pregame/endgame packets **********************/ # This packet is the first real (freeciv specific) packet send by the diff --git a/server/diplomats.c b/server/diplomats.c index 6fcd118778..a54c86a48d 100644 --- a/server/diplomats.c +++ b/server/diplomats.c @@ -354,6 +354,8 @@ bool diplomat_investigate(struct player *pplayer, struct unit *pdiplomat, log_debug("investigate: unit: %d", pdiplomat->id); + dlsend_packet_investigate_started(pplayer->connections, pdiplomat->id, pcity->id); + /* Do It... */ update_dumb_city(pplayer, pcity); /* Special case for a diplomat/spy investigating a city: @@ -376,7 +378,7 @@ bool diplomat_investigate(struct player *pplayer, struct unit *pdiplomat, lsend_packet_unit_short_info(pplayer->connections, &unit_packet, TRUE); } unit_list_iterate_end; /* Send city info to investigator's player. - As this is a special case we bypass send_city_info. */ + As this is a special case we bypass send_city_info(). */ if (any_web_conns()) { webp_ptr = &web_packet; @@ -400,7 +402,7 @@ bool diplomat_investigate(struct player *pplayer, struct unit *pdiplomat, } traderoute_packet_list_iterate_end; traderoute_packet_list_destroy(routes); - /* this may cause a diplomatic incident */ + /* This may cause a diplomatic incident */ action_consequence_success(paction, pplayer, act_utype, cplayer, city_tile(pcity), city_link(pcity)); @@ -412,6 +414,8 @@ bool diplomat_investigate(struct player *pplayer, struct unit *pdiplomat, send_unit_info(NULL, pdiplomat); } + dlsend_packet_investigate_finished(pplayer->connections, pdiplomat->id, pcity->id); + return TRUE; } -- 2.39.2