Author: cazfi
Date: Sat Sep  5 10:46:21 2015
New Revision: 29776

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

See bug #23765

Modified:
    trunk/client/packhand.c
    trunk/common/packets.def
    trunk/fc_version
    trunk/server/report.c
    trunk/server/report.h

Modified: trunk/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/packhand.c?rev=29776&r1=29775&r2=29776&view=diff
==============================================================================
--- trunk/client/packhand.c     (original)
+++ trunk/client/packhand.c     Sat Sep  5 10:46:21 2015
@@ -118,6 +118,15 @@
   .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()
 ****************************************************************************/
@@ -1343,16 +1352,48 @@
 }
 
 /****************************************************************************
-  Packet page_msg handler.
+  Page_msg header handler.
 ****************************************************************************/
 void handle_page_msg(const char *caption, const char *headline,
-                     const char *lines, enum event_type event)
+                     enum event_type event, int len, int parts)
 {
   if (!client_has_player()
       || !client_player()->ai_controlled
       || event != E_BROADCAST_REPORT) {
-    popup_notify_dialog(caption, headline, lines);
-    play_sound_for_event(event);
+    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: trunk/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/packets.def?rev=29776&r1=29775&r2=29776&view=diff
==============================================================================
--- trunk/common/packets.def    (original)
+++ trunk/common/packets.def    Sat Sep  5 10:46:21 2015
@@ -3,7 +3,7 @@
 Max used id:
 ============
 
-Max id: 249
+Max id: 250
 
 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.
@@ -1125,8 +1125,13 @@
 PACKET_PAGE_MSG = 110; sc, lsend
   STRING caption[MAX_LEN_MSG];
   STRING headline[MAX_LEN_MSG];
-  STRING lines[MAX_LEN_PACKET];
-  EVENT event;
+  EVENT  event;
+  UINT32 len;
+  UINT16 parts;
+end
+
+PACKET_PAGE_MSG_PART = 250; sc, lsend
+  STRING lines[MAX_LEN_CONTENT];
 end
 
 PACKET_REPORT_REQ = 111; cs, handle-per-conn, dsend
@@ -1721,7 +1726,7 @@
 
   STRING name[MAX_LEN_NAME];
   STRING version[MAX_LEN_NAME];
-  UINT16  desc_length;
+  UINT16 desc_length;
 end
 
 PACKET_RULESET_DESCRIPTION_PART = 247; sc, lsend

Modified: trunk/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=29776&r1=29775&r2=29776&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Sat Sep  5 10:46:21 2015
@@ -54,7 +54,7 @@
 #   - Avoid adding a new mandatory capability to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2015.Aug.30b"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2015.Sep.05"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/report.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/report.c?rev=29776&r1=29775&r2=29776&view=diff
==============================================================================
--- trunk/server/report.c       (original)
+++ trunk/server/report.c       Sat Sep  5 10:46:21 2015
@@ -30,6 +30,7 @@
 /* common */
 #include "achievements.h"
 #include "calendar.h"
+#include "connection.h"
 #include "events.h"
 #include "game.h"
 #include "government.h"
@@ -1651,11 +1652,32 @@
                             enum event_type event)
 {
   struct packet_page_msg packet;
+  int i;
+  int len;
 
   sz_strlcpy(packet.caption, caption);
   sz_strlcpy(packet.headline, headline);
-  sz_strlcpy(packet.lines, lines);
   packet.event = event;
+  len = strlen(lines);
+  if ((len % (MAX_LEN_CONTENT - 1)) == 0) {
+    packet.parts = len / (MAX_LEN_CONTENT - 1);
+  } else {
+    packet.parts = len / (MAX_LEN_CONTENT - 1) + 1;
+  }
+  packet.len = len;
 
   lsend_packet_page_msg(dest, &packet);
-}
+
+  for (i = 0; i < packet.parts; i++) {
+    struct packet_page_msg_part part;
+    int plen;
+
+    plen = MIN(len, (MAX_LEN_CONTENT - 1));
+    strncpy(part.lines, &(lines[(MAX_LEN_CONTENT - 1) * i]), plen);
+    part.lines[plen] = '\0';
+
+    lsend_packet_page_msg_part(dest, &part);
+
+    len -= plen;
+  }
+}

Modified: trunk/server/report.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/report.h?rev=29776&r1=29775&r2=29776&view=diff
==============================================================================
--- trunk/server/report.h       (original)
+++ trunk/server/report.h       Sat Sep  5 10:46:21 2015
@@ -19,7 +19,7 @@
 struct conn_list;
 
 #define REPORT_TITLESIZE 1024
-#define REPORT_BODYSIZE 4096
+#define REPORT_BODYSIZE (128 * MAX_NUM_PLAYER_SLOTS)
 
 struct history_report
 {


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

Reply via email to