chore(Core/Authserver): restyle authserver library with astyle (#3464)

This commit is contained in:
Kargatum
2020-09-11 09:55:28 +07:00
committed by GitHub
parent c197181468
commit 3a8ca806c5
4 changed files with 70 additions and 69 deletions
+30 -29
View File
@@ -154,7 +154,7 @@ public:
Patches::const_iterator begin() const { return _patches.begin(); } Patches::const_iterator begin() const { return _patches.begin(); }
Patches::const_iterator end() const { return _patches.end(); } Patches::const_iterator end() const { return _patches.end(); }
void LoadPatchMD5(char*); void LoadPatchMD5(char*);
bool GetHash(char * pat, uint8 mymd5[16]); bool GetHash(char* pat, uint8 mymd5[16]);
private: private:
void LoadPatchesInfo(); void LoadPatchesInfo();
@@ -206,16 +206,16 @@ void AuthSocket::OnClose(void)
// Read the packet from the client // Read the packet from the client
void AuthSocket::OnRead() void AuthSocket::OnRead()
{ {
#define MAX_AUTH_LOGON_CHALLENGES_IN_A_ROW 3 #define MAX_AUTH_LOGON_CHALLENGES_IN_A_ROW 3
uint32 challengesInARow = 0; uint32 challengesInARow = 0;
#define MAX_AUTH_GET_REALM_LIST 10 #define MAX_AUTH_GET_REALM_LIST 10
uint32 challengesInARowRealmList = 0; uint32 challengesInARowRealmList = 0;
uint8 _cmd; uint8 _cmd;
while (1) while (1)
{ {
if (!socket().recv_soft((char *)&_cmd, 1)) if (!socket().recv_soft((char*)&_cmd, 1))
return; return;
if (_cmd == AUTH_LOGON_CHALLENGE) if (_cmd == AUTH_LOGON_CHALLENGE)
@@ -228,7 +228,8 @@ void AuthSocket::OnRead()
return; return;
} }
} }
else if (_cmd == REALM_LIST) { else if (_cmd == REALM_LIST)
{
challengesInARowRealmList++; challengesInARowRealmList++;
if (challengesInARowRealmList == MAX_AUTH_GET_REALM_LIST) if (challengesInARowRealmList == MAX_AUTH_GET_REALM_LIST)
{ {
@@ -297,7 +298,7 @@ void AuthSocket::_SetVSFields(const std::string& rI)
v = g.ModExp(x, N); v = g.ModExp(x, N);
// No SQL injection (username escaped) // No SQL injection (username escaped)
char *v_hex, *s_hex; char* v_hex, *s_hex;
v_hex = v.AsHexStr(); v_hex = v.AsHexStr();
s_hex = s.AsHexStr(); s_hex = s.AsHexStr();
@@ -342,7 +343,7 @@ bool AuthSocket::_HandleLogonChallenge()
socket().send((char const*)pkt.contents(), pkt.size()); socket().send((char const*)pkt.contents(), pkt.size());
return true; return true;
} }
if (LastLoginAttemptCleanTime+60 < currTime) if (LastLoginAttemptCleanTime + 60 < currTime)
{ {
LastLoginAttemptTimeForIP.clear(); LastLoginAttemptTimeForIP.clear();
LastLoginAttemptCleanTime = currTime; LastLoginAttemptCleanTime = currTime;
@@ -355,11 +356,11 @@ bool AuthSocket::_HandleLogonChallenge()
std::vector<uint8> buf; std::vector<uint8> buf;
buf.resize(4); buf.resize(4);
socket().recv((char *)&buf[0], 4); socket().recv((char*)&buf[0], 4);
EndianConvertPtr<uint16>(&buf[0]); EndianConvertPtr<uint16>(&buf[0]);
uint16 remaining = ((sAuthLogonChallenge_C *)&buf[0])->size; uint16 remaining = ((sAuthLogonChallenge_C*)&buf[0])->size;
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) #if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "[AuthChallenge] got header, body is %#04x bytes", remaining); sLog->outDebug(LOG_FILTER_NETWORKIO, "[AuthChallenge] got header, body is %#04x bytes", remaining);
#endif #endif
@@ -370,10 +371,10 @@ bool AuthSocket::_HandleLogonChallenge()
//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.resize(remaining + buf.size() + 1);
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);
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) #if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "[AuthChallenge] got full packet, %#04x bytes", ch->size); sLog->outDebug(LOG_FILTER_NETWORKIO, "[AuthChallenge] got full packet, %#04x bytes", ch->size);
sLog->outDebug(LOG_FILTER_NETWORKIO, "[AuthChallenge] name(%d): '%s'", ch->I_len, ch->I); sLog->outDebug(LOG_FILTER_NETWORKIO, "[AuthChallenge] name(%d): '%s'", ch->I_len, ch->I);
@@ -416,7 +417,7 @@ bool AuthSocket::_HandleLogonChallenge()
{ {
pkt << uint8(WOW_FAIL_BANNED); pkt << uint8(WOW_FAIL_BANNED);
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) #if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "'%s:%d' [AuthChallenge] Banned ip tries to login!",socket().getRemoteAddress().c_str(), socket().getRemotePort()); sLog->outDebug(LOG_FILTER_NETWORKIO, "'%s:%d' [AuthChallenge] Banned ip tries to login!", socket().getRemoteAddress().c_str(), socket().getRemotePort());
#endif #endif
} }
else else
@@ -577,7 +578,7 @@ bool AuthSocket::_HandleLogonChallenge()
_localizationName.resize(4); _localizationName.resize(4);
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];
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) #if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
@@ -606,7 +607,7 @@ bool AuthSocket::_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;
_status = STATUS_CLOSED; _status = STATUS_CLOSED;
@@ -707,9 +708,9 @@ bool AuthSocket::_HandleLogonProof()
// 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();
PreparedStatement *stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_LOGONPROOF); PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_LOGONPROOF);
stmt->setString(0, K_hex); stmt->setString(0, K_hex);
stmt->setString(1, socket().getRemoteAddress().c_str()); stmt->setString(1, socket().getRemoteAddress().c_str());
stmt->setUInt32(2, GetLocaleByName(_localizationName)); stmt->setUInt32(2, GetLocaleByName(_localizationName));
@@ -752,7 +753,7 @@ bool AuthSocket::_HandleLogonProof()
proof.unk1 = 0x00800000; // Accountflags. 0x01 = GM, 0x08 = Trial, 0x00800000 = Pro pass (arena tournament) proof.unk1 = 0x00800000; // Accountflags. 0x01 = GM, 0x08 = Trial, 0x00800000 = Pro pass (arena tournament)
proof.unk2 = 0x00; // SurveyId proof.unk2 = 0x00; // SurveyId
proof.unk3 = 0x00; proof.unk3 = 0x00;
socket().send((char *)&proof, sizeof(proof)); socket().send((char*)&proof, sizeof(proof));
} }
else else
{ {
@@ -761,7 +762,7 @@ bool AuthSocket::_HandleLogonProof()
proof.cmd = AUTH_LOGON_PROOF; proof.cmd = AUTH_LOGON_PROOF;
proof.error = 0; proof.error = 0;
proof.unk2 = 0x00; proof.unk2 = 0x00;
socket().send((char *)&proof, sizeof(proof)); socket().send((char*)&proof, sizeof(proof));
} }
///- Set _status to authed! ///- Set _status to authed!
@@ -853,11 +854,11 @@ bool AuthSocket::_HandleReconnectChallenge()
std::vector<uint8> buf; std::vector<uint8> buf;
buf.resize(4); buf.resize(4);
socket().recv((char *)&buf[0], 4); socket().recv((char*)&buf[0], 4);
EndianConvertPtr<uint16>(&buf[0]); EndianConvertPtr<uint16>(&buf[0]);
uint16 remaining = ((sAuthLogonChallenge_C *)&buf[0])->size; uint16 remaining = ((sAuthLogonChallenge_C*)&buf[0])->size;
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) #if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "[ReconnectChallenge] got header, body is %#04x bytes", remaining); sLog->outDebug(LOG_FILTER_NETWORKIO, "[ReconnectChallenge] got header, body is %#04x bytes", remaining);
#endif #endif
@@ -871,10 +872,10 @@ bool AuthSocket::_HandleReconnectChallenge()
// 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.resize(remaining + buf.size() + 1);
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);
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) #if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "[ReconnectChallenge] got full packet, %#04x bytes", ch->size); sLog->outDebug(LOG_FILTER_NETWORKIO, "[ReconnectChallenge] got full packet, %#04x bytes", ch->size);
sLog->outDebug(LOG_FILTER_NETWORKIO, "[ReconnectChallenge] name(%d): '%s'", ch->I_len, ch->I); sLog->outDebug(LOG_FILTER_NETWORKIO, "[ReconnectChallenge] name(%d): '%s'", ch->I_len, ch->I);
@@ -933,7 +934,7 @@ bool AuthSocket::_HandleReconnectProof()
#endif #endif
// 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;
_status = STATUS_CLOSED; _status = STATUS_CLOSED;
@@ -1032,7 +1033,7 @@ bool AuthSocket::_HandleRealmList()
size_t RealmListSize = 0; size_t RealmListSize = 0;
for (RealmList::RealmMap::const_iterator i = sRealmList->begin(); i != sRealmList->end(); ++i) for (RealmList::RealmMap::const_iterator i = sRealmList->begin(); i != sRealmList->end(); ++i)
{ {
const Realm &realm = i->second; const Realm& realm = i->second;
// don't work with realms which not compatible with the client // don't work with realms which not compatible with the client
bool okBuild = ((_expversion & POST_BC_EXP_FLAG) && realm.gamebuild == _build) || ((_expversion & PRE_BC_EXP_FLAG) && !AuthHelper::IsPreBCAcceptedClientBuild(realm.gamebuild)); bool okBuild = ((_expversion & POST_BC_EXP_FLAG) && realm.gamebuild == _build) || ((_expversion & PRE_BC_EXP_FLAG) && !AuthHelper::IsPreBCAcceptedClientBuild(realm.gamebuild));
@@ -1199,8 +1200,8 @@ void PatcherRunnable::run() { }
#include <errno.h> #include <errno.h>
void Patcher::LoadPatchesInfo() void Patcher::LoadPatchesInfo()
{ {
DIR *dirp; DIR* dirp;
struct dirent *dp; struct dirent* dp;
dirp = opendir("./patches/"); dirp = opendir("./patches/");
if (!dirp) if (!dirp)
@@ -1248,7 +1249,7 @@ 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/";
@@ -1280,11 +1281,11 @@ void Patcher::LoadPatchMD5(char *szFileName)
// 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)
if (!stricmp(pat, i->first.c_str())) if (!stricmp(pat, i->first.c_str()))
+1 -1
View File
@@ -24,7 +24,7 @@ public:
} }
protected: protected:
virtual int make_svc_handler(RealmSocket* &sh) virtual int make_svc_handler(RealmSocket*& sh)
{ {
if (sh == 0) if (sh == 0)
ACE_NEW_RETURN(sh, RealmSocket, -1); ACE_NEW_RETURN(sh, RealmSocket, -1);
+5 -5
View File
@@ -26,7 +26,7 @@ int base32_decode(const char* encoded, char* result, int bufSize)
int buffer = 0; int buffer = 0;
int bitsLeft = 0; int bitsLeft = 0;
int count = 0; int count = 0;
for (const char *ptr = encoded; count < bufSize && *ptr; ++ptr) for (const char* ptr = encoded; count < bufSize && *ptr; ++ptr)
{ {
char ch = *ptr; char ch = *ptr;
if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n' || ch == '-') if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n' || ch == '-')
@@ -66,19 +66,19 @@ namespace TOTP
unsigned int GenerateToken(const char* b32key) unsigned int GenerateToken(const char* b32key)
{ {
size_t keySize = strlen(b32key); size_t keySize = strlen(b32key);
int bufsize = (keySize + 7)/8*5; int bufsize = (keySize + 7) / 8 * 5;
char* encoded = new char[bufsize]; char* encoded = new char[bufsize];
memset(encoded, 0, bufsize); memset(encoded, 0, bufsize);
unsigned int hmacResSize = HMAC_RES_SIZE; unsigned int hmacResSize = HMAC_RES_SIZE;
unsigned char hmacRes[HMAC_RES_SIZE]; unsigned char hmacRes[HMAC_RES_SIZE];
unsigned long timestamp = time(nullptr)/30; unsigned long timestamp = time(nullptr) / 30;
unsigned char challenge[8]; unsigned char challenge[8];
for (int i = 8; i--;timestamp >>= 8) for (int i = 8; i--; timestamp >>= 8)
challenge[i] = timestamp; challenge[i] = timestamp;
base32_decode(b32key, encoded, bufsize); base32_decode(b32key, encoded, bufsize);
HMAC(EVP_sha1(), encoded, bufsize, challenge, 8, hmacRes, &hmacResSize); HMAC(EVP_sha1(), encoded, bufsize, challenge, 8, hmacRes, &hmacResSize);
unsigned int offset = hmacRes[19] & 0xF; unsigned int offset = hmacRes[19] & 0xF;
unsigned int truncHash = (hmacRes[offset] << 24) | (hmacRes[offset+1] << 16 )| (hmacRes[offset+2] << 8) | (hmacRes[offset+3]); unsigned int truncHash = (hmacRes[offset] << 24) | (hmacRes[offset + 1] << 16 ) | (hmacRes[offset + 2] << 8) | (hmacRes[offset + 3]);
truncHash &= 0x7FFFFFFF; truncHash &= 0x7FFFFFFF;
delete[] encoded; delete[] encoded;
return truncHash % 1000000; return truncHash % 1000000;