mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-08 23:19:40 +00:00
Change: [Network] Update server's NetworkServerGameInfo only when needed
Split the updating in a "static" version that only needs to be called when a new map is loaded or some settings are changed, and a "dynamic" version that updates everything that changes regularly such as the current game date or the number of spectators.
This commit is contained in:
parent
72bd62fd70
commit
e7581fd42d
@ -122,10 +122,10 @@ void CheckGameCompatibility(NetworkGameInfo &ngi)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 *GetCurrentNetworkServerGameInfo()
|
||||
|
||||
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();
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -1416,6 +1416,7 @@ static bool UpdateServerPassword(int32 p1)
|
||||
_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;
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user