summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-05-05 19:21:12 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-05-05 21:01:23 +0200
commite7581fd42d9740ca68adfc2ec55edb49d51af237 (patch)
tree51c7a9c14c282e2105e3bf3d298528488eb896e4 /src/network
parent72bd62fd705c495d90f08adc964ff8d7f84c6cc1 (diff)
downloadopenttd-e7581fd42d9740ca68adfc2ec55edb49d51af237.tar.xz
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.
Diffstat (limited to 'src/network')
-rw-r--r--src/network/core/game_info.cpp13
-rw-r--r--src/network/core/game_info.h1
-rw-r--r--src/network/network.cpp1
-rw-r--r--src/network/network_func.h1
-rw-r--r--src/network/network_server.cpp6
5 files changed, 19 insertions, 3 deletions
diff --git a/src/network/core/game_info.cpp b/src/network/core/game_info.cpp
index e5e85105e..9f4d23b3b 100644
--- a/src/network/core/game_info.cpp
+++ b/src/network/core/game_info.cpp
@@ -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();
diff --git a/src/network/core/game_info.h b/src/network/core/game_info.h
index 10f922f31..7c84d7b15 100644
--- 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
index c00a3650f..470815186 100644
--- 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
index 5f3e27c12..ba26e06c0 100644
--- 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
index 905290bfc..1a9ddecfb 100644
--- 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.