Author: cazfi
Date: Fri Aug 14 18:59:04 2015
New Revision: 29503

URL: http://svn.gna.org/viewcvs/freeciv?rev=29503&view=rev
Log:
Support ruleset descriptions longer than what would fit in single network 
packet with rest of the
ruleset control content.

See patch #3349

Modified:
    branches/S2_6/client/helpdata.c
    branches/S2_6/client/packhand.c
    branches/S2_6/common/connection.h
    branches/S2_6/common/game.c
    branches/S2_6/common/game.h
    branches/S2_6/common/packets.def
    branches/S2_6/fc_version
    branches/S2_6/server/ruleset.c
    branches/S2_6/server/stdinhand.c
    branches/S2_6/tools/ruledit/rulesave.c

Modified: branches/S2_6/client/helpdata.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/helpdata.c?rev=29503&r1=29502&r2=29503&view=diff
==============================================================================
--- branches/S2_6/client/helpdata.c     (original)
+++ branches/S2_6/client/helpdata.c     Fri Aug 14 18:59:04 2015
@@ -2983,28 +2983,28 @@
             fc_snprintf(name, sizeof(name), "%*s%s", level, "",
                         Q_(HELP_RULESET_ITEM));
             pitem->topic = fc_strdup(name);
-            if (game.control.description[0] != '\0') {
+            if (game.ruleset_description != NULL) {
               if (game.control.version[0] != '\0') {
                 int len = strlen(_(game.control.name))
                   + strlen(" ")
                   + strlen(game.control.version)
                   + strlen("\n\n")
-                  + strlen(_(game.control.description))
+                  + strlen(_(game.ruleset_description))
                   + 1;
 
                 pitem->text = fc_malloc(len);
                 fc_snprintf(pitem->text, len, "%s %s\n\n%s",
                             _(game.control.name), game.control.version,
-                            _(game.control.description));
+                            _(game.ruleset_description));
               } else {
                 int len = strlen(_(game.control.name))
                   + strlen("\n\n")
-                  + strlen(_(game.control.description))
+                  + strlen(_(game.ruleset_description))
                   + 1;
 
                 pitem->text = fc_malloc(len);
                 fc_snprintf(pitem->text, len, "%s\n\n%s",
-                            _(game.control.name), _(game.control.description));
+                            _(game.control.name), _(game.ruleset_description));
               }
             } else {
               const char *nodesc = _("Current ruleset contains no 
description.");

Modified: branches/S2_6/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/packhand.c?rev=29503&r1=29502&r2=29503&view=diff
==============================================================================
--- branches/S2_6/client/packhand.c     (original)
+++ branches/S2_6/client/packhand.c     Fri Aug 14 18:59:04 2015
@@ -2887,6 +2887,11 @@
   city_styles_alloc(game.control.styles_count);
   music_styles_alloc(game.control.num_music_styles);
 
+  if (game.control.desc_length > 0) {
+    game.ruleset_description = fc_malloc(game.control.desc_length + 1);
+    game.ruleset_description[0] = '\0';
+  }
+
   if (packet->prefered_tileset[0] != '\0') {
     /* There is tileset suggestion */
     if (strcmp(packet->prefered_tileset, tileset_get_name(tileset))) {
@@ -2924,6 +2929,16 @@
   }
 
   tileset_ruleset_reset(tileset);
+}
+
+/****************************************************************************
+  Next part of ruleset description.
+****************************************************************************/
+void handle_ruleset_description_part(
+                        const struct packet_ruleset_description_part *packet)
+{
+  fc_strlcat(game.ruleset_description, packet->text,
+             game.control.desc_length + 1);
 }
 
 /****************************************************************************

Modified: branches/S2_6/common/connection.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/connection.h?rev=29503&r1=29502&r2=29503&view=diff
==============================================================================
--- branches/S2_6/common/connection.h   (original)
+++ branches/S2_6/common/connection.h   Fri Aug 14 18:59:04 2015
@@ -56,6 +56,7 @@
 #define MAX_LEN_PACKET   4096
 #define MAX_LEN_CAPSTR    512
 #define MAX_LEN_PASSWORD  512 /* do not change this under any circumstances */
+#define MAX_LEN_CONTENT  (MAX_LEN_PACKET - 20)
 
 #define MAX_LEN_BUFFER   (MAX_LEN_PACKET * 128)
 

Modified: branches/S2_6/common/game.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/game.c?rev=29503&r1=29502&r2=29503&view=diff
==============================================================================
--- branches/S2_6/common/game.c (original)
+++ branches/S2_6/common/game.c Fri Aug 14 18:59:04 2015
@@ -272,6 +272,8 @@
   game.control.resource_count          = 0;
   game.control.styles_count            = 0;
   game.control.terrain_count           = 0;
+
+  game.ruleset_description   = NULL;
 
   /* The info packet. */
   game.info.aifill           = GAME_DEFAULT_AIFILL;
@@ -600,6 +602,11 @@
   for (i = 0; i < MAX_CALENDAR_FRAGMENTS; i++) {
     game.info.calendar_fragment_name[i][0] = '\0';
   }
+
+  if (game.ruleset_description != NULL) {
+    free(game.ruleset_description);
+    game.ruleset_description = NULL;
+  }
 }
 
 /***************************************************************

Modified: branches/S2_6/common/game.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/game.h?rev=29503&r1=29502&r2=29503&view=diff
==============================================================================
--- branches/S2_6/common/game.h (original)
+++ branches/S2_6/common/game.h Fri Aug 14 18:59:04 2015
@@ -79,6 +79,7 @@
 
 struct civ_game {
   struct packet_ruleset_control control;
+  char *ruleset_description;
   struct packet_scenario_info scenario;
   struct packet_game_info info;
   struct packet_timeout_info tinfo;

Modified: branches/S2_6/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/packets.def?rev=29503&r1=29502&r2=29503&view=diff
==============================================================================
--- branches/S2_6/common/packets.def    (original)
+++ branches/S2_6/common/packets.def    Fri Aug 14 18:59:04 2015
@@ -3,7 +3,7 @@
 Max used id:
 ============
 
-Max id: 246
+Max id: 247
 
 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.
@@ -1697,7 +1697,11 @@
 
   STRING name[MAX_LEN_NAME];
   STRING version[MAX_LEN_NAME];
-  STRING description[MAX_LEN_PACKET];
+  UINT16  desc_length;
+end
+
+PACKET_RULESET_DESCRIPTION_PART = 247; sc, lsend
+  STRING text[MAX_LEN_CONTENT];
 end
 
 /*********************************************************

Modified: branches/S2_6/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/fc_version?rev=29503&r1=29502&r2=29503&view=diff
==============================================================================
--- branches/S2_6/fc_version    (original)
+++ branches/S2_6/fc_version    Fri Aug 14 18:59:04 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.11"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-2.6-2015.Aug.14"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: branches/S2_6/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/ruleset.c?rev=29503&r1=29502&r2=29503&view=diff
==============================================================================
--- branches/S2_6/server/ruleset.c      (original)
+++ branches/S2_6/server/ruleset.c      Fri Aug 14 18:59:04 2015
@@ -3434,9 +3434,28 @@
 static void send_ruleset_control(struct conn_list *dest)
 {
   struct packet_ruleset_control packet;
+  int desc_left = game.control.desc_length;
+  int index = 0;
 
   packet = game.control;
   lsend_packet_ruleset_control(dest, &packet);
+
+  while (desc_left > 0) {
+    struct packet_ruleset_description_part part;
+    int this_len = desc_left;
+
+    if (this_len > MAX_LEN_CONTENT - 21) {
+      this_len = MAX_LEN_CONTENT - 1;
+    }
+
+    part.text[this_len] = '\0';
+
+    strncpy(part.text, &game.ruleset_description[index], this_len);
+    index += this_len;
+    desc_left -= this_len;
+
+    lsend_packet_ruleset_description_part(dest, &part);
+  }
 }
 
 /****************************************************************************
@@ -4882,11 +4901,20 @@
 
   text = secfile_lookup_str_default(file, "", "about.description");
   if (text[0] != '\0') {
+    int len;
+
     /* Ruleset/modpack description found */
-    sz_strlcpy(game.control.description, text);
+    len = strlen(text);
+    game.ruleset_description = fc_malloc(len + 1);
+    fc_strlcpy(game.ruleset_description, text, len + 1);
+    game.control.desc_length = len;
   } else {
     /* No description */
-    game.control.description[0] = '\0';
+    if (game.ruleset_description != NULL) {
+      free(game.ruleset_description);
+      game.ruleset_description = NULL;
+    }
+    game.control.desc_length = 0;
   }
 
   /* section: options */

Modified: branches/S2_6/server/stdinhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/stdinhand.c?rev=29503&r1=29502&r2=29503&view=diff
==============================================================================
--- branches/S2_6/server/stdinhand.c    (original)
+++ branches/S2_6/server/stdinhand.c    Fri Aug 14 18:59:04 2015
@@ -2007,8 +2007,8 @@
 
   show_settings(caller, cmd, show_arg, check);
 
-  if (game.control.description[0] != '\0') {
-    char *translated = fc_strdup(_(game.control.description));
+  if (game.ruleset_description != NULL) {
+    char *translated = fc_strdup(_(game.ruleset_description));
     fc_break_lines(translated, LINE_BREAK);
     cmd_reply(cmd, caller, C_COMMENT, "%s", translated);
     cmd_reply(cmd, caller, C_COMMENT, horiz_line);

Modified: branches/S2_6/tools/ruledit/rulesave.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/tools/ruledit/rulesave.c?rev=29503&r1=29502&r2=29503&view=diff
==============================================================================
--- branches/S2_6/tools/ruledit/rulesave.c      (original)
+++ branches/S2_6/tools/ruledit/rulesave.c      Fri Aug 14 18:59:04 2015
@@ -659,8 +659,8 @@
   secfile_insert_str(sfile, game.control.name, "about.name");
   secfile_insert_str(sfile, game.control.version, "about.version");
 
-  if (game.control.description[0] != '\0') {
-    secfile_insert_str(sfile, game.control.description,
+  if (game.ruleset_description != NULL) {
+    secfile_insert_str(sfile, game.ruleset_description,
                        "about.description");
   }
 


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

Reply via email to