From 0b609007071f1718b99bd2ac76a1e31e7f8b0f11 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 25 Mar 2023 02:51:40 +0200 Subject: [PATCH 12/12] 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 ad2ab80b35..fc8164c376 100644 --- a/client/packhand.c +++ b/client/packhand.c @@ -3289,8 +3289,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'; } @@ -3360,7 +3364,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 fff4f85d09..c076d6b3b6 100644 --- a/common/networking/packets.def +++ b/common/networking/packets.def @@ -1878,7 +1878,8 @@ PACKET_RULESET_CONTROL = 155; sc, lsend STRING name[MAX_LEN_NAME]; STRING version[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 a8b6f0f0f2..04911cdaba 100755 --- a/fc_version +++ b/fc_version @@ -70,7 +70,7 @@ DEFAULT_FOLLOW_TAG=stable # as long as possible. We want to maintain network compatibility with # the stable branch for as long as possible. NETWORK_CAPSTRING_MANDATORY="+Freeciv-3.0-network" -NETWORK_CAPSTRING_OPTIONAL="year32 plrculture32 pingfix researchclr cityculture32" +NETWORK_CAPSTRING_OPTIONAL="year32 plrculture32 pingfix researchclr cityculture32 rsdesc32" FREECIV_DISTRIBUTOR="" diff --git a/server/ruleset.c b/server/ruleset.c index 28d10e9b21..a1928b575b 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -3996,9 +3996,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) { @@ -5840,14 +5841,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