summaryrefslogtreecommitdiff
path: root/src/network/network_server.cpp
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-05-02 09:07:09 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-05-14 23:22:04 +0200
commit1de5cdeab8387b23b566142f205ac9232a6f61a3 (patch)
treebb234a1704f3ec3449e0f0b7daf4a50929b09a42 /src/network/network_server.cpp
parent98283116fac58053ebd282772b0311a0b417cef7 (diff)
downloadopenttd-1de5cdeab8387b23b566142f205ac9232a6f61a3.tar.xz
Codechange: [Network] Use std::string for the internal handling of company passwords
Diffstat (limited to 'src/network/network_server.cpp')
-rw-r--r--src/network/network_server.cpp22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 1a6012fb1..4d35af116 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -978,8 +978,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMPANY_PASSWOR
return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
}
- char password[NETWORK_PASSWORD_LENGTH];
- p->Recv_string(password, sizeof(password));
+ std::string password = p->Recv_string(NETWORK_PASSWORD_LENGTH);
/* Check company password. Allow joining if we cleared the password meanwhile.
* Also, check the company is still valid - client could be moved to spectators
@@ -1389,11 +1388,8 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_SET_PASSWORD(Pa
return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
}
- char password[NETWORK_PASSWORD_LENGTH];
- const NetworkClientInfo *ci;
-
- p->Recv_string(password, sizeof(password));
- ci = this->GetInfo();
+ std::string password = p->Recv_string(NETWORK_PASSWORD_LENGTH);
+ const NetworkClientInfo *ci = this->GetInfo();
NetworkServerSetCompanyPassword(ci->client_playas, password);
return NETWORK_RECV_STATUS_OKAY;
@@ -1469,8 +1465,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_MOVE(Packet *p)
/* Check if we require a password for this company */
if (company_id != COMPANY_SPECTATOR && !_network_company_states[company_id].password.empty()) {
/* we need a password from the client - should be in this packet */
- char password[NETWORK_PASSWORD_LENGTH];
- p->Recv_string(password, sizeof(password));
+ std::string password = p->Recv_string(NETWORK_PASSWORD_LENGTH);
/* Incorrect password sent, return! */
if (_network_company_states[company_id].password.compare(password) != 0) {
@@ -1757,15 +1752,16 @@ bool NetworkServerChangeClientName(ClientID client_id, const char *new_name)
* @param password The new password.
* @param already_hashed Is the given password already hashed?
*/
-void NetworkServerSetCompanyPassword(CompanyID company_id, const char *password, bool already_hashed)
+void NetworkServerSetCompanyPassword(CompanyID company_id, const std::string &password, bool already_hashed)
{
if (!Company::IsValidHumanID(company_id)) return;
- if (!already_hashed) {
- password = GenerateCompanyPasswordHash(password, _settings_client.network.network_id.c_str(), _settings_game.game_creation.generation_seed);
+ if (already_hashed) {
+ _network_company_states[company_id].password = password;
+ } else {
+ _network_company_states[company_id].password = GenerateCompanyPasswordHash(password, _settings_client.network.network_id, _settings_game.game_creation.generation_seed);
}
- _network_company_states[company_id].password = password;
NetworkServerUpdateCompanyPassworded(company_id, !_network_company_states[company_id].password.empty());
}