summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-05-11 18:53:23 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-05-11 19:09:04 +0200
commit0968d009c8b4ec5b3f5d84000f2f9f5636f9198a (patch)
treee9dc435e00ca470a200386e4acf1e3f429ba2dac /src/network
parent9e7e87ce3e7a7a4f5373883550c6f05a5d023ab6 (diff)
downloadopenttd-0968d009c8b4ec5b3f5d84000f2f9f5636f9198a.tar.xz
Fix #9243: [Network] For a dedicated server use a fallback client and server name
Also warn when the client or server name has not been set and provide pointers on how to set them
Diffstat (limited to 'src/network')
-rw-r--r--src/network/network.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp
index 29e66d932..d8f002547 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -841,6 +841,27 @@ static void NetworkInitGameInfo()
strecpy(ci->client_name, _settings_client.network.client_name, lastof(ci->client_name));
}
+/**
+ * Check whether the client and server name are set, for a dedicated server and if not set them to some default
+ * value and tell the user to change this as soon as possible.
+ * If the saved name is the default value, then the user is told to override this value too.
+ * This is only meant dedicated servers, as for the other servers the GUI ensures a name has been entered.
+ */
+static void CheckClientAndServerName()
+{
+ static const char *fallback_client_name = "Unnamed Client";
+ if (StrEmpty(_settings_client.network.client_name) || strcmp(_settings_client.network.client_name, fallback_client_name) == 0) {
+ DEBUG(net, 0, "No \"client_name\" has been set, using \"%s\" instead. Please set this now using the \"name <new name>\" command.", fallback_client_name);
+ strecpy(_settings_client.network.client_name, fallback_client_name, lastof(_settings_client.network.client_name));
+ }
+
+ static const char *fallback_server_name = "Unnamed Server";
+ if (StrEmpty(_settings_client.network.server_name) || strcmp(_settings_client.network.server_name, fallback_server_name) == 0) {
+ DEBUG(net, 0, "No \"server_name\" has been set, using \"%s\" instead. Please set this now using the \"server_name <new name>\" command.", fallback_server_name);
+ strecpy(_settings_client.network.server_name, fallback_server_name, lastof(_settings_client.network.server_name));
+ }
+}
+
bool NetworkServerStart()
{
if (!_network_available) return false;
@@ -849,6 +870,9 @@ bool NetworkServerStart()
IConsoleCmdExec("exec scripts/pre_server.scr 0");
if (_network_dedicated) IConsoleCmdExec("exec scripts/pre_dedicated.scr 0");
+ /* Check for the client and server names to be set, but only after the scripts had a chance to set them.*/
+ if (_network_dedicated) CheckClientAndServerName();
+
NetworkDisconnect(false, false);
NetworkInitialize(false);
DEBUG(net, 1, "starting listeners for clients");