Cleanup on some database-related files: merge some DB-related files, add some consistency to callhandles in sourcetree (M
+ combine MySQL-specific files into main database-files (click) + fix vcproj-files, adjust handler-function names for consistency (Machiavelli) --HG-- branch : trunk
This commit is contained in:
+20
-20
@@ -27,7 +27,7 @@
|
||||
#include "Util.h"
|
||||
#include "Auth/Sha1.h"
|
||||
|
||||
extern DatabaseType loginDatabase;
|
||||
extern DatabaseType LoginDatabase;
|
||||
|
||||
INSTANTIATE_SINGLETON_1(AccountMgr);
|
||||
|
||||
@@ -50,16 +50,16 @@ AccountOpResult AccountMgr::CreateAccount(std::string username, std::string pass
|
||||
return AOR_NAME_ALREDY_EXIST; // username does already exist
|
||||
}
|
||||
|
||||
if (!loginDatabase.PExecute("INSERT INTO account(username,sha_pass_hash,joindate) VALUES('%s','%s',NOW())", username.c_str(), CalculateShaPassHash(username, password).c_str()))
|
||||
if (!LoginDatabase.PExecute("INSERT INTO account(username,sha_pass_hash,joindate) VALUES('%s','%s',NOW())", username.c_str(), CalculateShaPassHash(username, password).c_str()))
|
||||
return AOR_DB_INTERNAL_ERROR; // unexpected error
|
||||
loginDatabase.Execute("INSERT INTO realmcharacters (realmid, acctid, numchars) SELECT realmlist.id, account.id, 0 FROM realmlist,account LEFT JOIN realmcharacters ON acctid=account.id WHERE acctid IS NULL");
|
||||
LoginDatabase.Execute("INSERT INTO realmcharacters (realmid, acctid, numchars) SELECT realmlist.id, account.id, 0 FROM realmlist,account LEFT JOIN realmcharacters ON acctid=account.id WHERE acctid IS NULL");
|
||||
|
||||
return AOR_OK; // everything's fine
|
||||
}
|
||||
|
||||
AccountOpResult AccountMgr::DeleteAccount(uint32 accid)
|
||||
{
|
||||
QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT 1 FROM account WHERE id='%d'", accid);
|
||||
QueryResult_AutoPtr result = LoginDatabase.PQuery("SELECT 1 FROM account WHERE id='%d'", accid);
|
||||
if (!result)
|
||||
return AOR_NAME_NOT_EXIST; // account doesn't exist
|
||||
|
||||
@@ -88,14 +88,14 @@ AccountOpResult AccountMgr::DeleteAccount(uint32 accid)
|
||||
CharacterDatabase.PExecute("DELETE FROM character_tutorial WHERE account = '%u'",accid);
|
||||
CharacterDatabase.PExecute("DELETE FROM account_data WHERE account = '%u'",accid);
|
||||
|
||||
loginDatabase.BeginTransaction();
|
||||
LoginDatabase.BeginTransaction();
|
||||
|
||||
bool res =
|
||||
loginDatabase.PExecute("DELETE FROM account WHERE id='%d'", accid) &&
|
||||
loginDatabase.PExecute("DELETE FROM account_access WHERE id ='%d'", accid) &&
|
||||
loginDatabase.PExecute("DELETE FROM realmcharacters WHERE acctid='%d'", accid);
|
||||
LoginDatabase.PExecute("DELETE FROM account WHERE id='%d'", accid) &&
|
||||
LoginDatabase.PExecute("DELETE FROM account_access WHERE id ='%d'", accid) &&
|
||||
LoginDatabase.PExecute("DELETE FROM realmcharacters WHERE acctid='%d'", accid);
|
||||
|
||||
loginDatabase.CommitTransaction();
|
||||
LoginDatabase.CommitTransaction();
|
||||
|
||||
if (!res)
|
||||
return AOR_DB_INTERNAL_ERROR; // unexpected error;
|
||||
@@ -105,7 +105,7 @@ AccountOpResult AccountMgr::DeleteAccount(uint32 accid)
|
||||
|
||||
AccountOpResult AccountMgr::ChangeUsername(uint32 accid, std::string new_uname, std::string new_passwd)
|
||||
{
|
||||
QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT 1 FROM account WHERE id='%d'", accid);
|
||||
QueryResult_AutoPtr result = LoginDatabase.PQuery("SELECT 1 FROM account WHERE id='%d'", accid);
|
||||
if (!result)
|
||||
return AOR_NAME_NOT_EXIST; // account doesn't exist
|
||||
|
||||
@@ -119,9 +119,9 @@ AccountOpResult AccountMgr::ChangeUsername(uint32 accid, std::string new_uname,
|
||||
normalizeString(new_passwd);
|
||||
|
||||
std::string safe_new_uname = new_uname;
|
||||
loginDatabase.escape_string(safe_new_uname);
|
||||
LoginDatabase.escape_string(safe_new_uname);
|
||||
|
||||
if (!loginDatabase.PExecute("UPDATE account SET v='0',s='0',username='%s',sha_pass_hash='%s' WHERE id='%d'", safe_new_uname.c_str(),
|
||||
if (!LoginDatabase.PExecute("UPDATE account SET v='0',s='0',username='%s',sha_pass_hash='%s' WHERE id='%d'", safe_new_uname.c_str(),
|
||||
CalculateShaPassHash(new_uname, new_passwd).c_str(), accid))
|
||||
return AOR_DB_INTERNAL_ERROR; // unexpected error
|
||||
|
||||
@@ -142,7 +142,7 @@ AccountOpResult AccountMgr::ChangePassword(uint32 accid, std::string new_passwd)
|
||||
normalizeString(new_passwd);
|
||||
|
||||
// also reset s and v to force update at next realmd login
|
||||
if (!loginDatabase.PExecute("UPDATE account SET v='0', s='0', sha_pass_hash='%s' WHERE id='%d'",
|
||||
if (!LoginDatabase.PExecute("UPDATE account SET v='0', s='0', sha_pass_hash='%s' WHERE id='%d'",
|
||||
CalculateShaPassHash(username, new_passwd).c_str(), accid))
|
||||
return AOR_DB_INTERNAL_ERROR; // unexpected error
|
||||
|
||||
@@ -151,8 +151,8 @@ AccountOpResult AccountMgr::ChangePassword(uint32 accid, std::string new_passwd)
|
||||
|
||||
uint32 AccountMgr::GetId(std::string username)
|
||||
{
|
||||
loginDatabase.escape_string(username);
|
||||
QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT id FROM account WHERE username = '%s'", username.c_str());
|
||||
LoginDatabase.escape_string(username);
|
||||
QueryResult_AutoPtr result = LoginDatabase.PQuery("SELECT id FROM account WHERE username = '%s'", username.c_str());
|
||||
if (!result)
|
||||
return 0;
|
||||
else
|
||||
@@ -164,7 +164,7 @@ uint32 AccountMgr::GetId(std::string username)
|
||||
|
||||
uint32 AccountMgr::GetSecurity(uint32 acc_id)
|
||||
{
|
||||
QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT gmlevel FROM account_access WHERE id = '%u'", acc_id);
|
||||
QueryResult_AutoPtr result = LoginDatabase.PQuery("SELECT gmlevel FROM account_access WHERE id = '%u'", acc_id);
|
||||
if (result)
|
||||
{
|
||||
uint32 sec = (*result)[0].GetUInt32();
|
||||
@@ -177,8 +177,8 @@ uint32 AccountMgr::GetSecurity(uint32 acc_id)
|
||||
uint32 AccountMgr::GetSecurity(uint32 acc_id, int32 realm_id)
|
||||
{
|
||||
QueryResult_AutoPtr result = (realm_id == -1)
|
||||
? loginDatabase.PQuery("SELECT gmlevel FROM account_access WHERE id = '%u' AND RealmID = '%d'", acc_id, realm_id)
|
||||
: loginDatabase.PQuery("SELECT gmlevel FROM account_access WHERE id = '%u' AND (RealmID = '%d' OR RealmID = '-1')", acc_id, realm_id);
|
||||
? LoginDatabase.PQuery("SELECT gmlevel FROM account_access WHERE id = '%u' AND RealmID = '%d'", acc_id, realm_id)
|
||||
: LoginDatabase.PQuery("SELECT gmlevel FROM account_access WHERE id = '%u' AND (RealmID = '%d' OR RealmID = '-1')", acc_id, realm_id);
|
||||
if (result)
|
||||
{
|
||||
uint32 sec = (*result)[0].GetUInt32();
|
||||
@@ -190,7 +190,7 @@ uint32 AccountMgr::GetSecurity(uint32 acc_id, int32 realm_id)
|
||||
|
||||
bool AccountMgr::GetName(uint32 acc_id, std::string &name)
|
||||
{
|
||||
QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT username FROM account WHERE id = '%u'", acc_id);
|
||||
QueryResult_AutoPtr result = LoginDatabase.PQuery("SELECT username FROM account WHERE id = '%u'", acc_id);
|
||||
if (result)
|
||||
{
|
||||
name = (*result)[0].GetCppString();
|
||||
@@ -209,7 +209,7 @@ bool AccountMgr::CheckPassword(uint32 accid, std::string passwd)
|
||||
normalizeString(username);
|
||||
normalizeString(passwd);
|
||||
|
||||
QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT 1 FROM account WHERE id='%d' AND sha_pass_hash='%s'", accid, CalculateShaPassHash(username, passwd).c_str());
|
||||
QueryResult_AutoPtr result = LoginDatabase.PQuery("SELECT 1 FROM account WHERE id='%d' AND sha_pass_hash='%s'", accid, CalculateShaPassHash(username, passwd).c_str());
|
||||
if (result)
|
||||
return true;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "Auth/Sha1.h"
|
||||
#include "ProgressBar.h"
|
||||
|
||||
extern DatabaseType loginDatabase;
|
||||
extern DatabaseType LoginDatabase;
|
||||
|
||||
INSTANTIATE_SINGLETON_1(AddonMgr);
|
||||
|
||||
|
||||
@@ -279,7 +279,7 @@ void WorldSession::HandleCharCreateOpcode(WorldPacket & recv_data)
|
||||
return;
|
||||
}
|
||||
|
||||
QueryResult_AutoPtr resultacct = loginDatabase.PQuery("SELECT SUM(numchars) FROM realmcharacters WHERE acctid = '%d'", GetAccountId());
|
||||
QueryResult_AutoPtr resultacct = LoginDatabase.PQuery("SELECT SUM(numchars) FROM realmcharacters WHERE acctid = '%d'", GetAccountId());
|
||||
if (resultacct)
|
||||
{
|
||||
Field *fields=resultacct->Fetch();
|
||||
@@ -466,8 +466,8 @@ void WorldSession::HandleCharCreateOpcode(WorldPacket & recv_data)
|
||||
pNewChar->SaveToDB();
|
||||
charcount+=1;
|
||||
|
||||
loginDatabase.PExecute("DELETE FROM realmcharacters WHERE acctid= '%d' AND realmid = '%d'", GetAccountId(), realmID);
|
||||
loginDatabase.PExecute("INSERT INTO realmcharacters (numchars, acctid, realmid) VALUES (%u, %u, %u)", charcount, GetAccountId(), realmID);
|
||||
LoginDatabase.PExecute("DELETE FROM realmcharacters WHERE acctid= '%d' AND realmid = '%d'", GetAccountId(), realmID);
|
||||
LoginDatabase.PExecute("INSERT INTO realmcharacters (numchars, acctid, realmid) VALUES (%u, %u, %u)", charcount, GetAccountId(), realmID);
|
||||
|
||||
pNewChar->CleanupsBeforeDelete();
|
||||
delete pNewChar; // created only to call SaveToDB()
|
||||
@@ -723,7 +723,7 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder * holder)
|
||||
pCurrChar->SendInitialPacketsAfterAddToMap();
|
||||
|
||||
CharacterDatabase.PExecute("UPDATE characters SET online = 1 WHERE guid = '%u'", pCurrChar->GetGUIDLow());
|
||||
loginDatabase.PExecute("UPDATE account SET online = 1 WHERE id = '%u'", GetAccountId());
|
||||
LoginDatabase.PExecute("UPDATE account SET online = 1 WHERE id = '%u'", GetAccountId());
|
||||
pCurrChar->SetInGameTime(getMSTime());
|
||||
|
||||
// announce group about member online (must be after add to player list to receive announce to self)
|
||||
|
||||
+3
-3
@@ -254,7 +254,7 @@ bool ChatHandler::HandleAccountAddonCommand(const char* args)
|
||||
return false;
|
||||
|
||||
// No SQL injection
|
||||
loginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'", expansion, account_id);
|
||||
LoginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'", expansion, account_id);
|
||||
PSendSysMessage(LANG_ACCOUNT_ADDON, expansion);
|
||||
return true;
|
||||
}
|
||||
@@ -270,14 +270,14 @@ bool ChatHandler::HandleAccountLockCommand(const char* args)
|
||||
std::string argstr = (char*)args;
|
||||
if (argstr == "on")
|
||||
{
|
||||
loginDatabase.PExecute("UPDATE account SET locked = '1' WHERE id = '%d'",m_session->GetAccountId());
|
||||
LoginDatabase.PExecute("UPDATE account SET locked = '1' WHERE id = '%d'",m_session->GetAccountId());
|
||||
PSendSysMessage(LANG_COMMAND_ACCLOCKLOCKED);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (argstr == "off")
|
||||
{
|
||||
loginDatabase.PExecute("UPDATE account SET locked = '0' WHERE id = '%d'",m_session->GetAccountId());
|
||||
LoginDatabase.PExecute("UPDATE account SET locked = '0' WHERE id = '%d'",m_session->GetAccountId());
|
||||
PSendSysMessage(LANG_COMMAND_ACCLOCKUNLOCKED);
|
||||
return true;
|
||||
}
|
||||
|
||||
+9
-9
@@ -84,7 +84,7 @@ bool ChatHandler::HandleMuteCommand(const char* args)
|
||||
if (target)
|
||||
target->GetSession()->m_muteTime = mutetime;
|
||||
|
||||
loginDatabase.PExecute("UPDATE account SET mutetime = " UI64FMTD " WHERE id = '%u'",uint64(mutetime), account_id);
|
||||
LoginDatabase.PExecute("UPDATE account SET mutetime = " UI64FMTD " WHERE id = '%u'",uint64(mutetime), account_id);
|
||||
|
||||
if (target)
|
||||
ChatHandler(target).PSendSysMessage(LANG_YOUR_CHAT_DISABLED, notspeaktime, mutereasonstr.c_str());
|
||||
@@ -128,7 +128,7 @@ bool ChatHandler::HandleUnmuteCommand(const char* args)
|
||||
target->GetSession()->m_muteTime = 0;
|
||||
}
|
||||
|
||||
loginDatabase.PExecute("UPDATE account SET mutetime = '0' WHERE id = '%u'", account_id);
|
||||
LoginDatabase.PExecute("UPDATE account SET mutetime = '0' WHERE id = '%u'", account_id);
|
||||
|
||||
if (target)
|
||||
ChatHandler(target).PSendSysMessage(LANG_YOUR_CHAT_ENABLED);
|
||||
@@ -2215,7 +2215,7 @@ bool ChatHandler::HandlePInfoCommand(const char* args)
|
||||
uint32 security = 0;
|
||||
std::string last_login = GetTrinityString(LANG_ERROR);
|
||||
|
||||
QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT a.username,aa.gmlevel,a.email,a.last_ip,a.last_login "
|
||||
QueryResult_AutoPtr result = LoginDatabase.PQuery("SELECT a.username,aa.gmlevel,a.email,a.last_ip,a.last_login "
|
||||
"FROM account a "
|
||||
"LEFT JOIN account_access aa "
|
||||
"ON (a.id = aa.id) "
|
||||
@@ -3741,9 +3741,9 @@ bool ChatHandler::HandleLookupPlayerIpCommand(const char* args)
|
||||
char* limit_str = strtok (NULL, " ");
|
||||
int32 limit = limit_str ? atoi (limit_str) : -1;
|
||||
|
||||
loginDatabase.escape_string (ip);
|
||||
LoginDatabase.escape_string (ip);
|
||||
|
||||
QueryResult_AutoPtr result = loginDatabase.PQuery ("SELECT id,username FROM account WHERE last_ip = '%s'", ip.c_str ());
|
||||
QueryResult_AutoPtr result = LoginDatabase.PQuery ("SELECT id,username FROM account WHERE last_ip = '%s'", ip.c_str ());
|
||||
|
||||
return LookupPlayerSearchCommand (result,limit);
|
||||
}
|
||||
@@ -3760,9 +3760,9 @@ bool ChatHandler::HandleLookupPlayerAccountCommand(const char* args)
|
||||
if (!AccountMgr::normalizeString (account))
|
||||
return false;
|
||||
|
||||
loginDatabase.escape_string (account);
|
||||
LoginDatabase.escape_string (account);
|
||||
|
||||
QueryResult_AutoPtr result = loginDatabase.PQuery ("SELECT id,username FROM account WHERE username = '%s'", account.c_str ());
|
||||
QueryResult_AutoPtr result = LoginDatabase.PQuery ("SELECT id,username FROM account WHERE username = '%s'", account.c_str ());
|
||||
|
||||
return LookupPlayerSearchCommand (result,limit);
|
||||
}
|
||||
@@ -3777,9 +3777,9 @@ bool ChatHandler::HandleLookupPlayerEmailCommand(const char* args)
|
||||
char* limit_str = strtok (NULL, " ");
|
||||
int32 limit = limit_str ? atoi (limit_str) : -1;
|
||||
|
||||
loginDatabase.escape_string (email);
|
||||
LoginDatabase.escape_string (email);
|
||||
|
||||
QueryResult_AutoPtr result = loginDatabase.PQuery ("SELECT id,username FROM account WHERE email = '%s'", email.c_str ());
|
||||
QueryResult_AutoPtr result = LoginDatabase.PQuery ("SELECT id,username FROM account WHERE email = '%s'", email.c_str ());
|
||||
|
||||
return LookupPlayerSearchCommand (result,limit);
|
||||
}
|
||||
|
||||
+21
-21
@@ -1465,7 +1465,7 @@ bool ChatHandler::HandleAccountSetGmLevelCommand(const char *args)
|
||||
// Check and abort if the target gm has a higher rank on one of the realms and the new realm is -1
|
||||
if (gmRealmID == -1)
|
||||
{
|
||||
QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT * FROM account_access WHERE id = '%u' AND gmlevel > '%d'", targetAccountId, gm);
|
||||
QueryResult_AutoPtr result = LoginDatabase.PQuery("SELECT * FROM account_access WHERE id = '%u' AND gmlevel > '%d'", targetAccountId, gm);
|
||||
if (result)
|
||||
{
|
||||
SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
|
||||
@@ -1484,12 +1484,12 @@ bool ChatHandler::HandleAccountSetGmLevelCommand(const char *args)
|
||||
|
||||
// If gmRealmID is -1, delete all values for the account id, else, insert values for the specific realmID
|
||||
if (gmRealmID == -1)
|
||||
loginDatabase.PExecute("DELETE FROM account_access WHERE id = '%u'", targetAccountId);
|
||||
LoginDatabase.PExecute("DELETE FROM account_access WHERE id = '%u'", targetAccountId);
|
||||
else
|
||||
loginDatabase.PExecute("DELETE FROM account_access WHERE id = '%u' AND (RealmID = '%d' OR RealmID = '-1')", targetAccountId, realmID);
|
||||
LoginDatabase.PExecute("DELETE FROM account_access WHERE id = '%u' AND (RealmID = '%d' OR RealmID = '-1')", targetAccountId, realmID);
|
||||
|
||||
if (gm != 0)
|
||||
loginDatabase.PExecute("INSERT INTO account_access VALUES ('%u','%d','%d')", targetAccountId, gm, realmID);
|
||||
LoginDatabase.PExecute("INSERT INTO account_access VALUES ('%u','%d','%d')", targetAccountId, gm, realmID);
|
||||
PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
|
||||
return true;
|
||||
}
|
||||
@@ -5914,7 +5914,7 @@ bool ChatHandler::HandleBanInfoCharacterCommand(const char *args)
|
||||
|
||||
bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
|
||||
{
|
||||
QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid);
|
||||
QueryResult_AutoPtr result = LoginDatabase.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid);
|
||||
if (!result)
|
||||
{
|
||||
PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
|
||||
@@ -5953,8 +5953,8 @@ bool ChatHandler::HandleBanInfoIPCommand(const char *args)
|
||||
|
||||
std::string IP = cIP;
|
||||
|
||||
loginDatabase.escape_string(IP);
|
||||
QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",IP.c_str());
|
||||
LoginDatabase.escape_string(IP);
|
||||
QueryResult_AutoPtr result = LoginDatabase.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",IP.c_str());
|
||||
if (!result)
|
||||
{
|
||||
PSendSysMessage(LANG_BANINFO_NOIP);
|
||||
@@ -5972,14 +5972,14 @@ bool ChatHandler::HandleBanInfoIPCommand(const char *args)
|
||||
|
||||
bool ChatHandler::HandleBanListCharacterCommand(const char *args)
|
||||
{
|
||||
loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate<>bandate");
|
||||
LoginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate<>bandate");
|
||||
|
||||
char* cFilter = strtok ((char*)args, " ");
|
||||
if (!cFilter)
|
||||
return false;
|
||||
|
||||
std::string filter = cFilter;
|
||||
loginDatabase.escape_string(filter);
|
||||
LoginDatabase.escape_string(filter);
|
||||
QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
|
||||
if (!result)
|
||||
{
|
||||
@@ -5992,22 +5992,22 @@ bool ChatHandler::HandleBanListCharacterCommand(const char *args)
|
||||
|
||||
bool ChatHandler::HandleBanListAccountCommand(const char *args)
|
||||
{
|
||||
loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate<>bandate");
|
||||
LoginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate<>bandate");
|
||||
|
||||
char* cFilter = strtok((char*)args, " ");
|
||||
std::string filter = cFilter ? cFilter : "";
|
||||
loginDatabase.escape_string(filter);
|
||||
LoginDatabase.escape_string(filter);
|
||||
|
||||
QueryResult_AutoPtr result;
|
||||
|
||||
if (filter.empty())
|
||||
{
|
||||
result = loginDatabase.Query("SELECT account.id, username FROM account, account_banned"
|
||||
result = LoginDatabase.Query("SELECT account.id, username FROM account, account_banned"
|
||||
" WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
|
||||
}
|
||||
else
|
||||
{
|
||||
result = loginDatabase.PQuery("SELECT account.id, username FROM account, account_banned"
|
||||
result = LoginDatabase.PQuery("SELECT account.id, username FROM account, account_banned"
|
||||
" WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
|
||||
filter.c_str());
|
||||
}
|
||||
@@ -6033,7 +6033,7 @@ bool ChatHandler::HandleBanListHelper(QueryResult_AutoPtr result)
|
||||
Field* fields = result->Fetch();
|
||||
uint32 accountid = fields[0].GetUInt32();
|
||||
|
||||
QueryResult_AutoPtr banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
|
||||
QueryResult_AutoPtr banresult = LoginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
|
||||
if (banresult)
|
||||
{
|
||||
Field* fields2 = banresult->Fetch();
|
||||
@@ -6063,7 +6063,7 @@ bool ChatHandler::HandleBanListHelper(QueryResult_AutoPtr result)
|
||||
accmgr.GetName (account_id,account_name);
|
||||
|
||||
// No SQL injection. id is uint32.
|
||||
QueryResult_AutoPtr banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
|
||||
QueryResult_AutoPtr banInfo = LoginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
|
||||
if (banInfo)
|
||||
{
|
||||
Field *fields2 = banInfo->Fetch();
|
||||
@@ -6097,23 +6097,23 @@ bool ChatHandler::HandleBanListHelper(QueryResult_AutoPtr result)
|
||||
|
||||
bool ChatHandler::HandleBanListIPCommand(const char *args)
|
||||
{
|
||||
loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate<>bandate");
|
||||
LoginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate<>bandate");
|
||||
|
||||
char* cFilter = strtok((char*)args, " ");
|
||||
std::string filter = cFilter ? cFilter : "";
|
||||
loginDatabase.escape_string(filter);
|
||||
LoginDatabase.escape_string(filter);
|
||||
|
||||
QueryResult_AutoPtr result;
|
||||
|
||||
if (filter.empty())
|
||||
{
|
||||
result = loginDatabase.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
|
||||
result = LoginDatabase.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
|
||||
" WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
|
||||
" ORDER BY unbandate");
|
||||
}
|
||||
else
|
||||
{
|
||||
result = loginDatabase.PQuery("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
|
||||
result = LoginDatabase.PQuery("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
|
||||
" WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")
|
||||
" ORDER BY unbandate",filter.c_str());
|
||||
}
|
||||
@@ -6868,7 +6868,7 @@ bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
|
||||
bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
|
||||
{
|
||||
///- Get the accounts with GM Level >0
|
||||
QueryResult_AutoPtr result = loginDatabase.Query("SELECT a.username,aa.gmlevel FROM account a, account_access aa WHERE a.id=aa.id AND aa.gmlevel > 0");
|
||||
QueryResult_AutoPtr result = LoginDatabase.Query("SELECT a.username,aa.gmlevel FROM account a, account_access aa WHERE a.id=aa.id AND aa.gmlevel > 0");
|
||||
if (result)
|
||||
{
|
||||
SendSysMessage(LANG_GMLIST);
|
||||
@@ -6976,7 +6976,7 @@ bool ChatHandler::HandleAccountSetAddonCommand(const char *args)
|
||||
return false;
|
||||
|
||||
// No SQL injection
|
||||
loginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",expansion,account_id);
|
||||
LoginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",expansion,account_id);
|
||||
PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,expansion);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1310,7 +1310,7 @@ void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data)
|
||||
|
||||
uint32 accid = plr->GetSession()->GetAccountId();
|
||||
|
||||
QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT username,email,last_ip FROM account WHERE id=%u", accid);
|
||||
QueryResult_AutoPtr result = LoginDatabase.PQuery("SELECT username,email,last_ip FROM account WHERE id=%u", accid);
|
||||
if (!result)
|
||||
{
|
||||
SendNotification(LANG_ACCOUNT_FOR_PLAYER_NOT_FOUND, charname.c_str());
|
||||
|
||||
+1
-1
@@ -4354,7 +4354,7 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC
|
||||
|
||||
CharacterDatabase.CommitTransaction();
|
||||
|
||||
//loginDatabase.PExecute("UPDATE realmcharacters SET numchars = numchars - 1 WHERE acctid = %d AND realmid = %d", accountId, realmID);
|
||||
//LoginDatabase.PExecute("UPDATE realmcharacters SET numchars = numchars - 1 WHERE acctid = %d AND realmid = %d", accountId, realmID);
|
||||
if (updateRealmChars) sWorld.UpdateRealmCharCount(accountId);
|
||||
}
|
||||
|
||||
|
||||
+18
-18
@@ -1275,7 +1275,7 @@ void World::SetInitialWorldSettings()
|
||||
// not send custom type REALM_FFA_PVP to realm list
|
||||
uint32 server_type = IsFFAPvPRealm() ? REALM_TYPE_PVP : getConfig(CONFIG_GAME_TYPE);
|
||||
uint32 realm_zone = getConfig(CONFIG_REALM_ZONE);
|
||||
loginDatabase.PExecute("UPDATE realmlist SET icon = %u, timezone = %u WHERE id = '%d'", server_type, realm_zone, realmID);
|
||||
LoginDatabase.PExecute("UPDATE realmlist SET icon = %u, timezone = %u WHERE id = '%d'", server_type, realm_zone, realmID);
|
||||
|
||||
///- Remove the bones after a restart
|
||||
CharacterDatabase.Execute("DELETE FROM corpse WHERE corpse_type = '0'");
|
||||
@@ -1619,7 +1619,7 @@ void World::SetInitialWorldSettings()
|
||||
sprintf(isoDate, "%04d-%02d-%02d %02d:%02d:%02d",
|
||||
local.tm_year+1900, local.tm_mon+1, local.tm_mday, local.tm_hour, local.tm_min, local.tm_sec);
|
||||
|
||||
loginDatabase.PExecute("INSERT INTO uptime (realmid, starttime, startstring, uptime, revision) VALUES('%u', " UI64FMTD ", '%s', 0, '%s')",
|
||||
LoginDatabase.PExecute("INSERT INTO uptime (realmid, starttime, startstring, uptime, revision) VALUES('%u', " UI64FMTD ", '%s', 0, '%s')",
|
||||
realmID, uint64(m_startTime), isoDate, _FULLVERSION);
|
||||
|
||||
static uint32 abtimer = 0;
|
||||
@@ -1679,7 +1679,7 @@ void World::SetInitialWorldSettings()
|
||||
objmgr.LoadTransportEvents();
|
||||
|
||||
sLog.outString("Deleting expired bans...");
|
||||
loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate<>bandate");
|
||||
LoginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate<>bandate");
|
||||
|
||||
sLog.outString("Calculate next daily quest reset time...");
|
||||
InitDailyQuestResetTime();
|
||||
@@ -1905,7 +1905,7 @@ void World::Update(uint32 diff)
|
||||
uint32 maxClientsNum = GetMaxActiveSessionCount();
|
||||
|
||||
m_timers[WUPDATE_UPTIME].Reset();
|
||||
loginDatabase.PExecute("UPDATE uptime SET uptime = %u, maxplayers = %u WHERE realmid = %u AND starttime = " UI64FMTD, tmpDiff, maxClientsNum, realmID, uint64(m_startTime));
|
||||
LoginDatabase.PExecute("UPDATE uptime SET uptime = %u, maxplayers = %u WHERE realmid = %u AND starttime = " UI64FMTD, tmpDiff, maxClientsNum, realmID, uint64(m_startTime));
|
||||
}
|
||||
|
||||
/// <li> Clean logs table
|
||||
@@ -1917,7 +1917,7 @@ void World::Update(uint32 diff)
|
||||
//uint32 maxClientsNum = sWorld.GetMaxActiveSessionCount();
|
||||
|
||||
m_timers[WUPDATE_CLEANDB].Reset();
|
||||
loginDatabase.PExecute("DELETE FROM logs WHERE (time + %u) < "UI64FMTD";",
|
||||
LoginDatabase.PExecute("DELETE FROM logs WHERE (time + %u) < "UI64FMTD";",
|
||||
sWorld.getConfig(CONFIG_LOGDB_CLEARTIME), uint64(time(0)));
|
||||
}
|
||||
}
|
||||
@@ -2184,10 +2184,10 @@ void World::KickAllLess(AccountTypes sec)
|
||||
/// Ban an account or ban an IP address, duration will be parsed using TimeStringToSecs if it is positive, otherwise permban
|
||||
BanReturn World::BanAccount(BanMode mode, std::string nameOrIP, std::string duration, std::string reason, std::string author)
|
||||
{
|
||||
loginDatabase.escape_string(nameOrIP);
|
||||
loginDatabase.escape_string(reason);
|
||||
LoginDatabase.escape_string(nameOrIP);
|
||||
LoginDatabase.escape_string(reason);
|
||||
std::string safe_author=author;
|
||||
loginDatabase.escape_string(safe_author);
|
||||
LoginDatabase.escape_string(safe_author);
|
||||
|
||||
uint32 duration_secs = TimeStringToSecs(duration);
|
||||
QueryResult_AutoPtr resultAccounts = QueryResult_AutoPtr(NULL); //used for kicking
|
||||
@@ -2197,12 +2197,12 @@ BanReturn World::BanAccount(BanMode mode, std::string nameOrIP, std::string dura
|
||||
{
|
||||
case BAN_IP:
|
||||
//No SQL injection as strings are escaped
|
||||
resultAccounts = loginDatabase.PQuery("SELECT id FROM account WHERE last_ip = '%s'",nameOrIP.c_str());
|
||||
loginDatabase.PExecute("INSERT INTO ip_banned VALUES ('%s',UNIX_TIMESTAMP(),UNIX_TIMESTAMP()+%u,'%s','%s')",nameOrIP.c_str(),duration_secs,safe_author.c_str(),reason.c_str());
|
||||
resultAccounts = LoginDatabase.PQuery("SELECT id FROM account WHERE last_ip = '%s'",nameOrIP.c_str());
|
||||
LoginDatabase.PExecute("INSERT INTO ip_banned VALUES ('%s',UNIX_TIMESTAMP(),UNIX_TIMESTAMP()+%u,'%s','%s')",nameOrIP.c_str(),duration_secs,safe_author.c_str(),reason.c_str());
|
||||
break;
|
||||
case BAN_ACCOUNT:
|
||||
//No SQL injection as string is escaped
|
||||
resultAccounts = loginDatabase.PQuery("SELECT id FROM account WHERE username = '%s'",nameOrIP.c_str());
|
||||
resultAccounts = LoginDatabase.PQuery("SELECT id FROM account WHERE username = '%s'",nameOrIP.c_str());
|
||||
break;
|
||||
case BAN_CHARACTER:
|
||||
//No SQL injection as string is escaped
|
||||
@@ -2229,7 +2229,7 @@ BanReturn World::BanAccount(BanMode mode, std::string nameOrIP, std::string dura
|
||||
if (mode != BAN_IP)
|
||||
{
|
||||
//No SQL injection as strings are escaped
|
||||
loginDatabase.PExecute("INSERT INTO account_banned VALUES ('%u', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()+%u, '%s', '%s', '1')",
|
||||
LoginDatabase.PExecute("INSERT INTO account_banned VALUES ('%u', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()+%u, '%s', '%s', '1')",
|
||||
account,duration_secs,safe_author.c_str(),reason.c_str());
|
||||
}
|
||||
|
||||
@@ -2247,8 +2247,8 @@ bool World::RemoveBanAccount(BanMode mode, std::string nameOrIP)
|
||||
{
|
||||
if (mode == BAN_IP)
|
||||
{
|
||||
loginDatabase.escape_string(nameOrIP);
|
||||
loginDatabase.PExecute("DELETE FROM ip_banned WHERE ip = '%s'",nameOrIP.c_str());
|
||||
LoginDatabase.escape_string(nameOrIP);
|
||||
LoginDatabase.PExecute("DELETE FROM ip_banned WHERE ip = '%s'",nameOrIP.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2262,7 +2262,7 @@ bool World::RemoveBanAccount(BanMode mode, std::string nameOrIP)
|
||||
return false;
|
||||
|
||||
//NO SQL injection as account is uint32
|
||||
loginDatabase.PExecute("UPDATE account_banned SET active = '0' WHERE id = '%u'",account);
|
||||
LoginDatabase.PExecute("UPDATE account_banned SET active = '0' WHERE id = '%u'",account);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -2491,8 +2491,8 @@ void World::_UpdateRealmCharCount(QueryResult_AutoPtr resultCharCount, uint32 ac
|
||||
Field *fields = resultCharCount->Fetch();
|
||||
uint32 charCount = fields[0].GetUInt32();
|
||||
|
||||
loginDatabase.PExecute("DELETE FROM realmcharacters WHERE acctid= '%d' AND realmid = '%d'", accountId, realmID);
|
||||
loginDatabase.PExecute("INSERT INTO realmcharacters (numchars, acctid, realmid) VALUES (%u, %u, %u)", charCount, accountId, realmID);
|
||||
LoginDatabase.PExecute("DELETE FROM realmcharacters WHERE acctid= '%d' AND realmid = '%d'", accountId, realmID);
|
||||
LoginDatabase.PExecute("INSERT INTO realmcharacters (numchars, acctid, realmid) VALUES (%u, %u, %u)", charCount, accountId, realmID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2552,7 +2552,7 @@ void World::ResetDailyQuests()
|
||||
|
||||
void World::UpdateAllowedSecurity()
|
||||
{
|
||||
QueryResult_AutoPtr result = loginDatabase.PQuery("SELECT allowedSecurityLevel from realmlist WHERE id = '%d'", realmID);
|
||||
QueryResult_AutoPtr result = LoginDatabase.PQuery("SELECT allowedSecurityLevel from realmlist WHERE id = '%d'", realmID);
|
||||
if (result)
|
||||
{
|
||||
m_allowedSecurityLevel = AccountTypes(result->Fetch()->GetUInt16());
|
||||
|
||||
@@ -55,7 +55,7 @@ m_latency(0), m_TutorialsChanged(false), m_timeOutTime(0)
|
||||
{
|
||||
m_Address = sock->GetRemoteAddress ();
|
||||
sock->AddReference ();
|
||||
loginDatabase.PExecute("UPDATE account SET online = 1 WHERE id = %u;", GetAccountId());
|
||||
LoginDatabase.PExecute("UPDATE account SET online = 1 WHERE id = %u;", GetAccountId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ WorldSession::~WorldSession()
|
||||
while (_recvQueue.next(packet))
|
||||
delete packet;
|
||||
|
||||
loginDatabase.PExecute("UPDATE account SET online = 0 WHERE id = %u;", GetAccountId());
|
||||
LoginDatabase.PExecute("UPDATE account SET online = 0 WHERE id = %u;", GetAccountId());
|
||||
CharacterDatabase.PExecute("UPDATE characters SET online = 0 WHERE account = %u;", GetAccountId());
|
||||
}
|
||||
|
||||
|
||||
@@ -753,11 +753,11 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
||||
|
||||
// Get the account information from the realmd database
|
||||
std::string safe_account = account; // Duplicate, else will screw the SHA hash verification below
|
||||
loginDatabase.escape_string (safe_account);
|
||||
LoginDatabase.escape_string (safe_account);
|
||||
// No SQL injection, username escaped.
|
||||
|
||||
QueryResult_AutoPtr result =
|
||||
loginDatabase.PQuery ("SELECT "
|
||||
LoginDatabase.PQuery ("SELECT "
|
||||
"id, " //0
|
||||
"sessionkey, " //1
|
||||
"last_ip, " //2
|
||||
@@ -837,7 +837,7 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
||||
|
||||
// Checks gmlevel per Realm
|
||||
result =
|
||||
loginDatabase.PQuery ("SELECT "
|
||||
LoginDatabase.PQuery ("SELECT "
|
||||
"RealmID, " //0
|
||||
"gmlevel " //1
|
||||
"FROM account_access "
|
||||
@@ -855,7 +855,7 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
||||
|
||||
// Re-check account ban (same check as in realmd)
|
||||
QueryResult_AutoPtr banresult =
|
||||
loginDatabase.PQuery ("SELECT 1 FROM account_banned WHERE id = %u AND active = 1 "
|
||||
LoginDatabase.PQuery ("SELECT 1 FROM account_banned WHERE id = %u AND active = 1 "
|
||||
"UNION "
|
||||
"SELECT 1 FROM ip_banned WHERE ip = '%s'",
|
||||
id, GetRemoteAddress().c_str());
|
||||
@@ -917,9 +917,9 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
||||
|
||||
// Update the last_ip in the database
|
||||
// No SQL injection, username escaped.
|
||||
loginDatabase.escape_string (address);
|
||||
LoginDatabase.escape_string (address);
|
||||
|
||||
loginDatabase.PExecute ("UPDATE account "
|
||||
LoginDatabase.PExecute ("UPDATE account "
|
||||
"SET last_ip = '%s' "
|
||||
"WHERE username = '%s'",
|
||||
address.c_str (),
|
||||
|
||||
Reference in New Issue
Block a user