From 96d491f888a431b7c1a4b26b635681aa35fac2bc Mon Sep 17 00:00:00 2001 From: Alina Lenk Date: Mon, 14 Feb 2022 17:02:04 +0100 Subject: [PATCH] Remove support for rulesets with mixed format versions Requested by Marko Lindqvist See osdn #43708 Signed-off-by: Alina Lenk --- server/rscompat.c | 58 ++++++++++++++++++++++++++++++----------------- server/rscompat.h | 16 ++++--------- server/ruleset.c | 42 +++++++++++++--------------------- 3 files changed, 58 insertions(+), 58 deletions(-) diff --git a/server/rscompat.c b/server/rscompat.c index 85d675d09d..b16592cf53 100644 --- a/server/rscompat.c +++ b/server/rscompat.c @@ -64,7 +64,7 @@ void rscompat_init_info(struct rscompat_info *info) **************************************************************************/ int rscompat_check_capabilities(struct section_file *file, const char *filename, - struct rscompat_info *info) + const struct rscompat_info *info) { const char *datafile_options; bool ok = FALSE; @@ -120,6 +120,39 @@ int rscompat_check_capabilities(struct section_file *file, return format; } +/**********************************************************************//** + Different ruleset files within a ruleset directory should all have + identical datafile.format_version + This checks the file version against the expected version. + + See also rscompat_check_capabilities +**************************************************************************/ +bool rscompat_check_cap_and_version(struct section_file *file, + const char *filename, + const struct rscompat_info *info) +{ + int format_version; + + fc_assert_ret_val(info->version > 0, FALSE); + + format_version = rscompat_check_capabilities(file, filename, info); + if (format_version <= 0) { + /* Already logged in rscompat_check_capabilities */ + return FALSE; + } + + if (format_version != info->version) { + log_fatal("\"%s\": ruleset datafile format version differs from" + " other ruleset datafile(s):", filename); + log_fatal(" datafile format version: %d", format_version); + log_fatal(" expected format version: %d", info->version); + ruleset_error(LOG_ERROR, "Inconsistent format versions"); + + return FALSE; + } + + return TRUE; +} /**********************************************************************//** Add all hard obligatory requirements to an action enabler or disable it. @@ -321,7 +354,7 @@ void rscompat_postprocess(struct rscompat_info *info) * the new effects from being upgraded by accident. */ iterate_effect_cache(effect_list_compat_cb, info); - if (info->ver_effects < RSFORMAT_3_2) { + if (info->version < RSFORMAT_3_2) { struct effect *peffect; /* Nuke blast radius has moved to the ruleset. */ @@ -371,7 +404,7 @@ enum impr_genus_id rscompat_genus_3_2(struct rscompat_info *compat, const bv_impr_flags flags, enum impr_genus_id old_genus) { - if (compat->compat_mode && compat->ver_buildings < RSFORMAT_3_2) { + if (compat->compat_mode && compat->version < RSFORMAT_3_2) { if (BV_ISSET(flags, IF_GOLD) && IG_SPECIAL == old_genus) { return IG_CONVERT; } @@ -387,24 +420,7 @@ const char *rscompat_req_range_3_2(struct rscompat_info *compat, const char *type, const char *old_range) { - /* FIXME: do a more appropriate version check - * - * Requirements are used in multiple ruleset files, so there is no single - * version to check. Instead, we check everything that could contain - * affected requirements, i.e. those where some requirements are - * evaluated against tiles. - * If some ruleset files are already in the new format, and others are - * not, we assume the ruleset author knows what they are doing. - * - * Once support for mixed version rulesets is officially dropped with - * osdn#43708, this will become moot. - */ - if (compat->compat_mode - && compat->ver_buildings < RSFORMAT_3_2 - && compat->ver_effects < RSFORMAT_3_2 - && compat->ver_game < RSFORMAT_3_2 - && compat->ver_styles < RSFORMAT_3_2 - && compat->ver_terrain < RSFORMAT_3_2) { + if (compat->compat_mode && compat->version < RSFORMAT_3_2) { /* Requirement types that refer to the target tile and now use the * "Tile" range instead of the "Local" range */ if (!fc_strcasecmp(req_range_name(REQ_RANGE_LOCAL), old_range) diff --git a/server/rscompat.h b/server/rscompat.h index 4ea4c8b12d..43348e8598 100644 --- a/server/rscompat.h +++ b/server/rscompat.h @@ -29,22 +29,16 @@ struct rscompat_info { bool compat_mode; rs_conversion_logger log_cb; - int ver_buildings; - int ver_cities; - int ver_effects; - int ver_game; - int ver_governments; - int ver_nations; - int ver_styles; - int ver_techs; - int ver_terrain; - int ver_units; + int version; }; void rscompat_init_info(struct rscompat_info *info); int rscompat_check_capabilities(struct section_file *file, const char *filename, - struct rscompat_info *info); + const struct rscompat_info *info); +bool rscompat_check_cap_and_version(struct section_file *file, + const char *filename, + const struct rscompat_info *info); bool rscompat_names(struct rscompat_info *info); diff --git a/server/ruleset.c b/server/ruleset.c index 0b5a746fcf..abb1c61351 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -1334,8 +1334,8 @@ static bool load_game_names(struct section_file *file, bool ok = TRUE; /* section: datafile */ - compat->ver_game = rscompat_check_capabilities(file, filename, compat); - if (compat->ver_game <= 0) { + compat->version = rscompat_check_capabilities(file, filename, compat); + if (compat->version <= 0) { return FALSE; } @@ -1425,8 +1425,7 @@ static bool load_tech_names(struct section_file *file, bool ok = TRUE; const char *flag; - compat->ver_techs = rscompat_check_capabilities(file, filename, compat); - if (compat->ver_techs <= 0) { + if (!rscompat_check_cap_and_version(file, filename, compat)) { return FALSE; } @@ -1748,8 +1747,7 @@ static bool load_unit_names(struct section_file *file, const char *flag; bool ok = TRUE; - compat->ver_units = rscompat_check_capabilities(file, filename, compat); - if (compat->ver_units <= 0) { + if (!rscompat_check_cap_and_version(file, filename, compat)) { return FALSE; } @@ -2564,9 +2562,7 @@ static bool load_building_names(struct section_file *file, const char *filename = secfile_name(file); bool ok = TRUE; - compat->ver_buildings = rscompat_check_capabilities(file, filename, - compat); - if (compat->ver_buildings <= 0) { + if (!rscompat_check_cap_and_version(file, filename, compat)) { return FALSE; } @@ -2739,9 +2735,7 @@ static bool load_terrain_names(struct section_file *file, const char *filename = secfile_name(file); bool ok = TRUE; - compat->ver_terrain = rscompat_check_capabilities(file, filename, - compat); - if (compat->ver_terrain <= 0) { + if (!rscompat_check_cap_and_version(file, filename, compat)) { return FALSE; } @@ -4157,9 +4151,7 @@ static bool load_government_names(struct section_file *file, const char *filename = secfile_name(file); bool ok = TRUE; - compat->ver_governments = rscompat_check_capabilities(file, filename, - compat); - if (compat->ver_governments <= 0) { + if (!rscompat_check_cap_and_version(file, filename, compat)) { return FALSE; } @@ -4481,9 +4473,7 @@ static bool load_nation_names(struct section_file *file, bool ok = TRUE; const char *filename = secfile_name(file); - compat->ver_nations = rscompat_check_capabilities(file, filename, - compat); - if (compat->ver_nations <= 0) { + if (!rscompat_check_cap_and_version(file, filename, compat)) { return FALSE; } @@ -5500,8 +5490,7 @@ static bool load_style_names(struct section_file *file, struct section_list *sec; const char *filename = secfile_name(file); - compat->ver_styles = rscompat_check_capabilities(file, filename, compat); - if (compat->ver_styles <= 0) { + if (!rscompat_check_cap_and_version(file, filename, compat)) { return FALSE; } @@ -5741,8 +5730,7 @@ static bool load_ruleset_cities(struct section_file *file, struct section_list *sec; bool ok = TRUE; - compat->ver_cities = rscompat_check_capabilities(file, filename, compat); - if (compat->ver_cities <= 0) { + if (!rscompat_check_cap_and_version(file, filename, compat)) { return FALSE; } @@ -5948,10 +5936,10 @@ static bool load_ruleset_effects(struct section_file *file, filename = secfile_name(file); - compat->ver_effects = rscompat_check_capabilities(file, filename, compat); - if (compat->ver_effects <= 0) { + if (!rscompat_check_cap_and_version(file, filename, compat)) { return FALSE; } + (void) secfile_entry_by_path(file, "datafile.description"); /* unused */ (void) secfile_entry_by_path(file, "datafile.ruledit"); /* unused */ @@ -6564,7 +6552,7 @@ static bool load_ruleset_game(struct section_file *file, bool act, RS_MAX_BASE_TECH_COST, "research.base_tech_cost"); - if (compat->compat_mode && compat->ver_game < RSFORMAT_3_2) { + if (compat->compat_mode && compat->version < RSFORMAT_3_2) { /* base_tech_cost used to be used for this too. */ game.info.min_tech_cost = secfile_lookup_int_default_min_max(file, @@ -8945,6 +8933,8 @@ static bool load_rulesetdir(const char *rsdir, bool compat_mode, } if (ok) { + /* Note: Keep load_game_names first so that compat_info.version is + * correctly initialized. */ ok = load_game_names(gamefile, &compat_info) && load_tech_names(techfile, &compat_info) && load_building_names(buildfile, &compat_info) @@ -9011,7 +9001,7 @@ static bool load_rulesetdir(const char *rsdir, bool compat_mode, /* Only load settings for a sane ruleset */ ok = settings_ruleset(gamefile, "settings", act, compat_info.compat_mode - && compat_info.ver_game < RSFORMAT_3_2); + && compat_info.version < RSFORMAT_3_2); if (ok) { secfile_check_unused(gamefile); -- 2.17.1