summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2010-02-10 15:17:27 +0000
committersmatz <smatz@openttd.org>2010-02-10 15:17:27 +0000
commit73ed81b1c78232c14de861207db9b40ff2550536 (patch)
treeb426188d7abe9279c2d94cdbadf82f360bc8b55c /src
parentb91b3ac836604ad364e5d8027a30e0c9bc7b4fcc (diff)
downloadopenttd-73ed81b1c78232c14de861207db9b40ff2550536.tar.xz
(svn r19075) -Codechange: unhackify NetworkChangeCompanyPassword()
Diffstat (limited to 'src')
-rw-r--r--src/company_cmd.cpp3
-rw-r--r--src/console_cmds.cpp19
-rw-r--r--src/network/network_client.cpp20
-rw-r--r--src/network/network_func.h3
-rw-r--r--src/network/network_gui.cpp5
-rw-r--r--src/openttd.cpp3
6 files changed, 31 insertions, 22 deletions
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp
index dfe7478a6..06baa2aef 100644
--- a/src/company_cmd.cpp
+++ b/src/company_cmd.cpp
@@ -772,8 +772,7 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
assert(_local_company == COMPANY_SPECTATOR);
SetLocalCompany(c->index);
if (!StrEmpty(_settings_client.network.default_company_pass)) {
- char *password = _settings_client.network.default_company_pass;
- NetworkChangeCompanyPassword(1, &password);
+ NetworkChangeCompanyPassword(_settings_client.network.default_company_pass);
}
_current_company = _local_company;
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index 2237c956d..8989b340f 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -1544,8 +1544,7 @@ DEF_CONSOLE_CMD(ConSayClient)
extern void HashCurrentCompanyPassword(const char *password);
-/* Also use from within company_gui to change the password graphically */
-bool NetworkChangeCompanyPassword(byte argc, char *argv[])
+DEF_CONSOLE_CMD(ConCompanyPassword)
{
if (argc == 0) {
IConsoleHelp("Change the password of your company. Usage: 'company_pw \"<password>\"'");
@@ -1553,23 +1552,21 @@ bool NetworkChangeCompanyPassword(byte argc, char *argv[])
return true;
}
+ if (argc != 1) return false;
+
if (!Company::IsValidID(_local_company)) {
IConsoleError("You have to own a company to make use of this command.");
return false;
}
- if (argc != 1) return false;
-
- if (strcmp(argv[0], "*") == 0) argv[0][0] = '\0';
+ const char *password = NetworkChangeCompanyPassword(argv[0]);
- if (!_network_server) {
- NetworkClientSetPassword(argv[0]);
+ if (StrEmpty(password)) {
+ IConsolePrintF(CC_WARNING, "Company password cleared");
} else {
- HashCurrentCompanyPassword(argv[0]);
+ IConsolePrintF(CC_WARNING, "Company password changed to: %s", password);
}
- IConsolePrintF(CC_WARNING, "'company_pw' changed to: %s", argv[0]);
-
return true;
}
@@ -1909,7 +1906,7 @@ void IConsoleStdLibRegister()
/*** Networking variables ***/
IConsoleVarStringRegister("company_pw", NULL, 0, "Set a password for your company, so no one without the correct password can join. Use '*' to clear the password");
IConsoleVarHookAdd("company_pw", ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
- IConsoleVarProcAdd("company_pw", NetworkChangeCompanyPassword);
+ IConsoleVarProcAdd("company_pw", ConCompanyPassword);
IConsoleAliasRegister("company_password", "company_pw %+");
IConsoleAliasRegister("net_frame_freq", "setting frame_freq %+");
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()
diff --git a/src/openttd.cpp b/src/openttd.cpp
index 641557b0d..255e76767 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -816,8 +816,7 @@ 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)) {
- char *password = _settings_client.network.default_company_pass;
- NetworkChangeCompanyPassword(1, &password);
+ NetworkChangeCompanyPassword(_settings_client.network.default_company_pass);
}
#endif /* ENABLE_NETWORK */