From 200af303bd925353d1a90e373d706c2f062086ac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C5=82awomir=20Lach?= <slawek@lach.art.pl>
Date: Fri, 3 Feb 2023 19:09:09 +0100
Subject: [PATCH] =?UTF-8?q?!OSDN:=20TICKET:=2046496:=20S=C5=82awomir=20Lac?=
 =?UTF-8?q?h=20<slawek@lach.art.pl>?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Server send only necessary data to clients from now.

diff --git a/client/packhand.c b/client/packhand.c
index 16bb1b0c4e..19b4cd03d3 100644
--- a/client/packhand.c
+++ b/client/packhand.c
@@ -5563,8 +5563,8 @@ Handle updating city's counter, when server request
 **************************************************************************/
 void handle_city_update_counters(const struct packet_city_update_counters *packet)
 {
-  int i;
-  int counters_count = counters_get_city_counters_count();
+  uint8_t i;
+  uint8_t counters_count = counters_get_city_counters_count();
 
   struct city *pcity = game_city_by_number(packet->city);
 
@@ -5572,6 +5572,11 @@ void handle_city_update_counters(const struct packet_city_update_counters *packe
 
     return;
   }
+  
+  if (counters_count != packet->count) {
+  
+    return;
+  }
 
   counters_count = counters_get_city_counters_count();
   for (i = 0; i < counters_count; i++) {
diff --git a/common/networking/packets.def b/common/networking/packets.def
index d0146f1f1c..67daf4637a 100644
--- a/common/networking/packets.def
+++ b/common/networking/packets.def
@@ -779,7 +779,8 @@ end
 
 PACKET_CITY_UPDATE_COUNTERS = 514; sc, lsend, is-game-info
   CITY city; key
-  COUNTER counters[MAX_COUNTERS];
+  UINT8 count; # MAX_COUNTERS is set to 20 currently
+  COUNTER counters[MAX_COUNTERS: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), cancel(PACKET_CITY_RALLY_POINT)
diff --git a/server/cityturn.c b/server/cityturn.c
index 3ec2fb9be0..3dfe3c5cf0 100644
--- a/server/cityturn.c
+++ b/server/cityturn.c
@@ -4422,18 +4422,14 @@ void city_style_refresh(struct city *pcity)
 **************************************************************************/
 void city_counters_refresh(struct city *pcity)
 {
-  int i, counter_count;
+  uint8_t i, counter_count;
   struct packet_city_update_counters packet;
 
-  /* Needed, because we use delta protocol
-   * We do not need to sending seldom data
-   * with seldom possibility.
-   */
-  memset(packet.counters, 0, sizeof(packet.counters));
   packet.city = pcity->id;
 
   counter_count = counters_get_city_counters_count();
 
+  packet.count = counter_count;
   for (i = 0; i < counter_count; i++) {
     packet.counters[i] = pcity->counter_values[i];
   }
-- 
2.39.1

