diff options
author | rubidium42 <rubidium@openttd.org> | 2021-05-02 09:15:12 +0200 |
---|---|---|
committer | rubidium42 <rubidium42@users.noreply.github.com> | 2021-05-14 23:22:04 +0200 |
commit | ebe32ad9129bb5846433366509728fb594f3be62 (patch) | |
tree | 3cd9b58a5da8531796762f33ca53fc6d79de9926 /src/network | |
parent | 6db52d52d00516b71a982e61b3b9592a887091aa (diff) | |
download | openttd-ebe32ad9129bb5846433366509728fb594f3be62.tar.xz |
Codechange: [Network] Use std::string for the internal handling of admin/rcon passwords
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/network_admin.cpp | 3 | ||||
-rw-r--r-- | src/network/network_client.cpp | 2 | ||||
-rw-r--r-- | src/network/network_client.h | 2 | ||||
-rw-r--r-- | src/network/network_server.cpp | 5 |
4 files changed, 5 insertions, 7 deletions
diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp index 057ce32c0..dfe09344a 100644 --- a/src/network/network_admin.cpp +++ b/src/network/network_admin.cpp @@ -664,8 +664,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_JOIN(Packet *p) { if (this->status != ADMIN_STATUS_INACTIVE) 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); if (_settings_client.network.admin_password.empty() || _settings_client.network.admin_password.compare(password) != 0) { diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 4740849a0..7e2c7bb23 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -516,7 +516,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendQuit() * @param pass The password for the remote command. * @param command The actual command. */ -NetworkRecvStatus ClientNetworkGameSocketHandler::SendRCon(const char *pass, const char *command) +NetworkRecvStatus ClientNetworkGameSocketHandler::SendRCon(const std::string &pass, const char *command) { Packet *p = new Packet(PACKET_CLIENT_RCON); p->Send_string(pass); diff --git a/src/network/network_client.h b/src/network/network_client.h index baf4f5996..7d0d22810 100644 --- a/src/network/network_client.h +++ b/src/network/network_client.h @@ -96,7 +96,7 @@ public: static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data); static NetworkRecvStatus SendSetPassword(const std::string &password); static NetworkRecvStatus SendSetName(const char *name); - static NetworkRecvStatus SendRCon(const char *password, const char *command); + static NetworkRecvStatus SendRCon(const std::string &password, const char *command); static NetworkRecvStatus SendMove(CompanyID company, const std::string &password); static bool IsConnected(); diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index 314407348..7b77c76c4 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -1431,15 +1431,14 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_RCON(Packet *p) { if (this->status != STATUS_ACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED); - char pass[NETWORK_PASSWORD_LENGTH]; char command[NETWORK_RCONCOMMAND_LENGTH]; if (_settings_client.network.rcon_password.empty()) return NETWORK_RECV_STATUS_OKAY; - p->Recv_string(pass, sizeof(pass)); + std::string password = p->Recv_string(NETWORK_PASSWORD_LENGTH); p->Recv_string(command, sizeof(command)); - if (_settings_client.network.rcon_password.compare(pass) != 0) { + if (_settings_client.network.rcon_password.compare(password) != 0) { DEBUG(net, 1, "[rcon] Wrong password from client-id %d", this->client_id); return NETWORK_RECV_STATUS_OKAY; } |