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

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

See bug #23765

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

Modified: branches/S2_6/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/packhand.c?rev=29777&r1=29776&r2=29777&view=diff
==============================================================================
--- branches/S2_6/client/packhand.c     (original)
+++ branches/S2_6/client/packhand.c     Sat Sep  5 10:46:46 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()
 ****************************************************************************/
@@ -1308,16 +1317,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: branches/S2_6/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/packets.def?rev=29777&r1=29776&r2=29777&view=diff
==============================================================================
--- branches/S2_6/common/packets.def    (original)
+++ branches/S2_6/common/packets.def    Sat Sep  5 10:46:46 2015
@@ -3,7 +3,7 @@
 Max used id:
 ============
 
-Max id: 247
+Max id: 248
 
 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.
@@ -1118,8 +1118,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 = 248; sc, lsend
+  STRING lines[MAX_LEN_CONTENT];
 end
 
 PACKET_REPORT_REQ = 111; cs, handle-per-conn, dsend
@@ -1701,7 +1706,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: branches/S2_6/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/fc_version?rev=29777&r1=29776&r2=29777&view=diff
==============================================================================
--- branches/S2_6/fc_version    (original)
+++ branches/S2_6/fc_version    Sat Sep  5 10:46:46 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-2.6-2015.Aug.30"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2015.Sep.05"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: branches/S2_6/server/report.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/report.c?rev=29777&r1=29776&r2=29777&view=diff
==============================================================================
--- branches/S2_6/server/report.c       (original)
+++ branches/S2_6/server/report.c       Sat Sep  5 10:46:46 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: branches/S2_6/server/report.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/report.h?rev=29777&r1=29776&r2=29777&view=diff
==============================================================================
--- branches/S2_6/server/report.h       (original)
+++ branches/S2_6/server/report.h       Sat Sep  5 10:46:46 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