From 297d6e20bf0467d2a42e49bee291829ce3bb7c58 Mon Sep 17 00:00:00 2001 From: rubidium42 Date: Sun, 2 May 2021 09:18:56 +0200 Subject: Codechange: [Network] Pass passwords as std::string to the network code --- src/network/network.cpp | 6 +++--- src/network/network_client.cpp | 2 +- src/network/network_func.h | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/network') diff --git a/src/network/network.cpp b/src/network/network.cpp index 61baa7617..80ecfc2cd 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -152,9 +152,9 @@ byte NetworkSpectatorCount() * @param password The unhashed password we like to set ('*' or '' resets the password) * @return The password. */ -const char *NetworkChangeCompanyPassword(CompanyID company_id, const char *password) +std::string NetworkChangeCompanyPassword(CompanyID company_id, std::string password) { - if (strcmp(password, "*") == 0) password = ""; + if (password.compare("*") == 0) password = ""; if (_network_server) { NetworkServerSetCompanyPassword(company_id, password, false); @@ -787,7 +787,7 @@ public: * @param join_company_password The password for the company. * @return Whether the join has started. */ -bool NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const char *join_server_password, const char *join_company_password) +bool NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const std::string &join_server_password, const std::string &join_company_password) { CompanyID join_as = default_company; std::string resolved_connection_string = ParseGameConnectionString(connection_string, NETWORK_DEFAULT_PORT, &join_as).GetAddressAsString(false); diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 7e2c7bb23..b6da3dc18 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -1261,7 +1261,7 @@ void NetworkClient_Connected() * @param password The password. * @param command The command to execute. */ -void NetworkClientSendRcon(const char *password, const char *command) +void NetworkClientSendRcon(const std::string &password, const char *command) { MyClient::SendRCon(password, command); } diff --git a/src/network/network_func.h b/src/network/network_func.h index bedc9bc54..82a5deb45 100644 --- a/src/network/network_func.h +++ b/src/network/network_func.h @@ -40,7 +40,7 @@ bool NetworkValidateClientName(); bool NetworkValidateClientName(std::string &client_name); void NetworkUpdateClientName(); bool NetworkCompanyHasClients(CompanyID company); -const char *NetworkChangeCompanyPassword(CompanyID company_id, const char *password); +std::string NetworkChangeCompanyPassword(CompanyID company_id, std::string password); void NetworkReboot(); void NetworkDisconnect(bool blocking = false, bool close_admins = true); void NetworkGameLoop(); @@ -51,10 +51,10 @@ void NetworkPopulateCompanyStats(NetworkCompanyStats *stats); void NetworkUpdateClientInfo(ClientID client_id); void NetworkClientsToSpectators(CompanyID cid); -bool NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const char *join_server_password = nullptr, const char *join_company_password = nullptr); +bool NetworkClientConnectGame(const std::string &connection_string, CompanyID default_company, const std::string &join_server_password = "", const std::string &join_company_password = ""); void NetworkClientJoinGame(); void NetworkClientRequestMove(CompanyID company, const std::string &pass = ""); -void NetworkClientSendRcon(const char *password, const char *command); +void NetworkClientSendRcon(const std::string &password, const char *command); void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data = 0); bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio); bool NetworkCompanyIsPassworded(CompanyID company_id); -- cgit v1.2.3-70-g09d2