From 9f23d8149f9d0afc22a3b420ca668682957f8ef3 Mon Sep 17 00:00:00 2001 From: Chaz Brown Date: Fri, 18 Sep 2009 22:58:37 -0400 Subject: Make adding/removing realm builds easier for use in multirealm environments - original patch provided by Kudlaty --HG-- branch : trunk --- src/trinityrealm/AuthSocket.cpp | 154 +++++++++++++++++++++++++--------------- 1 file changed, 95 insertions(+), 59 deletions(-) (limited to 'src/trinityrealm/AuthSocket.cpp') diff --git a/src/trinityrealm/AuthSocket.cpp b/src/trinityrealm/AuthSocket.cpp index d5c9e1445fb..a80459c77cc 100644 --- a/src/trinityrealm/AuthSocket.cpp +++ b/src/trinityrealm/AuthSocket.cpp @@ -63,7 +63,7 @@ enum eStatus }; // GCC have alternative #pragma pack(N) syntax and old gcc version not support pack(push,N), also any gcc version not support it at some paltform -#if defined( __GNUC__ ) +#if defined(__GNUC__) #pragma pack(1) #else #pragma pack(push,1) @@ -176,7 +176,7 @@ typedef struct AuthHandler }AuthHandler; // GCC have alternative #pragma pack() syntax and old gcc version not support pack(pop), also any gcc version not support it at some paltform -#if defined( __GNUC__ ) +#if defined(__GNUC__) #pragma pack() #else #pragma pack(pop) @@ -248,7 +248,7 @@ AuthSocket::~AuthSocket() { ACE_Guard g(patcherLock); - if(pPatch) + if (pPatch) fclose(pPatch); } @@ -330,7 +330,7 @@ void AuthSocket::_SetVSFields(const std::string& rI) const char *v_hex, *s_hex; v_hex = v.AsHexStr(); s_hex = s.AsHexStr(); - loginDatabase.PExecute("UPDATE account SET v = '%s', s = '%s' WHERE username = '%s'", v_hex, s_hex, _safelogin.c_str() ); + loginDatabase.PExecute("UPDATE account SET v = '%s', s = '%s' WHERE username = '%s'", v_hex, s_hex, _safelogin.c_str()); OPENSSL_free((void*)v_hex); OPENSSL_free((void*)s_hex); } @@ -397,8 +397,8 @@ bool AuthSocket::_HandleLogonChallenge() std::string address = GetRemoteAddress(); loginDatabase.escape_string(address); - QueryResult *result = loginDatabase.PQuery( "SELECT * FROM ip_banned WHERE ip = '%s'",address.c_str()); - if(result) + QueryResult *result = loginDatabase.PQuery("SELECT * FROM ip_banned WHERE ip = '%s'",address.c_str()); + if (result) { pkt << (uint8)REALM_AUTH_ACCOUNT_BANNED; sLog.outBasic("[AuthChallenge] Banned ip %s tries to login!",GetRemoteAddress().c_str ()); @@ -410,15 +410,15 @@ bool AuthSocket::_HandleLogonChallenge() // No SQL injection (escaped user name) result = loginDatabase.PQuery("SELECT sha_pass_hash,id,locked,last_ip,gmlevel,v,s FROM account WHERE username = '%s'",_safelogin.c_str ()); - if( result ) + if (result) { ///- If the IP is 'locked', check that the player comes indeed from the correct IP address bool locked = false; - if((*result)[2].GetUInt8() == 1) // if ip is locked + if ((*result)[2].GetUInt8() == 1) // if ip is locked { DEBUG_LOG("[AuthChallenge] Account '%s' is locked to IP - '%s'", _login.c_str(), (*result)[3].GetString()); DEBUG_LOG("[AuthChallenge] Player address is '%s'", GetRemoteAddress().c_str()); - if ( strcmp((*result)[3].GetString(),GetRemoteAddress().c_str()) ) + if (strcmp((*result)[3].GetString(),GetRemoteAddress().c_str())) { DEBUG_LOG("[AuthChallenge] Account IP differs"); pkt << (uint8) REALM_AUTH_ACCOUNT_FREEZED; @@ -440,9 +440,9 @@ bool AuthSocket::_HandleLogonChallenge() loginDatabase.Execute("UPDATE account_banned SET active = 0 WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate"); ///- If the account is banned, reject the logon attempt QueryResult *banresult = loginDatabase.PQuery("SELECT bandate,unbandate FROM account_banned WHERE id = %u AND active = 1", (*result)[1].GetUInt32()); - if(banresult) + if (banresult) { - if((*banresult)[0].GetUInt64() == (*banresult)[1].GetUInt64()) + if ((*banresult)[0].GetUInt64() == (*banresult)[1].GetUInt64()) { pkt << (uint8) REALM_AUTH_ACCOUNT_BANNED; sLog.outBasic("[AuthChallenge] Banned account %s tries to login!",_login.c_str ()); @@ -467,7 +467,7 @@ bool AuthSocket::_HandleLogonChallenge() sLog.outDebug("database authentication values: v='%s' s='%s'", databaseV.c_str(), databaseS.c_str()); // multiply with 2, bytes are stored as hexstring - if(databaseV.size() != s_BYTE_SIZE*2 || databaseS.size() != s_BYTE_SIZE*2) + if (databaseV.size() != s_BYTE_SIZE*2 || databaseS.size() != s_BYTE_SIZE*2) _SetVSFields(rI); else { @@ -498,13 +498,13 @@ bool AuthSocket::_HandleLogonChallenge() uint8 securityFlags = 0; pkt << uint8(securityFlags); // security flags (0x0...0x04) - if(securityFlags & REALM_AUTH_FAILURE) // PIN input + if (securityFlags & REALM_AUTH_FAILURE) // PIN input { pkt << uint32(0); pkt << uint64(0) << uint64(0); // 16 bytes hash? } - if(securityFlags & REALM_AUTH_UNKNOWN1) // Matrix input + if (securityFlags & REALM_AUTH_UNKNOWN1) // Matrix input { pkt << uint8(0); pkt << uint8(0); @@ -513,7 +513,7 @@ bool AuthSocket::_HandleLogonChallenge() pkt << uint64(0); } - if(securityFlags & REALM_AUTH_NO_MATCH) // Security token input + if (securityFlags & REALM_AUTH_NO_MATCH) // Security token input { pkt << uint8(1); } @@ -522,7 +522,7 @@ bool AuthSocket::_HandleLogonChallenge() _accountSecurityLevel = secLevel <= SEC_ADMINISTRATOR ? AccountTypes(secLevel) : SEC_ADMINISTRATOR; _localizationName.resize(4); - for(int i = 0; i < 4; ++i) + for (int i = 0; i < 4; ++i) _localizationName[i] = ch->country[4-i-1]; sLog.outBasic("[AuthChallenge] account %s is using '%c%c%c%c' locale (%u)", _login.c_str (), ch->country[3], ch->country[2], ch->country[1], ch->country[0], GetLocaleByName(_localizationName)); @@ -550,19 +550,37 @@ bool AuthSocket::_HandleLogonProof() ibuf.Read((char *)&lp, sizeof(sAuthLogonProof_C)); ///- Check if the client has one of the expected version numbers - bool valid_version = false; - int accepted_versions[] = EXPECTED_TRINITY_CLIENT_BUILD; - for(int i = 0; accepted_versions[i]; ++i) + bool valid_pre_version = false; + bool valid_tbc_version = false; + bool valid_wlk_version = false; + //int accepted_versions[] = EXPECTED_TRINITY_CLIENT_BUILD; + for (int i = 0; accepted_versions[1][i]; ++i) { - if(_build == accepted_versions[i]) + if (_build == accepted_versions[1][i]) { - valid_version = true; + valid_pre_version = true; + break; + } + } + for (int i = 0; accepted_versions[2][i]; ++i) + { + if (_build == accepted_versions[2][i]) + { + valid_tbc_version = true; + break; + } + } + for (int i = 0; accepted_versions[3][i]; ++i) + { + if (_build == accepted_versions[3][i]) + { + valid_wlk_version = true; break; } } ///