Mercurial > hg > openttd
changeset 17115:0b87f5699faa draft
(svn r21852) -Codechange: generalise GenerateCompanyPasswordHash (dihedral)
author | rubidium <rubidium@openttd.org> |
---|---|
date | Wed, 19 Jan 2011 16:35:11 +0000 |
parents | 175826e70c28 |
children | 9148abb72809 |
files | src/network/network.cpp src/network/network.h src/network/network_client.cpp |
diffstat | 3 files changed, 18 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -150,9 +150,6 @@ return count; } -extern uint32 _password_game_seed; -extern char _password_server_id[NETWORK_SERVER_ID_LENGTH]; - /** * Sets/resets company password * @param password new password, "" or "*" resets password @@ -172,11 +169,13 @@ } /** - * Generates a hashed password for the company name. - * @param password the password to 'encrypt'. - * @return the hashed password. + * Hash the given password using server ID and game seed. + * @param password Password to hash. + * @param password_server_id Server ID. + * @param password_game_seed Game seed. + * @return The hashed password. */ -const char *GenerateCompanyPasswordHash(const char *password) +const char *GenerateCompanyPasswordHash(const char *password, const char *password_server_id, uint32 password_game_seed) { if (StrEmpty(password)) return password; @@ -186,7 +185,7 @@ snprintf(salted_password, sizeof(salted_password), "%s", password); /* Add the game seed and the server's ID as the salt. */ for (uint i = 0; i < NETWORK_SERVER_ID_LENGTH - 1; i++) { - salted_password[i] ^= _password_server_id[i] ^ (_password_game_seed >> (i % 32)); + salted_password[i] ^= password_server_id[i] ^ (password_game_seed >> (i % 32)); } Md5 checksum; @@ -208,10 +207,13 @@ */ void HashCurrentCompanyPassword(const char *password) { - _password_game_seed = _settings_game.game_creation.generation_seed; - strecpy(_password_server_id, _settings_client.network.network_id, lastof(_password_server_id)); + uint32 password_game_seed; + char password_server_id[NETWORK_SERVER_ID_LENGTH]; - const char *new_pw = GenerateCompanyPasswordHash(password); + 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) {
--- a/src/network/network.h +++ b/src/network/network.h @@ -19,7 +19,7 @@ void NetworkShutDown(); void NetworkDrawChatMessage(); -const char *GenerateCompanyPasswordHash(const char *password); +const char *GenerateCompanyPasswordHash(const char *password, const char *password_server_id, uint32 password_game_seed); void HashCurrentCompanyPassword(const char *password); extern bool _networking; ///< are we in networking mode?
--- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -347,7 +347,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendCompanyPassword(const char *password) { Packet *p = new Packet(PACKET_CLIENT_COMPANY_PASSWORD); - p->Send_string(GenerateCompanyPasswordHash(password)); + p->Send_string(GenerateCompanyPasswordHash(password, _password_server_id, _password_game_seed)); my_client->SendPacket(p); return NETWORK_RECV_STATUS_OKAY; } @@ -426,7 +426,7 @@ { Packet *p = new Packet(PACKET_CLIENT_SET_PASSWORD); - p->Send_string(GenerateCompanyPasswordHash(password)); + p->Send_string(GenerateCompanyPasswordHash(password, _password_server_id, _password_game_seed)); my_client->SendPacket(p); return NETWORK_RECV_STATUS_OKAY; } @@ -457,11 +457,11 @@ return NETWORK_RECV_STATUS_OKAY; } -NetworkRecvStatus ClientNetworkGameSocketHandler::SendMove(CompanyID company, const char *pass) +NetworkRecvStatus ClientNetworkGameSocketHandler::SendMove(CompanyID company, const char *password) { Packet *p = new Packet(PACKET_CLIENT_MOVE); p->Send_uint8(company); - p->Send_string(GenerateCompanyPasswordHash(pass)); + p->Send_string(GenerateCompanyPasswordHash(password, _password_server_id, _password_game_seed)); my_client->SendPacket(p); return NETWORK_RECV_STATUS_OKAY; }