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)
|
#pragma pack(pop)
|
||||||
#endif
|
#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
|
class PatcherRunnable: public ACE_Based::Runnable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -167,7 +167,7 @@ typedef struct PATCH_INFO
|
|||||||
uint8 md5[MD5_DIGEST_LENGTH];
|
uint8 md5[MD5_DIGEST_LENGTH];
|
||||||
} PATCH_INFO;
|
} PATCH_INFO;
|
||||||
|
|
||||||
/// Caches MD5 hash of client patches present on the server
|
// Caches MD5 hash of client patches present on the server
|
||||||
class Patcher
|
class Patcher
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -198,10 +198,10 @@ const AuthHandler table[] =
|
|||||||
|
|
||||||
#define AUTH_TOTAL_COMMANDS sizeof(table)/sizeof(AuthHandler)
|
#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;
|
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)
|
AuthSocket::AuthSocket(RealmSocket& socket) : socket_(socket)
|
||||||
{
|
{
|
||||||
N.SetHexStr("894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7");
|
N.SetHexStr("894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7");
|
||||||
@@ -210,12 +210,10 @@ AuthSocket::AuthSocket(RealmSocket& socket) : socket_(socket)
|
|||||||
_accountSecurityLevel = SEC_PLAYER;
|
_accountSecurityLevel = SEC_PLAYER;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Close patch file descriptor before leaving
|
// Close patch file descriptor before leaving
|
||||||
AuthSocket::~AuthSocket(void)
|
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)
|
void AuthSocket::OnAccept(void)
|
||||||
{
|
{
|
||||||
sLog.outBasic("Accepting connection from '%s'", socket().get_remote_address().c_str());
|
sLog.outBasic("Accepting connection from '%s'", socket().get_remote_address().c_str());
|
||||||
@@ -226,7 +224,7 @@ void AuthSocket::OnClose(void)
|
|||||||
sLog.outDebug("AuthSocket::OnClose");
|
sLog.outDebug("AuthSocket::OnClose");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read the packet from the client
|
// Read the packet from the client
|
||||||
void AuthSocket::OnRead()
|
void AuthSocket::OnRead()
|
||||||
{
|
{
|
||||||
uint8 _cmd;
|
uint8 _cmd;
|
||||||
@@ -237,7 +235,7 @@ void AuthSocket::OnRead()
|
|||||||
|
|
||||||
size_t i;
|
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)
|
for (i = 0; i < AUTH_TOTAL_COMMANDS; ++i)
|
||||||
{
|
{
|
||||||
if ((uint8)table[i].cmd == _cmd &&
|
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)
|
void AuthSocket::_SetVSFields(const std::string& rI)
|
||||||
{
|
{
|
||||||
s.SetRand(s_BYTE_SIZE * 8);
|
s.SetRand(s_BYTE_SIZE * 8);
|
||||||
@@ -303,14 +301,14 @@ void AuthSocket::_SetVSFields(const std::string& rI)
|
|||||||
OPENSSL_free((void*)s_hex);
|
OPENSSL_free((void*)s_hex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Logon Challenge command handler
|
// Logon Challenge command handler
|
||||||
bool AuthSocket::_HandleLogonChallenge()
|
bool AuthSocket::_HandleLogonChallenge()
|
||||||
{
|
{
|
||||||
sLog.outStaticDebug("Entering _HandleLogonChallenge");
|
sLog.outStaticDebug("Entering _HandleLogonChallenge");
|
||||||
if (socket().recv_len() < sizeof(sAuthLogonChallenge_C))
|
if (socket().recv_len() < sizeof(sAuthLogonChallenge_C))
|
||||||
return false;
|
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;
|
std::vector<uint8> buf;
|
||||||
buf.resize(4);
|
buf.resize(4);
|
||||||
|
|
||||||
@@ -328,7 +326,7 @@ bool AuthSocket::_HandleLogonChallenge()
|
|||||||
buf[buf.size() - 1] = 0;
|
buf[buf.size() - 1] = 0;
|
||||||
sAuthLogonChallenge_C *ch = (sAuthLogonChallenge_C*)&buf[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);
|
socket().recv((char *)&buf[4], remaining);
|
||||||
sLog.outStaticDebug("[AuthChallenge] got full packet, %#04x bytes", ch->size);
|
sLog.outStaticDebug("[AuthChallenge] got full packet, %#04x bytes", ch->size);
|
||||||
sLog.outStaticDebug("[AuthChallenge] name(%d): '%s'", ch->I_len, ch->I);
|
sLog.outStaticDebug("[AuthChallenge] name(%d): '%s'", ch->I_len, ch->I);
|
||||||
@@ -349,15 +347,10 @@ bool AuthSocket::_HandleLogonChallenge()
|
|||||||
_build = ch->build;
|
_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);
|
||||||
|
|
||||||
///- Normalize account name
|
|
||||||
//utf8ToUpperOnlyLatin(_login); -- client already send account in expected form
|
|
||||||
|
|
||||||
_build = ch->build;
|
|
||||||
|
|
||||||
pkt << (uint8) AUTH_LOGON_CHALLENGE;
|
pkt << (uint8) AUTH_LOGON_CHALLENGE;
|
||||||
pkt << (uint8) 0x00;
|
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.Execute(
|
||||||
LoginDatabase.GetPreparedStatement(LOGIN_SET_EXPIREDIPBANS)
|
LoginDatabase.GetPreparedStatement(LOGIN_SET_EXPIREDIPBANS)
|
||||||
);
|
);
|
||||||
@@ -373,7 +366,7 @@ bool AuthSocket::_HandleLogonChallenge()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
///- Get the account details from the account table
|
// Get the account details from the account table
|
||||||
// No SQL injection (prepared statement)
|
// No SQL injection (prepared statement)
|
||||||
stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_LOGONCHALLENGE);
|
stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_LOGONCHALLENGE);
|
||||||
stmt->setString(0, _login);
|
stmt->setString(0, _login);
|
||||||
@@ -383,12 +376,13 @@ bool AuthSocket::_HandleLogonChallenge()
|
|||||||
{
|
{
|
||||||
Field* fields = res2->Fetch();
|
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;
|
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] Account '%s' is locked to IP - '%s'", _login.c_str(), fields[3].GetCString());
|
||||||
sLog.outStaticDebug("[AuthChallenge] Player address is '%s'", ip_address.c_str());
|
sLog.outStaticDebug("[AuthChallenge] Player address is '%s'", ip_address.c_str());
|
||||||
|
|
||||||
if (strcmp(fields[3].GetCString(), ip_address.c_str()))
|
if (strcmp(fields[3].GetCString(), ip_address.c_str()))
|
||||||
{
|
{
|
||||||
sLog.outStaticDebug("[AuthChallenge] Account IP differs");
|
sLog.outStaticDebug("[AuthChallenge] Account IP differs");
|
||||||
@@ -408,7 +402,7 @@ bool AuthSocket::_HandleLogonChallenge()
|
|||||||
LoginDatabase.GetPreparedStatement(LOGIN_SET_EXPIREDACCBANS)
|
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 = LoginDatabase.GetPreparedStatement(LOGIN_GET_ACCBANNED);
|
||||||
stmt->setUInt32(0, fields[1].GetUInt32());
|
stmt->setUInt32(0, fields[1].GetUInt32());
|
||||||
PreparedQueryResult banresult = LoginDatabase.Query(stmt);
|
PreparedQueryResult banresult = LoginDatabase.Query(stmt);
|
||||||
@@ -427,10 +421,10 @@ bool AuthSocket::_HandleLogonChallenge()
|
|||||||
}
|
}
|
||||||
else
|
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();
|
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 databaseV = fields[5].GetString();
|
||||||
std::string databaseS = fields[6].GetString();
|
std::string databaseS = fields[6].GetString();
|
||||||
|
|
||||||
@@ -454,7 +448,7 @@ bool AuthSocket::_HandleLogonChallenge()
|
|||||||
BigNumber unk3;
|
BigNumber unk3;
|
||||||
unk3.SetRand(16 * 8);
|
unk3.SetRand(16 * 8);
|
||||||
|
|
||||||
///- Fill the response packet with the result
|
// Fill the response packet with the result
|
||||||
pkt << uint8(WOW_SUCCESS);
|
pkt << uint8(WOW_SUCCESS);
|
||||||
|
|
||||||
// B may be calculated < 32B so we force minimal length to 32B
|
// B may be calculated < 32B so we force minimal length to 32B
|
||||||
@@ -493,42 +487,40 @@ bool AuthSocket::_HandleLogonChallenge()
|
|||||||
for (int i = 0; i < 4; ++i)
|
for (int i = 0; i < 4; ++i)
|
||||||
_localizationName[i] = ch->country[4-i-1];
|
_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;
|
pkt<< (uint8) WOW_FAIL_UNKNOWN_ACCOUNT;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
socket().send((char const*)pkt.contents(), pkt.size());
|
socket().send((char const*)pkt.contents(), pkt.size());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Logon Proof command handler
|
// Logon Proof command handler
|
||||||
bool AuthSocket::_HandleLogonProof()
|
bool AuthSocket::_HandleLogonProof()
|
||||||
{
|
{
|
||||||
sLog.outStaticDebug("Entering _HandleLogonProof");
|
sLog.outStaticDebug("Entering _HandleLogonProof");
|
||||||
///- Read the packet
|
// Read the packet
|
||||||
sAuthLogonProof_C lp;
|
sAuthLogonProof_C lp;
|
||||||
|
|
||||||
if (!socket().recv((char *)&lp, sizeof(sAuthLogonProof_C)))
|
if (!socket().recv((char *)&lp, sizeof(sAuthLogonProof_C)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/// <ul><li> If the client has no valid version
|
// If the client has no valid version
|
||||||
if (_expversion == NO_VALID_EXP_FLAG)
|
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");
|
sLog.outDebug("Client with invalid version, patching is not implemented");
|
||||||
socket().shutdown();
|
socket().shutdown();
|
||||||
return true;
|
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;
|
BigNumber A;
|
||||||
|
|
||||||
A.SetBinary(lp.A, 32);
|
A.SetBinary(lp.A, 32);
|
||||||
@@ -551,28 +543,27 @@ bool AuthSocket::_HandleLogonProof()
|
|||||||
uint8 t1[16];
|
uint8 t1[16];
|
||||||
uint8 vK[40];
|
uint8 vK[40];
|
||||||
memcpy(t, S.AsByteArray(32), 32);
|
memcpy(t, S.AsByteArray(32), 32);
|
||||||
|
|
||||||
for (int i = 0; i < 16; ++i)
|
for (int i = 0; i < 16; ++i)
|
||||||
{
|
|
||||||
t1[i] = t[i * 2];
|
t1[i] = t[i * 2];
|
||||||
}
|
|
||||||
sha.Initialize();
|
sha.Initialize();
|
||||||
sha.UpdateData(t1, 16);
|
sha.UpdateData(t1, 16);
|
||||||
sha.Finalize();
|
sha.Finalize();
|
||||||
|
|
||||||
for (int i = 0; i < 20; ++i)
|
for (int i = 0; i < 20; ++i)
|
||||||
{
|
|
||||||
vK[i * 2] = sha.GetDigest()[i];
|
vK[i * 2] = sha.GetDigest()[i];
|
||||||
}
|
|
||||||
for (int i = 0; i < 16; ++i)
|
for (int i = 0; i < 16; ++i)
|
||||||
{
|
|
||||||
t1[i] = t[i * 2 + 1];
|
t1[i] = t[i * 2 + 1];
|
||||||
}
|
|
||||||
sha.Initialize();
|
sha.Initialize();
|
||||||
sha.UpdateData(t1, 16);
|
sha.UpdateData(t1, 16);
|
||||||
sha.Finalize();
|
sha.Finalize();
|
||||||
|
|
||||||
for (int i = 0; i < 20; ++i)
|
for (int i = 0; i < 20; ++i)
|
||||||
{
|
|
||||||
vK[i * 2 + 1] = sha.GetDigest()[i];
|
vK[i * 2 + 1] = sha.GetDigest()[i];
|
||||||
}
|
|
||||||
K.SetBinary(vK, 40);
|
K.SetBinary(vK, 40);
|
||||||
|
|
||||||
uint8 hash[20];
|
uint8 hash[20];
|
||||||
@@ -584,10 +575,10 @@ bool AuthSocket::_HandleLogonProof()
|
|||||||
sha.Initialize();
|
sha.Initialize();
|
||||||
sha.UpdateBigNumbers(&g, NULL);
|
sha.UpdateBigNumbers(&g, NULL);
|
||||||
sha.Finalize();
|
sha.Finalize();
|
||||||
|
|
||||||
for (int i = 0; i < 20; ++i)
|
for (int i = 0; i < 20; ++i)
|
||||||
{
|
|
||||||
hash[i] ^= sha.GetDigest()[i];
|
hash[i] ^= sha.GetDigest()[i];
|
||||||
}
|
|
||||||
BigNumber t3;
|
BigNumber t3;
|
||||||
t3.SetBinary(hash, 20);
|
t3.SetBinary(hash, 20);
|
||||||
|
|
||||||
@@ -605,12 +596,12 @@ bool AuthSocket::_HandleLogonProof()
|
|||||||
BigNumber M;
|
BigNumber M;
|
||||||
M.SetBinary(sha.GetDigest(), 20);
|
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))
|
if (!memcmp(M.AsByteArray(), lp.M1, 20))
|
||||||
{
|
{
|
||||||
sLog.outBasic("User '%s' successfully authenticated", _login.c_str());
|
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
|
// No SQL injection (escaped user name) and IP address as received by socket
|
||||||
const char* K_hex = K.AsHexStr();
|
const char* K_hex = K.AsHexStr();
|
||||||
|
|
||||||
@@ -623,7 +614,7 @@ bool AuthSocket::_HandleLogonProof()
|
|||||||
|
|
||||||
OPENSSL_free((void*)K_hex);
|
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.Initialize();
|
||||||
sha.UpdateBigNumbers(&A, &M, &K, NULL);
|
sha.UpdateBigNumbers(&A, &M, &K, NULL);
|
||||||
sha.Finalize();
|
sha.Finalize();
|
||||||
@@ -651,7 +642,7 @@ bool AuthSocket::_HandleLogonProof()
|
|||||||
socket().send((char *)&proof, sizeof(proof));
|
socket().send((char *)&proof, sizeof(proof));
|
||||||
}
|
}
|
||||||
|
|
||||||
///- Set _authed to true!
|
// Set _authed to true!
|
||||||
_authed = true;
|
_authed = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -710,14 +701,14 @@ bool AuthSocket::_HandleLogonProof()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reconnect Challenge command handler
|
// Reconnect Challenge command handler
|
||||||
bool AuthSocket::_HandleReconnectChallenge()
|
bool AuthSocket::_HandleReconnectChallenge()
|
||||||
{
|
{
|
||||||
sLog.outStaticDebug("Entering _HandleReconnectChallenge");
|
sLog.outStaticDebug("Entering _HandleReconnectChallenge");
|
||||||
if (socket().recv_len() < sizeof(sAuthLogonChallenge_C))
|
if (socket().recv_len() < sizeof(sAuthLogonChallenge_C))
|
||||||
return false;
|
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;
|
std::vector<uint8> buf;
|
||||||
buf.resize(4);
|
buf.resize(4);
|
||||||
|
|
||||||
@@ -735,7 +726,7 @@ bool AuthSocket::_HandleReconnectChallenge()
|
|||||||
buf[buf.size() - 1] = 0;
|
buf[buf.size() - 1] = 0;
|
||||||
sAuthLogonChallenge_C *ch = (sAuthLogonChallenge_C*)&buf[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);
|
socket().recv((char *)&buf[4], remaining);
|
||||||
sLog.outStaticDebug("[ReconnectChallenge] got full packet, %#04x bytes", ch->size);
|
sLog.outStaticDebug("[ReconnectChallenge] got full packet, %#04x bytes", ch->size);
|
||||||
sLog.outStaticDebug("[ReconnectChallenge] name(%d): '%s'", ch->I_len, ch->I);
|
sLog.outStaticDebug("[ReconnectChallenge] name(%d): '%s'", ch->I_len, ch->I);
|
||||||
@@ -756,7 +747,7 @@ bool AuthSocket::_HandleReconnectChallenge()
|
|||||||
|
|
||||||
K.SetHexStr ((*result)[0].GetCString());
|
K.SetHexStr ((*result)[0].GetCString());
|
||||||
|
|
||||||
///- Sending response
|
// Sending response
|
||||||
ByteBuffer pkt;
|
ByteBuffer pkt;
|
||||||
pkt << (uint8) AUTH_RECONNECT_CHALLENGE;
|
pkt << (uint8) AUTH_RECONNECT_CHALLENGE;
|
||||||
pkt << (uint8) 0x00;
|
pkt << (uint8) 0x00;
|
||||||
@@ -767,11 +758,11 @@ bool AuthSocket::_HandleReconnectChallenge()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reconnect Proof command handler
|
// Reconnect Proof command handler
|
||||||
bool AuthSocket::_HandleReconnectProof()
|
bool AuthSocket::_HandleReconnectProof()
|
||||||
{
|
{
|
||||||
sLog.outStaticDebug("Entering _HandleReconnectProof");
|
sLog.outStaticDebug("Entering _HandleReconnectProof");
|
||||||
///- Read the packet
|
// Read the packet
|
||||||
sAuthReconnectProof_C lp;
|
sAuthReconnectProof_C lp;
|
||||||
if (!socket().recv((char *)&lp, sizeof(sAuthReconnectProof_C)))
|
if (!socket().recv((char *)&lp, sizeof(sAuthReconnectProof_C)))
|
||||||
return false;
|
return false;
|
||||||
@@ -790,14 +781,14 @@ bool AuthSocket::_HandleReconnectProof()
|
|||||||
|
|
||||||
if (!memcmp(sha.GetDigest(), lp.R2, SHA_DIGEST_LENGTH))
|
if (!memcmp(sha.GetDigest(), lp.R2, SHA_DIGEST_LENGTH))
|
||||||
{
|
{
|
||||||
///- Sending response
|
// Sending response
|
||||||
ByteBuffer pkt;
|
ByteBuffer pkt;
|
||||||
pkt << (uint8) AUTH_RECONNECT_PROOF;
|
pkt << (uint8) AUTH_RECONNECT_PROOF;
|
||||||
pkt << (uint8) 0x00;
|
pkt << (uint8) 0x00;
|
||||||
pkt << (uint16) 0x00; // 2 bytes zeros
|
pkt << (uint16) 0x00; // 2 bytes zeros
|
||||||
socket().send((char const*)pkt.contents(), pkt.size());
|
socket().send((char const*)pkt.contents(), pkt.size());
|
||||||
|
|
||||||
///- Set _authed to true!
|
// Set _authed to true!
|
||||||
_authed = true;
|
_authed = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -810,7 +801,7 @@ bool AuthSocket::_HandleReconnectProof()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// %Realm List command handler
|
// Realm List command handler
|
||||||
bool AuthSocket::_HandleRealmList()
|
bool AuthSocket::_HandleRealmList()
|
||||||
{
|
{
|
||||||
sLog.outStaticDebug("Entering _HandleRealmList");
|
sLog.outStaticDebug("Entering _HandleRealmList");
|
||||||
@@ -819,7 +810,7 @@ bool AuthSocket::_HandleRealmList()
|
|||||||
|
|
||||||
socket().recv_skip(5);
|
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)
|
// No SQL injection (prepared statement)
|
||||||
|
|
||||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_ACCIDBYNAME);
|
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_ACCIDBYNAME);
|
||||||
@@ -835,10 +826,10 @@ bool AuthSocket::_HandleRealmList()
|
|||||||
Field* fields = result->Fetch();
|
Field* fields = result->Fetch();
|
||||||
uint32 id = fields[0].GetUInt32();
|
uint32 id = fields[0].GetUInt32();
|
||||||
|
|
||||||
///- Update realm list if need
|
// Update realm list if need
|
||||||
sRealmList->UpdateIfNeed();
|
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;
|
ByteBuffer pkt;
|
||||||
|
|
||||||
size_t RealmListSize = 0;
|
size_t RealmListSize = 0;
|
||||||
@@ -891,7 +882,9 @@ bool AuthSocket::_HandleRealmList()
|
|||||||
{
|
{
|
||||||
pkt << (uint8) 0x10;
|
pkt << (uint8) 0x10;
|
||||||
pkt << (uint8) 0x00;
|
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) 0x00;
|
||||||
pkt << (uint8) 0x02;
|
pkt << (uint8) 0x02;
|
||||||
}
|
}
|
||||||
@@ -899,7 +892,7 @@ bool AuthSocket::_HandleRealmList()
|
|||||||
// make a ByteBuffer which stores the RealmList's size
|
// make a ByteBuffer which stores the RealmList's size
|
||||||
ByteBuffer RealmListSizeBuffer;
|
ByteBuffer RealmListSizeBuffer;
|
||||||
RealmListSizeBuffer << (uint32)0;
|
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;
|
RealmListSizeBuffer << (uint16)RealmListSize;
|
||||||
else
|
else
|
||||||
RealmListSizeBuffer << (uint32)RealmListSize;
|
RealmListSizeBuffer << (uint32)RealmListSize;
|
||||||
@@ -915,18 +908,18 @@ bool AuthSocket::_HandleRealmList()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resume patch transfer
|
// Resume patch transfer
|
||||||
bool AuthSocket::_HandleXferResume()
|
bool AuthSocket::_HandleXferResume()
|
||||||
{
|
{
|
||||||
sLog.outStaticDebug("Entering _HandleXferResume");
|
sLog.outStaticDebug("Entering _HandleXferResume");
|
||||||
///- Check packet length and patch existence
|
// Check packet length and patch existence
|
||||||
if (socket().recv_len() < 9 || !pPatch)
|
if (socket().recv_len() < 9 || !pPatch)
|
||||||
{
|
{
|
||||||
sLog.outError("Error while resuming patch transfer (wrong packet)");
|
sLog.outError("Error while resuming patch transfer (wrong packet)");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
///- Launch a PatcherRunnable thread starting at given patch file offset
|
// Launch a PatcherRunnable thread starting at given patch file offset
|
||||||
uint64 start;
|
uint64 start;
|
||||||
socket().recv_skip(1);
|
socket().recv_skip(1);
|
||||||
socket().recv((char*)&start,sizeof(start));
|
socket().recv((char*)&start,sizeof(start));
|
||||||
@@ -936,32 +929,31 @@ bool AuthSocket::_HandleXferResume()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Cancel patch transfer
|
// Cancel patch transfer
|
||||||
bool AuthSocket::_HandleXferCancel()
|
bool AuthSocket::_HandleXferCancel()
|
||||||
{
|
{
|
||||||
sLog.outStaticDebug("Entering _HandleXferCancel");
|
sLog.outStaticDebug("Entering _HandleXferCancel");
|
||||||
|
|
||||||
///- Close and delete the socket
|
// Close and delete the socket
|
||||||
socket().recv_skip(1); //clear input buffer
|
socket().recv_skip(1); //clear input buffer
|
||||||
|
|
||||||
socket().shutdown();
|
socket().shutdown();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Accept patch transfer
|
// Accept patch transfer
|
||||||
bool AuthSocket::_HandleXferAccept()
|
bool AuthSocket::_HandleXferAccept()
|
||||||
{
|
{
|
||||||
sLog.outStaticDebug("Entering _HandleXferAccept");
|
sLog.outStaticDebug("Entering _HandleXferAccept");
|
||||||
|
|
||||||
///- Check packet length and patch existence
|
// Check packet length and patch existence
|
||||||
if (!pPatch)
|
if (!pPatch)
|
||||||
{
|
{
|
||||||
sLog.outError("Error while accepting patch transfer (wrong packet)");
|
sLog.outError("Error while accepting patch transfer (wrong packet)");
|
||||||
return false;
|
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
|
socket().recv_skip(1); // clear input buffer
|
||||||
fseek(pPatch, 0, 0);
|
fseek(pPatch, 0, 0);
|
||||||
|
|
||||||
@@ -974,12 +966,10 @@ PatcherRunnable::PatcherRunnable(class AuthSocket * as)
|
|||||||
mySocket = as;
|
mySocket = as;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send content of patch file to the client
|
// Send content of patch file to the client
|
||||||
void PatcherRunnable::run()
|
void PatcherRunnable::run() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Preload MD5 hashes of existing patch files on server
|
// Preload MD5 hashes of existing patch files on server
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -1033,21 +1023,22 @@ void Patcher::LoadPatchesInfo()
|
|||||||
}
|
}
|
||||||
#endif
|
#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)
|
void Patcher::LoadPatchMD5(char * szFileName)
|
||||||
{
|
{
|
||||||
///- Try to open the patch file
|
// Try to open the patch file
|
||||||
std::string path = "./patches/";
|
std::string path = "./patches/";
|
||||||
path += szFileName;
|
path += szFileName;
|
||||||
FILE *pPatch = fopen(path.c_str(), "rb");
|
FILE *pPatch = fopen(path.c_str(), "rb");
|
||||||
sLog.outDebug("Loading patch info from %s\n", path.c_str());
|
sLog.outDebug("Loading patch info from %s\n", path.c_str());
|
||||||
|
|
||||||
if (!pPatch)
|
if (!pPatch)
|
||||||
{
|
{
|
||||||
sLog.outError("Error loading patch %s\n", path.c_str());
|
sLog.outError("Error loading patch %s\n", path.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
///- Calculate the MD5 hash
|
// Calculate the MD5 hash
|
||||||
MD5_CTX ctx;
|
MD5_CTX ctx;
|
||||||
MD5_Init(&ctx);
|
MD5_Init(&ctx);
|
||||||
uint8* buf = new uint8[512*1024];
|
uint8* buf = new uint8[512*1024];
|
||||||
@@ -1060,12 +1051,12 @@ void Patcher::LoadPatchMD5(char * szFileName)
|
|||||||
delete [] buf;
|
delete [] buf;
|
||||||
fclose(pPatch);
|
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;
|
_patches[path] = new PATCH_INFO;
|
||||||
MD5_Final((uint8 *)&_patches[path]->md5, &ctx);
|
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])
|
bool Patcher::GetHash(char * pat, uint8 mymd5[16])
|
||||||
{
|
{
|
||||||
for (Patches::iterator i = _patches.begin(); i != _patches.end(); ++i)
|
for (Patches::iterator i = _patches.begin(); i != _patches.end(); ++i)
|
||||||
@@ -1078,13 +1069,13 @@ bool Patcher::GetHash(char * pat, uint8 mymd5[16])
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Launch the patch hashing mechanism on object creation
|
// Launch the patch hashing mechanism on object creation
|
||||||
Patcher::Patcher()
|
Patcher::Patcher()
|
||||||
{
|
{
|
||||||
LoadPatchesInfo();
|
LoadPatchesInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Empty and delete the patch map on termination
|
// Empty and delete the patch map on termination
|
||||||
Patcher::~Patcher()
|
Patcher::~Patcher()
|
||||||
{
|
{
|
||||||
for (Patches::iterator i = _patches.begin(); i != _patches.end(); ++i)
|
for (Patches::iterator i = _patches.begin(); i != _patches.end(); ++i)
|
||||||
|
|||||||
Reference in New Issue
Block a user