mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-22 18:15:31 +01:00
Core/Authserver: Clean up authserver base code a bit + follow codingstyle
--HG-- branch : trunk
This commit is contained in:
@@ -151,7 +151,7 @@ typedef struct AuthHandler
|
||||
#pragma pack(pop)
|
||||
#endif
|
||||
|
||||
/// Launch a thread to transfer a patch to the client
|
||||
// Launch a thread to transfer a patch to the client
|
||||
class PatcherRunnable: public ACE_Based::Runnable
|
||||
{
|
||||
public:
|
||||
@@ -167,7 +167,7 @@ typedef struct PATCH_INFO
|
||||
uint8 md5[MD5_DIGEST_LENGTH];
|
||||
} PATCH_INFO;
|
||||
|
||||
/// Caches MD5 hash of client patches present on the server
|
||||
// Caches MD5 hash of client patches present on the server
|
||||
class Patcher
|
||||
{
|
||||
public:
|
||||
@@ -198,10 +198,10 @@ const AuthHandler table[] =
|
||||
|
||||
#define AUTH_TOTAL_COMMANDS sizeof(table)/sizeof(AuthHandler)
|
||||
|
||||
///Holds the MD5 hash of client patches present on the server
|
||||
// Holds the MD5 hash of client patches present on the server
|
||||
Patcher PatchesCache;
|
||||
|
||||
/// Constructor - set the N and g values for SRP6
|
||||
// Constructor - set the N and g values for SRP6
|
||||
AuthSocket::AuthSocket(RealmSocket& socket) : socket_(socket)
|
||||
{
|
||||
N.SetHexStr("894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7");
|
||||
@@ -210,12 +210,10 @@ AuthSocket::AuthSocket(RealmSocket& socket) : socket_(socket)
|
||||
_accountSecurityLevel = SEC_PLAYER;
|
||||
}
|
||||
|
||||
/// Close patch file descriptor before leaving
|
||||
AuthSocket::~AuthSocket(void)
|
||||
{
|
||||
}
|
||||
// Close patch file descriptor before leaving
|
||||
AuthSocket::~AuthSocket(void) {}
|
||||
|
||||
/// Accept the connection and set the s random value for SRP6
|
||||
// Accept the connection and set the s random value for SRP6
|
||||
void AuthSocket::OnAccept(void)
|
||||
{
|
||||
sLog.outBasic("Accepting connection from '%s'", socket().get_remote_address().c_str());
|
||||
@@ -226,7 +224,7 @@ void AuthSocket::OnClose(void)
|
||||
sLog.outDebug("AuthSocket::OnClose");
|
||||
}
|
||||
|
||||
/// Read the packet from the client
|
||||
// Read the packet from the client
|
||||
void AuthSocket::OnRead()
|
||||
{
|
||||
uint8 _cmd;
|
||||
@@ -237,7 +235,7 @@ void AuthSocket::OnRead()
|
||||
|
||||
size_t i;
|
||||
|
||||
///- Circle through known commands and call the correct command handler
|
||||
// Circle through known commands and call the correct command handler
|
||||
for (i = 0; i < AUTH_TOTAL_COMMANDS; ++i)
|
||||
{
|
||||
if ((uint8)table[i].cmd == _cmd &&
|
||||
@@ -265,7 +263,7 @@ void AuthSocket::OnRead()
|
||||
}
|
||||
}
|
||||
|
||||
/// Make the SRP6 calculation from hash in dB
|
||||
// Make the SRP6 calculation from hash in dB
|
||||
void AuthSocket::_SetVSFields(const std::string& rI)
|
||||
{
|
||||
s.SetRand(s_BYTE_SIZE * 8);
|
||||
@@ -303,14 +301,14 @@ void AuthSocket::_SetVSFields(const std::string& rI)
|
||||
OPENSSL_free((void*)s_hex);
|
||||
}
|
||||
|
||||
/// Logon Challenge command handler
|
||||
// Logon Challenge command handler
|
||||
bool AuthSocket::_HandleLogonChallenge()
|
||||
{
|
||||
sLog.outStaticDebug("Entering _HandleLogonChallenge");
|
||||
if (socket().recv_len() < sizeof(sAuthLogonChallenge_C))
|
||||
return false;
|
||||
|
||||
///- Read the first 4 bytes (header) to get the length of the remaining of the packet
|
||||
// Read the first 4 bytes (header) to get the length of the remaining of the packet
|
||||
std::vector<uint8> buf;
|
||||
buf.resize(4);
|
||||
|
||||
@@ -328,7 +326,7 @@ bool AuthSocket::_HandleLogonChallenge()
|
||||
buf[buf.size() - 1] = 0;
|
||||
sAuthLogonChallenge_C *ch = (sAuthLogonChallenge_C*)&buf[0];
|
||||
|
||||
///- Read the remaining of the packet
|
||||
// Read the remaining of the packet
|
||||
socket().recv((char *)&buf[4], remaining);
|
||||
sLog.outStaticDebug("[AuthChallenge] got full packet, %#04x bytes", ch->size);
|
||||
sLog.outStaticDebug("[AuthChallenge] name(%d): '%s'", ch->I_len, ch->I);
|
||||
@@ -349,15 +347,10 @@ bool AuthSocket::_HandleLogonChallenge()
|
||||
_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);
|
||||
|
||||
///- Normalize account name
|
||||
//utf8ToUpperOnlyLatin(_login); -- client already send account in expected form
|
||||
|
||||
_build = ch->build;
|
||||
|
||||
pkt << (uint8) AUTH_LOGON_CHALLENGE;
|
||||
pkt << (uint8) 0x00;
|
||||
|
||||
///- Verify that this IP is not in the ip_banned table
|
||||
// Verify that this IP is not in the ip_banned table
|
||||
LoginDatabase.Execute(
|
||||
LoginDatabase.GetPreparedStatement(LOGIN_SET_EXPIREDIPBANS)
|
||||
);
|
||||
@@ -373,7 +366,7 @@ bool AuthSocket::_HandleLogonChallenge()
|
||||
}
|
||||
else
|
||||
{
|
||||
///- Get the account details from the account table
|
||||
// Get the account details from the account table
|
||||
// No SQL injection (prepared statement)
|
||||
stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_LOGONCHALLENGE);
|
||||
stmt->setString(0, _login);
|
||||
@@ -383,12 +376,13 @@ bool AuthSocket::_HandleLogonChallenge()
|
||||
{
|
||||
Field* fields = res2->Fetch();
|
||||
|
||||
///- If the IP is 'locked', check that the player comes indeed from the correct IP address
|
||||
// If the IP is 'locked', check that the player comes indeed from the correct IP address
|
||||
bool locked = false;
|
||||
if (fields[2].GetUInt8() == 1) // if ip is locked
|
||||
if (fields[2].GetUInt8() == 1) // if ip is locked
|
||||
{
|
||||
sLog.outStaticDebug("[AuthChallenge] Account '%s' is locked to IP - '%s'", _login.c_str(), fields[3].GetCString());
|
||||
sLog.outStaticDebug("[AuthChallenge] Player address is '%s'", ip_address.c_str());
|
||||
|
||||
if (strcmp(fields[3].GetCString(), ip_address.c_str()))
|
||||
{
|
||||
sLog.outStaticDebug("[AuthChallenge] Account IP differs");
|
||||
@@ -408,7 +402,7 @@ bool AuthSocket::_HandleLogonChallenge()
|
||||
LoginDatabase.GetPreparedStatement(LOGIN_SET_EXPIREDACCBANS)
|
||||
);
|
||||
|
||||
///- If the account is banned, reject the logon attempt
|
||||
// If the account is banned, reject the logon attempt
|
||||
stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_ACCBANNED);
|
||||
stmt->setUInt32(0, fields[1].GetUInt32());
|
||||
PreparedQueryResult banresult = LoginDatabase.Query(stmt);
|
||||
@@ -427,10 +421,10 @@ bool AuthSocket::_HandleLogonChallenge()
|
||||
}
|
||||
else
|
||||
{
|
||||
///- Get the password from the account table, upper it, and make the SRP6 calculation
|
||||
// Get the password from the account table, upper it, and make the SRP6 calculation
|
||||
std::string rI = fields[0].GetString();
|
||||
|
||||
///- Don't calculate (v, s) if there are already some in the database
|
||||
// Don't calculate (v, s) if there are already some in the database
|
||||
std::string databaseV = fields[5].GetString();
|
||||
std::string databaseS = fields[6].GetString();
|
||||
|
||||
@@ -454,7 +448,7 @@ bool AuthSocket::_HandleLogonChallenge()
|
||||
BigNumber unk3;
|
||||
unk3.SetRand(16 * 8);
|
||||
|
||||
///- Fill the response packet with the result
|
||||
// Fill the response packet with the result
|
||||
pkt << uint8(WOW_SUCCESS);
|
||||
|
||||
// B may be calculated < 32B so we force minimal length to 32B
|
||||
@@ -468,13 +462,13 @@ bool AuthSocket::_HandleLogonChallenge()
|
||||
uint8 securityFlags = 0;
|
||||
pkt << uint8(securityFlags); // security flags (0x0...0x04)
|
||||
|
||||
if (securityFlags & 0x01) // PIN input
|
||||
if (securityFlags & 0x01) // PIN input
|
||||
{
|
||||
pkt << uint32(0);
|
||||
pkt << uint64(0) << uint64(0); // 16 bytes hash?
|
||||
}
|
||||
|
||||
if (securityFlags & 0x02) // Matrix input
|
||||
if (securityFlags & 0x02) // Matrix input
|
||||
{
|
||||
pkt << uint8(0);
|
||||
pkt << uint8(0);
|
||||
@@ -483,7 +477,7 @@ bool AuthSocket::_HandleLogonChallenge()
|
||||
pkt << uint64(0);
|
||||
}
|
||||
|
||||
if (securityFlags & 0x04) // Security token input
|
||||
if (securityFlags & 0x04) // Security token input
|
||||
pkt << uint8(1);
|
||||
|
||||
uint8 secLevel = fields[4].GetUInt8();
|
||||
@@ -493,42 +487,40 @@ bool AuthSocket::_HandleLogonChallenge()
|
||||
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));
|
||||
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)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
else //no account
|
||||
{
|
||||
else //no account
|
||||
pkt<< (uint8) WOW_FAIL_UNKNOWN_ACCOUNT;
|
||||
}
|
||||
}
|
||||
|
||||
socket().send((char const*)pkt.contents(), pkt.size());
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Logon Proof command handler
|
||||
// Logon Proof command handler
|
||||
bool AuthSocket::_HandleLogonProof()
|
||||
{
|
||||
sLog.outStaticDebug("Entering _HandleLogonProof");
|
||||
///- Read the packet
|
||||
// Read the packet
|
||||
sAuthLogonProof_C lp;
|
||||
|
||||
if (!socket().recv((char *)&lp, sizeof(sAuthLogonProof_C)))
|
||||
return false;
|
||||
|
||||
/// <ul><li> If the client has no valid version
|
||||
// If the client has no valid version
|
||||
if (_expversion == NO_VALID_EXP_FLAG)
|
||||
{
|
||||
///- Check if we have the appropriate patch on the disk
|
||||
|
||||
// Check if we have the appropriate patch on the disk
|
||||
sLog.outDebug("Client with invalid version, patching is not implemented");
|
||||
socket().shutdown();
|
||||
return true;
|
||||
}
|
||||
/// </ul>
|
||||
|
||||
///- Continue the SRP6 calculation based on data received from the client
|
||||
// Continue the SRP6 calculation based on data received from the client
|
||||
BigNumber A;
|
||||
|
||||
A.SetBinary(lp.A, 32);
|
||||
@@ -551,28 +543,27 @@ bool AuthSocket::_HandleLogonProof()
|
||||
uint8 t1[16];
|
||||
uint8 vK[40];
|
||||
memcpy(t, S.AsByteArray(32), 32);
|
||||
|
||||
for (int i = 0; i < 16; ++i)
|
||||
{
|
||||
t1[i] = t[i * 2];
|
||||
}
|
||||
|
||||
sha.Initialize();
|
||||
sha.UpdateData(t1, 16);
|
||||
sha.Finalize();
|
||||
|
||||
for (int i = 0; i < 20; ++i)
|
||||
{
|
||||
vK[i * 2] = sha.GetDigest()[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < 16; ++i)
|
||||
{
|
||||
t1[i] = t[i * 2 + 1];
|
||||
}
|
||||
|
||||
sha.Initialize();
|
||||
sha.UpdateData(t1, 16);
|
||||
sha.Finalize();
|
||||
|
||||
for (int i = 0; i < 20; ++i)
|
||||
{
|
||||
vK[i * 2 + 1] = sha.GetDigest()[i];
|
||||
}
|
||||
|
||||
K.SetBinary(vK, 40);
|
||||
|
||||
uint8 hash[20];
|
||||
@@ -584,10 +575,10 @@ bool AuthSocket::_HandleLogonProof()
|
||||
sha.Initialize();
|
||||
sha.UpdateBigNumbers(&g, NULL);
|
||||
sha.Finalize();
|
||||
|
||||
for (int i = 0; i < 20; ++i)
|
||||
{
|
||||
hash[i] ^= sha.GetDigest()[i];
|
||||
}
|
||||
|
||||
BigNumber t3;
|
||||
t3.SetBinary(hash, 20);
|
||||
|
||||
@@ -605,12 +596,12 @@ bool AuthSocket::_HandleLogonProof()
|
||||
BigNumber M;
|
||||
M.SetBinary(sha.GetDigest(), 20);
|
||||
|
||||
///- Check if SRP6 results match (password is correct), else send an error
|
||||
// Check if SRP6 results match (password is correct), else send an error
|
||||
if (!memcmp(M.AsByteArray(), lp.M1, 20))
|
||||
{
|
||||
sLog.outBasic("User '%s' successfully authenticated", _login.c_str());
|
||||
|
||||
///- Update the sessionkey, last_ip, last login time and reset number of failed logins in the account table for this account
|
||||
// Update the sessionkey, last_ip, last login time and reset number of failed logins in the account table for this account
|
||||
// No SQL injection (escaped user name) and IP address as received by socket
|
||||
const char* K_hex = K.AsHexStr();
|
||||
|
||||
@@ -623,12 +614,12 @@ bool AuthSocket::_HandleLogonProof()
|
||||
|
||||
OPENSSL_free((void*)K_hex);
|
||||
|
||||
///- Finish SRP6 and send the final result to the client
|
||||
// Finish SRP6 and send the final result to the client
|
||||
sha.Initialize();
|
||||
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.4.3 and 3.1.3 clients (10146 is Chinese build for 3.1.3)
|
||||
{
|
||||
sAuthLogonProof_S proof;
|
||||
memcpy(proof.M2, sha.GetDigest(), 20);
|
||||
@@ -651,7 +642,7 @@ bool AuthSocket::_HandleLogonProof()
|
||||
socket().send((char *)&proof, sizeof(proof));
|
||||
}
|
||||
|
||||
///- Set _authed to true!
|
||||
// Set _authed to true!
|
||||
_authed = true;
|
||||
}
|
||||
else
|
||||
@@ -710,14 +701,14 @@ bool AuthSocket::_HandleLogonProof()
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Reconnect Challenge command handler
|
||||
// Reconnect Challenge command handler
|
||||
bool AuthSocket::_HandleReconnectChallenge()
|
||||
{
|
||||
sLog.outStaticDebug("Entering _HandleReconnectChallenge");
|
||||
if (socket().recv_len() < sizeof(sAuthLogonChallenge_C))
|
||||
return false;
|
||||
|
||||
///- Read the first 4 bytes (header) to get the length of the remaining of the packet
|
||||
// Read the first 4 bytes (header) to get the length of the remaining of the packet
|
||||
std::vector<uint8> buf;
|
||||
buf.resize(4);
|
||||
|
||||
@@ -730,12 +721,12 @@ bool AuthSocket::_HandleReconnectChallenge()
|
||||
if ((remaining < sizeof(sAuthLogonChallenge_C) - buf.size()) || (socket().recv_len() < remaining))
|
||||
return false;
|
||||
|
||||
//No big fear of memory outage (size is int16, i.e. < 65536)
|
||||
// No big fear of memory outage (size is int16, i.e. < 65536)
|
||||
buf.resize(remaining + buf.size() + 1);
|
||||
buf[buf.size() - 1] = 0;
|
||||
sAuthLogonChallenge_C *ch = (sAuthLogonChallenge_C*)&buf[0];
|
||||
|
||||
///- Read the remaining of the packet
|
||||
// Read the remaining of the packet
|
||||
socket().recv((char *)&buf[4], remaining);
|
||||
sLog.outStaticDebug("[ReconnectChallenge] got full packet, %#04x bytes", ch->size);
|
||||
sLog.outStaticDebug("[ReconnectChallenge] name(%d): '%s'", ch->I_len, ch->I);
|
||||
@@ -756,22 +747,22 @@ bool AuthSocket::_HandleReconnectChallenge()
|
||||
|
||||
K.SetHexStr ((*result)[0].GetCString());
|
||||
|
||||
///- Sending response
|
||||
// Sending response
|
||||
ByteBuffer pkt;
|
||||
pkt << (uint8) AUTH_RECONNECT_CHALLENGE;
|
||||
pkt << (uint8) 0x00;
|
||||
_reconnectProof.SetRand(16 * 8);
|
||||
pkt.append(_reconnectProof.AsByteArray(16), 16); // 16 bytes random
|
||||
pkt.append(_reconnectProof.AsByteArray(16), 16); // 16 bytes random
|
||||
pkt << (uint64) 0x00 << (uint64) 0x00; // 16 bytes zeros
|
||||
socket().send((char const*)pkt.contents(), pkt.size());
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Reconnect Proof command handler
|
||||
// Reconnect Proof command handler
|
||||
bool AuthSocket::_HandleReconnectProof()
|
||||
{
|
||||
sLog.outStaticDebug("Entering _HandleReconnectProof");
|
||||
///- Read the packet
|
||||
// Read the packet
|
||||
sAuthReconnectProof_C lp;
|
||||
if (!socket().recv((char *)&lp, sizeof(sAuthReconnectProof_C)))
|
||||
return false;
|
||||
@@ -790,14 +781,14 @@ bool AuthSocket::_HandleReconnectProof()
|
||||
|
||||
if (!memcmp(sha.GetDigest(), lp.R2, SHA_DIGEST_LENGTH))
|
||||
{
|
||||
///- Sending response
|
||||
// Sending response
|
||||
ByteBuffer pkt;
|
||||
pkt << (uint8) AUTH_RECONNECT_PROOF;
|
||||
pkt << (uint8) 0x00;
|
||||
pkt << (uint16) 0x00; // 2 bytes zeros
|
||||
socket().send((char const*)pkt.contents(), pkt.size());
|
||||
|
||||
///- Set _authed to true!
|
||||
// Set _authed to true!
|
||||
_authed = true;
|
||||
|
||||
return true;
|
||||
@@ -810,7 +801,7 @@ bool AuthSocket::_HandleReconnectProof()
|
||||
}
|
||||
}
|
||||
|
||||
/// %Realm List command handler
|
||||
// Realm List command handler
|
||||
bool AuthSocket::_HandleRealmList()
|
||||
{
|
||||
sLog.outStaticDebug("Entering _HandleRealmList");
|
||||
@@ -819,7 +810,7 @@ bool AuthSocket::_HandleRealmList()
|
||||
|
||||
socket().recv_skip(5);
|
||||
|
||||
///- Get the user id (else close the connection)
|
||||
// Get the user id (else close the connection)
|
||||
// No SQL injection (prepared statement)
|
||||
|
||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_ACCIDBYNAME);
|
||||
@@ -835,22 +826,22 @@ bool AuthSocket::_HandleRealmList()
|
||||
Field* fields = result->Fetch();
|
||||
uint32 id = fields[0].GetUInt32();
|
||||
|
||||
///- Update realm list if need
|
||||
// Update realm list if need
|
||||
sRealmList->UpdateIfNeed();
|
||||
|
||||
///- Circle through realms in the RealmList and construct the return packet (including # of user characters in each realm)
|
||||
// Circle through realms in the RealmList and construct the return packet (including # of user characters in each realm)
|
||||
ByteBuffer pkt;
|
||||
|
||||
size_t RealmListSize = 0;
|
||||
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 (_expversion & POST_BC_EXP_FLAG) // 2.4.3 and 3.1.3 cliens
|
||||
{
|
||||
if (i->second.gamebuild != _build)
|
||||
continue;
|
||||
}
|
||||
else if (_expversion & PRE_BC_EXP_FLAG) // 1.12.1 and 1.12.2 clients are compatible with eachother
|
||||
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))
|
||||
continue;
|
||||
@@ -870,28 +861,30 @@ 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
|
||||
pkt << lock; // if 1, then realm locked
|
||||
pkt << i->second.color; // if 2, then realm is offline
|
||||
pkt << i->second.icon; // realm type
|
||||
if ( _expversion & POST_BC_EXP_FLAG ) // only 2.4.3 and 3.1.3 cliens
|
||||
pkt << lock; // if 1, then realm locked
|
||||
pkt << i->second.color; // if 2, then realm is offline
|
||||
pkt << i->first;
|
||||
pkt << i->second.address;
|
||||
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
|
||||
pkt << (uint8) 0x2C; // unk, may be realm number/id?
|
||||
if ( _expversion & POST_BC_EXP_FLAG ) // 2.4.3 and 3.1.3 clients
|
||||
pkt << (uint8) 0x2C; // unk, may be realm number/id?
|
||||
else
|
||||
pkt << (uint8) 0x0; //1.12.1 and 1.12.2 clients
|
||||
pkt << (uint8) 0x0; // 1.12.1 and 1.12.2 clients
|
||||
|
||||
++RealmListSize;
|
||||
}
|
||||
|
||||
if ( _expversion & POST_BC_EXP_FLAG )//2.4.3 and 3.1.3 cliens
|
||||
if ( _expversion & POST_BC_EXP_FLAG ) // 2.4.3 and 3.1.3 cliens
|
||||
{
|
||||
pkt << (uint8) 0x10;
|
||||
pkt << (uint8) 0x00;
|
||||
}else{//1.12.1 and 1.12.2 clients
|
||||
}
|
||||
else // 1.12.1 and 1.12.2 clients
|
||||
{
|
||||
pkt << (uint8) 0x00;
|
||||
pkt << (uint8) 0x02;
|
||||
}
|
||||
@@ -899,7 +892,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 cliens
|
||||
if (_expversion & POST_BC_EXP_FLAG) // only 2.4.3 and 3.1.3 clients
|
||||
RealmListSizeBuffer << (uint16)RealmListSize;
|
||||
else
|
||||
RealmListSizeBuffer << (uint32)RealmListSize;
|
||||
@@ -907,26 +900,26 @@ bool AuthSocket::_HandleRealmList()
|
||||
ByteBuffer hdr;
|
||||
hdr << (uint8) REALM_LIST;
|
||||
hdr << (uint16)(pkt.size() + RealmListSizeBuffer.size());
|
||||
hdr.append(RealmListSizeBuffer); // append RealmList's size buffer
|
||||
hdr.append(pkt); // append realms in the realmlist
|
||||
hdr.append(RealmListSizeBuffer); // append RealmList's size buffer
|
||||
hdr.append(pkt); // append realms in the realmlist
|
||||
|
||||
socket().send((char const*)hdr.contents(), hdr.size());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Resume patch transfer
|
||||
// Resume patch transfer
|
||||
bool AuthSocket::_HandleXferResume()
|
||||
{
|
||||
sLog.outStaticDebug("Entering _HandleXferResume");
|
||||
///- Check packet length and patch existence
|
||||
// Check packet length and patch existence
|
||||
if (socket().recv_len() < 9 || !pPatch)
|
||||
{
|
||||
sLog.outError("Error while resuming patch transfer (wrong packet)");
|
||||
return false;
|
||||
}
|
||||
|
||||
///- Launch a PatcherRunnable thread starting at given patch file offset
|
||||
// Launch a PatcherRunnable thread starting at given patch file offset
|
||||
uint64 start;
|
||||
socket().recv_skip(1);
|
||||
socket().recv((char*)&start,sizeof(start));
|
||||
@@ -936,32 +929,31 @@ bool AuthSocket::_HandleXferResume()
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Cancel patch transfer
|
||||
// Cancel patch transfer
|
||||
bool AuthSocket::_HandleXferCancel()
|
||||
{
|
||||
sLog.outStaticDebug("Entering _HandleXferCancel");
|
||||
|
||||
///- Close and delete the socket
|
||||
// Close and delete the socket
|
||||
socket().recv_skip(1); //clear input buffer
|
||||
|
||||
socket().shutdown();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Accept patch transfer
|
||||
// Accept patch transfer
|
||||
bool AuthSocket::_HandleXferAccept()
|
||||
{
|
||||
sLog.outStaticDebug("Entering _HandleXferAccept");
|
||||
|
||||
///- Check packet length and patch existence
|
||||
// Check packet length and patch existence
|
||||
if (!pPatch)
|
||||
{
|
||||
sLog.outError("Error while accepting patch transfer (wrong packet)");
|
||||
return false;
|
||||
}
|
||||
|
||||
///- Launch a PatcherRunnable thread, starting at the beginning of the patch file
|
||||
// Launch a PatcherRunnable thread, starting at the beginning of the patch file
|
||||
socket().recv_skip(1); // clear input buffer
|
||||
fseek(pPatch, 0, 0);
|
||||
|
||||
@@ -974,12 +966,10 @@ PatcherRunnable::PatcherRunnable(class AuthSocket * as)
|
||||
mySocket = as;
|
||||
}
|
||||
|
||||
/// Send content of patch file to the client
|
||||
void PatcherRunnable::run()
|
||||
{
|
||||
}
|
||||
// Send content of patch file to the client
|
||||
void PatcherRunnable::run() {}
|
||||
|
||||
/// Preload MD5 hashes of existing patch files on server
|
||||
// Preload MD5 hashes of existing patch files on server
|
||||
#ifndef _WIN32
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
@@ -1033,21 +1023,22 @@ void Patcher::LoadPatchesInfo()
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Calculate and store MD5 hash for a given patch file
|
||||
// Calculate and store MD5 hash for a given patch file
|
||||
void Patcher::LoadPatchMD5(char * szFileName)
|
||||
{
|
||||
///- Try to open the patch file
|
||||
// Try to open the patch file
|
||||
std::string path = "./patches/";
|
||||
path += szFileName;
|
||||
FILE *pPatch = fopen(path.c_str(), "rb");
|
||||
sLog.outDebug("Loading patch info from %s\n", path.c_str());
|
||||
|
||||
if (!pPatch)
|
||||
{
|
||||
sLog.outError("Error loading patch %s\n", path.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
///- Calculate the MD5 hash
|
||||
// Calculate the MD5 hash
|
||||
MD5_CTX ctx;
|
||||
MD5_Init(&ctx);
|
||||
uint8* buf = new uint8[512*1024];
|
||||
@@ -1060,12 +1051,12 @@ void Patcher::LoadPatchMD5(char * szFileName)
|
||||
delete [] buf;
|
||||
fclose(pPatch);
|
||||
|
||||
///- Store the result in the internal patch hash map
|
||||
// Store the result in the internal patch hash map
|
||||
_patches[path] = new PATCH_INFO;
|
||||
MD5_Final((uint8 *)&_patches[path]->md5, &ctx);
|
||||
}
|
||||
|
||||
/// Get cached MD5 hash for a given patch file
|
||||
// Get cached MD5 hash for a given patch file
|
||||
bool Patcher::GetHash(char * pat, uint8 mymd5[16])
|
||||
{
|
||||
for (Patches::iterator i = _patches.begin(); i != _patches.end(); ++i)
|
||||
@@ -1078,13 +1069,13 @@ bool Patcher::GetHash(char * pat, uint8 mymd5[16])
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Launch the patch hashing mechanism on object creation
|
||||
// Launch the patch hashing mechanism on object creation
|
||||
Patcher::Patcher()
|
||||
{
|
||||
LoadPatchesInfo();
|
||||
}
|
||||
|
||||
/// Empty and delete the patch map on termination
|
||||
// Empty and delete the patch map on termination
|
||||
Patcher::~Patcher()
|
||||
{
|
||||
for (Patches::iterator i = _patches.begin(); i != _patches.end(); ++i)
|
||||
|
||||
Reference in New Issue
Block a user