mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-04 06:00:15 +00:00
(svn r19075) -Codechange: unhackify NetworkChangeCompanyPassword()
This commit is contained in:
parent
b91b3ac836
commit
73ed81b1c7
@ -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;
|
||||
|
@ -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;
|
||||
const char *password = NetworkChangeCompanyPassword(argv[0]);
|
||||
|
||||
if (strcmp(argv[0], "*") == 0) argv[0][0] = '\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 %+");
|
||||
|
@ -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);
|
||||
}
|
||||
@ -1053,6 +1053,24 @@ bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
@ -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();
|
||||
|
@ -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()
|
||||
|
@ -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 */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user