From ede21ad9c4840d7e88562db050d7737f4cefd952 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 4 Nov 2022 01:33:26 +0200 Subject: [PATCH 22/22] Send nation groups and sets counts in PACKET_RULESET_CONTROL See osdn #45195 Signed-off-by: Marko Lindqvist --- client/packhand.c | 20 +++++++++++++------- common/game.c | 2 ++ common/nation.c | 31 ++++++++++++++++++++++++++----- common/networking/packets.def | 2 ++ fc_version | 2 +- server/ruleset.c | 8 ++++++-- 6 files changed, 50 insertions(+), 15 deletions(-) diff --git a/client/packhand.c b/client/packhand.c index 2bc0a3d696..3c1c11eb68 100644 --- a/client/packhand.c +++ b/client/packhand.c @@ -4486,13 +4486,15 @@ void handle_ruleset_nation_sets int i; for (i = 0; i < packet->nsets; i++) { -#ifndef FREECIV_NDEBUG struct nation_set *pset = -#endif nation_set_new(packet->names[i], packet->rule_names[i], packet->descriptions[i]); - fc_assert(NULL != pset); - fc_assert(i == nation_set_index(pset)); + + if (pset == NULL) { + break; + } else { + fc_assert(i == nation_set_index(pset)); + } } } @@ -4508,9 +4510,13 @@ void handle_ruleset_nation_groups struct nation_group *pgroup; pgroup = nation_group_new(packet->groups[i]); - fc_assert_action(NULL != pgroup, continue); - fc_assert(i == nation_group_index(pgroup)); - pgroup->hidden = packet->hidden[i]; + + if (pgroup != NULL) { + fc_assert(i == nation_group_index(pgroup)); + pgroup->hidden = packet->hidden[i]; + } else { + break; + } } } diff --git a/common/game.c b/common/game.c index 75a339f4d6..233caf3956 100644 --- a/common/game.c +++ b/common/game.c @@ -245,6 +245,8 @@ static void game_defaults(bool keep_ruleset_value) game.control.num_achievement_types = 0; game.control.num_styles = 0; game.control.num_music_styles = 0; + game.control.num_nation_groups = 0; + game.control.num_nation_sets = 0; game.control.preferred_tileset[0] = '\0'; game.control.preferred_soundset[0] = '\0'; game.control.preferred_musicset[0] = '\0'; diff --git a/common/nation.c b/common/nation.c index f8d711352e..510099782d 100644 --- a/common/nation.c +++ b/common/nation.c @@ -11,7 +11,7 @@ GNU General Public License for more details. ***********************************************************************/ -/********************************************************************** +/*********************************************************************** Functions for handling the nations. ***********************************************************************/ @@ -509,7 +509,6 @@ Nation_type_id nation_count(void) return game.control.nation_count; } - /**************************************************************************** Nation iterator. ****************************************************************************/ @@ -716,6 +715,12 @@ struct nation_set *nation_set_new(const char *set_name, { struct nation_set *pset; + if (game.control.num_nation_sets <= num_nation_sets) { + log_error("More nation sets than reported (%d).", + game.control.num_nation_sets); + return NULL; + } + if (MAX_NUM_NATION_SETS <= num_nation_sets) { log_error("Too many nation sets (%d is the maximum).", MAX_NUM_NATION_SETS); @@ -752,9 +757,14 @@ struct nation_set *nation_set_new(const char *set_name, ****************************************************************************/ struct nation_set *nation_set_by_number(int id) { - if (id < 0 || id >= num_nation_sets) { + /* Return valid pointer on client side even when the data of the + * group is not yet received. So compare against expected number + * of sets (game.control.num_nation_sets) and not + * what we have already set up (num_nation_sets) */ + if (id < 0 || id >= game.control.num_nation_sets) { return NULL; } + return nation_sets + id; } @@ -947,7 +957,13 @@ struct nation_group *nation_group_new(const char *name) { struct nation_group *pgroup; - if (MAX_NUM_NATION_GROUPS <= num_nation_groups) { + if (game.control.num_nation_groups <= num_nation_groups) { + log_error("More nation groups than reported (%d).", + game.control.num_nation_groups); + return NULL; + } + + if (MAX_NUM_NATION_GROUPS <= num_nation_groups) { log_error("Too many nation groups (%d is the maximum).", MAX_NUM_NATION_GROUPS); return NULL; @@ -983,9 +999,14 @@ struct nation_group *nation_group_new(const char *name) ****************************************************************************/ struct nation_group *nation_group_by_number(int id) { - if (id < 0 || id >= num_nation_groups) { + /* Return valid pointer on client side even when the data of the + * group is not yet received. So compare against expected number + * of groups (game.control.num_nation_groups) and not + * what we have already set up (num_nation_groups) */ + if (id < 0 || id >= game.control.num_nation_groups) { return NULL; } + return nation_groups + id; } diff --git a/common/networking/packets.def b/common/networking/packets.def index 2c34eec9ad..e3b5880e88 100644 --- a/common/networking/packets.def +++ b/common/networking/packets.def @@ -1956,6 +1956,8 @@ PACKET_RULESET_CONTROL = 155; sc, lsend UINT16 num_city_styles; UINT16 terrain_count; UINT16 num_specialist_types; + UINT16 num_nation_groups; + UINT16 num_nation_sets; STRING preferred_tileset[MAX_LEN_NAME]; STRING preferred_soundset[MAX_LEN_NAME]; diff --git a/fc_version b/fc_version index 7d72beef68..8f12af6500 100755 --- a/fc_version +++ b/fc_version @@ -61,7 +61,7 @@ DEFAULT_FOLLOW_TAG=S3_2 # - No new mandatory capabilities can be added to the release branch; doing # so would break network capability of supposedly "compatible" releases. # -NETWORK_CAPSTRING="+Freeciv.Devel-${MAIN_VERSION}-2022.Nov.04" +NETWORK_CAPSTRING="+Freeciv.Devel-${MAIN_VERSION}-2022.Nov.04b" FREECIV_DISTRIBUTOR="" if test "x$FREECIV_LABEL_FORCE" != "x" ; then diff --git a/server/ruleset.c b/server/ruleset.c index 9bcaeaddf0..697d24535b 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -4697,7 +4697,9 @@ static bool load_nation_names(struct section_file *file, if (ok) { sec = secfile_sections_by_name_prefix(file, NATION_GROUP_SECTION_PREFIX); - if (sec) { + if (sec != NULL) { + game.control.num_nation_groups = section_list_size(sec); + section_list_iterate(sec, psection) { struct nation_group *pgroup; const char *name; @@ -5041,7 +5043,9 @@ static bool load_ruleset_nations(struct section_file *file, if (ok) { sec = secfile_sections_by_name_prefix(file, NATION_SET_SECTION_PREFIX); - if (sec) { + if (sec != NULL) { + game.control.num_nation_sets = section_list_size(sec); + section_list_iterate(sec, psection) { const char *set_name, *set_rule_name, *set_description; -- 2.35.1