From ba3ccdf6490e94009826fab54ac8b52225baa919 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 25 Mar 2023 02:50:13 +0200 Subject: [PATCH 20/20] Protocol: Make ruleset description length UINT32 See osdn #47658 Signed-off-by: Marko Lindqvist --- client/packhand.c | 10 +++++++--- common/networking/packets.def | 3 ++- fc_version | 2 +- server/ruleset.c | 7 ++++--- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/client/packhand.c b/client/packhand.c index ffedeb3eda..1ad853befb 100644 --- a/client/packhand.c +++ b/client/packhand.c @@ -3424,8 +3424,12 @@ void handle_ruleset_control(const struct packet_ruleset_control *packet) 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); + if (!has_capability("rsdesc32", client.conn.capability)) { + game.control.desc_length32 = game.control.desc_length16; + } + + if (game.control.desc_length32 > 0) { + game.ruleset_description = fc_malloc(game.control.desc_length32 + 1); game.ruleset_description[0] = '\0'; } @@ -3495,7 +3499,7 @@ void handle_ruleset_description_part( const struct packet_ruleset_description_part *packet) { fc_strlcat(game.ruleset_description, packet->text, - game.control.desc_length + 1); + game.control.desc_length32 + 1); } /************************************************************************//** diff --git a/common/networking/packets.def b/common/networking/packets.def index a19573d98c..e5e5323a25 100644 --- a/common/networking/packets.def +++ b/common/networking/packets.def @@ -1936,7 +1936,8 @@ PACKET_RULESET_CONTROL = 155; sc, lsend STRING name[MAX_LEN_NAME]; STRING version[MAX_LEN_NAME]; STRING alt_dir[MAX_LEN_NAME]; - UINT16 desc_length; + UINT16 desc_length16; remove-cap(rsdesc32) + UINT32 desc_length32; add-cap(rsdesc32) end PACKET_RULESET_SUMMARY = 251; sc, lsend diff --git a/fc_version b/fc_version index 8d63224f3d..3b09f06e0c 100755 --- a/fc_version +++ b/fc_version @@ -73,7 +73,7 @@ DEFAULT_FOLLOW_TAG=S3_1 # - No new mandatory capabilities can be added to the release branch; doing # so would break network capability of supposedly "compatible" releases. # -NETWORK_CAPSTRING="+Freeciv-3.1-network city-original" +NETWORK_CAPSTRING="+Freeciv-3.1-network city-original rsdesc32" FREECIV_DISTRIBUTOR="" if test "x$FREECIV_LABEL_FORCE" != "x" ; then diff --git a/server/ruleset.c b/server/ruleset.c index f30526bf37..4b486cbb26 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -4619,9 +4619,10 @@ static bool load_ruleset_governments(struct section_file *file, **************************************************************************/ static void send_ruleset_control(struct conn_list *dest) { - int desc_left = game.control.desc_length; + int desc_left = game.control.desc_length32; int idx = 0; + game.control.desc_length16 = game.control.desc_length32; lsend_packet_ruleset_control(dest, &(game.control)); if (game.ruleset_summary != NULL) { @@ -6652,14 +6653,14 @@ static bool load_ruleset_game(struct section_file *file, bool act, len = strlen(pref_text); game.ruleset_description = fc_malloc(len + 1); fc_strlcpy(game.ruleset_description, pref_text, len + 1); - game.control.desc_length = len; + game.control.desc_length32 = len; } else { /* No description */ if (game.ruleset_description != NULL) { free(game.ruleset_description); game.ruleset_description = NULL; } - game.control.desc_length = 0; + game.control.desc_length32 = 0; } pref_text = secfile_lookup_str_default(file, "", "about.capabilities"); -- 2.39.2