From 0ac3fa919a6ff96d0de31e33ef8ece1a6f12da78 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 6 Oct 2022 03:16:25 +0300 Subject: [PATCH 35/35] Send "unknown research" notifications to client Even when the client does not know research details, it needs to be informed about that fact to initialize values, or to clear old ones. Reported by ihnatus See osdn #45076 Signed-off-by: Marko Lindqvist --- client/packhand.c | 30 ++++++++++++++++++++++++++++++ common/networking/packets.def | 4 ++++ fc_version | 2 +- server/techtools.c | 12 +++++++++++- 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/client/packhand.c b/client/packhand.c index d3c06c8552..c906de3eda 100644 --- a/client/packhand.c +++ b/client/packhand.c @@ -2713,6 +2713,36 @@ void handle_research_info(const struct packet_research_info *packet) } } +/************************************************************************//** + Received a packet indicating we don't know the research details any more. +****************************************************************************/ +void handle_unknown_research(int id) +{ + struct research *presearch = research_by_number(id); + + if (presearch == NULL) { + log_error("Received unknown research for clearing: %d.", id); + return; + } + + /* Do we need to set other fields? */ + presearch->researching = A_UNKNOWN; + presearch->future_tech = 0; + presearch->tech_goal = A_UNKNOWN; + + advance_index_iterate(A_NONE, advi) { + research_invention_set(presearch, advi, TECH_UNKNOWN); + } advance_index_iterate_end; + + if (editor_is_active()) { + editgui_refresh(); + research_players_iterate(presearch, pplayer) { + editgui_notify_object_changed(OBJTYPE_PLAYER, player_number(pplayer), + FALSE); + } research_players_iterate_end; + } +} + /************************************************************************//** Packet player_diplstate handler. ****************************************************************************/ diff --git a/common/networking/packets.def b/common/networking/packets.def index b12195f26c..e459e0f46f 100644 --- a/common/networking/packets.def +++ b/common/networking/packets.def @@ -1013,6 +1013,10 @@ PACKET_RESEARCH_INFO = 60; sc, lsend, is-game-info STRING inventions[A_LAST + 1]; end +PACKET_UNKNOWN_RESEARCH = 66; sc, is-game-info, handle-via-fields, cancel(PACKET_RESEARCH_INFO) + RESEARCH id; +end + PACKET_PLAYER_RESEARCH = 55; cs, dsend, handle-via-fields TECH tech; end diff --git a/fc_version b/fc_version index 39495dfce2..f37712112b 100755 --- a/fc_version +++ b/fc_version @@ -61,7 +61,7 @@ DEFAULT_FOLLOW_TAG=S3_2 # - No new mandatory capabilities can be added to the release branch; doing # so would break network capability of supposedly "compatible" releases. # -NETWORK_CAPSTRING="+Freeciv.Devel-${MAIN_VERSION}-2022.Oct.05" +NETWORK_CAPSTRING="+Freeciv.Devel-${MAIN_VERSION}-2022.Oct.06" FREECIV_DISTRIBUTOR="" diff --git a/server/techtools.c b/server/techtools.c index db0a88ba72..8b4e65a38d 100644 --- a/server/techtools.c +++ b/server/techtools.c @@ -294,6 +294,7 @@ void send_research_info(const struct research *presearch, const struct conn_list *dest) { struct packet_research_info full_info, restricted_info; + struct packet_unknown_research unknown_info; const struct player *pplayer; fc_assert_ret(NULL != presearch); @@ -306,6 +307,7 @@ void send_research_info(const struct research *presearch, restricted_info = full_info; restricted_info.tech_goal = A_UNSET; restricted_info.total_bulbs_prod = 0; + unknown_info.id = research_number(presearch); conn_list_iterate(dest, pconn) { pplayer = conn_get_player(pconn); @@ -315,12 +317,20 @@ void send_research_info(const struct research *presearch, send_packet_research_info(pconn, &full_info); } else { /* 'pplayer' may have an embassy for looking to 'presearch'. */ + bool embassy = FALSE; + research_players_iterate(presearch, powner) { if (team_has_embassy(pplayer->team, powner)) { - send_packet_research_info(pconn, &restricted_info); + embassy = TRUE; break; } } research_players_iterate_end; + + if (embassy) { + send_packet_research_info(pconn, &restricted_info); + } else { + send_packet_unknown_research(pconn, &unknown_info); + } } } else if (pconn->observer) { /* Case global observer. */ -- 2.35.1