mirror of
https://github.com/mangosfour/server.git
synced 2025-12-18 10:37:01 +00:00
Various Cleanups (realmd/)
This commit is contained in:
parent
ed3220dbf2
commit
a4cbed3199
10 changed files with 206 additions and 204 deletions
|
|
@ -148,14 +148,14 @@ typedef struct XFER_INIT
|
||||||
uint8 fileName[5]; // fileName[fileNameLen]
|
uint8 fileName[5]; // fileName[fileNameLen]
|
||||||
uint64 file_size; // file size (bytes)
|
uint64 file_size; // file size (bytes)
|
||||||
uint8 md5[MD5_DIGEST_LENGTH]; // MD5
|
uint8 md5[MD5_DIGEST_LENGTH]; // MD5
|
||||||
}XFER_INIT;
|
} XFER_INIT;
|
||||||
|
|
||||||
typedef struct AuthHandler
|
typedef struct AuthHandler
|
||||||
{
|
{
|
||||||
eAuthCmd cmd;
|
eAuthCmd cmd;
|
||||||
uint32 status;
|
uint32 status;
|
||||||
bool (AuthSocket::*handler)(void);
|
bool (AuthSocket::*handler)(void);
|
||||||
}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
|
// 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__ )
|
||||||
|
|
@ -194,7 +194,7 @@ AuthSocket::AuthSocket()
|
||||||
/// Close patch file descriptor before leaving
|
/// Close patch file descriptor before leaving
|
||||||
AuthSocket::~AuthSocket()
|
AuthSocket::~AuthSocket()
|
||||||
{
|
{
|
||||||
if(patch_ != ACE_INVALID_HANDLE)
|
if (patch_ != ACE_INVALID_HANDLE)
|
||||||
ACE_OS::close(patch_);
|
ACE_OS::close(patch_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -210,7 +210,7 @@ void AuthSocket::OnRead()
|
||||||
uint8 _cmd;
|
uint8 _cmd;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
if(!recv_soft((char *)&_cmd, 1))
|
if (!recv_soft((char*)&_cmd, 1))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
@ -269,17 +269,17 @@ void AuthSocket::_SetVSFields(const std::string& rI)
|
||||||
x.SetBinary(sha.GetDigest(), sha.GetLength());
|
x.SetBinary(sha.GetDigest(), sha.GetLength());
|
||||||
v = g.ModExp(x, N);
|
v = g.ModExp(x, N);
|
||||||
// No SQL injection (username escaped)
|
// No SQL injection (username escaped)
|
||||||
const char *v_hex, *s_hex;
|
const char* v_hex, *s_hex;
|
||||||
v_hex = v.AsHexStr();
|
v_hex = v.AsHexStr();
|
||||||
s_hex = s.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*)v_hex);
|
||||||
OPENSSL_free((void*)s_hex);
|
OPENSSL_free((void*)s_hex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AuthSocket::SendProof(Sha1Hash sha)
|
void AuthSocket::SendProof(Sha1Hash sha)
|
||||||
{
|
{
|
||||||
switch(_build)
|
switch (_build)
|
||||||
{
|
{
|
||||||
case 5875: // 1.12.1
|
case 5875: // 1.12.1
|
||||||
case 6005: // 1.12.2
|
case 6005: // 1.12.2
|
||||||
|
|
@ -290,7 +290,7 @@ void AuthSocket::SendProof(Sha1Hash sha)
|
||||||
proof.error = 0;
|
proof.error = 0;
|
||||||
proof.unk2 = 0x00;
|
proof.unk2 = 0x00;
|
||||||
|
|
||||||
send((char *)&proof, sizeof(proof));
|
send((char*)&proof, sizeof(proof));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 8606: // 2.4.3
|
case 8606: // 2.4.3
|
||||||
|
|
@ -309,7 +309,7 @@ void AuthSocket::SendProof(Sha1Hash sha)
|
||||||
proof.surveyId = 0x00000000;
|
proof.surveyId = 0x00000000;
|
||||||
proof.unkFlags = 0x0000;
|
proof.unkFlags = 0x0000;
|
||||||
|
|
||||||
send((char *)&proof, sizeof(proof));
|
send((char*)&proof, sizeof(proof));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -326,10 +326,10 @@ bool AuthSocket::_HandleLogonChallenge()
|
||||||
std::vector<uint8> buf;
|
std::vector<uint8> buf;
|
||||||
buf.resize(4);
|
buf.resize(4);
|
||||||
|
|
||||||
recv((char *)&buf[0], 4);
|
recv((char*)&buf[0], 4);
|
||||||
|
|
||||||
EndianConvert(*((uint16*)(buf[0])));
|
EndianConvert(*((uint16*)(buf[0])));
|
||||||
uint16 remaining = ((sAuthLogonChallenge_C *)&buf[0])->size;
|
uint16 remaining = ((sAuthLogonChallenge_C*)&buf[0])->size;
|
||||||
DEBUG_LOG("[AuthChallenge] got header, body is %#04x bytes", remaining);
|
DEBUG_LOG("[AuthChallenge] got header, body is %#04x bytes", remaining);
|
||||||
|
|
||||||
if ((remaining < sizeof(sAuthLogonChallenge_C) - buf.size()) || (recv_len() < remaining))
|
if ((remaining < sizeof(sAuthLogonChallenge_C) - buf.size()) || (recv_len() < remaining))
|
||||||
|
|
@ -338,10 +338,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
|
||||||
recv((char *)&buf[4], remaining);
|
recv((char*)&buf[4], remaining);
|
||||||
DEBUG_LOG("[AuthChallenge] got full packet, %#04x bytes", ch->size);
|
DEBUG_LOG("[AuthChallenge] got full packet, %#04x bytes", ch->size);
|
||||||
DEBUG_LOG("[AuthChallenge] name(%d): '%s'", ch->I_len, ch->I);
|
DEBUG_LOG("[AuthChallenge] name(%d): '%s'", ch->I_len, ch->I);
|
||||||
|
|
||||||
|
|
@ -375,7 +375,7 @@ bool AuthSocket::_HandleLogonChallenge()
|
||||||
// No SQL injection possible (paste the IP address as passed by the socket)
|
// No SQL injection possible (paste the IP address as passed by the socket)
|
||||||
std::string address = get_remote_address();
|
std::string address = get_remote_address();
|
||||||
LoginDatabase.escape_string(address);
|
LoginDatabase.escape_string(address);
|
||||||
QueryResult *result = LoginDatabase.PQuery("SELECT unbandate FROM ip_banned WHERE "
|
QueryResult* result = LoginDatabase.PQuery("SELECT unbandate FROM ip_banned WHERE "
|
||||||
// permanent still banned
|
// permanent still banned
|
||||||
"(unbandate = bandate OR unbandate > UNIX_TIMESTAMP()) AND ip = '%s'", address.c_str());
|
"(unbandate = bandate OR unbandate > UNIX_TIMESTAMP()) AND ip = '%s'", address.c_str());
|
||||||
if (result)
|
if (result)
|
||||||
|
|
@ -389,16 +389,16 @@ bool AuthSocket::_HandleLogonChallenge()
|
||||||
///- Get the account details from the account table
|
///- Get the account details from the account table
|
||||||
// No SQL injection (escaped user name)
|
// 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 ());
|
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
|
///- If the IP is 'locked', check that the player comes indeed from the correct IP address
|
||||||
bool locked = false;
|
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] Account '%s' is locked to IP - '%s'", _login.c_str(), (*result)[3].GetString());
|
||||||
DEBUG_LOG("[AuthChallenge] Player address is '%s'", get_remote_address().c_str());
|
DEBUG_LOG("[AuthChallenge] Player address is '%s'", get_remote_address().c_str());
|
||||||
if ( strcmp((*result)[3].GetString(),get_remote_address().c_str()) )
|
if (strcmp((*result)[3].GetString(),get_remote_address().c_str()))
|
||||||
{
|
{
|
||||||
DEBUG_LOG("[AuthChallenge] Account IP differs");
|
DEBUG_LOG("[AuthChallenge] Account IP differs");
|
||||||
pkt << (uint8) WOW_FAIL_SUSPENDED;
|
pkt << (uint8) WOW_FAIL_SUSPENDED;
|
||||||
|
|
@ -417,19 +417,19 @@ bool AuthSocket::_HandleLogonChallenge()
|
||||||
if (!locked)
|
if (!locked)
|
||||||
{
|
{
|
||||||
///- If the account is banned, reject the logon attempt
|
///- If the account is banned, reject the logon attempt
|
||||||
QueryResult *banresult = LoginDatabase.PQuery("SELECT bandate,unbandate FROM account_banned WHERE "
|
QueryResult* banresult = LoginDatabase.PQuery("SELECT bandate,unbandate FROM account_banned WHERE "
|
||||||
"id = %u AND active = 1 AND (unbandate > UNIX_TIMESTAMP() OR unbandate = bandate)", (*result)[1].GetUInt32());
|
"id = %u AND active = 1 AND (unbandate > UNIX_TIMESTAMP() OR unbandate = bandate)", (*result)[1].GetUInt32());
|
||||||
if(banresult)
|
if (banresult)
|
||||||
{
|
{
|
||||||
if((*banresult)[0].GetUInt64() == (*banresult)[1].GetUInt64())
|
if ((*banresult)[0].GetUInt64() == (*banresult)[1].GetUInt64())
|
||||||
{
|
{
|
||||||
pkt << (uint8) WOW_FAIL_BANNED;
|
pkt << (uint8) WOW_FAIL_BANNED;
|
||||||
BASIC_LOG("[AuthChallenge] Banned account %s tries to login!",_login.c_str ());
|
BASIC_LOG("[AuthChallenge] Banned account %s tries to login!",_login.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pkt << (uint8) WOW_FAIL_SUSPENDED;
|
pkt << (uint8) WOW_FAIL_SUSPENDED;
|
||||||
BASIC_LOG("[AuthChallenge] Temporarily banned account %s tries to login!",_login.c_str ());
|
BASIC_LOG("[AuthChallenge] Temporarily banned account %s tries to login!",_login.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
delete banresult;
|
delete banresult;
|
||||||
|
|
@ -446,7 +446,7 @@ bool AuthSocket::_HandleLogonChallenge()
|
||||||
DEBUG_LOG("database authentication values: v='%s' s='%s'", databaseV.c_str(), databaseS.c_str());
|
DEBUG_LOG("database authentication values: v='%s' s='%s'", databaseV.c_str(), databaseS.c_str());
|
||||||
|
|
||||||
// multiply with 2, bytes are stored as hexstring
|
// 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);
|
_SetVSFields(rI);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -477,13 +477,13 @@ bool AuthSocket::_HandleLogonChallenge()
|
||||||
uint8 securityFlags = 0;
|
uint8 securityFlags = 0;
|
||||||
pkt << uint8(securityFlags); // security flags (0x0...0x04)
|
pkt << uint8(securityFlags); // security flags (0x0...0x04)
|
||||||
|
|
||||||
if(securityFlags & 0x01) // PIN input
|
if (securityFlags & 0x01) // PIN input
|
||||||
{
|
{
|
||||||
pkt << uint32(0);
|
pkt << uint32(0);
|
||||||
pkt << uint64(0) << uint64(0); // 16 bytes hash?
|
pkt << uint64(0) << uint64(0); // 16 bytes hash?
|
||||||
}
|
}
|
||||||
|
|
||||||
if(securityFlags & 0x02) // Matrix input
|
if (securityFlags & 0x02) // Matrix input
|
||||||
{
|
{
|
||||||
pkt << uint8(0);
|
pkt << uint8(0);
|
||||||
pkt << uint8(0);
|
pkt << uint8(0);
|
||||||
|
|
@ -492,7 +492,7 @@ bool AuthSocket::_HandleLogonChallenge()
|
||||||
pkt << uint64(0);
|
pkt << uint64(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(securityFlags & 0x04) // Security token input
|
if (securityFlags & 0x04) // Security token input
|
||||||
{
|
{
|
||||||
pkt << uint8(1);
|
pkt << uint8(1);
|
||||||
}
|
}
|
||||||
|
|
@ -501,10 +501,10 @@ bool AuthSocket::_HandleLogonChallenge()
|
||||||
_accountSecurityLevel = secLevel <= SEC_ADMINISTRATOR ? AccountTypes(secLevel) : SEC_ADMINISTRATOR;
|
_accountSecurityLevel = secLevel <= SEC_ADMINISTRATOR ? AccountTypes(secLevel) : SEC_ADMINISTRATOR;
|
||||||
|
|
||||||
_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];
|
||||||
|
|
||||||
BASIC_LOG("[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));
|
BASIC_LOG("[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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete result;
|
delete result;
|
||||||
|
|
@ -524,14 +524,14 @@ bool AuthSocket::_HandleLogonProof()
|
||||||
DEBUG_LOG("Entering _HandleLogonProof");
|
DEBUG_LOG("Entering _HandleLogonProof");
|
||||||
///- Read the packet
|
///- Read the packet
|
||||||
sAuthLogonProof_C lp;
|
sAuthLogonProof_C lp;
|
||||||
if(!recv((char *)&lp, sizeof(sAuthLogonProof_C)))
|
if (!recv((char*)&lp, sizeof(sAuthLogonProof_C)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
///- Check if the client has one of the expected version numbers
|
///- Check if the client has one of the expected version numbers
|
||||||
bool valid_version = FindBuildInfo(_build) != NULL;
|
bool valid_version = FindBuildInfo(_build) != NULL;
|
||||||
|
|
||||||
/// <ul><li> If the client has no valid version
|
/// <ul><li> If the client has no valid version
|
||||||
if(!valid_version)
|
if (!valid_version)
|
||||||
{
|
{
|
||||||
if (this->patch_ != ACE_INVALID_HANDLE)
|
if (this->patch_ != ACE_INVALID_HANDLE)
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -672,7 +672,7 @@ 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();
|
||||||
LoginDatabase.PExecute("UPDATE account SET sessionkey = '%s', last_ip = '%s', last_login = NOW(), locale = '%u', failed_logins = 0 WHERE username = '%s'", K_hex, get_remote_address().c_str(), GetLocaleByName(_localizationName), _safelogin.c_str() );
|
LoginDatabase.PExecute("UPDATE account SET sessionkey = '%s', last_ip = '%s', last_login = NOW(), locale = '%u', failed_logins = 0 WHERE username = '%s'", K_hex, get_remote_address().c_str(), GetLocaleByName(_localizationName), _safelogin.c_str());
|
||||||
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
|
||||||
|
|
@ -698,25 +698,25 @@ bool AuthSocket::_HandleLogonProof()
|
||||||
char data[2] = { CMD_AUTH_LOGON_PROOF, WOW_FAIL_UNKNOWN_ACCOUNT};
|
char data[2] = { CMD_AUTH_LOGON_PROOF, WOW_FAIL_UNKNOWN_ACCOUNT};
|
||||||
send(data, sizeof(data));
|
send(data, sizeof(data));
|
||||||
}
|
}
|
||||||
BASIC_LOG("[AuthChallenge] account %s tried to login with wrong password!",_login.c_str ());
|
BASIC_LOG("[AuthChallenge] account %s tried to login with wrong password!",_login.c_str());
|
||||||
|
|
||||||
uint32 MaxWrongPassCount = sConfig.GetIntDefault("WrongPass.MaxCount", 0);
|
uint32 MaxWrongPassCount = sConfig.GetIntDefault("WrongPass.MaxCount", 0);
|
||||||
if(MaxWrongPassCount > 0)
|
if (MaxWrongPassCount > 0)
|
||||||
{
|
{
|
||||||
//Increment number of failed logins by one and if it reaches the limit temporarily ban that account or IP
|
//Increment number of failed logins by one and if it reaches the limit temporarily ban that account or IP
|
||||||
LoginDatabase.PExecute("UPDATE account SET failed_logins = failed_logins + 1 WHERE username = '%s'",_safelogin.c_str());
|
LoginDatabase.PExecute("UPDATE account SET failed_logins = failed_logins + 1 WHERE username = '%s'",_safelogin.c_str());
|
||||||
|
|
||||||
if(QueryResult *loginfail = LoginDatabase.PQuery("SELECT id, failed_logins FROM account WHERE username = '%s'", _safelogin.c_str()))
|
if (QueryResult* loginfail = LoginDatabase.PQuery("SELECT id, failed_logins FROM account WHERE username = '%s'", _safelogin.c_str()))
|
||||||
{
|
{
|
||||||
Field* fields = loginfail->Fetch();
|
Field* fields = loginfail->Fetch();
|
||||||
uint32 failed_logins = fields[1].GetUInt32();
|
uint32 failed_logins = fields[1].GetUInt32();
|
||||||
|
|
||||||
if( failed_logins >= MaxWrongPassCount )
|
if (failed_logins >= MaxWrongPassCount)
|
||||||
{
|
{
|
||||||
uint32 WrongPassBanTime = sConfig.GetIntDefault("WrongPass.BanTime", 600);
|
uint32 WrongPassBanTime = sConfig.GetIntDefault("WrongPass.BanTime", 600);
|
||||||
bool WrongPassBanType = sConfig.GetBoolDefault("WrongPass.BanType", false);
|
bool WrongPassBanType = sConfig.GetBoolDefault("WrongPass.BanType", false);
|
||||||
|
|
||||||
if(WrongPassBanType)
|
if (WrongPassBanType)
|
||||||
{
|
{
|
||||||
uint32 acc_id = fields[0].GetUInt32();
|
uint32 acc_id = fields[0].GetUInt32();
|
||||||
LoginDatabase.PExecute("INSERT INTO account_banned VALUES ('%u',UNIX_TIMESTAMP(),UNIX_TIMESTAMP()+'%u','MaNGOS realmd','Failed login autoban',1)",
|
LoginDatabase.PExecute("INSERT INTO account_banned VALUES ('%u',UNIX_TIMESTAMP(),UNIX_TIMESTAMP()+'%u','MaNGOS realmd','Failed login autoban',1)",
|
||||||
|
|
@ -752,10 +752,10 @@ bool AuthSocket::_HandleReconnectChallenge()
|
||||||
std::vector<uint8> buf;
|
std::vector<uint8> buf;
|
||||||
buf.resize(4);
|
buf.resize(4);
|
||||||
|
|
||||||
recv((char *)&buf[0], 4);
|
recv((char*)&buf[0], 4);
|
||||||
|
|
||||||
EndianConvert(*((uint16*)(buf[0])));
|
EndianConvert(*((uint16*)(buf[0])));
|
||||||
uint16 remaining = ((sAuthLogonChallenge_C *)&buf[0])->size;
|
uint16 remaining = ((sAuthLogonChallenge_C*)&buf[0])->size;
|
||||||
DEBUG_LOG("[ReconnectChallenge] got header, body is %#04x bytes", remaining);
|
DEBUG_LOG("[ReconnectChallenge] got header, body is %#04x bytes", remaining);
|
||||||
|
|
||||||
if ((remaining < sizeof(sAuthLogonChallenge_C) - buf.size()) || (recv_len() < remaining))
|
if ((remaining < sizeof(sAuthLogonChallenge_C) - buf.size()) || (recv_len() < remaining))
|
||||||
|
|
@ -764,10 +764,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
|
||||||
recv((char *)&buf[4], remaining);
|
recv((char*)&buf[4], remaining);
|
||||||
DEBUG_LOG("[ReconnectChallenge] got full packet, %#04x bytes", ch->size);
|
DEBUG_LOG("[ReconnectChallenge] got full packet, %#04x bytes", ch->size);
|
||||||
DEBUG_LOG("[ReconnectChallenge] name(%d): '%s'", ch->I_len, ch->I);
|
DEBUG_LOG("[ReconnectChallenge] name(%d): '%s'", ch->I_len, ch->I);
|
||||||
|
|
||||||
|
|
@ -779,7 +779,7 @@ bool AuthSocket::_HandleReconnectChallenge()
|
||||||
EndianConvert(ch->build);
|
EndianConvert(ch->build);
|
||||||
_build = ch->build;
|
_build = ch->build;
|
||||||
|
|
||||||
QueryResult *result = LoginDatabase.PQuery ("SELECT sessionkey FROM account WHERE username = '%s'", _safelogin.c_str ());
|
QueryResult* result = LoginDatabase.PQuery("SELECT sessionkey FROM account WHERE username = '%s'", _safelogin.c_str());
|
||||||
|
|
||||||
// Stop if the account is not found
|
// Stop if the account is not found
|
||||||
if (!result)
|
if (!result)
|
||||||
|
|
@ -789,8 +789,8 @@ bool AuthSocket::_HandleReconnectChallenge()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Field* fields = result->Fetch ();
|
Field* fields = result->Fetch();
|
||||||
K.SetHexStr (fields[0].GetString ());
|
K.SetHexStr(fields[0].GetString());
|
||||||
delete result;
|
delete result;
|
||||||
|
|
||||||
///- Sending response
|
///- Sending response
|
||||||
|
|
@ -810,7 +810,7 @@ bool AuthSocket::_HandleReconnectProof()
|
||||||
DEBUG_LOG("Entering _HandleReconnectProof");
|
DEBUG_LOG("Entering _HandleReconnectProof");
|
||||||
///- Read the packet
|
///- Read the packet
|
||||||
sAuthReconnectProof_C lp;
|
sAuthReconnectProof_C lp;
|
||||||
if(!recv((char *)&lp, sizeof(sAuthReconnectProof_C)))
|
if (!recv((char*)&lp, sizeof(sAuthReconnectProof_C)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (_login.empty() || !_reconnectProof.GetNumBytes() || !K.GetNumBytes())
|
if (_login.empty() || !_reconnectProof.GetNumBytes() || !K.GetNumBytes())
|
||||||
|
|
@ -859,8 +859,8 @@ bool AuthSocket::_HandleRealmList()
|
||||||
///- Get the user id (else close the connection)
|
///- Get the user id (else close the connection)
|
||||||
// No SQL injection (escaped user name)
|
// No SQL injection (escaped user name)
|
||||||
|
|
||||||
QueryResult *result = LoginDatabase.PQuery("SELECT id,sha_pass_hash FROM account WHERE username = '%s'",_safelogin.c_str());
|
QueryResult* result = LoginDatabase.PQuery("SELECT id,sha_pass_hash FROM account WHERE username = '%s'",_safelogin.c_str());
|
||||||
if(!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
sLog.outError("[ERROR] user %s tried to login and we cannot find him in the database.",_login.c_str());
|
sLog.outError("[ERROR] user %s tried to login and we cannot find him in the database.",_login.c_str());
|
||||||
close_connection();
|
close_connection();
|
||||||
|
|
@ -888,9 +888,9 @@ bool AuthSocket::_HandleRealmList()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AuthSocket::LoadRealmlist(ByteBuffer &pkt, uint32 acctid)
|
void AuthSocket::LoadRealmlist(ByteBuffer& pkt, uint32 acctid)
|
||||||
{
|
{
|
||||||
switch(_build)
|
switch (_build)
|
||||||
{
|
{
|
||||||
case 5875: // 1.12.1
|
case 5875: // 1.12.1
|
||||||
case 6005: // 1.12.2
|
case 6005: // 1.12.2
|
||||||
|
|
@ -898,15 +898,15 @@ void AuthSocket::LoadRealmlist(ByteBuffer &pkt, uint32 acctid)
|
||||||
pkt << uint32(0); // unused value
|
pkt << uint32(0); // unused value
|
||||||
pkt << uint8(sRealmList.size());
|
pkt << uint8(sRealmList.size());
|
||||||
|
|
||||||
for(RealmList::RealmMap::const_iterator i = sRealmList.begin(); i != sRealmList.end(); ++i)
|
for (RealmList::RealmMap::const_iterator i = sRealmList.begin(); i != sRealmList.end(); ++i)
|
||||||
{
|
{
|
||||||
uint8 AmountOfCharacters;
|
uint8 AmountOfCharacters;
|
||||||
|
|
||||||
// No SQL injection. id of realm is controlled by the database.
|
// No SQL injection. id of realm is controlled by the database.
|
||||||
QueryResult *result = LoginDatabase.PQuery( "SELECT numchars FROM realmcharacters WHERE realmid = '%d' AND acctid='%u'", i->second.m_ID, acctid);
|
QueryResult* result = LoginDatabase.PQuery("SELECT numchars FROM realmcharacters WHERE realmid = '%d' AND acctid='%u'", i->second.m_ID, acctid);
|
||||||
if( result )
|
if (result)
|
||||||
{
|
{
|
||||||
Field *fields = result->Fetch();
|
Field* fields = result->Fetch();
|
||||||
AmountOfCharacters = fields[0].GetUInt8();
|
AmountOfCharacters = fields[0].GetUInt8();
|
||||||
delete result;
|
delete result;
|
||||||
}
|
}
|
||||||
|
|
@ -959,15 +959,15 @@ void AuthSocket::LoadRealmlist(ByteBuffer &pkt, uint32 acctid)
|
||||||
pkt << uint32(0); // unused value
|
pkt << uint32(0); // unused value
|
||||||
pkt << uint16(sRealmList.size());
|
pkt << uint16(sRealmList.size());
|
||||||
|
|
||||||
for(RealmList::RealmMap::const_iterator i = sRealmList.begin(); i != sRealmList.end(); ++i)
|
for (RealmList::RealmMap::const_iterator i = sRealmList.begin(); i != sRealmList.end(); ++i)
|
||||||
{
|
{
|
||||||
uint8 AmountOfCharacters;
|
uint8 AmountOfCharacters;
|
||||||
|
|
||||||
// No SQL injection. id of realm is controlled by the database.
|
// No SQL injection. id of realm is controlled by the database.
|
||||||
QueryResult *result = LoginDatabase.PQuery( "SELECT numchars FROM realmcharacters WHERE realmid = '%d' AND acctid='%u'", i->second.m_ID, acctid);
|
QueryResult* result = LoginDatabase.PQuery("SELECT numchars FROM realmcharacters WHERE realmid = '%d' AND acctid='%u'", i->second.m_ID, acctid);
|
||||||
if( result )
|
if (result)
|
||||||
{
|
{
|
||||||
Field *fields = result->Fetch();
|
Field* fields = result->Fetch();
|
||||||
AmountOfCharacters = fields[0].GetUInt8();
|
AmountOfCharacters = fields[0].GetUInt8();
|
||||||
delete result;
|
delete result;
|
||||||
}
|
}
|
||||||
|
|
@ -1021,15 +1021,15 @@ bool AuthSocket::_HandleXferResume()
|
||||||
{
|
{
|
||||||
DEBUG_LOG("Entering _HandleXferResume");
|
DEBUG_LOG("Entering _HandleXferResume");
|
||||||
|
|
||||||
if(recv_len() < 9)
|
if (recv_len() < 9)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
recv_skip(1);
|
recv_skip(1);
|
||||||
|
|
||||||
uint64 start_pos;
|
uint64 start_pos;
|
||||||
recv((char *)&start_pos, 8);
|
recv((char*)&start_pos, 8);
|
||||||
|
|
||||||
if(patch_ == ACE_INVALID_HANDLE)
|
if (patch_ == ACE_INVALID_HANDLE)
|
||||||
{
|
{
|
||||||
close_connection();
|
close_connection();
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -1037,13 +1037,13 @@ bool AuthSocket::_HandleXferResume()
|
||||||
|
|
||||||
ACE_OFF_T file_size = ACE_OS::filesize(patch_);
|
ACE_OFF_T file_size = ACE_OS::filesize(patch_);
|
||||||
|
|
||||||
if(file_size == -1 || start_pos >= (uint64)file_size)
|
if (file_size == -1 || start_pos >= (uint64)file_size)
|
||||||
{
|
{
|
||||||
close_connection();
|
close_connection();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ACE_OS::lseek(patch_, start_pos, SEEK_SET) == -1)
|
if (ACE_OS::lseek(patch_, start_pos, SEEK_SET) == -1)
|
||||||
{
|
{
|
||||||
close_connection();
|
close_connection();
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -1083,7 +1083,7 @@ void AuthSocket::InitPatch()
|
||||||
|
|
||||||
patch_ = ACE_INVALID_HANDLE;
|
patch_ = ACE_INVALID_HANDLE;
|
||||||
|
|
||||||
if(handler->open() == -1)
|
if (handler->open() == -1)
|
||||||
{
|
{
|
||||||
handler->close();
|
handler->close();
|
||||||
close_connection();
|
close_connection();
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class AuthSocket: public BufferedSocket
|
||||||
void OnAccept();
|
void OnAccept();
|
||||||
void OnRead();
|
void OnRead();
|
||||||
void SendProof(Sha1Hash sha);
|
void SendProof(Sha1Hash sha);
|
||||||
void LoadRealmlist(ByteBuffer &pkt, uint32 acctid);
|
void LoadRealmlist(ByteBuffer& pkt, uint32 acctid);
|
||||||
|
|
||||||
bool _HandleLogonChallenge();
|
bool _HandleLogonChallenge();
|
||||||
bool _HandleLogonProof();
|
bool _HandleLogonProof();
|
||||||
|
|
|
||||||
|
|
@ -40,14 +40,14 @@ BufferedSocket::BufferedSocket(void):
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*virtual*/ int BufferedSocket::open(void * arg)
|
/*virtual*/ int BufferedSocket::open(void* arg)
|
||||||
{
|
{
|
||||||
if(Base::open(arg) == -1)
|
if (Base::open(arg) == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ACE_INET_Addr addr;
|
ACE_INET_Addr addr;
|
||||||
|
|
||||||
if(peer().get_remote_addr(addr) == -1)
|
if (peer().get_remote_addr(addr) == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
char address[1024];
|
char address[1024];
|
||||||
|
|
@ -71,9 +71,9 @@ size_t BufferedSocket::recv_len(void) const
|
||||||
return this->input_buffer_.length();
|
return this->input_buffer_.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BufferedSocket::recv_soft(char *buf, size_t len)
|
bool BufferedSocket::recv_soft(char* buf, size_t len)
|
||||||
{
|
{
|
||||||
if(this->input_buffer_.length() < len)
|
if (this->input_buffer_.length() < len)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ACE_OS::memcpy(buf, this->input_buffer_.rd_ptr(), len);
|
ACE_OS::memcpy(buf, this->input_buffer_.rd_ptr(), len);
|
||||||
|
|
@ -81,11 +81,11 @@ bool BufferedSocket::recv_soft(char *buf, size_t len)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BufferedSocket::recv(char *buf, size_t len)
|
bool BufferedSocket::recv(char* buf, size_t len)
|
||||||
{
|
{
|
||||||
bool ret = this->recv_soft(buf, len);
|
bool ret = this->recv_soft(buf, len);
|
||||||
|
|
||||||
if(ret)
|
if (ret)
|
||||||
this->recv_skip(len);
|
this->recv_skip(len);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -96,26 +96,26 @@ void BufferedSocket::recv_skip(size_t len)
|
||||||
this->input_buffer_.rd_ptr(len);
|
this->input_buffer_.rd_ptr(len);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t BufferedSocket::noblk_send(ACE_Message_Block &message_block)
|
ssize_t BufferedSocket::noblk_send(ACE_Message_Block& message_block)
|
||||||
{
|
{
|
||||||
const size_t len = message_block.length();
|
const size_t len = message_block.length();
|
||||||
|
|
||||||
if(len == 0)
|
if (len == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// Try to send the message directly.
|
// Try to send the message directly.
|
||||||
ssize_t n = this->peer().send(message_block.rd_ptr(), len, MSG_NOSIGNAL);
|
ssize_t n = this->peer().send(message_block.rd_ptr(), len, MSG_NOSIGNAL);
|
||||||
|
|
||||||
if(n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
if(errno == EWOULDBLOCK)
|
if (errno == EWOULDBLOCK)
|
||||||
// Blocking signal
|
// Blocking signal
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
// Error
|
// Error
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else if(n == 0)
|
else if (n == 0)
|
||||||
{
|
{
|
||||||
// Can this happen ?
|
// Can this happen ?
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -125,9 +125,9 @@ ssize_t BufferedSocket::noblk_send(ACE_Message_Block &message_block)
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BufferedSocket::send(const char *buf, size_t len)
|
bool BufferedSocket::send(const char* buf, size_t len)
|
||||||
{
|
{
|
||||||
if(buf == NULL || len == 0)
|
if (buf == NULL || len == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
ACE_Data_Block db(
|
ACE_Data_Block db(
|
||||||
|
|
@ -146,14 +146,14 @@ bool BufferedSocket::send(const char *buf, size_t len)
|
||||||
|
|
||||||
message_block.wr_ptr(len);
|
message_block.wr_ptr(len);
|
||||||
|
|
||||||
if(this->msg_queue()->is_empty())
|
if (this->msg_queue()->is_empty())
|
||||||
{
|
{
|
||||||
// Try to send it directly.
|
// Try to send it directly.
|
||||||
ssize_t n = this->noblk_send(message_block);
|
ssize_t n = this->noblk_send(message_block);
|
||||||
|
|
||||||
if(n < 0)
|
if (n < 0)
|
||||||
return false;
|
return false;
|
||||||
else if(n == len)
|
else if (n == len)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// adjust how much bytes we sent
|
// adjust how much bytes we sent
|
||||||
|
|
@ -163,16 +163,16 @@ bool BufferedSocket::send(const char *buf, size_t len)
|
||||||
}
|
}
|
||||||
|
|
||||||
// enqueue the message, note: clone is needed cause we cant enqueue stuff on the stack
|
// enqueue the message, note: clone is needed cause we cant enqueue stuff on the stack
|
||||||
ACE_Message_Block *mb = message_block.clone();
|
ACE_Message_Block* mb = message_block.clone();
|
||||||
|
|
||||||
if(this->msg_queue()->enqueue_tail(mb, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1)
|
if (this->msg_queue()->enqueue_tail(mb, (ACE_Time_Value*) &ACE_Time_Value::zero) == -1)
|
||||||
{
|
{
|
||||||
mb->release();
|
mb->release();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// tell reactor to call handle_output() when we can send more data
|
// tell reactor to call handle_output() when we can send more data
|
||||||
if(this->reactor()->schedule_wakeup(this, ACE_Event_Handler::WRITE_MASK) == -1)
|
if (this->reactor()->schedule_wakeup(this, ACE_Event_Handler::WRITE_MASK) == -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -180,26 +180,26 @@ bool BufferedSocket::send(const char *buf, size_t len)
|
||||||
|
|
||||||
/*virtual*/ int BufferedSocket::handle_output(ACE_HANDLE /*= ACE_INVALID_HANDLE*/)
|
/*virtual*/ int BufferedSocket::handle_output(ACE_HANDLE /*= ACE_INVALID_HANDLE*/)
|
||||||
{
|
{
|
||||||
ACE_Message_Block *mb = 0;
|
ACE_Message_Block* mb = 0;
|
||||||
|
|
||||||
if(this->msg_queue()->is_empty())
|
if (this->msg_queue()->is_empty())
|
||||||
{
|
{
|
||||||
// if no more data to send, then cancel notification
|
// if no more data to send, then cancel notification
|
||||||
this->reactor()->cancel_wakeup(this, ACE_Event_Handler::WRITE_MASK);
|
this->reactor()->cancel_wakeup(this, ACE_Event_Handler::WRITE_MASK);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this->msg_queue()->dequeue_head(mb, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1)
|
if (this->msg_queue()->dequeue_head(mb, (ACE_Time_Value*) &ACE_Time_Value::zero) == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ssize_t n = this->noblk_send(*mb);
|
ssize_t n = this->noblk_send(*mb);
|
||||||
|
|
||||||
if(n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
mb->release();
|
mb->release();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else if(n == mb->length())
|
else if (n == mb->length())
|
||||||
{
|
{
|
||||||
mb->release();
|
mb->release();
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -208,7 +208,7 @@ bool BufferedSocket::send(const char *buf, size_t len)
|
||||||
{
|
{
|
||||||
mb->rd_ptr(n);
|
mb->rd_ptr(n);
|
||||||
|
|
||||||
if(this->msg_queue()->enqueue_head(mb, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1)
|
if (this->msg_queue()->enqueue_head(mb, (ACE_Time_Value*) &ACE_Time_Value::zero) == -1)
|
||||||
{
|
{
|
||||||
mb->release();
|
mb->release();
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -226,12 +226,12 @@ bool BufferedSocket::send(const char *buf, size_t len)
|
||||||
|
|
||||||
ssize_t n = this->peer().recv(this->input_buffer_.wr_ptr(), space);
|
ssize_t n = this->peer().recv(this->input_buffer_.wr_ptr(), space);
|
||||||
|
|
||||||
if(n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
// blocking signal or error
|
// blocking signal or error
|
||||||
return errno == EWOULDBLOCK ? 0 : -1;
|
return errno == EWOULDBLOCK ? 0 : -1;
|
||||||
}
|
}
|
||||||
else if(n == 0)
|
else if (n == 0)
|
||||||
{
|
{
|
||||||
// EOF
|
// EOF
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
||||||
|
|
@ -46,15 +46,15 @@ class BufferedSocket: public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
|
||||||
virtual ~BufferedSocket(void);
|
virtual ~BufferedSocket(void);
|
||||||
|
|
||||||
size_t recv_len(void) const;
|
size_t recv_len(void) const;
|
||||||
bool recv_soft(char *buf, size_t len);
|
bool recv_soft(char* buf, size_t len);
|
||||||
bool recv(char *buf, size_t len);
|
bool recv(char* buf, size_t len);
|
||||||
void recv_skip(size_t len);
|
void recv_skip(size_t len);
|
||||||
|
|
||||||
bool send(const char *buf, size_t len);
|
bool send(const char* buf, size_t len);
|
||||||
|
|
||||||
const std::string& get_remote_address(void) const;
|
const std::string& get_remote_address(void) const;
|
||||||
|
|
||||||
virtual int open(void *);
|
virtual int open(void*);
|
||||||
|
|
||||||
void close_connection(void);
|
void close_connection(void);
|
||||||
|
|
||||||
|
|
@ -65,7 +65,7 @@ class BufferedSocket: public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
|
||||||
ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK);
|
ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ssize_t noblk_send(ACE_Message_Block &message_block);
|
ssize_t noblk_send(ACE_Message_Block& message_block);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ACE_Message_Block input_buffer_;
|
ACE_Message_Block input_buffer_;
|
||||||
|
|
|
||||||
|
|
@ -67,31 +67,31 @@ bool stopEvent = false; ///< Setting it to t
|
||||||
DatabaseType LoginDatabase; ///< Accessor to the realm server database
|
DatabaseType LoginDatabase; ///< Accessor to the realm server database
|
||||||
|
|
||||||
/// Print out the usage string for this program on the console.
|
/// Print out the usage string for this program on the console.
|
||||||
void usage(const char *prog)
|
void usage(const char* prog)
|
||||||
{
|
{
|
||||||
sLog.outString("Usage: \n %s [<options>]\n"
|
sLog.outString("Usage: \n %s [<options>]\n"
|
||||||
" -v, --version print version and exist\n\r"
|
" -v, --version print version and exist\n\r"
|
||||||
" -c config_file use config_file as configuration file\n\r"
|
" -c config_file use config_file as configuration file\n\r"
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
" Running as service functions:\n\r"
|
" Running as service functions:\n\r"
|
||||||
" -s run run as service\n\r"
|
" -s run run as service\n\r"
|
||||||
" -s install install service\n\r"
|
" -s install install service\n\r"
|
||||||
" -s uninstall uninstall service\n\r"
|
" -s uninstall uninstall service\n\r"
|
||||||
#else
|
#else
|
||||||
" Running as daemon functions:\n\r"
|
" Running as daemon functions:\n\r"
|
||||||
" -s run run as daemon\n\r"
|
" -s run run as daemon\n\r"
|
||||||
" -s stop stop daemon\n\r"
|
" -s stop stop daemon\n\r"
|
||||||
#endif
|
#endif
|
||||||
,prog);
|
,prog);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Launch the realm server
|
/// Launch the realm server
|
||||||
extern int main(int argc, char **argv)
|
extern int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
///- Command line parsing
|
///- Command line parsing
|
||||||
char const* cfg_file = _REALMD_CONFIG;
|
char const* cfg_file = _REALMD_CONFIG;
|
||||||
|
|
||||||
char const *options = ":c:s:";
|
char const* options = ":c:s:";
|
||||||
|
|
||||||
ACE_Get_Opt cmd_opts(argc, argv, options);
|
ACE_Get_Opt cmd_opts(argc, argv, options);
|
||||||
cmd_opts.long_option("version", 'v');
|
cmd_opts.long_option("version", 'v');
|
||||||
|
|
@ -112,7 +112,7 @@ extern int main(int argc, char **argv)
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
{
|
{
|
||||||
const char *mode = cmd_opts.opt_arg();
|
const char* mode = cmd_opts.opt_arg();
|
||||||
|
|
||||||
if (!strcmp(mode, "run"))
|
if (!strcmp(mode, "run"))
|
||||||
serviceDaemonMode = 'r';
|
serviceDaemonMode = 'r';
|
||||||
|
|
@ -185,8 +185,8 @@ extern int main(int argc, char **argv)
|
||||||
|
|
||||||
sLog.Initialize();
|
sLog.Initialize();
|
||||||
|
|
||||||
sLog.outString( "%s [realm-daemon]", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID) );
|
sLog.outString("%s [realm-daemon]", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID));
|
||||||
sLog.outString( "<Ctrl-C> to stop.\n" );
|
sLog.outString("<Ctrl-C> to stop.\n");
|
||||||
sLog.outString("Using configuration file %s.", cfg_file);
|
sLog.outString("Using configuration file %s.", cfg_file);
|
||||||
|
|
||||||
///- Check the version of the configuration file
|
///- Check the version of the configuration file
|
||||||
|
|
@ -202,7 +202,7 @@ extern int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
DETAIL_LOG("%s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
|
DETAIL_LOG("%s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
|
||||||
if (SSLeay() < 0x009080bfL )
|
if (SSLeay() < 0x009080bfL)
|
||||||
{
|
{
|
||||||
DETAIL_LOG("WARNING: Outdated version of OpenSSL lib. Logins to server may not work!");
|
DETAIL_LOG("WARNING: Outdated version of OpenSSL lib. Logins to server may not work!");
|
||||||
DETAIL_LOG("WARNING: Minimal required version [OpenSSL 0.9.8k]");
|
DETAIL_LOG("WARNING: Minimal required version [OpenSSL 0.9.8k]");
|
||||||
|
|
@ -220,21 +220,21 @@ extern int main(int argc, char **argv)
|
||||||
|
|
||||||
/// realmd PID file creation
|
/// realmd PID file creation
|
||||||
std::string pidfile = sConfig.GetStringDefault("PidFile", "");
|
std::string pidfile = sConfig.GetStringDefault("PidFile", "");
|
||||||
if(!pidfile.empty())
|
if (!pidfile.empty())
|
||||||
{
|
{
|
||||||
uint32 pid = CreatePIDFile(pidfile);
|
uint32 pid = CreatePIDFile(pidfile);
|
||||||
if( !pid )
|
if (!pid)
|
||||||
{
|
{
|
||||||
sLog.outError( "Cannot create PID file %s.\n", pidfile.c_str() );
|
sLog.outError("Cannot create PID file %s.\n", pidfile.c_str());
|
||||||
Log::WaitBeforeContinueIfNeed();
|
Log::WaitBeforeContinueIfNeed();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sLog.outString( "Daemon PID: %u\n", pid );
|
sLog.outString("Daemon PID: %u\n", pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
///- Initialize the database connection
|
///- Initialize the database connection
|
||||||
if(!StartDB())
|
if (!StartDB())
|
||||||
{
|
{
|
||||||
Log::WaitBeforeContinueIfNeed();
|
Log::WaitBeforeContinueIfNeed();
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -264,7 +264,7 @@ extern int main(int argc, char **argv)
|
||||||
|
|
||||||
ACE_INET_Addr bind_addr(rmport, bind_ip.c_str());
|
ACE_INET_Addr bind_addr(rmport, bind_ip.c_str());
|
||||||
|
|
||||||
if(acceptor.open(bind_addr, ACE_Reactor::instance(), ACE_NONBLOCK) == -1)
|
if (acceptor.open(bind_addr, ACE_Reactor::instance(), ACE_NONBLOCK) == -1)
|
||||||
{
|
{
|
||||||
sLog.outError("MaNGOS realmd can not bind to %s:%d", bind_ip.c_str(), rmport);
|
sLog.outError("MaNGOS realmd can not bind to %s:%d", bind_ip.c_str(), rmport);
|
||||||
Log::WaitBeforeContinueIfNeed();
|
Log::WaitBeforeContinueIfNeed();
|
||||||
|
|
@ -275,27 +275,27 @@ extern int main(int argc, char **argv)
|
||||||
HookSignals();
|
HookSignals();
|
||||||
|
|
||||||
///- Handle affinity for multiple processors and process priority on Windows
|
///- Handle affinity for multiple processors and process priority on Windows
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
{
|
{
|
||||||
HANDLE hProcess = GetCurrentProcess();
|
HANDLE hProcess = GetCurrentProcess();
|
||||||
|
|
||||||
uint32 Aff = sConfig.GetIntDefault("UseProcessors", 0);
|
uint32 Aff = sConfig.GetIntDefault("UseProcessors", 0);
|
||||||
if(Aff > 0)
|
if (Aff > 0)
|
||||||
{
|
{
|
||||||
ULONG_PTR appAff;
|
ULONG_PTR appAff;
|
||||||
ULONG_PTR sysAff;
|
ULONG_PTR sysAff;
|
||||||
|
|
||||||
if(GetProcessAffinityMask(hProcess,&appAff,&sysAff))
|
if (GetProcessAffinityMask(hProcess,&appAff,&sysAff))
|
||||||
{
|
{
|
||||||
ULONG_PTR curAff = Aff & appAff; // remove non accessible processors
|
ULONG_PTR curAff = Aff & appAff; // remove non accessible processors
|
||||||
|
|
||||||
if(!curAff )
|
if (!curAff)
|
||||||
{
|
{
|
||||||
sLog.outError("Processors marked in UseProcessors bitmask (hex) %x not accessible for realmd. Accessible processors bitmask (hex): %x",Aff,appAff);
|
sLog.outError("Processors marked in UseProcessors bitmask (hex) %x not accessible for realmd. Accessible processors bitmask (hex): %x",Aff,appAff);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(SetProcessAffinityMask(hProcess,curAff))
|
if (SetProcessAffinityMask(hProcess,curAff))
|
||||||
sLog.outString("Using processors (bitmask, hex): %x", curAff);
|
sLog.outString("Using processors (bitmask, hex): %x", curAff);
|
||||||
else
|
else
|
||||||
sLog.outError("Can't set used processors (hex): %x", curAff);
|
sLog.outError("Can't set used processors (hex): %x", curAff);
|
||||||
|
|
@ -306,27 +306,27 @@ extern int main(int argc, char **argv)
|
||||||
|
|
||||||
bool Prio = sConfig.GetBoolDefault("ProcessPriority", false);
|
bool Prio = sConfig.GetBoolDefault("ProcessPriority", false);
|
||||||
|
|
||||||
if(Prio)
|
if (Prio)
|
||||||
{
|
{
|
||||||
if(SetPriorityClass(hProcess,HIGH_PRIORITY_CLASS))
|
if (SetPriorityClass(hProcess,HIGH_PRIORITY_CLASS))
|
||||||
sLog.outString("realmd process priority class set to HIGH");
|
sLog.outString("realmd process priority class set to HIGH");
|
||||||
else
|
else
|
||||||
sLog.outError("Can't set realmd process priority class.");
|
sLog.outError("Can't set realmd process priority class.");
|
||||||
sLog.outString();
|
sLog.outString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//server has started up successfully => enable async DB requests
|
//server has started up successfully => enable async DB requests
|
||||||
LoginDatabase.AllowAsyncTransactions();
|
LoginDatabase.AllowAsyncTransactions();
|
||||||
|
|
||||||
// maximum counter for next ping
|
// maximum counter for next ping
|
||||||
uint32 numLoops = (sConfig.GetIntDefault( "MaxPingTime", 30 ) * (MINUTE * 1000000 / 100000));
|
uint32 numLoops = (sConfig.GetIntDefault("MaxPingTime", 30) * (MINUTE * 1000000 / 100000));
|
||||||
uint32 loopCounter = 0;
|
uint32 loopCounter = 0;
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
detachDaemon();
|
detachDaemon();
|
||||||
#endif
|
#endif
|
||||||
///- Wait for termination signal
|
///- Wait for termination signal
|
||||||
while (!stopEvent)
|
while (!stopEvent)
|
||||||
{
|
{
|
||||||
|
|
@ -336,7 +336,7 @@ extern int main(int argc, char **argv)
|
||||||
if (ACE_Reactor::instance()->run_reactor_event_loop(interval) == -1)
|
if (ACE_Reactor::instance()->run_reactor_event_loop(interval) == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if( (++loopCounter) == numLoops )
|
if ((++loopCounter) == numLoops)
|
||||||
{
|
{
|
||||||
loopCounter = 0;
|
loopCounter = 0;
|
||||||
DETAIL_LOG("Ping MySQL to keep connection alive");
|
DETAIL_LOG("Ping MySQL to keep connection alive");
|
||||||
|
|
@ -354,7 +354,7 @@ extern int main(int argc, char **argv)
|
||||||
///- Remove signal handling before leaving
|
///- Remove signal handling before leaving
|
||||||
UnhookSignals();
|
UnhookSignals();
|
||||||
|
|
||||||
sLog.outString( "Halting process..." );
|
sLog.outString("Halting process...");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -368,11 +368,11 @@ void OnSignal(int s)
|
||||||
case SIGTERM:
|
case SIGTERM:
|
||||||
stopEvent = true;
|
stopEvent = true;
|
||||||
break;
|
break;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
case SIGBREAK:
|
case SIGBREAK:
|
||||||
stopEvent = true;
|
stopEvent = true;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
signal(s, OnSignal);
|
signal(s, OnSignal);
|
||||||
|
|
@ -382,7 +382,7 @@ void OnSignal(int s)
|
||||||
bool StartDB()
|
bool StartDB()
|
||||||
{
|
{
|
||||||
std::string dbstring = sConfig.GetStringDefault("LoginDatabaseInfo", "");
|
std::string dbstring = sConfig.GetStringDefault("LoginDatabaseInfo", "");
|
||||||
if(dbstring.empty())
|
if (dbstring.empty())
|
||||||
{
|
{
|
||||||
sLog.outError("Database not specified");
|
sLog.outError("Database not specified");
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -390,13 +390,13 @@ bool StartDB()
|
||||||
|
|
||||||
sLog.outString("Login Database total connections: %i", 1 + 1);
|
sLog.outString("Login Database total connections: %i", 1 + 1);
|
||||||
|
|
||||||
if(!LoginDatabase.Initialize(dbstring.c_str()))
|
if (!LoginDatabase.Initialize(dbstring.c_str()))
|
||||||
{
|
{
|
||||||
sLog.outError("Cannot connect to database");
|
sLog.outError("Cannot connect to database");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!LoginDatabase.CheckRequiredField("realmd_db_version",REVISION_DB_REALMD))
|
if (!LoginDatabase.CheckRequiredField("realmd_db_version",REVISION_DB_REALMD))
|
||||||
{
|
{
|
||||||
///- Wait for already started DB delay threads to end
|
///- Wait for already started DB delay threads to end
|
||||||
LoginDatabase.HaltDelayThread();
|
LoginDatabase.HaltDelayThread();
|
||||||
|
|
@ -411,9 +411,9 @@ void HookSignals()
|
||||||
{
|
{
|
||||||
signal(SIGINT, OnSignal);
|
signal(SIGINT, OnSignal);
|
||||||
signal(SIGTERM, OnSignal);
|
signal(SIGTERM, OnSignal);
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
signal(SIGBREAK, OnSignal);
|
signal(SIGBREAK, OnSignal);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unhook the signals before leaving
|
/// Unhook the signals before leaving
|
||||||
|
|
@ -421,9 +421,9 @@ void UnhookSignals()
|
||||||
{
|
{
|
||||||
signal(SIGINT, 0);
|
signal(SIGINT, 0);
|
||||||
signal(SIGTERM, 0);
|
signal(SIGTERM, 0);
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
signal(SIGBREAK, 0);
|
signal(SIGBREAK, 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
||||||
|
|
@ -64,13 +64,13 @@ PatchHandler::PatchHandler(ACE_HANDLE socket, ACE_HANDLE patch)
|
||||||
|
|
||||||
PatchHandler::~PatchHandler()
|
PatchHandler::~PatchHandler()
|
||||||
{
|
{
|
||||||
if(patch_fd_ != ACE_INVALID_HANDLE)
|
if (patch_fd_ != ACE_INVALID_HANDLE)
|
||||||
ACE_OS::close(patch_fd_);
|
ACE_OS::close(patch_fd_);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PatchHandler::open(void*)
|
int PatchHandler::open(void*)
|
||||||
{
|
{
|
||||||
if(get_handle() == ACE_INVALID_HANDLE || patch_fd_ == ACE_INVALID_HANDLE)
|
if (get_handle() == ACE_INVALID_HANDLE || patch_fd_ == ACE_INVALID_HANDLE)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
int nodelay = 0;
|
int nodelay = 0;
|
||||||
|
|
@ -111,11 +111,11 @@ int PatchHandler::svc(void)
|
||||||
|
|
||||||
ssize_t r;
|
ssize_t r;
|
||||||
|
|
||||||
while((r = ACE_OS::read(patch_fd_, data.data, sizeof(data.data))) > 0)
|
while ((r = ACE_OS::read(patch_fd_, data.data, sizeof(data.data))) > 0)
|
||||||
{
|
{
|
||||||
data.data_size = (ACE_UINT16)r;
|
data.data_size = (ACE_UINT16)r;
|
||||||
|
|
||||||
if(peer().send((const char*)&data,
|
if (peer().send((const char*)&data,
|
||||||
((size_t) r) + sizeof(data) - sizeof(data.data),
|
((size_t) r) + sizeof(data) - sizeof(data.data),
|
||||||
flags) == -1)
|
flags) == -1)
|
||||||
{
|
{
|
||||||
|
|
@ -123,7 +123,7 @@ int PatchHandler::svc(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(r == -1)
|
if (r == -1)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -133,7 +133,7 @@ int PatchHandler::svc(void)
|
||||||
|
|
||||||
PatchCache::~PatchCache()
|
PatchCache::~PatchCache()
|
||||||
{
|
{
|
||||||
for (Patches::iterator i = patches_.begin (); i != patches_.end (); i++)
|
for (Patches::iterator i = patches_.begin(); i != patches_.end(); i++)
|
||||||
delete i->second;
|
delete i->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -152,10 +152,10 @@ void PatchCache::LoadPatchMD5(const 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", path.c_str());
|
sLog.outDebug("Loading patch info from %s", path.c_str());
|
||||||
|
|
||||||
if(!pPatch)
|
if (!pPatch)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Calculate the MD5 hash
|
// Calculate the MD5 hash
|
||||||
|
|
@ -166,7 +166,7 @@ void PatchCache::LoadPatchMD5(const char* szFileName)
|
||||||
|
|
||||||
ACE_UINT8 buf[check_chunk_size];
|
ACE_UINT8 buf[check_chunk_size];
|
||||||
|
|
||||||
while(!feof (pPatch))
|
while (!feof(pPatch))
|
||||||
{
|
{
|
||||||
size_t read = fread(buf, 1, check_chunk_size, pPatch);
|
size_t read = fread(buf, 1, check_chunk_size, pPatch);
|
||||||
MD5_Update(&ctx, buf, read);
|
MD5_Update(&ctx, buf, read);
|
||||||
|
|
@ -176,13 +176,13 @@ void PatchCache::LoadPatchMD5(const 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((ACE_UINT8 *) & patches_[path]->md5, &ctx);
|
MD5_Final((ACE_UINT8*) & patches_[path]->md5, &ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PatchCache::GetHash(const char * pat, ACE_UINT8 mymd5[MD5_DIGEST_LENGTH])
|
bool PatchCache::GetHash(const char* pat, ACE_UINT8 mymd5[MD5_DIGEST_LENGTH])
|
||||||
{
|
{
|
||||||
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()))
|
||||||
{
|
{
|
||||||
memcpy(mymd5, i->second->md5, MD5_DIGEST_LENGTH);
|
memcpy(mymd5, i->second->md5, MD5_DIGEST_LENGTH);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -195,18 +195,18 @@ void PatchCache::LoadPatchesInfo()
|
||||||
{
|
{
|
||||||
ACE_DIR* dirp = ACE_OS::opendir(ACE_TEXT("./patches/"));
|
ACE_DIR* dirp = ACE_OS::opendir(ACE_TEXT("./patches/"));
|
||||||
|
|
||||||
if(!dirp)
|
if (!dirp)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ACE_DIRENT* dp;
|
ACE_DIRENT* dp;
|
||||||
|
|
||||||
while((dp = ACE_OS::readdir(dirp)) != NULL)
|
while ((dp = ACE_OS::readdir(dirp)) != NULL)
|
||||||
{
|
{
|
||||||
int l = strlen(dp->d_name);
|
int l = strlen(dp->d_name);
|
||||||
if (l < 8)
|
if (l < 8)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(!memcmp(&dp->d_name[l - 4], ".mpq", 4))
|
if (!memcmp(&dp->d_name[l - 4], ".mpq", 4))
|
||||||
LoadPatchMD5(dp->d_name);
|
LoadPatchMD5(dp->d_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ class PatchCache
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadPatchMD5(const char*);
|
void LoadPatchMD5(const char*);
|
||||||
bool GetHash(const char * pat, ACE_UINT8 mymd5[MD5_DIGEST_LENGTH]);
|
bool GetHash(const char* pat, ACE_UINT8 mymd5[MD5_DIGEST_LENGTH]);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void LoadPatchesInfo();
|
void LoadPatchesInfo();
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
#include "Policies/SingletonImp.h"
|
#include "Policies/SingletonImp.h"
|
||||||
#include "Database/DatabaseEnv.h"
|
#include "Database/DatabaseEnv.h"
|
||||||
|
|
||||||
INSTANTIATE_SINGLETON_1( RealmList );
|
INSTANTIATE_SINGLETON_1(RealmList);
|
||||||
|
|
||||||
extern DatabaseType LoginDatabase;
|
extern DatabaseType LoginDatabase;
|
||||||
|
|
||||||
|
|
@ -35,7 +35,8 @@ extern DatabaseType LoginDatabase;
|
||||||
// if you need more from old build then add it in cases in realmd sources code
|
// if you need more from old build then add it in cases in realmd sources code
|
||||||
// list sorted from high to low build and first build used as low bound for accepted by default range (any > it will accepted by realmd at least)
|
// list sorted from high to low build and first build used as low bound for accepted by default range (any > it will accepted by realmd at least)
|
||||||
|
|
||||||
static RealmBuildInfo ExpectedRealmdClientBuilds[] = {
|
static RealmBuildInfo ExpectedRealmdClientBuilds[] =
|
||||||
|
{
|
||||||
{12340, 3, 3, 5, 'a'}, // highest supported build, also auto accept all above for simplify future supported builds testing
|
{12340, 3, 3, 5, 'a'}, // highest supported build, also auto accept all above for simplify future supported builds testing
|
||||||
{11723, 3, 3, 3, 'a'},
|
{11723, 3, 3, 3, 'a'},
|
||||||
{11403, 3, 3, 2, ' '},
|
{11403, 3, 3, 2, ' '},
|
||||||
|
|
@ -54,15 +55,15 @@ RealmBuildInfo const* FindBuildInfo(uint16 _build)
|
||||||
return &ExpectedRealmdClientBuilds[0];
|
return &ExpectedRealmdClientBuilds[0];
|
||||||
|
|
||||||
// continue from 1 with explicit equal check
|
// continue from 1 with explicit equal check
|
||||||
for(int i = 1; ExpectedRealmdClientBuilds[i].build; ++i)
|
for (int i = 1; ExpectedRealmdClientBuilds[i].build; ++i)
|
||||||
if(_build == ExpectedRealmdClientBuilds[i].build)
|
if (_build == ExpectedRealmdClientBuilds[i].build)
|
||||||
return &ExpectedRealmdClientBuilds[i];
|
return &ExpectedRealmdClientBuilds[i];
|
||||||
|
|
||||||
// none appropriate build
|
// none appropriate build
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
RealmList::RealmList( ) : m_UpdateInterval(0), m_NextUpdateTime(time(NULL))
|
RealmList::RealmList() : m_UpdateInterval(0), m_NextUpdateTime(time(NULL))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,7 +82,7 @@ void RealmList::Initialize(uint32 updateInterval)
|
||||||
UpdateRealms(true);
|
UpdateRealms(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RealmList::UpdateRealm( uint32 ID, const std::string& name, const std::string& address, uint32 port, uint8 icon, RealmFlags realmflags, uint8 timezone, AccountTypes allowedSecurityLevel, float popu, const std::string& builds)
|
void RealmList::UpdateRealm(uint32 ID, const std::string& name, const std::string& address, uint32 port, uint8 icon, RealmFlags realmflags, uint8 timezone, AccountTypes allowedSecurityLevel, float popu, const std::string& builds)
|
||||||
{
|
{
|
||||||
///- Create new if not exist or update existed
|
///- Create new if not exist or update existed
|
||||||
Realm& realm = m_realms[name];
|
Realm& realm = m_realms[name];
|
||||||
|
|
@ -124,7 +125,7 @@ void RealmList::UpdateRealm( uint32 ID, const std::string& name, const std::stri
|
||||||
void RealmList::UpdateIfNeed()
|
void RealmList::UpdateIfNeed()
|
||||||
{
|
{
|
||||||
// maybe disabled or updated recently
|
// maybe disabled or updated recently
|
||||||
if(!m_UpdateInterval || m_NextUpdateTime > time(NULL))
|
if (!m_UpdateInterval || m_NextUpdateTime > time(NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_NextUpdateTime = time(NULL) + m_UpdateInterval;
|
m_NextUpdateTime = time(NULL) + m_UpdateInterval;
|
||||||
|
|
@ -141,14 +142,14 @@ void RealmList::UpdateRealms(bool init)
|
||||||
DETAIL_LOG("Updating Realm List...");
|
DETAIL_LOG("Updating Realm List...");
|
||||||
|
|
||||||
//// 0 1 2 3 4 5 6 7 8 9
|
//// 0 1 2 3 4 5 6 7 8 9
|
||||||
QueryResult *result = LoginDatabase.Query( "SELECT id, name, address, port, icon, realmflags, timezone, allowedSecurityLevel, population, realmbuilds FROM realmlist WHERE (realmflags & 1) = 0 ORDER BY name" );
|
QueryResult* result = LoginDatabase.Query("SELECT id, name, address, port, icon, realmflags, timezone, allowedSecurityLevel, population, realmbuilds FROM realmlist WHERE (realmflags & 1) = 0 ORDER BY name");
|
||||||
|
|
||||||
///- Circle through results and add them to the realm map
|
///- Circle through results and add them to the realm map
|
||||||
if(result)
|
if (result)
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
Field *fields = result->Fetch();
|
Field* fields = result->Fetch();
|
||||||
|
|
||||||
uint8 allowedSecurityLevel = fields[7].GetUInt8();
|
uint8 allowedSecurityLevel = fields[7].GetUInt8();
|
||||||
|
|
||||||
|
|
@ -166,9 +167,10 @@ void RealmList::UpdateRealms(bool init)
|
||||||
(allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR),
|
(allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR),
|
||||||
fields[8].GetFloat(), fields[9].GetCppString());
|
fields[8].GetFloat(), fields[9].GetCppString());
|
||||||
|
|
||||||
if(init)
|
if (init)
|
||||||
sLog.outString("Added realm \"%s\"", fields[1].GetString());
|
sLog.outString("Added realm \"%s\"", fields[1].GetString());
|
||||||
} while( result->NextRow() );
|
}
|
||||||
|
while (result->NextRow());
|
||||||
delete result;
|
delete result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ class RealmList
|
||||||
uint32 size() const { return m_realms.size(); }
|
uint32 size() const { return m_realms.size(); }
|
||||||
private:
|
private:
|
||||||
void UpdateRealms(bool init);
|
void UpdateRealms(bool init);
|
||||||
void UpdateRealm( uint32 ID, const std::string& name, const std::string& address, uint32 port, uint8 icon, RealmFlags realmflags, uint8 timezone, AccountTypes allowedSecurityLevel, float popu, const std::string& builds);
|
void UpdateRealm(uint32 ID, const std::string& name, const std::string& address, uint32 port, uint8 icon, RealmFlags realmflags, uint8 timezone, AccountTypes allowedSecurityLevel, float popu, const std::string& builds);
|
||||||
private:
|
private:
|
||||||
RealmMap m_realms; ///< Internal map of realms
|
RealmMap m_realms; ///< Internal map of realms
|
||||||
uint32 m_UpdateInterval;
|
uint32 m_UpdateInterval;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue