diff options
author | rubidium42 <rubidium@openttd.org> | 2021-04-27 20:26:56 +0200 |
---|---|---|
committer | rubidium42 <rubidium42@users.noreply.github.com> | 2021-05-13 23:13:17 +0200 |
commit | c73d64adf984036a99d6974b130eda65dfc18c6c (patch) | |
tree | 05390f3269bf3279d51b290cde02cf17c395a626 /src | |
parent | f219354f891c45dcefad2dd0a2f1fd92b07e4ba5 (diff) | |
download | openttd-c73d64adf984036a99d6974b130eda65dfc18c6c.tar.xz |
Codechange: move passwords in settings to std::string
Diffstat (limited to 'src')
-rw-r--r-- | src/company_cmd.cpp | 4 | ||||
-rw-r--r-- | src/fios_gui.cpp | 2 | ||||
-rw-r--r-- | src/network/core/game_info.cpp | 2 | ||||
-rw-r--r-- | src/network/network.cpp | 2 | ||||
-rw-r--r-- | src/network/network_admin.cpp | 6 | ||||
-rw-r--r-- | src/network/network_gui.cpp | 6 | ||||
-rw-r--r-- | src/network/network_server.cpp | 10 | ||||
-rw-r--r-- | src/openttd.cpp | 4 | ||||
-rw-r--r-- | src/settings.cpp | 8 | ||||
-rw-r--r-- | src/settings_type.h | 8 | ||||
-rw-r--r-- | src/table/settings.h.preamble | 3 | ||||
-rw-r--r-- | src/table/settings.ini | 21 |
12 files changed, 42 insertions, 34 deletions
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 063d32d3f..45a679c10 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -843,8 +843,8 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 if (client_id == _network_own_client_id) { assert(_local_company == COMPANY_SPECTATOR); SetLocalCompany(c->index); - if (!StrEmpty(_settings_client.network.default_company_pass)) { - NetworkChangeCompanyPassword(_local_company, _settings_client.network.default_company_pass); + if (!_settings_client.network.default_company_pass.empty()) { + NetworkChangeCompanyPassword(_local_company, _settings_client.network.default_company_pass.c_str()); } /* Now that we have a new company, broadcast our company settings to diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index e4de1acaa..40a082d64 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -53,7 +53,7 @@ void LoadCheckData::Clear() this->map_size_x = this->map_size_y = 256; // Default for old savegames which do not store mapsize. this->current_date = 0; - memset(&this->settings, 0, sizeof(this->settings)); + this->settings = {}; for (auto &pair : this->companies) { delete pair.second; diff --git a/src/network/core/game_info.cpp b/src/network/core/game_info.cpp index 46bb42ec1..dd58ae500 100644 --- a/src/network/core/game_info.cpp +++ b/src/network/core/game_info.cpp @@ -127,7 +127,7 @@ void CheckGameCompatibility(NetworkGameInfo &ngi) */ void FillStaticNetworkServerGameInfo() { - _network_game_info.use_password = !StrEmpty(_settings_client.network.server_password); + _network_game_info.use_password = !_settings_client.network.server_password.empty(); _network_game_info.start_date = ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1); _network_game_info.clients_max = _settings_client.network.max_clients; _network_game_info.companies_max = _settings_client.network.max_companies; diff --git a/src/network/network.cpp b/src/network/network.cpp index a87aab88c..b9160e208 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -887,7 +887,7 @@ bool NetworkServerStart() if (!ServerNetworkGameSocketHandler::Listen(_settings_client.network.server_port)) return false; /* Only listen for admins when the password isn't empty. */ - if (!StrEmpty(_settings_client.network.admin_password)) { + if (!_settings_client.network.admin_password.empty()) { DEBUG(net, 5, "Starting listeners for admins"); if (!ServerNetworkAdminSocketHandler::Listen(_settings_client.network.server_admin_port)) return false; } diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp index 4e73aed0f..057ce32c0 100644 --- a/src/network/network_admin.cpp +++ b/src/network/network_admin.cpp @@ -84,7 +84,7 @@ ServerNetworkAdminSocketHandler::~ServerNetworkAdminSocketHandler() */ /* static */ bool ServerNetworkAdminSocketHandler::AllowConnection() { - bool accept = !StrEmpty(_settings_client.network.admin_password) && _network_admins_connected < MAX_ADMINS; + bool accept = !_settings_client.network.admin_password.empty() && _network_admins_connected < MAX_ADMINS; /* We can't go over the MAX_ADMINS limit here. However, if we accept * the connection, there has to be space in the pool. */ static_assert(NetworkAdminSocketPool::MAX_SIZE == MAX_ADMINS); @@ -667,8 +667,8 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_JOIN(Packet *p) char password[NETWORK_PASSWORD_LENGTH]; p->Recv_string(password, sizeof(password)); - if (StrEmpty(_settings_client.network.admin_password) || - strcmp(password, _settings_client.network.admin_password) != 0) { + if (_settings_client.network.admin_password.empty() || + _settings_client.network.admin_password.compare(password) != 0) { /* Password is invalid */ return this->SendError(NETWORK_ERROR_WRONG_PASSWORD); } diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 56fdc7309..67992cac7 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -1032,7 +1032,7 @@ struct NetworkStartServerWindow : public Window { switch (widget) { case WID_NSS_SETPWD: /* If password is set, draw red '*' next to 'Set password' button. */ - if (!StrEmpty(_settings_client.network.server_password)) DrawString(r.right + WD_FRAMERECT_LEFT, this->width - WD_FRAMERECT_RIGHT, r.top, "*", TC_RED); + if (!_settings_client.network.server_password.empty()) DrawString(r.right + WD_FRAMERECT_LEFT, this->width - WD_FRAMERECT_RIGHT, r.top, "*", TC_RED); } } @@ -1156,7 +1156,7 @@ struct NetworkStartServerWindow : public Window { if (str == nullptr) return; if (this->widget_id == WID_NSS_SETPWD) { - strecpy(_settings_client.network.server_password, str, lastof(_settings_client.network.server_password)); + _settings_client.network.server_password = str; } else { int32 value = atoi(str); this->SetWidgetDirty(this->widget_id); @@ -2583,7 +2583,7 @@ struct NetworkCompanyPasswordWindow : public Window { void OnOk() { if (this->IsWidgetLowered(WID_NCP_SAVE_AS_DEFAULT_PASSWORD)) { - strecpy(_settings_client.network.default_company_pass, this->password_editbox.text.buf, lastof(_settings_client.network.default_company_pass)); + _settings_client.network.default_company_pass = this->password_editbox.text.buf; } NetworkChangeCompanyPassword(_local_company, this->password_editbox.text.buf); diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index bbadbeba4..c7a70300b 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -859,7 +859,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_NEWGRFS_CHECKED NetworkClientInfo *ci = this->GetInfo(); /* We now want a password from the client else we do not allow him in! */ - if (!StrEmpty(_settings_client.network.server_password)) { + if (!_settings_client.network.server_password.empty()) { return this->SendNeedGamePassword(); } @@ -957,8 +957,8 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_GAME_PASSWORD(P p->Recv_string(password, sizeof(password)); /* Check game password. Allow joining if we cleared the password meanwhile */ - if (!StrEmpty(_settings_client.network.server_password) && - strcmp(password, _settings_client.network.server_password) != 0) { + if (!_settings_client.network.server_password.empty() && + _settings_client.network.server_password.compare(password) != 0) { /* Password is invalid */ return this->SendError(NETWORK_ERROR_WRONG_PASSWORD); } @@ -1439,12 +1439,12 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_RCON(Packet *p) char pass[NETWORK_PASSWORD_LENGTH]; char command[NETWORK_RCONCOMMAND_LENGTH]; - if (StrEmpty(_settings_client.network.rcon_password)) return NETWORK_RECV_STATUS_OKAY; + if (_settings_client.network.rcon_password.empty()) return NETWORK_RECV_STATUS_OKAY; p->Recv_string(pass, sizeof(pass)); p->Recv_string(command, sizeof(command)); - if (strcmp(pass, _settings_client.network.rcon_password) != 0) { + if (_settings_client.network.rcon_password.compare(pass) != 0) { DEBUG(net, 1, "[rcon] Wrong password from client-id %d", this->client_id); return NETWORK_RECV_STATUS_OKAY; } diff --git a/src/openttd.cpp b/src/openttd.cpp index a416f531a..5674a4671 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -874,8 +874,8 @@ static void MakeNewGameDone() /* We are the server, we start a new company (not dedicated), * so set the default password *if* needed. */ - if (_network_server && !StrEmpty(_settings_client.network.default_company_pass)) { - NetworkChangeCompanyPassword(_local_company, _settings_client.network.default_company_pass); + if (_network_server && !_settings_client.network.default_company_pass.empty()) { + NetworkChangeCompanyPassword(_local_company, _settings_client.network.default_company_pass.c_str()); } if (_settings_client.gui.pause_on_newgame) DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE); diff --git a/src/settings.cpp b/src/settings.cpp index e347d7c0a..0c6c08f9a 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1420,8 +1420,8 @@ static bool UpdateClientName(int32 p1) static bool UpdateServerPassword(int32 p1) { - if (strcmp(_settings_client.network.server_password, "*") == 0) { - _settings_client.network.server_password[0] = '\0'; + if (_settings_client.network.server_password.compare("*") == 0) { + _settings_client.network.server_password.clear(); } NetworkServerUpdateGameInfo(); @@ -1430,8 +1430,8 @@ static bool UpdateServerPassword(int32 p1) static bool UpdateRconPassword(int32 p1) { - if (strcmp(_settings_client.network.rcon_password, "*") == 0) { - _settings_client.network.rcon_password[0] = '\0'; + if (_settings_client.network.rcon_password.compare("*") == 0) { + _settings_client.network.rcon_password.clear(); } return true; diff --git a/src/settings_type.h b/src/settings_type.h index 5361fc3f1..248761fe6 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -263,12 +263,12 @@ struct NetworkSettings { 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 - char server_password[NETWORK_PASSWORD_LENGTH]; ///< password for joining this server - char rcon_password[NETWORK_PASSWORD_LENGTH]; ///< password for rconsole (server side) - char admin_password[NETWORK_PASSWORD_LENGTH]; ///< password for the admin network + 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 bool server_advertise; ///< advertise the server to the masterserver char client_name[NETWORK_CLIENT_NAME_LENGTH]; ///< name of the player (as client) - char default_company_pass[NETWORK_PASSWORD_LENGTH]; ///< default password for new companies in encrypted form + std::string default_company_pass; ///< default password for new companies in encrypted form char connect_to_ip[NETWORK_HOSTNAME_PORT_LENGTH]; ///< default for the "Add server" query char network_id[NETWORK_SERVER_ID_LENGTH]; ///< network ID for servers bool autoclean_companies; ///< automatically remove companies that are not in use diff --git a/src/table/settings.h.preamble b/src/table/settings.h.preamble index c3e0678b7..09a89821a 100644 --- a/src/table/settings.h.preamble +++ b/src/table/settings.h.preamble @@ -129,6 +129,9 @@ static size_t ConvertLandscape(const char *value); #define SDTC_STR(var, type, flags, guiflags, def, str, strhelp, strval, proc, from, to, cat, extra, startup)\ SDTG_GENERAL(#var, SDT_STRING, SL_STR, type, flags, guiflags, _settings_client.var, sizeof(_settings_client.var), def, 0, 0, 0, nullptr, str, strhelp, strval, proc, from, to, cat, extra, startup) +#define SDTC_SSTR(var, type, flags, guiflags, def, max_length, str, strhelp, strval, proc, from, to, cat, extra, startup)\ + SDTG_GENERAL(#var, SDT_STDSTRING, SL_STDSTR, type, flags, guiflags, _settings_client.var, sizeof(_settings_client.var), def, 0, max_length, 0, nullptr, str, strhelp, strval, proc, from, to, cat, extra, startup) + #define SDTC_OMANY(var, type, flags, guiflags, def, max, full, str, strhelp, strval, proc, from, to, cat, extra, startup)\ SDTG_GENERAL(#var, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, _settings_client.var, 1, def, 0, max, 0, full, str, strhelp, strval, proc, from, to, cat, extra, startup) diff --git a/src/table/settings.ini b/src/table/settings.ini index d12f58236..e8fa4560b 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -70,6 +70,7 @@ SDTC_BOOL = SDTC_BOOL( $var, $flags, $guiflags, $def, SDTC_LIST = SDTC_LIST( $var, $type, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup), SDTC_OMANY = SDTC_OMANY( $var, $type, $flags, $guiflags, $def, $max, $full, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup), SDTC_STR = SDTC_STR( $var, $type, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup), +SDTC_SSTR = SDTC_SSTR( $var, $type, $flags, $guiflags, $def, $length, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup), SDTC_VAR = SDTC_VAR( $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup), SDT_BOOL = SDT_BOOL($base, $var, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup), SDT_OMANY = SDT_OMANY($base, $var, $type, $flags, $guiflags, $def, $max, $full, $str, $strhelp, $strval, $proc, $from, $to, $load, $cat, $extra, $startup), @@ -3924,35 +3925,39 @@ def = nullptr proc = UpdateClientName cat = SC_BASIC -[SDTC_STR] +[SDTC_SSTR] var = network.server_password -type = SLE_STRB +type = SLE_STR +length = NETWORK_PASSWORD_LENGTH flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC guiflags = SGF_NETWORK_ONLY def = nullptr proc = UpdateServerPassword cat = SC_BASIC -[SDTC_STR] +[SDTC_SSTR] var = network.rcon_password -type = SLE_STRB +type = SLE_STR +length = NETWORK_PASSWORD_LENGTH flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC guiflags = SGF_NETWORK_ONLY def = nullptr proc = UpdateRconPassword cat = SC_BASIC -[SDTC_STR] +[SDTC_SSTR] var = network.admin_password -type = SLE_STRB +type = SLE_STR +length = NETWORK_PASSWORD_LENGTH flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC guiflags = SGF_NETWORK_ONLY def = nullptr cat = SC_BASIC -[SDTC_STR] +[SDTC_SSTR] var = network.default_company_pass -type = SLE_STRB +type = SLE_STR +length = NETWORK_PASSWORD_LENGTH flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC def = nullptr |