Author: cazfi Date: Fri Aug 14 18:58:30 2015 New Revision: 29502 URL: http://svn.gna.org/viewcvs/freeciv?rev=29502&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: trunk/client/helpdata.c trunk/client/packhand.c trunk/common/connection.h trunk/common/game.c trunk/common/game.h trunk/common/packets.def trunk/fc_version trunk/server/ruleset.c trunk/server/stdinhand.c trunk/tools/ruledit/rulesave.c Modified: trunk/client/helpdata.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/helpdata.c?rev=29502&r1=29501&r2=29502&view=diff ============================================================================== --- trunk/client/helpdata.c (original) +++ trunk/client/helpdata.c Fri Aug 14 18:58:30 2015 @@ -3001,28 +3001,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: trunk/client/packhand.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/packhand.c?rev=29502&r1=29501&r2=29502&view=diff ============================================================================== --- trunk/client/packhand.c (original) +++ trunk/client/packhand.c Fri Aug 14 18:58:30 2015 @@ -2919,6 +2919,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))) { @@ -2956,6 +2961,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: trunk/common/connection.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/connection.h?rev=29502&r1=29501&r2=29502&view=diff ============================================================================== --- trunk/common/connection.h (original) +++ trunk/common/connection.h Fri Aug 14 18:58:30 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: trunk/common/game.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/game.c?rev=29502&r1=29501&r2=29502&view=diff ============================================================================== --- trunk/common/game.c (original) +++ trunk/common/game.c Fri Aug 14 18:58:30 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; @@ -602,6 +604,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: trunk/common/game.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/game.h?rev=29502&r1=29501&r2=29502&view=diff ============================================================================== --- trunk/common/game.h (original) +++ trunk/common/game.h Fri Aug 14 18:58:30 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: trunk/common/packets.def URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/packets.def?rev=29502&r1=29501&r2=29502&view=diff ============================================================================== --- trunk/common/packets.def (original) +++ trunk/common/packets.def Fri Aug 14 18:58:30 2015 @@ -3,7 +3,7 @@ Max used id: ============ -Max id: 248 +Max id: 249 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. @@ -672,7 +672,7 @@ STRING name[MAX_LEN_NAME]; end -PACKET_TRADEROUTE_INFO = 248; sc, lsend, handle-via-packet +PACKET_TRADEROUTE_INFO = 249; sc, lsend, handle-via-packet CITY city; UINT8 index; CITY partner; @@ -1609,7 +1609,7 @@ BV_ROAD_FLAGS flags; end -PACKET_RULESET_GOODS = 247; sc, lsend +PACKET_RULESET_GOODS = 248; sc, lsend UINT8 id; STRING name[MAX_LEN_NAME]; STRING rule_name[MAX_LEN_NAME]; @@ -1710,7 +1710,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: trunk/fc_version URL: http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=29502&r1=29501&r2=29502&view=diff ============================================================================== --- trunk/fc_version (original) +++ trunk/fc_version Fri Aug 14 18:58:30 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.13" +NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2015.Aug.14" NETWORK_CAPSTRING_OPTIONAL="" FREECIV_DISTRIBUTOR="" Modified: trunk/server/ruleset.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/ruleset.c?rev=29502&r1=29501&r2=29502&view=diff ============================================================================== --- trunk/server/ruleset.c (original) +++ trunk/server/ruleset.c Fri Aug 14 18:58:30 2015 @@ -3464,9 +3464,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); + } } /**************************************************************************** @@ -4925,11 +4944,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: trunk/server/stdinhand.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/stdinhand.c?rev=29502&r1=29501&r2=29502&view=diff ============================================================================== --- trunk/server/stdinhand.c (original) +++ trunk/server/stdinhand.c Fri Aug 14 18:58:30 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: trunk/tools/ruledit/rulesave.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruledit/rulesave.c?rev=29502&r1=29501&r2=29502&view=diff ============================================================================== --- trunk/tools/ruledit/rulesave.c (original) +++ trunk/tools/ruledit/rulesave.c Fri Aug 14 18:58:30 2015 @@ -663,8 +663,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