(svn r21854) -Codechange: refactor the password setting methods to make it possible to change the password of other companies (on the server)

This commit is contained in:
rubidium
2011-01-19 16:47:40 +00:00
parent e54a1f6721
commit 795a528328
9 changed files with 32 additions and 32 deletions

View File

@@ -1287,10 +1287,7 @@ DEF_GAME_RECEIVE_COMMAND(Server, PACKET_CLIENT_SET_PASSWORD)
p->Recv_string(password, sizeof(password));
ci = this->GetInfo();
if (Company::IsValidID(ci->client_playas)) {
strecpy(_network_company_states[ci->client_playas].password, password, lastof(_network_company_states[ci->client_playas].password));
NetworkServerUpdateCompanyPassworded(ci->client_playas, !StrEmpty(_network_company_states[ci->client_playas].password));
}
NetworkServerSetCompanyPassword(ci->client_playas, password);
return NETWORK_RECV_STATUS_OKAY;
}
@@ -1630,23 +1627,21 @@ bool NetworkServerChangeClientName(ClientID client_id, const char *new_name)
}
/**
* Hash the current company password; used when the server 'company' sets his/her password.
* @param password The password to hash.
* Set/Reset a company password on the server end.
* @param company_id ID of the company the password should be changed for.
* @param password The new password.
* @param already_hashed Is the given password already hashed?
*/
void HashCurrentCompanyPassword(const char *password)
void NetworkServerSetCompanyPassword(CompanyID company_id, const char *password, bool already_hashed)
{
uint32 password_game_seed;
char password_server_id[NETWORK_SERVER_ID_LENGTH];
if (!Company::IsValidHumanID(company_id)) return;
password_game_seed = _settings_game.game_creation.generation_seed;
strecpy(password_server_id, _settings_client.network.network_id, lastof(password_server_id));
const char *new_pw = GenerateCompanyPasswordHash(password, password_server_id, password_game_seed);
strecpy(_network_company_states[_local_company].password, new_pw, lastof(_network_company_states[_local_company].password));
if (_network_server) {
NetworkServerUpdateCompanyPassworded(_local_company, !StrEmpty(_network_company_states[_local_company].password));
if (!already_hashed) {
password = GenerateCompanyPasswordHash(password, _settings_client.network.network_id, _settings_game.game_creation.generation_seed);
}
strecpy(_network_company_states[company_id].password, password, lastof(_network_company_states[company_id].password));
NetworkServerUpdateCompanyPassworded(company_id, !StrEmpty(_network_company_states[company_id].password));
}
/* Handle the local command-queue */