Author: cazfi
Date: Sat Sep  5 10:47:06 2015
New Revision: 29778

URL: http://svn.gna.org/viewcvs/freeciv?rev=29778&view=rev
Log:
Support history reports for a high player count both in memory storage and 
network protocol.

See bug #23765

Modified:
    branches/S2_5/client/packhand.c
    branches/S2_5/common/packets.def
    branches/S2_5/fc_version
    branches/S2_5/server/report.c

Modified: branches/S2_5/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/packhand.c?rev=29778&r1=29777&r2=29778&view=diff
==============================================================================
--- branches/S2_5/client/packhand.c     (original)
+++ branches/S2_5/client/packhand.c     Sat Sep  5 10:47:06 2015
@@ -110,6 +110,15 @@
   .cities = NULL,
   .placeholder = NULL
 };
+
+static struct {
+  int len;
+  enum event_type event;
+  char *caption;
+  char *headline;
+  char *lines;
+  int parts;
+} page_msg_report = { .parts = 0 };
 
 /****************************************************************************
   Called below, and by client/client_main.c client_game_free()
@@ -1254,16 +1263,62 @@
 }
 
 /****************************************************************************
-  Packet page_msg handler.
-****************************************************************************/
-void handle_page_msg(const char *caption, const char *headline,
-                     const char *lines, enum event_type event)
+  Compatibility page_msg header handler.
+****************************************************************************/
+void handle_page_msg_old(const char *caption, const char *headline,
+                         const char *lines, enum event_type event)
 {
   if (!client_has_player()
       || !client_player()->ai_controlled
       || event != E_BROADCAST_REPORT) {
     popup_notify_dialog(caption, headline, lines);
     play_sound_for_event(event);
+  }
+}
+
+/****************************************************************************
+  Page_msg header handler.
+****************************************************************************/
+void handle_page_msg_new(const char *caption, const char *headline,
+                         enum event_type event, int len, int parts)
+{
+  if (!client_has_player()
+      || !client_player()->ai_controlled
+      || event != E_BROADCAST_REPORT) {
+    if (page_msg_report.parts > 0) {
+      /* Previous one was never finished */
+      free(page_msg_report.caption);
+      free(page_msg_report.headline);
+      free(page_msg_report.lines);
+    }
+    page_msg_report.len = len;
+    page_msg_report.event = event;
+    page_msg_report.caption = fc_strdup(caption);
+    page_msg_report.headline = fc_strdup(headline);
+    page_msg_report.parts = parts;
+    page_msg_report.lines = fc_malloc(len + 1);
+    page_msg_report.lines[0] = '\0';
+  }
+}
+
+/****************************************************************************
+  Page_msg part handler.
+****************************************************************************/
+void handle_page_msg_part(const char *lines)
+{
+  fc_strlcat(page_msg_report.lines, lines, page_msg_report.len + 1);
+  page_msg_report.parts--;
+
+  if (page_msg_report.parts == 0) {
+    /* This is the final part */
+    popup_notify_dialog(page_msg_report.caption,
+                        page_msg_report.headline,
+                        page_msg_report.lines);
+    play_sound_for_event(page_msg_report.event);
+
+    free(page_msg_report.caption);
+    free(page_msg_report.headline);
+    free(page_msg_report.lines);
   }
 }
 

Modified: branches/S2_5/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/packets.def?rev=29778&r1=29777&r2=29778&view=diff
==============================================================================
--- branches/S2_5/common/packets.def    (original)
+++ branches/S2_5/common/packets.def    Sat Sep  5 10:47:06 2015
@@ -3,7 +3,7 @@
 Max used id:
 ============
 
-Max id: 234
+Max id: 236
 
 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.
@@ -1057,11 +1057,23 @@
 
 /**************  Report packets **********************/
 
-PACKET_PAGE_MSG = 110; sc, lsend
+PACKET_PAGE_MSG_OLD = 110; sc, lsend
   STRING caption[MAX_LEN_MSG];
   STRING headline[MAX_LEN_MSG];
   STRING lines[MAX_LEN_PACKET];
-  EVENT event;
+  EVENT  event;
+end
+
+PACKET_PAGE_MSG_NEW = 235; sc, lsend
+  STRING caption[MAX_LEN_MSG];
+  STRING headline[MAX_LEN_MSG];
+  EVENT  event;
+  UINT32 len;
+  UINT16 parts;
+end
+
+PACKET_PAGE_MSG_PART = 236; sc, lsend
+  STRING lines[MAX_LEN_MSG];
 end
 
 PACKET_REPORT_REQ = 111; cs, handle-per-conn, dsend

Modified: branches/S2_5/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/fc_version?rev=29778&r1=29777&r2=29778&view=diff
==============================================================================
--- branches/S2_5/fc_version    (original)
+++ branches/S2_5/fc_version    Sat Sep  5 10:47:06 2015
@@ -55,7 +55,7 @@
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
 NETWORK_CAPSTRING_MANDATORY="+Freeciv-2.5-network"
-NETWORK_CAPSTRING_OPTIONAL="nationset_change tech_cost"
+NETWORK_CAPSTRING_OPTIONAL="nationset_change tech_cost split_reports"
 
 FREECIV_DISTRIBUTOR=""
 

Modified: branches/S2_5/server/report.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/report.c?rev=29778&r1=29777&r2=29778&view=diff
==============================================================================
--- branches/S2_5/server/report.c       (original)
+++ branches/S2_5/server/report.c       Sat Sep  5 10:47:06 2015
@@ -20,6 +20,7 @@
 
 /* utility */
 #include "bitvector.h"
+#include "capability.h"
 #include "fciconv.h"
 #include "fcintl.h"
 #include "log.h"
@@ -227,7 +228,7 @@
 static void historian_generic(enum historian_type which_news)
 {
   int i, j = 0, rank = 0;
-  char buffer[4096];
+  char buffer[128 * MAX_NUM_PLAYER_SLOTS];
   char title[1024];
   struct player_score_entry size[player_count()];
 
@@ -1555,12 +1556,49 @@
                             const char *headline, const char *lines,
                             enum event_type event)
 {
-  struct packet_page_msg packet;
+  struct packet_page_msg_new packet;
+  struct packet_page_msg_old packet_old;
+  int i;
+  int len;
 
   sz_strlcpy(packet.caption, caption);
   sz_strlcpy(packet.headline, headline);
-  sz_strlcpy(packet.lines, lines);
   packet.event = event;
-
-  lsend_packet_page_msg(dest, &packet);
-}
+  len = strlen(lines);
+  if ((len % (MAX_LEN_MSG / 2 - 1)) == 0) {
+    packet.parts = len / (MAX_LEN_MSG / 2 - 1);
+  } else {
+    packet.parts = len / (MAX_LEN_MSG / 2 - 1) + 1;
+  }
+  packet.len = len;
+
+  sz_strlcpy(packet_old.caption, caption);
+  sz_strlcpy(packet_old.headline, headline);
+  strncpy(packet_old.lines, lines, MIN(MAX_LEN_MSG, strlen(lines)));
+  packet_old.event = event;
+
+  conn_list_iterate(dest, pconn) {
+    if (has_capability("split_reports", pconn->capability)) {
+      send_packet_page_msg_new(pconn, &packet);
+    } else {
+      send_packet_page_msg_old(pconn, &packet_old);
+    }
+  } conn_list_iterate_end;
+
+  for (i = 0; i < packet.parts; i++) {
+    struct packet_page_msg_part part;
+    int plen;
+
+    plen = MIN(len, (MAX_LEN_MSG / 2 - 1));
+    strncpy(part.lines, &(lines[(MAX_LEN_MSG / 2 - 1) * i]), plen);
+    part.lines[plen] = '\0';
+
+    conn_list_iterate(dest, pconn) {
+      if (has_capability("split_reports", pconn->capability)) {
+        send_packet_page_msg_part(pconn, &part);
+      }
+    } conn_list_iterate_end;
+
+    len -= plen;
+  }
+}


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to