* Load the specified savegame but on error do different things. * If loading fails due to corrupt savegame, bad version, etc. go back to * a previous correct state. In the menu for example load the intro game again. * @param filename file to be loaded * @param fop mode of loading, always SLO_LOAD * @param newgm switch to this mode of loading fails due to some unknown error * @param subdir de
| 939 | * @param lf Load filter to use, if nullptr: use filename + subdir. |
| 940 | */ |
| 941 | bool SafeLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, std::shared_ptr<LoadFilter> lf = nullptr) |
| 942 | { |
| 943 | assert(fop == SLO_LOAD); |
| 944 | assert(dft == DFT_GAME_FILE || (lf == nullptr && dft == DFT_OLD_GAME_FILE)); |
| 945 | GameMode ogm = _game_mode; |
| 946 | |
| 947 | _game_mode = newgm; |
| 948 | |
| 949 | SaveOrLoadResult result = (lf == nullptr) ? SaveOrLoad(filename, fop, dft, subdir) : LoadWithFilter(std::move(lf)); |
| 950 | if (result == SL_OK) return true; |
| 951 | |
| 952 | if (_network_dedicated && ogm == GM_MENU) { |
| 953 | /* |
| 954 | * If we are a dedicated server *and* we just were in the menu, then we |
| 955 | * are loading the first savegame. If that fails, not starting the |
| 956 | * server is a better reaction than starting the server with a newly |
| 957 | * generated map as it is quite likely to be started from a script. |
| 958 | */ |
| 959 | Debug(net, 0, "Loading requested map failed; closing server."); |
| 960 | _exit_game = true; |
| 961 | return false; |
| 962 | } |
| 963 | |
| 964 | if (result != SL_REINIT) { |
| 965 | _game_mode = ogm; |
| 966 | return false; |
| 967 | } |
| 968 | |
| 969 | if (_network_dedicated) { |
| 970 | /* |
| 971 | * If we are a dedicated server, have already loaded/started a game, |
| 972 | * and then loading the savegame fails in a manner that we need to |
| 973 | * reinitialize everything. We must not fall back into the menu mode |
| 974 | * with the intro game, as that is unjoinable by clients. So there is |
| 975 | * nothing else to do than start a new game, as it might have failed |
| 976 | * trying to reload the originally loaded savegame/scenario. |
| 977 | */ |
| 978 | Debug(net, 0, "Loading game failed, so a new (random) game will be started"); |
| 979 | MakeNewGame(false, true); |
| 980 | return false; |
| 981 | } |
| 982 | |
| 983 | if (_network_server) { |
| 984 | /* We can't load the intro game as server, so disconnect first. */ |
| 985 | NetworkDisconnect(); |
| 986 | } |
| 987 | |
| 988 | switch (ogm) { |
| 989 | default: |
| 990 | case GM_MENU: LoadIntroGame(); break; |
| 991 | case GM_EDITOR: MakeNewEditorWorld(); break; |
| 992 | } |
| 993 | return false; |
| 994 | } |
| 995 | |
| 996 | static void UpdateSocialIntegration(GameMode game_mode) |
| 997 | { |
no test coverage detected