From 29b7da18a197742ce0ecb764b5346a514e193dda Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 26 Nov 2022 07:27:51 +0200 Subject: [PATCH 30/30] Send rally point separately from PACKET_CITY_INFO Use existing PACKET_CITY_RALLY_POINT See osdn #46080 Signed-off-by: Marko Lindqvist --- client/goto.c | 2 +- client/packhand.c | 14 +++++++++++++- common/networking/packets.def | 11 +++-------- server/citytools.c | 28 ++++++++++++++++++++-------- server/citytools.h | 1 + server/diplomats.c | 5 ++++- 6 files changed, 42 insertions(+), 19 deletions(-) diff --git a/client/goto.c b/client/goto.c index 6a6e4b80f6..cc1a33dec6 100644 --- a/client/goto.c +++ b/client/goto.c @@ -1518,7 +1518,7 @@ static void send_rally_path_orders(struct city *pcity, struct unit *punit, make_path_orders(punit, path, orders, final_order, p.orders, &p.length, NULL); - send_packet_city_rally_point(&client.conn, &p); + send_packet_city_rally_point(&client.conn, &p, FALSE); } /************************************************************************//** diff --git a/client/packhand.c b/client/packhand.c index af7f9bce9b..dfecf49264 100644 --- a/client/packhand.c +++ b/client/packhand.c @@ -637,7 +637,7 @@ static bool update_improvement_from_packet(struct city *pcity, } /************************************************************************//** - A city-info packet contains all information about a city. If we receive + A city-info packet contains all information about a city. If we receive this packet then we know everything about the city internals. ****************************************************************************/ void handle_city_info(const struct packet_city_info *packet) @@ -999,6 +999,18 @@ void handle_city_nationalities(const struct packet_city_nationalities *packet) } } +/************************************************************************//** + Handle city rally point packet. +****************************************************************************/ +void handle_city_rally_point(const struct packet_city_rally_point *packet) +{ + struct city *pcity = game_city_by_number(packet->city_id); + + if (pcity != NULL) { + city_rally_point_receive(packet, pcity); + } +} + /************************************************************************//** A helper function for handling city-info and city-short-info packets. Naturally, both require many of the same operations to be done on the diff --git a/common/networking/packets.def b/common/networking/packets.def index 6450d1c421..3ee5d59f3d 100644 --- a/common/networking/packets.def +++ b/common/networking/packets.def @@ -687,7 +687,7 @@ end /************** City packets **********************/ -PACKET_CITY_REMOVE = 30; sc, dsend, lsend, cancel(PACKET_CITY_INFO), cancel(PACKET_WEB_CITY_INFO_ADDITION), cancel(PACKET_CITY_NATIONALITIES), cancel(PACKET_CITY_SHORT_INFO) +PACKET_CITY_REMOVE = 30; sc, dsend, lsend, cancel(PACKET_CITY_INFO), cancel(PACKET_WEB_CITY_INFO_ADDITION), cancel(PACKET_CITY_NATIONALITIES), cancel(PACKET_CITY_RALLY_POINT), cancel(PACKET_CITY_SHORT_INFO) CITY city_id; end @@ -756,11 +756,6 @@ PACKET_CITY_INFO = 31; sc, lsend, is-game-info, force, cancel(PACKET_CITY_SHORT_ BV_IMPRS improvements; BV_CITY_OPTIONS city_options; ESTRING name[MAX_LEN_CITYNAME]; - - UINT16 rally_point_length; - BOOL rally_point_persistent; - BOOL rally_point_vigilant; - UNIT_ORDER rally_point_orders[MAX_LEN_ROUTE:rally_point_length]; end PACKET_CITY_NATIONALITIES = 46; sc, lsend, is-game-info, force, handle-via-packet @@ -770,7 +765,7 @@ PACKET_CITY_NATIONALITIES = 46; sc, lsend, is-game-info, force, handle-via-packe CITIZENS nation_citizens[MAX_CITY_NATIONALITIES:nationalities_count]; end -PACKET_CITY_SHORT_INFO = 32; sc, lsend, is-game-info, cancel(PACKET_CITY_INFO), cancel(PACKET_WEB_CITY_INFO_ADDITION), cancel(PACKET_CITY_NATIONALITIES) +PACKET_CITY_SHORT_INFO = 32; sc, lsend, is-game-info, cancel(PACKET_CITY_INFO), cancel(PACKET_WEB_CITY_INFO_ADDITION), cancel(PACKET_CITY_NATIONALITIES), cancel(PACKET_CITY_RALLY_POINT) CITY id; key TILE tile; @@ -873,7 +868,7 @@ PACKET_CITY_SABOTAGE_LIST = 45; sc, lsend UINT8 request_kind; end -PACKET_CITY_RALLY_POINT = 138; cs, handle-via-packet +PACKET_CITY_RALLY_POINT = 138; cs, sc, lsend, is-game-info, force, handle-via-packet CITY city_id; UINT16 length; BOOL persistent; diff --git a/server/citytools.c b/server/citytools.c index 8c0d03e28c..6de29e8ea2 100644 --- a/server/citytools.c +++ b/server/citytools.c @@ -2184,6 +2184,7 @@ void broadcast_city_info(struct city *pcity) { struct packet_city_info packet; struct packet_city_nationalities nat_packet; + struct packet_city_rally_point rally_packet; struct packet_web_city_info_addition web_packet; struct packet_city_short_info sc_pack; struct player *powner = city_owner(pcity); @@ -2201,7 +2202,8 @@ void broadcast_city_info(struct city *pcity) } routes = traderoute_packet_list_new(); - package_city(pcity, &packet, &nat_packet, &web_packet, routes, FALSE); + package_city(pcity, &packet, &nat_packet, &rally_packet, + &web_packet, routes, FALSE); players_iterate(pplayer) { if (!send_city_suppressed || pplayer != powner) { @@ -2209,6 +2211,7 @@ void broadcast_city_info(struct city *pcity) update_dumb_city(pplayer, pcity); lsend_packet_city_info(pplayer->connections, &packet, FALSE); lsend_packet_city_nationalities(pplayer->connections, &nat_packet, FALSE); + lsend_packet_city_rally_point(pplayer->connections, &rally_packet, FALSE); web_lsend_packet(city_info_addition, pplayer->connections, &web_packet, FALSE); traderoute_packet_list_iterate(routes, route_packet) { lsend_packet_traderoute_info(pplayer->connections, route_packet); @@ -2227,6 +2230,7 @@ void broadcast_city_info(struct city *pcity) if (conn_is_global_observer(pconn)) { send_packet_city_info(pconn, &packet, FALSE); send_packet_city_nationalities(pconn, &nat_packet, FALSE); + send_packet_city_rally_point(pconn, &rally_packet, FALSE); web_send_packet(city_info_addition, pconn, &web_packet, FALSE); } } conn_list_iterate_end; @@ -2338,6 +2342,7 @@ void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, { struct packet_city_info packet; struct packet_city_nationalities nat_packet; + struct packet_city_rally_point rally_packet; struct packet_web_city_info_addition web_packet; struct packet_city_short_info sc_pack; struct player *powner = NULL; @@ -2365,9 +2370,11 @@ void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, /* Send all info to the owner */ update_dumb_city(powner, pcity); - package_city(pcity, &packet, &nat_packet, &web_packet, routes, FALSE); + package_city(pcity, &packet, &nat_packet, &rally_packet, + &web_packet, routes, FALSE); lsend_packet_city_info(dest, &packet, FALSE); lsend_packet_city_nationalities(dest, &nat_packet, FALSE); + lsend_packet_city_rally_point(dest, &rally_packet, FALSE); web_lsend_packet(city_info_addition, dest, &web_packet, FALSE); traderoute_packet_list_iterate(routes, route_packet) { lsend_packet_traderoute_info(dest, route_packet); @@ -2391,9 +2398,11 @@ void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, routes = traderoute_packet_list_new(); /* Should be dumb_city info? */ - package_city(pcity, &packet, &nat_packet, &web_packet, routes, FALSE); + package_city(pcity, &packet, &nat_packet, &rally_packet, + &web_packet, routes, FALSE); lsend_packet_city_info(dest, &packet, FALSE); lsend_packet_city_nationalities(dest, &nat_packet, FALSE); + lsend_packet_city_rally_point(dest, &rally_packet, FALSE); web_lsend_packet(city_info_addition, dest, &web_packet, FALSE); traderoute_packet_list_iterate(routes, route_packet) { lsend_packet_traderoute_info(dest, route_packet); @@ -2429,6 +2438,7 @@ void send_city_info_at_tile(struct player *pviewer, struct conn_list *dest, ****************************************************************************/ void package_city(struct city *pcity, struct packet_city_info *packet, struct packet_city_nationalities *nat_packet, + struct packet_city_rally_point *rally_packet, struct packet_web_city_info_addition *web_packet, struct traderoute_packet_list *routes, bool dipl_invest) @@ -2517,7 +2527,8 @@ void package_city(struct city *pcity, struct packet_city_info *packet, /* And repackage */ recursion = TRUE; - package_city(pcity, packet, nat_packet, web_packet, routes, dipl_invest); + package_city(pcity, packet, nat_packet, rally_packet, + web_packet, routes, dipl_invest); recursion = FALSE; return; @@ -2587,11 +2598,12 @@ void package_city(struct city *pcity, struct packet_city_info *packet, packet->capital = pcity->capital; packet->steal = pcity->steal; - packet->rally_point_length = pcity->rally_point.length; - packet->rally_point_persistent = pcity->rally_point.persistent; - packet->rally_point_vigilant = pcity->rally_point.vigilant; + rally_packet->city_id = pcity->id; + rally_packet->length = pcity->rally_point.length; + rally_packet->persistent = pcity->rally_point.persistent; + rally_packet->vigilant = pcity->rally_point.vigilant; if (pcity->rally_point.length) { - memcpy(packet->rally_point_orders, pcity->rally_point.orders, + memcpy(rally_packet->orders, pcity->rally_point.orders, pcity->rally_point.length * sizeof(struct unit_order)); } diff --git a/server/citytools.h b/server/citytools.h index 6eeae3cd2e..dbf7fb49a4 100644 --- a/server/citytools.h +++ b/server/citytools.h @@ -53,6 +53,7 @@ void send_player_cities(struct player *pplayer); void broadcast_city_info(struct city *pcity); void package_city(struct city *pcity, struct packet_city_info *packet, struct packet_city_nationalities *nat_packet, + struct packet_city_rally_point *rally_packet, struct packet_web_city_info_addition *web_packet, struct traderoute_packet_list *routes, bool dipl_invest); diff --git a/server/diplomats.c b/server/diplomats.c index 1120914d90..ff9b2b5702 100644 --- a/server/diplomats.c +++ b/server/diplomats.c @@ -329,6 +329,7 @@ bool diplomat_investigate(struct player *pplayer, struct unit *pdiplomat, struct packet_unit_short_info unit_packet; struct packet_city_info city_packet; struct packet_city_nationalities nat_packet; + struct packet_city_rally_point rally_packet; struct packet_web_city_info_addition web_packet; struct traderoute_packet_list *routes; const struct unit_type *act_utype; @@ -376,11 +377,13 @@ bool diplomat_investigate(struct player *pplayer, struct unit *pdiplomat, /* Send city info to investigator's player. As this is a special case we bypass send_city_info. */ routes = traderoute_packet_list_new(); - package_city(pcity, &city_packet, &nat_packet, &web_packet, routes, TRUE); + package_city(pcity, &city_packet, &nat_packet, &rally_packet, + &web_packet, routes, TRUE); /* We need to force to send the packet to ensure the client will receive * something and popup the city dialog. */ lsend_packet_city_info(pplayer->connections, &city_packet, TRUE); lsend_packet_city_nationalities(pplayer->connections, &nat_packet, TRUE); + lsend_packet_city_rally_point(pplayer->connections, &rally_packet, TRUE); web_lsend_packet(city_info_addition, pplayer->connections, &web_packet, TRUE); traderoute_packet_list_iterate(routes, route_packet) { lsend_packet_traderoute_info(pplayer->connections, route_packet); -- 2.35.1