diff --git a/src/network/core/game_info.cpp b/src/network/core/game_info.cpp --- a/src/network/core/game_info.cpp +++ b/src/network/core/game_info.cpp @@ -122,10 +122,10 @@ void CheckGameCompatibility(NetworkGameI } /** - * Get the NetworkServerGameInfo structure with the latest information of the server. - * @return The current NetworkServerGameInfo. + * Fill a NetworkServerGameInfo structure with the static content, or things + * that are so static they can be updated on request from a settings change. */ -const NetworkServerGameInfo *GetCurrentNetworkServerGameInfo() +void FillStaticNetworkServerGameInfo() { _network_game_info.use_password = !StrEmpty(_settings_client.network.server_password); _network_game_info.start_date = ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1); @@ -140,7 +140,14 @@ const NetworkServerGameInfo *GetCurrentN strecpy(_network_game_info.server_name, _settings_client.network.server_name, lastof(_network_game_info.server_name)); strecpy(_network_game_info.server_revision, GetNetworkRevisionString(), lastof(_network_game_info.server_revision)); +} +/** + * Get the NetworkServerGameInfo structure with the latest information of the server. + * @return The current NetworkServerGameInfo. + */ +const NetworkServerGameInfo *GetCurrentNetworkServerGameInfo() +{ /* Client_on is used as global variable to keep track on the number of clients. */ _network_game_info.companies_on = (byte)Company::GetNumItems(); _network_game_info.spectators_on = NetworkSpectatorCount(); diff --git a/src/network/core/game_info.h b/src/network/core/game_info.h --- a/src/network/core/game_info.h +++ b/src/network/core/game_info.h @@ -94,6 +94,7 @@ const char *GetNetworkRevisionString(); bool IsNetworkCompatibleVersion(const char *other); void CheckGameCompatibility(NetworkGameInfo &ngi); +void FillStaticNetworkServerGameInfo(); const NetworkServerGameInfo *GetCurrentNetworkServerGameInfo(); void DeserializeGRFIdentifier(Packet *p, GRFIdentifier *grf); diff --git a/src/network/network.cpp b/src/network/network.cpp --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -805,6 +805,7 @@ static void NetworkInitGameInfo() strecpy(_settings_client.network.server_name, "Unnamed Server", lastof(_settings_client.network.server_name)); } + FillStaticNetworkServerGameInfo(); /* The server is a client too */ _network_game_info.clients_on = _network_dedicated ? 0 : 1; diff --git a/src/network/network_func.h b/src/network/network_func.h --- a/src/network/network_func.h +++ b/src/network/network_func.h @@ -68,6 +68,7 @@ void NetworkServerDailyLoop(); void NetworkServerMonthlyLoop(); void NetworkServerYearlyLoop(); void NetworkServerSendConfigUpdate(); +void NetworkServerUpdateGameInfo(); void NetworkServerShowStatusToConsole(); bool NetworkServerStart(); void NetworkServerNewCompany(const Company *company, NetworkClientInfo *ci); diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -1992,6 +1992,12 @@ void NetworkServerSendConfigUpdate() } } +/** Update the server's NetworkServerGameInfo due to changes in settings. */ +void NetworkServerUpdateGameInfo() +{ + if (_network_server) FillStaticNetworkServerGameInfo(); +} + /** * Tell that a particular company is (not) passworded. * @param company_id The company that got/removed the password. diff --git a/src/openttd.cpp b/src/openttd.cpp --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -832,15 +832,30 @@ void HandleExitGameRequest() } } +/** + * Triggers everything that should be triggered when starting a game. + * @param dedicated_server Whether this is a dedicated server or not. + */ +static void OnStartGame(bool dedicated_server) +{ + /* Update the local company for a loaded game. It is either always + * company #1 (eg 0) or in the case of a dedicated server a spectator */ + SetLocalCompany(dedicated_server ? COMPANY_SPECTATOR : COMPANY_FIRST); + + /* Update the static game info to set the values from the new game. */ + NetworkServerUpdateGameInfo(); + /* Execute the game-start script */ + IConsoleCmdExec("exec scripts/game_start.scr 0"); +} + static void MakeNewGameDone() { SettingsDisableElrail(_settings_game.vehicle.disable_elrails); /* In a dedicated server, the server does not play */ if (!VideoDriver::GetInstance()->HasGUI()) { - SetLocalCompany(COMPANY_SPECTATOR); + OnStartGame(true); if (_settings_client.gui.pause_on_newgame) DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE); - IConsoleCmdExec("exec scripts/game_start.scr 0"); return; } @@ -858,9 +873,7 @@ static void MakeNewGameDone() _company_colours[c->index] = (Colours)c->colour; } - IConsoleCmdExec("exec scripts/game_start.scr 0"); - - SetLocalCompany(COMPANY_FIRST); + OnStartGame(false); InitializeRailGUI(); InitializeRoadGUI(); @@ -1032,11 +1045,7 @@ void SwitchToMode(SwitchMode new_mode) /* Reset engine pool to simplify changing engine NewGRFs in scenario editor. */ EngineOverrideManager::ResetToCurrentNewGRFConfig(); } - /* Update the local company for a loaded game. It is either always - * company #1 (eg 0) or in the case of a dedicated server a spectator */ - SetLocalCompany(_network_dedicated ? COMPANY_SPECTATOR : COMPANY_FIRST); - /* Execute the game-start script */ - IConsoleCmdExec("exec scripts/game_start.scr 0"); + OnStartGame(_network_dedicated); /* Decrease pause counter (was increased from opening load dialog) */ DoCommandP(0, PM_PAUSED_SAVELOAD, 0, CMD_PAUSE); } diff --git a/src/settings.cpp b/src/settings.cpp --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1416,6 +1416,7 @@ static bool UpdateServerPassword(int32 p _settings_client.network.server_password[0] = '\0'; } + NetworkServerUpdateGameInfo(); return true; } @@ -1430,6 +1431,7 @@ static bool UpdateRconPassword(int32 p1) static bool UpdateClientConfigValues(int32 p1) { + NetworkServerUpdateGameInfo(); if (_network_server) NetworkServerSendConfigUpdate(); return true; diff --git a/src/table/settings.ini b/src/table/settings.ini --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -3962,6 +3962,7 @@ type = SLE_STRB flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC guiflags = SGF_NETWORK_ONLY def = nullptr +proc = UpdateClientConfigValues cat = SC_BASIC [SDTC_STR] @@ -4029,6 +4030,7 @@ guiflags = SGF_NETWORK_ONLY def = 25 min = 2 max = MAX_CLIENTS +proc = UpdateClientConfigValues cat = SC_BASIC [SDTC_VAR]