Core/Authserver: Cleanup.

--HG--
branch : trunk
This commit is contained in:
silinoron
2010-12-04 11:19:41 -08:00
parent 3201338eac
commit b8bf37264b
4 changed files with 64 additions and 77 deletions
@@ -6,26 +6,22 @@ namespace AuthHelper
bool IsPreBCAcceptedClientBuild(int build)
{
int accepted_versions[] = PRE_BC_ACCEPTED_CLIENT_BUILD;
for (int i = 0; accepted_versions[i]; ++i)
{
if (build == accepted_versions[i])
{
return true;
}
}
return false;
}
bool IsPostBCAcceptedClientBuild(int build)
{
int accepted_versions[] = POST_BC_ACCEPTED_CLIENT_BUILD;
for (int i = 0; accepted_versions[i]; ++i)
{
if (build == accepted_versions[i])
{
return true;
}
}
return false;
}
@@ -74,9 +74,11 @@ enum LoginResult
//3.1.3 build 9947
//3.1.3 build 10146 Chinese build
//3.2.2a build 10505
//3.3.0 build 10571
//3.3.0a build 11159
//3.3.2 build 11403
//3.3.3a build 11723
//3.3.5a build 12340
#define POST_BC_ACCEPTED_CLIENT_BUILD {12340, 11723, 11403, 11159, 10571, 10505, 10146, 9947, 8606, 0}
#define PRE_BC_ACCEPTED_CLIENT_BUILD {5875, 6005, 0}
+1 -1
View File
@@ -65,7 +65,7 @@ class RealmList
private:
void UpdateRealms(bool init);
void UpdateRealm(uint32 ID, const std::string& name, const std::string& address, uint32 port, uint8 icon, uint8 color, uint8 timezone, AccountTypes allowedSecurityLevel, float popu, uint32 build);
private:
RealmMap m_realms; ///< Internal map of realms
uint32 m_UpdateInterval;
time_t m_NextUpdateTime;
+25 -36
View File
@@ -30,18 +30,15 @@
#include "AuthCodes.h"
#include <openssl/md5.h>
#include "SHA1.h"
//#include "Util.h" -- for commented utf8ToUpperOnlyLatin
#define ChunkSize 2048
enum eAuthCmd
{
//AUTH_NO_CMD = 0xFF,
AUTH_LOGON_CHALLENGE = 0x00,
AUTH_LOGON_PROOF = 0x01,
AUTH_RECONNECT_CHALLENGE = 0x02,
AUTH_RECONNECT_PROOF = 0x03,
//update srv =4
REALM_LIST = 0x10,
XFER_INITIATE = 0x30,
XFER_DATA = 0x31,
@@ -107,9 +104,7 @@ typedef struct AUTH_LOGON_PROOF_S_OLD
uint8 cmd;
uint8 error;
uint8 M2[20];
//uint32 unk1;
uint32 unk2;
//uint16 unk3;
} sAuthLogonProof_S_Old;
typedef struct AUTH_RECONNECT_PROOF_C
@@ -314,7 +309,10 @@ bool AuthSocket::_HandleLogonChallenge()
socket().recv((char *)&buf[0], 4);
#if TRINITY_ENDIAN == TRINITY_BIGENDIAN
EndianConvert(*((uint16*)(buf[0])));
#endif
uint16 remaining = ((sAuthLogonChallenge_C *)&buf[0])->size;
sLog.outStaticDebug("[AuthChallenge] got header, body is %#04x bytes", remaining);
@@ -333,6 +331,7 @@ bool AuthSocket::_HandleLogonChallenge()
// BigEndian code, nop in little endian case
// size already converted
#if TRINITY_ENDIAN == TRINITY_BIGENDIAN
EndianConvert(*((uint32*)(&ch->gamename[0])));
EndianConvert(ch->build);
EndianConvert(*((uint32*)(&ch->platform[0])));
@@ -340,20 +339,19 @@ bool AuthSocket::_HandleLogonChallenge()
EndianConvert(*((uint32*)(&ch->country[0])));
EndianConvert(ch->timezone_bias);
EndianConvert(ch->ip);
#endif
ByteBuffer pkt;
_login = (const char*)ch->I;
_build = ch->build;
_expversion = (AuthHelper::IsPostBCAcceptedClientBuild(_build) ? POST_BC_EXP_FLAG : NO_VALID_EXP_FLAG) + (AuthHelper::IsPreBCAcceptedClientBuild(_build) ? PRE_BC_EXP_FLAG : NO_VALID_EXP_FLAG);
_expversion = (AuthHelper::IsPostBCAcceptedClientBuild(_build) ? POST_BC_EXP_FLAG : NO_VALID_EXP_FLAG) | (AuthHelper::IsPreBCAcceptedClientBuild(_build) ? PRE_BC_EXP_FLAG : NO_VALID_EXP_FLAG);
pkt << (uint8)AUTH_LOGON_CHALLENGE;
pkt << (uint8)0x00;
// Verify that this IP is not in the ip_banned table
LoginDatabase.Execute(
LoginDatabase.GetPreparedStatement(LOGIN_SET_EXPIREDIPBANS)
);
LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_SET_EXPIREDIPBANS));
const std::string& ip_address = socket().get_remote_address();
PreparedStatement *stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_IPBANNED);
@@ -362,7 +360,7 @@ bool AuthSocket::_HandleLogonChallenge()
if (result)
{
pkt << (uint8)WOW_FAIL_BANNED;
sLog.outBasic("[AuthChallenge] Banned ip %s tries to login!", ip_address.c_str());
sLog.outBasic("[AuthChallenge] Banned ip %s tried to login!", ip_address.c_str());
}
else
{
@@ -398,9 +396,7 @@ bool AuthSocket::_HandleLogonChallenge()
if (!locked)
{
//set expired bans to inactive
LoginDatabase.Execute(
LoginDatabase.GetPreparedStatement(LOGIN_SET_EXPIREDACCBANS)
);
LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_SET_EXPIREDACCBANS));
// If the account is banned, reject the logon attempt
stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_ACCBANNED);
@@ -411,12 +407,12 @@ bool AuthSocket::_HandleLogonChallenge()
if ((*banresult)[0].GetUInt64() == (*banresult)[1].GetUInt64())
{
pkt << (uint8)WOW_FAIL_BANNED;
sLog.outBasic("[AuthChallenge] Banned account %s tries to login!", _login.c_str());
sLog.outBasic("[AuthChallenge] Banned account %s tried to login!", _login.c_str());
}
else
{
pkt << (uint8)WOW_FAIL_SUSPENDED;
sLog.outBasic("[AuthChallenge] Temporarily banned account %s tries to login!", _login.c_str());
sLog.outBasic("[AuthChallenge] Temporarily banned account %s tried to login!", _login.c_str());
}
}
else
@@ -430,7 +426,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
// multiply with 2 since bytes are stored as hexstring
if (databaseV.size() != s_BYTE_SIZE * 2 || databaseS.size() != s_BYTE_SIZE * 2)
_SetVSFields(rI);
else
@@ -619,7 +615,7 @@ bool AuthSocket::_HandleLogonProof()
sha.UpdateBigNumbers(&A, &M, &K, NULL);
sha.Finalize();
if (_expversion & POST_BC_EXP_FLAG) // 2.4.3 and 3.1.3 clients (10146 is Chinese build for 3.1.3)
if (_expversion & POST_BC_EXP_FLAG) // 2.x and 3.x clients
{
sAuthLogonProof_S proof;
memcpy(proof.M2, sha.GetDigest(), 20);
@@ -636,13 +632,10 @@ bool AuthSocket::_HandleLogonProof()
memcpy(proof.M2, sha.GetDigest(), 20);
proof.cmd = AUTH_LOGON_PROOF;
proof.error = 0;
//proof.unk1 = 0x00800000;
proof.unk2 = 0x00;
//proof.unk3 = 0x00;
socket().send((char *)&proof, sizeof(proof));
}
// Set _authed to true!
_authed = true;
}
else
@@ -714,7 +707,10 @@ bool AuthSocket::_HandleReconnectChallenge()
socket().recv((char *)&buf[0], 4);
#if TRINITY_ENDIAN == TRINITY_BIGENDIAN
EndianConvert(*((uint16*)(buf[0])));
#endif
uint16 remaining = ((sAuthLogonChallenge_C *)&buf[0])->size;
sLog.outStaticDebug("[ReconnectChallenge] got header, body is %#04x bytes", remaining);
@@ -787,10 +783,7 @@ bool AuthSocket::_HandleReconnectProof()
pkt << (uint8)0x00;
pkt << (uint16)0x00; // 2 bytes zeros
socket().send((char const*)pkt.contents(), pkt.size());
// Set _authed to true!
_authed = true;
return true;
}
else
@@ -812,7 +805,6 @@ bool AuthSocket::_HandleRealmList()
// Get the user id (else close the connection)
// No SQL injection (prepared statement)
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_ACCIDBYNAME);
stmt->setString(0, _login);
PreparedQueryResult result = LoginDatabase.Query(stmt);
@@ -836,16 +828,10 @@ bool AuthSocket::_HandleRealmList()
for (RealmList::RealmMap::const_iterator i = sRealmList->begin(); i != sRealmList->end(); ++i)
{
// don't work with realms which not compatible with the client
if (_expversion & POST_BC_EXP_FLAG) // 2.4.3 and 3.1.3 cliens
{
if (i->second.gamebuild != _build)
if ((_expversion & POST_BC_EXP_FLAG) && i->second.gamebuild != _build)
continue;
}
else if (_expversion & PRE_BC_EXP_FLAG) // 1.12.1 and 1.12.2 clients are compatible with eachother
{
if (!AuthHelper::IsPreBCAcceptedClientBuild(i->second.gamebuild))
else if ((_expversion & PRE_BC_EXP_FLAG) && !AuthHelper::IsPreBCAcceptedClientBuild(i->second.gamebuild))
continue;
}
uint8 AmountOfCharacters;
@@ -862,7 +848,7 @@ bool AuthSocket::_HandleRealmList()
uint8 lock = (i->second.allowedSecurityLevel > _accountSecurityLevel) ? 1 : 0;
pkt << i->second.icon; // realm type
if ( _expversion & POST_BC_EXP_FLAG ) // only 2.4.3 and 3.1.3 cliens
if ( _expversion & POST_BC_EXP_FLAG ) // only 2.x and 3.x clients
pkt << lock; // if 1, then realm locked
pkt << i->second.color; // if 2, then realm is offline
pkt << i->first;
@@ -870,7 +856,7 @@ bool AuthSocket::_HandleRealmList()
pkt << i->second.populationLevel;
pkt << AmountOfCharacters;
pkt << i->second.timezone; // realm category
if ( _expversion & POST_BC_EXP_FLAG ) // 2.4.3 and 3.1.3 clients
if ( _expversion & POST_BC_EXP_FLAG ) // 2.x and 3.x clients
pkt << (uint8)0x2C; // unk, may be realm number/id?
else
pkt << (uint8)0x0; // 1.12.1 and 1.12.2 clients
@@ -878,7 +864,7 @@ bool AuthSocket::_HandleRealmList()
++RealmListSize;
}
if ( _expversion & POST_BC_EXP_FLAG ) // 2.4.3 and 3.1.3 cliens
if ( _expversion & POST_BC_EXP_FLAG ) // 2.x and 3.x clients
{
pkt << (uint8)0x10;
pkt << (uint8)0x00;
@@ -892,7 +878,7 @@ bool AuthSocket::_HandleRealmList()
// make a ByteBuffer which stores the RealmList's size
ByteBuffer RealmListSizeBuffer;
RealmListSizeBuffer << (uint32)0;
if (_expversion & POST_BC_EXP_FLAG) // only 2.4.3 and 3.1.3 clients
if (_expversion & POST_BC_EXP_FLAG) // only 2.x and 3.x clients
RealmListSizeBuffer << (uint16)RealmListSize;
else
RealmListSizeBuffer << (uint32)RealmListSize;
@@ -979,8 +965,10 @@ void Patcher::LoadPatchesInfo()
//int errno;
struct dirent * dp;
dirp = opendir("./patches/");
if (!dirp)
return;
while (dirp)
{
errno = 0;
@@ -1048,6 +1036,7 @@ void Patcher::LoadPatchMD5(char * szFileName)
size_t read = fread(buf, 1, 512 * 1024, pPatch);
MD5_Update(&ctx, buf, read);
}
delete [] buf;
fclose(pPatch);