mirror of https://github.com/OpenTTD/OpenTTD
(svn r19075) -Codechange: unhackify NetworkChangeCompanyPassword()
parent
b91b3ac836
commit
73ed81b1c7
|
@ -772,8 +772,7 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
||||||
assert(_local_company == COMPANY_SPECTATOR);
|
assert(_local_company == COMPANY_SPECTATOR);
|
||||||
SetLocalCompany(c->index);
|
SetLocalCompany(c->index);
|
||||||
if (!StrEmpty(_settings_client.network.default_company_pass)) {
|
if (!StrEmpty(_settings_client.network.default_company_pass)) {
|
||||||
char *password = _settings_client.network.default_company_pass;
|
NetworkChangeCompanyPassword(_settings_client.network.default_company_pass);
|
||||||
NetworkChangeCompanyPassword(1, &password);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_current_company = _local_company;
|
_current_company = _local_company;
|
||||||
|
|
|
@ -1544,8 +1544,7 @@ DEF_CONSOLE_CMD(ConSayClient)
|
||||||
|
|
||||||
extern void HashCurrentCompanyPassword(const char *password);
|
extern void HashCurrentCompanyPassword(const char *password);
|
||||||
|
|
||||||
/* Also use from within company_gui to change the password graphically */
|
DEF_CONSOLE_CMD(ConCompanyPassword)
|
||||||
bool NetworkChangeCompanyPassword(byte argc, char *argv[])
|
|
||||||
{
|
{
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
IConsoleHelp("Change the password of your company. Usage: 'company_pw \"<password>\"'");
|
IConsoleHelp("Change the password of your company. Usage: 'company_pw \"<password>\"'");
|
||||||
|
@ -1553,23 +1552,21 @@ bool NetworkChangeCompanyPassword(byte argc, char *argv[])
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (argc != 1) return false;
|
||||||
|
|
||||||
if (!Company::IsValidID(_local_company)) {
|
if (!Company::IsValidID(_local_company)) {
|
||||||
IConsoleError("You have to own a company to make use of this command.");
|
IConsoleError("You have to own a company to make use of this command.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc != 1) return false;
|
const char *password = NetworkChangeCompanyPassword(argv[0]);
|
||||||
|
|
||||||
if (strcmp(argv[0], "*") == 0) argv[0][0] = '\0';
|
if (StrEmpty(password)) {
|
||||||
|
IConsolePrintF(CC_WARNING, "Company password cleared");
|
||||||
if (!_network_server) {
|
|
||||||
NetworkClientSetPassword(argv[0]);
|
|
||||||
} else {
|
} 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1909,7 +1906,7 @@ void IConsoleStdLibRegister()
|
||||||
/*** Networking variables ***/
|
/*** 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");
|
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);
|
IConsoleVarHookAdd("company_pw", ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
|
||||||
IConsoleVarProcAdd("company_pw", NetworkChangeCompanyPassword);
|
IConsoleVarProcAdd("company_pw", ConCompanyPassword);
|
||||||
IConsoleAliasRegister("company_password", "company_pw %+");
|
IConsoleAliasRegister("company_password", "company_pw %+");
|
||||||
|
|
||||||
IConsoleAliasRegister("net_frame_freq", "setting frame_freq %+");
|
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);
|
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);
|
SEND_COMMAND(PACKET_CLIENT_SET_PASSWORD)(password);
|
||||||
}
|
}
|
||||||
|
@ -1053,6 +1053,24 @@ bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
|
||||||
return false;
|
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).
|
* 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.
|
* @return true if the max value has been reached or exceeded, false otherwise.
|
||||||
|
|
|
@ -36,7 +36,7 @@ extern StringList _network_ban_list;
|
||||||
byte NetworkSpectatorCount();
|
byte NetworkSpectatorCount();
|
||||||
void NetworkUpdateClientName();
|
void NetworkUpdateClientName();
|
||||||
bool NetworkCompanyHasClients(CompanyID company);
|
bool NetworkCompanyHasClients(CompanyID company);
|
||||||
bool NetworkChangeCompanyPassword(byte argc, char *argv[]);
|
const char *NetworkChangeCompanyPassword(const char *);
|
||||||
void NetworkReboot();
|
void NetworkReboot();
|
||||||
void NetworkDisconnect(bool blocking = false);
|
void NetworkDisconnect(bool blocking = false);
|
||||||
void NetworkGameLoop();
|
void NetworkGameLoop();
|
||||||
|
@ -51,7 +51,6 @@ void NetworkClientConnectGame(NetworkAddress address, CompanyID join_as, const c
|
||||||
void NetworkClientRequestMove(CompanyID company, const char *pass = "");
|
void NetworkClientRequestMove(CompanyID company, const char *pass = "");
|
||||||
void NetworkClientSendRcon(const char *password, const char *command);
|
void NetworkClientSendRcon(const char *password, const char *command);
|
||||||
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data = 0);
|
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 NetworkClientPreferTeamChat(const NetworkClientInfo *cio);
|
||||||
bool NetworkCompanyIsPassworded(CompanyID company_id);
|
bool NetworkCompanyIsPassworded(CompanyID company_id);
|
||||||
bool NetworkMaxCompaniesReached();
|
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);
|
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 */
|
NetworkChangeCompanyPassword(this->edit_str_buf);
|
||||||
if (StrEmpty(this->edit_str_buf)) snprintf(this->edit_str_buf, this->edit_str_size, "*");
|
|
||||||
char *password = this->edit_str_buf;
|
|
||||||
NetworkChangeCompanyPassword(1, &password);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnPaint()
|
virtual void OnPaint()
|
||||||
|
|
|
@ -816,8 +816,7 @@ static void MakeNewGameDone()
|
||||||
/* We are the server, we start a new company (not dedicated),
|
/* We are the server, we start a new company (not dedicated),
|
||||||
* so set the default password *if* needed. */
|
* so set the default password *if* needed. */
|
||||||
if (_network_server && !StrEmpty(_settings_client.network.default_company_pass)) {
|
if (_network_server && !StrEmpty(_settings_client.network.default_company_pass)) {
|
||||||
char *password = _settings_client.network.default_company_pass;
|
NetworkChangeCompanyPassword(_settings_client.network.default_company_pass);
|
||||||
NetworkChangeCompanyPassword(1, &password);
|
|
||||||
}
|
}
|
||||||
#endif /* ENABLE_NETWORK */
|
#endif /* ENABLE_NETWORK */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue