From c080161b5dc1e7dce12fbc9ea2f943cf5fc41cee Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 26 Feb 2023 14:36:29 +0200 Subject: [PATCH 6/6] Savegame: Store original version information See osdn #44865 Signed-off-by: Marko Lindqvist --- common/game.h | 19 ++++++++++--------- server/savegame/savecompat.c | 31 +++++++++++++++++++++++++++++++ server/savegame/savegame2.c | 4 ++++ server/savegame/savegame3.c | 9 +++++++++ server/srv_main.c | 6 +++++- 5 files changed, 59 insertions(+), 10 deletions(-) diff --git a/common/game.h b/common/game.h index eeab9eee03..1d27885c96 100644 --- a/common/game.h +++ b/common/game.h @@ -151,7 +151,7 @@ struct civ_game { int incite_unit_factor; int init_vis_radius_sq; int kick_time; - int killunhomed; /* slowly killing unhomed units */ + int killunhomed; /* Slowly killing unhomed units */ int maxconnectionsperhost; int max_players; char nationset[MAX_LEN_NAME]; @@ -195,17 +195,17 @@ struct civ_game { int tcptimeout; int techpenalty; bool turnblock; - int unitwaittime; /* minimal time between two movements of a unit */ + int unitwaittime; /* Minimal time between two movements of a unit */ int upgrade_veteran_loss; bool vision_reveal_tiles; bool debug[DEBUG_LAST]; - int timeoutint; /* increase timeout every N turns... */ + int timeoutint; /* Increase timeout every N turns... */ int timeoutinc; /* ... by this amount ... */ int timeoutincmult; /* ... and multiply timeoutinc by this amount ... */ int timeoutintinc; /* ... and increase timeoutint by this amount */ int timeoutcounter; /* timeoutcounter - timeoutint = turns to next inc. */ - int timeoutaddenemymove; /* minimum timeout after an enemy move is seen */ + int timeoutaddenemymove; /* Minimum timeout after an enemy move is seen */ time_t last_ping; struct timer *phase_timer; /* Time since seconds_to_phase_done was set. */ @@ -218,10 +218,11 @@ struct civ_game { float turn_change_time; char connectmsg[MAX_LEN_MSG]; char save_name[MAX_LEN_NAME]; + char orig_game_version[MAX_LEN_NAME]; bool scorelog; enum scorelog_level scoreloglevel; char scorefile[MAX_LEN_PATH]; - int scoreturn; /* next make_history_report() */ + int scoreturn; /* Next make_history_report() */ randseed seed_setting; randseed seed; @@ -230,7 +231,7 @@ struct civ_game { bool nuclear_winter; int nuclear_winter_percent; - bool fogofwar_old; /* as the fog_of_war bit get changed by setting + bool fogofwar_old; /* As the fog_of_war bit get changed by setting * the server we need to remember the old setting */ bool last_updated_year; /* last_updated is still counted as year in this * game. */ @@ -251,11 +252,11 @@ struct civ_game { bool info; } event_cache; - /* used by the map editor to control game_save. */ + /* Used by the map editor to control game_save. */ struct { - bool save_known; /* loading will just reveal the squares around + bool save_known; /* Loading will just reveal the squares around * cities and units */ - bool save_starts; /* start positions will be auto generated */ + bool save_starts; /* Start positions will be auto generated */ bool save_private_map; /* FoW map; will be created if not saved */ } save_options; diff --git a/server/savegame/savecompat.c b/server/savegame/savecompat.c index 344e96e651..a9f02ded05 100644 --- a/server/savegame/savecompat.c +++ b/server/savegame/savecompat.c @@ -1920,6 +1920,25 @@ static void compat_load_030200(struct loaddata *loading, log_debug("Upgrading data from savegame to version 3.2.0"); + { + const char *str = secfile_lookup_str_default(loading->file, NULL, + "savefile.orig_version"); + + if (str == NULL) { + /* Make sure CURRENTLY running version does not + * end as orig_version when we resave. */ + if (format_class == SAVEGAME_3) { + secfile_insert_str(loading->file, "old savegame3, or older", + "savefile.orig_version"); + } else { + fc_assert(format_class == SAVEGAME_2); + + secfile_insert_str(loading->file, "savegame2, or older", + "savefile.orig_version"); + } + } + } + { int action_count; @@ -2812,6 +2831,18 @@ static void compat_load_dev(struct loaddata *loading) } } + { + const char *str = secfile_lookup_str_default(loading->file, NULL, + "savefile.orig_version"); + + if (str == NULL) { + /* Make sure CURRENTLY running version does not + * end as orig_version when we resave. */ + secfile_insert_str(loading->file, "old savegame3, or older", + "savefile.orig_version"); + } + } + } /* Version < 3.1.93 */ #endif /* FREECIV_DEV_SAVE_COMPAT_3_2 */ diff --git a/server/savegame/savegame2.c b/server/savegame/savegame2.c index b0d2516199..741f818e5b 100644 --- a/server/savegame/savegame2.c +++ b/server/savegame/savegame2.c @@ -1185,6 +1185,7 @@ static void sg_load_savefile(struct loaddata *loading) { int i; const char *terr_name; + const char *str; /* Check status and return if not OK (sg_success FALSE). */ sg_check_ret(); @@ -1198,6 +1199,9 @@ static void sg_load_savefile(struct loaddata *loading) (void) secfile_entry_by_path(loading->file, "savefile.reason"); (void) secfile_entry_by_path(loading->file, "savefile.revision"); + str = secfile_lookup_str(loading->file, "savefile.orig_version"); + sz_strlcpy(game.server.orig_game_version, str); + /* In case of savegame2.c saves, missing entry means savegame older than support * for saving last_updated by turn. So this must default to TRUE. */ game.server.last_updated_year = secfile_lookup_bool_default(loading->file, TRUE, diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index 1ef846627e..67484f0c20 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -1256,6 +1256,7 @@ static void sg_load_savefile(struct loaddata *loading) const char *terr_name; bool ruleset_datafile; bool current_ruleset_rejected; + const char *str; /* Check status and return if not OK (sg_success FALSE). */ sg_check_ret(); @@ -1269,6 +1270,9 @@ static void sg_load_savefile(struct loaddata *loading) (void) secfile_entry_by_path(loading->file, "savefile.reason"); (void) secfile_entry_by_path(loading->file, "savefile.revision"); + str = secfile_lookup_str(loading->file, "savefile.orig_version"); + sz_strlcpy(game.server.orig_game_version, str); + if (game.scenario.datafile[0] != '\0') { ruleset_datafile = FALSE; } else { @@ -1700,6 +1704,11 @@ static void sg_save_savefile(struct savedata *saving) /* Save as accurate freeciv revision information as possible */ secfile_insert_str(saving->file, freeciv_datafile_version(), "savefile.revision"); + /* Freeciv version used in the very first launch of this game - + * or even saving in pregame. */ + secfile_insert_str(saving->file, game.server.orig_game_version, + "savefile.orig_version"); + /* Save rulesetdir at this point as this ruleset is required by this * savefile. */ secfile_insert_str(saving->file, game.server.rulesetdir, "savefile.rulesetdir"); diff --git a/server/srv_main.c b/server/srv_main.c index 8b4cfd84c5..a0993235cf 100644 --- a/server/srv_main.c +++ b/server/srv_main.c @@ -3090,9 +3090,12 @@ static void srv_prepare(void) sz_strlcpy(game.server.rulesetdir, srvarg.ruleset); } - /* load a saved game */ + /* Try to load a saved game */ if ('\0' == srvarg.load_filename[0] || !load_command(NULL, srvarg.load_filename, FALSE, TRUE)) { + /* Savegame not loaded */ + sz_strlcpy(game.server.orig_game_version, freeciv_datafile_version()); + /* Rulesets are loaded on game initialization, but may be changed later * if /load or /rulesetdir is done. */ load_rulesets(NULL, NULL, FALSE, NULL, TRUE, FALSE, TRUE); @@ -3555,6 +3558,7 @@ void fc__noreturn srv_main(void) fc_rand_uninit(); server_game_init(FALSE); mapimg_reset(); + sz_strlcpy(game.server.orig_game_version, freeciv_datafile_version()); load_rulesets(NULL, NULL, FALSE, NULL, TRUE, FALSE, TRUE); game.info.is_new_game = TRUE; } while (TRUE); -- 2.39.2