summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/network_client.cpp20
-rw-r--r--src/network/network_func.h3
-rw-r--r--src/network/network_gui.cpp5
3 files changed, 21 insertions, 7 deletions
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index 9a6db0d2e..09103da78 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -1030,7 +1030,7 @@ void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const
SEND_COMMAND(PACKET_CLIENT_CHAT)(action, type, dest, msg, data);
}
-void NetworkClientSetPassword(const char *password)
+static void NetworkClientSetPassword(const char *password)
{
SEND_COMMAND(PACKET_CLIENT_SET_PASSWORD)(password);
}
@@ -1054,6 +1054,24 @@ bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
}
/**
+ * Sets/resets company password
+ * @param password new password, "" or "*" resets password
+ * @return new password
+ */
+const char *NetworkChangeCompanyPassword(const char *password)
+{
+ if (strcmp(password, "*") == 0) password = "";
+
+ if (!_network_server) {
+ NetworkClientSetPassword(password);
+ } else {
+ HashCurrentCompanyPassword(password);
+ }
+
+ return password;
+}
+
+/**
* Check if max_companies has been reached on the server (local check only).
* @return true if the max value has been reached or exceeded, false otherwise.
*/
diff --git a/src/network/network_func.h b/src/network/network_func.h
index 02cc131f5..afc24aeb8 100644
--- a/src/network/network_func.h
+++ b/src/network/network_func.h
@@ -36,7 +36,7 @@ extern StringList _network_ban_list;
byte NetworkSpectatorCount();
void NetworkUpdateClientName();
bool NetworkCompanyHasClients(CompanyID company);
-bool NetworkChangeCompanyPassword(byte argc, char *argv[]);
+const char *NetworkChangeCompanyPassword(const char *);
void NetworkReboot();
void NetworkDisconnect(bool blocking = false);
void NetworkGameLoop();
@@ -51,7 +51,6 @@ void NetworkClientConnectGame(NetworkAddress address, CompanyID join_as, const c
void NetworkClientRequestMove(CompanyID company, const char *pass = "");
void NetworkClientSendRcon(const char *password, const char *command);
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data = 0);
-void NetworkClientSetPassword(const char *password);
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio);
bool NetworkCompanyIsPassworded(CompanyID company_id);
bool NetworkMaxCompaniesReached();
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index 6da123303..6c111786a 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -2285,10 +2285,7 @@ struct NetworkCompanyPasswordWindow : public QueryStringBaseWindow {
snprintf(_settings_client.network.default_company_pass, lengthof(_settings_client.network.default_company_pass), "%s", this->edit_str_buf);
}
- /* empty password is a '*' because of console argument */
- if (StrEmpty(this->edit_str_buf)) snprintf(this->edit_str_buf, this->edit_str_size, "*");
- char *password = this->edit_str_buf;
- NetworkChangeCompanyPassword(1, &password);
+ NetworkChangeCompanyPassword(this->edit_str_buf);
}
virtual void OnPaint()