mirror of https://github.com/OpenTTD/OpenTTD
(svn r20039) -Fix [FS#3907]: instead of loading the intro game when loading a savegame fails on the dedicated server, generate a new game.
Generating a new game is the least bad solution: * loading the intro game: desyncs due to GM_MENU on the server and GM_NORMAL on the clients, NewGRFs not being loaded on the server but being loaded on the client; * creating an empty map: OpenTTD will go crazy due to missing towns. Also clients can't properly join because of the missing towns; * loading the last saved game: doesn't always exist and loading it might fail causing an infinite loop; * stopping being a server: breaks the dedicated server horribly; if you loaded the game via rcon you can't connect with it anymore as you can't join the server; * generating a new game: should always succeed, although people might think a scenario loaded fine because there are no companies and such.release/1.1
parent
827a97a5ce
commit
939145c50b
|
@ -872,6 +872,18 @@ bool SafeSaveOrLoad(const char *filename, int mode, GameMode newgm, Subdirectory
|
||||||
case SL_OK: return true;
|
case SL_OK: return true;
|
||||||
|
|
||||||
case SL_REINIT:
|
case SL_REINIT:
|
||||||
|
if (_network_dedicated) {
|
||||||
|
/*
|
||||||
|
* We need to reinit a network map...
|
||||||
|
* We can't simply load the intro game here as that game has many
|
||||||
|
* special cases which make clients desync immediately. So we fall
|
||||||
|
* back to just generating a new game with the current settings.
|
||||||
|
*/
|
||||||
|
DEBUG(net, 0, "Loading game failed, so a new (random) game will be started!");
|
||||||
|
MakeNewGame(false, true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
switch (ogm) {
|
switch (ogm) {
|
||||||
default:
|
default:
|
||||||
case GM_MENU: LoadIntroGame(); break;
|
case GM_MENU: LoadIntroGame(); break;
|
||||||
|
@ -911,10 +923,10 @@ static void StartScenario()
|
||||||
ResetGRFConfig(true);
|
ResetGRFConfig(true);
|
||||||
|
|
||||||
/* Load game */
|
/* Load game */
|
||||||
if (SaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, SCENARIO_DIR) != SL_OK) {
|
if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, SCENARIO_DIR)) {
|
||||||
LoadIntroGame();
|
|
||||||
SetDParamStr(0, GetSaveLoadErrorString());
|
SetDParamStr(0, GetSaveLoadErrorString());
|
||||||
ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR);
|
ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_settings_game.difficulty = _settings_newgame.difficulty;
|
_settings_game.difficulty = _settings_newgame.difficulty;
|
||||||
|
@ -996,7 +1008,6 @@ void SwitchToMode(SwitchMode new_mode)
|
||||||
ResetWindowSystem();
|
ResetWindowSystem();
|
||||||
|
|
||||||
if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, NO_DIRECTORY)) {
|
if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, NO_DIRECTORY)) {
|
||||||
LoadIntroGame();
|
|
||||||
SetDParamStr(0, GetSaveLoadErrorString());
|
SetDParamStr(0, GetSaveLoadErrorString());
|
||||||
ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR);
|
ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue