Changeset - r27016:e0a49caf0cbc
[Not reviewed]
master
0 2 0
Rubidium - 20 months ago 2023-03-15 19:59:58
rubidium@openttd.org
Fix #10568: "can savegame be loaded check" failed in dedicated server

* If loading fails, it usually returns SL_REINIT which doesn't trigger check
* If savegame has NewGRFs, it complains NewGRFs are not allowed in intro game
2 files changed with 40 insertions and 37 deletions:
0 comments (0 inline, 0 general)
src/openttd.cpp
Show inline comments
 
@@ -966,43 +966,57 @@ bool SafeLoad(const std::string &filenam
 
	assert(fop == SLO_LOAD);
 
	assert(dft == DFT_GAME_FILE || (lf == nullptr && dft == DFT_OLD_GAME_FILE));
 
	GameMode ogm = _game_mode;
 

	
 
	_game_mode = newgm;
 

	
 
	switch (lf == nullptr ? SaveOrLoad(filename, fop, dft, subdir) : LoadWithFilter(lf)) {
 
		case SL_OK: return true;
 
	SaveOrLoadResult result = (lf == nullptr) ? SaveOrLoad(filename, fop, dft, subdir) : LoadWithFilter(lf);
 
	if (result == SL_OK) return true;
 

	
 
	if (_network_dedicated && ogm == GM_MENU) {
 
		/*
 
		 * If we are a dedicated server *and* we just were in the menu, then we
 
		 * are loading the first savegame. If that fails, not starting the
 
		 * server is a better reaction than starting the server with a newly
 
		 * generated map as it is quite likely to be started from a script.
 
		 */
 
		Debug(net, 0, "Loading requested map failed; closing server.");
 
		_exit_game = true;
 
		return false;
 
	}
 

	
 
	if (result != SL_REINIT) {
 
		_game_mode = ogm;
 
		return false;
 
	}
 

	
 
		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;
 
			}
 
			if (_network_server) {
 
				/* We can't load the intro game as server, so disconnect first. */
 
				NetworkDisconnect();
 
			}
 
	if (_network_dedicated) {
 
		/*
 
		 * If we are a dedicated server, have already loaded/started a game,
 
		 * and then loading the savegame fails in a manner that we need to
 
		 * reinitialize everything. We must not fall back into the menu mode
 
		 * with the intro game, as that is unjoinable by clients. So there is
 
		 * nothing else to do than start a new game, as it might have failed
 
		 * trying to reload the originally loaded savegame/scenario.
 
		 */
 
		Debug(net, 0, "Loading game failed, so a new (random) game will be started");
 
		MakeNewGame(false, true);
 
		return false;
 
	}
 

	
 
			switch (ogm) {
 
				default:
 
				case GM_MENU:   LoadIntroGame();      break;
 
				case GM_EDITOR: MakeNewEditorWorld(); break;
 
			}
 
			return false;
 
	if (_network_server) {
 
		/* We can't load the intro game as server, so disconnect first. */
 
		NetworkDisconnect();
 
	}
 

	
 
	switch (ogm) {
 
		default:
 
			_game_mode = ogm;
 
			return false;
 
		case GM_MENU:   LoadIntroGame();      break;
 
		case GM_EDITOR: MakeNewEditorWorld(); break;
 
	}
 
	return false;
 
}
 

	
 
void SwitchToMode(SwitchMode new_mode)
 
{
 
	/* If we are saving something, the network stays in its current state */
 
	if (new_mode != SM_SAVE_GAME) {
src/video/dedicated_v.cpp
Show inline comments
 
@@ -248,23 +248,12 @@ void VideoDriver_Dedicated::MainLoop()
 
	_network_dedicated = true;
 
	_current_company = _local_company = COMPANY_SPECTATOR;
 

	
 
	/* If SwitchMode is SM_LOAD_GAME, it means that the user used the '-g' options */
 
	if (_switch_mode != SM_LOAD_GAME) {
 
		StartNewGameWithoutGUI(GENERATE_NEW_SEED);
 
	} else {
 
		/* First we need to test if the savegame can be loaded, else we will end up playing the
 
		 *  intro game... */
 
		if (SaveOrLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.detail_ftype, BASE_DIR) == SL_ERROR) {
 
			/* Loading failed, pop out.. */
 
			Debug(net, 0, "Loading requested map failed; closing server.");
 
			return;
 
		} else {
 
			/* We can load this game, so go ahead */
 
			_switch_mode = SM_LOAD_GAME;
 
		}
 
	}
 

	
 
	this->is_game_threaded = false;
 

	
 
	/* Done loading, start game! */
 

	
0 comments (0 inline, 0 general)