summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-04-27 21:25:52 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-05-13 23:13:17 +0200
commit02fdb5b210ede022cb921e869cdb34758ee5299e (patch)
treeb9487874886a7f86d56a489f02c37cb78db6df15
parentcc6c078dec3792173b5d2057667bec9597c71d90 (diff)
downloadopenttd-02fdb5b210ede022cb921e869cdb34758ee5299e.tar.xz
Codechange: move server name/id in settings to std::string
-rw-r--r--src/network/network.cpp16
-rw-r--r--src/network/network_gui.cpp4
-rw-r--r--src/network/network_server.cpp2
-rw-r--r--src/settings_type.h4
-rw-r--r--src/table/settings.ini10
5 files changed, 19 insertions, 17 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp
index 94566d232..5a25c7acb 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -833,8 +833,8 @@ void NetworkClientJoinGame()
static void NetworkInitGameInfo()
{
- if (StrEmpty(_settings_client.network.server_name)) {
- strecpy(_settings_client.network.server_name, "Unnamed Server", lastof(_settings_client.network.server_name));
+ if (_settings_client.network.server_name.empty()) {
+ _settings_client.network.server_name = "Unnamed Server";
}
FillStaticNetworkServerGameInfo();
@@ -863,10 +863,10 @@ static void CheckClientAndServerName()
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, 1, "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));
+ static const std::string fallback_server_name = "Unnamed Server";
+ if (_settings_client.network.server_name.empty() || _settings_client.network.server_name.compare(fallback_server_name) == 0) {
+ DEBUG(net, 1, "No \"server_name\" has been set, using \"%s\" instead. Please set this now using the \"server_name <new name>\" command", fallback_server_name.c_str());
+ _settings_client.network.server_name = fallback_server_name;
}
}
@@ -1201,7 +1201,7 @@ static void NetworkGenerateServerId()
}
/* _settings_client.network.network_id is our id */
- seprintf(_settings_client.network.network_id, lastof(_settings_client.network.network_id), "%s", hex_output);
+ _settings_client.network.network_id = hex_output;
}
class TCPNetworkDebugConnecter : TCPConnecter {
@@ -1241,7 +1241,7 @@ void NetworkStartUp()
_network_need_advertise = true;
/* Generate an server id when there is none yet */
- if (StrEmpty(_settings_client.network.network_id)) NetworkGenerateServerId();
+ if (_settings_client.network.network_id.empty()) NetworkGenerateServerId();
_network_game_info = {};
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index ca0e67d0a..6fdf73bc4 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -990,7 +990,7 @@ struct NetworkStartServerWindow : public Window {
this->InitNested(WN_NETWORK_WINDOW_START);
this->querystrings[WID_NSS_GAMENAME] = &this->name_editbox;
- this->name_editbox.text.Assign(_settings_client.network.server_name);
+ this->name_editbox.text.Assign(_settings_client.network.server_name.c_str());
this->SetFocusedWidget(WID_NSS_GAMENAME);
}
@@ -1136,7 +1136,7 @@ struct NetworkStartServerWindow : public Window {
void OnEditboxChanged(int wid) override
{
if (wid == WID_NSS_GAMENAME) {
- strecpy(_settings_client.network.server_name, this->name_editbox.text.buf, lastof(_settings_client.network.server_name));
+ _settings_client.network.server_name = this->name_editbox.text.buf;
}
}
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index c7a70300b..f2a8a5230 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -1762,7 +1762,7 @@ void NetworkServerSetCompanyPassword(CompanyID company_id, const char *password,
if (!Company::IsValidHumanID(company_id)) return;
if (!already_hashed) {
- password = GenerateCompanyPasswordHash(password, _settings_client.network.network_id, _settings_game.game_creation.generation_seed);
+ password = GenerateCompanyPasswordHash(password, _settings_client.network.network_id.c_str(), _settings_game.game_creation.generation_seed);
}
strecpy(_network_company_states[company_id].password, password, lastof(_network_company_states[company_id].password));
diff --git a/src/settings_type.h b/src/settings_type.h
index 0828baa58..8cff37142 100644
--- a/src/settings_type.h
+++ b/src/settings_type.h
@@ -262,7 +262,7 @@ struct NetworkSettings {
uint16 server_port; ///< port the server listens on
uint16 server_admin_port; ///< port the server listens on for the admin network
bool server_admin_chat; ///< allow private chat for the server to be distributed to the admin network
- char server_name[NETWORK_NAME_LENGTH]; ///< name of the server
+ std::string server_name; ///< name of the server
std::string server_password; ///< password for joining this server
std::string rcon_password; ///< password for rconsole (server side)
std::string admin_password; ///< password for the admin network
@@ -270,7 +270,7 @@ struct NetworkSettings {
char client_name[NETWORK_CLIENT_NAME_LENGTH]; ///< name of the player (as client)
std::string default_company_pass; ///< default password for new companies in encrypted form
std::string connect_to_ip; ///< default for the "Add server" query
- char network_id[NETWORK_SERVER_ID_LENGTH]; ///< network ID for servers
+ std::string network_id; ///< network ID for servers
bool autoclean_companies; ///< automatically remove companies that are not in use
uint8 autoclean_unprotected; ///< remove passwordless companies after this many months
uint8 autoclean_protected; ///< remove the password from passworded companies after this many months
diff --git a/src/table/settings.ini b/src/table/settings.ini
index 6dbff01db..0a439edaa 100644
--- a/src/table/settings.ini
+++ b/src/table/settings.ini
@@ -3961,9 +3961,10 @@ length = NETWORK_PASSWORD_LENGTH
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
def = nullptr
-[SDTC_STR]
+[SDTC_SSTR]
var = network.server_name
-type = SLE_STRB
+type = SLE_STR
+length = NETWORK_NAME_LENGTH
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
guiflags = SGF_NETWORK_ONLY
def = nullptr
@@ -3977,9 +3978,10 @@ length = 0
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
def = nullptr
-[SDTC_STR]
+[SDTC_SSTR]
var = network.network_id
-type = SLE_STRB
+type = SLE_STR
+length = NETWORK_SERVER_ID_LENGTH
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
guiflags = SGF_NETWORK_ONLY
def = nullptr