From 06a89120d61f89ffaca0262cd03b569422e41aa3 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Mon, 10 Aug 2026 21:27:49 +0300
Subject: [PATCH 53/53] Send city->aarea information to client

See RM #2130

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/packhand.c             | 30 ++++++++++++++++++++++++++++++
 common/networking/packets.def |  7 ++++++-
 server/aahand.c               |  7 +++++++
 3 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/client/packhand.c b/client/packhand.c
index aa0f17e33b..80c1d1a95c 100644
--- a/client/packhand.c
+++ b/client/packhand.c
@@ -5878,3 +5878,33 @@ void handle_access_area(const struct packet_access_area *packet)
 
   aarea_list_append(alist, aarea);
 }
+
+/**********************************************************************//**
+  Handle city access area packet.
+**************************************************************************/
+void handle_city_access_area(const struct packet_city_access_area *packet)
+{
+  struct city *pcity = game_city_by_number(packet->city);
+  struct player *plr;
+  struct aarea_list *alist;
+
+  if (pcity == nullptr) {
+    log_warn("handle_city_access_area() received illegal city");
+    return;
+  }
+
+  plr = city_owner(pcity);
+
+  /* Currently we support only packets about our own cities. */
+  fc_assert(plr == client_player());
+
+  alist = area_list_for_player(plr);
+  aarea_list_iterate(alist, aarea) {
+    if (aarea->index == packet->aarea) {
+      fc_assert(pcity->aarea == nullptr);
+
+      pcity->aarea = aarea;
+      break;
+    }
+  } aarea_list_iterate_end;
+}
diff --git a/common/networking/packets.def b/common/networking/packets.def
index 760b6bd4aa..59ccfef855 100644
--- a/common/networking/packets.def
+++ b/common/networking/packets.def
@@ -3,7 +3,7 @@
 Max used id:
 ============
 
-Max id: 521
+Max id: 522
 
 Packets are not ordered by their id, but by their category. New packet
 with higher id may get added to existing category, and not to the end of file.
@@ -2445,6 +2445,11 @@ PACKET_ACCESS_AREA = 521; sc, lsend
   BV_TILEDEFS tiledefs;
 end
 
+PACKET_CITY_ACCESS_AREA = 522; sc, lsend
+  CITY city;
+  UINT16 aarea;
+end
+
 /*************** Webclient specific packets ****************/
 /* Use range 256:511 for these                             */
 
diff --git a/server/aahand.c b/server/aahand.c
index ad3817cb2e..a14488c87b 100644
--- a/server/aahand.c
+++ b/server/aahand.c
@@ -55,6 +55,8 @@ void access_areas_refresh(struct civ_map *nmap, struct player *plr)
     packet.player = player_number(plr);
 
     city_list_iterate(plr->cities, pcity) {
+      struct packet_city_access_area caarea_packet;
+
       if (pcity->aarea == nullptr) {
         struct access_area *aarea = fc_malloc(sizeof(struct access_area));
         struct pf_parameter parameter;
@@ -112,6 +114,11 @@ void access_areas_refresh(struct civ_map *nmap, struct player *plr)
 
         lsend_packet_access_area(plr->connections, &packet);
       }
+
+      caarea_packet.city = pcity->id;
+      caarea_packet.aarea = pcity->aarea->index;
+
+      lsend_packet_city_access_area(plr->connections, &caarea_packet);
     } city_list_iterate_end;
 
     unit_virtual_destroy(access_unit);
-- 
2.53.0

