From ad5f559dadd59943fde80f29c4bca9c1794dc414 Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Mon, 20 Oct 2008 07:30:59 +0400 Subject: [PATCH] * Move account related functions from ObjectMgr to AccountMgr and drop duplicate function also. --- src/game/AccountMgr.cpp | 30 ++++++++++++++++++++++++-- src/game/AccountMgr.h | 3 +++ src/game/Level2.cpp | 4 ++-- src/game/Level3.cpp | 7 +++--- src/game/ObjectMgr.cpp | 43 ++----------------------------------- src/game/ObjectMgr.h | 3 --- src/mangosd/CliRunnable.cpp | 4 ++-- 7 files changed, 41 insertions(+), 53 deletions(-) diff --git a/src/game/AccountMgr.cpp b/src/game/AccountMgr.cpp index 12aed7219..459cdbeac 100644 --- a/src/game/AccountMgr.cpp +++ b/src/game/AccountMgr.cpp @@ -18,7 +18,7 @@ #include "AccountMgr.h" #include "Database/DatabaseEnv.h" -#include "ObjectMgr.h" +#include "ObjectAccessor.h" #include "Player.h" #include "Policies/SingletonImp.h" #include "Util.h" @@ -79,7 +79,7 @@ AccountOpResult AccountMgr::DeleteAccount(uint32 accid) uint64 guid = MAKE_NEW_GUID(guidlo, 0, HIGHGUID_PLAYER); // kick if player currently - if(Player* p = objmgr.GetPlayer(guid)) + if(Player* p = ObjectAccessor::FindPlayer(guid)) { WorldSession* s = p->GetSession(); s->KickPlayer(); // mark session to remove at next session list update @@ -166,6 +166,32 @@ uint32 AccountMgr::GetId(std::string username) } } +uint32 AccountMgr::GetSecurity(uint32 acc_id) +{ + QueryResult *result = loginDatabase.PQuery("SELECT gmlevel FROM account WHERE id = '%u'", acc_id); + if(result) + { + uint32 sec = (*result)[0].GetUInt32(); + delete result; + return sec; + } + + return 0; +} + +bool AccountMgr::GetName(uint32 acc_id, std::string &name) +{ + QueryResult *result = loginDatabase.PQuery("SELECT username FROM account WHERE id = '%u'", acc_id); + if(result) + { + name = (*result)[0].GetCppString(); + delete result; + return true; + } + + return false; +} + bool AccountMgr::CheckPassword(uint32 accid, std::string passwd) { normilizeString(passwd); diff --git a/src/game/AccountMgr.h b/src/game/AccountMgr.h index 22b4eff48..b54f86327 100644 --- a/src/game/AccountMgr.h +++ b/src/game/AccountMgr.h @@ -48,6 +48,9 @@ class AccountMgr bool CheckPassword(uint32 accid, std::string passwd); uint32 GetId(std::string username); + uint32 GetIdByGUID(const uint64 &guid) const; + uint32 GetSecurity(uint32 acc_id); + bool GetName(uint32 acc_id, std::string &name); static bool normilizeString(std::string& utf8str); }; diff --git a/src/game/Level2.cpp b/src/game/Level2.cpp index 27369cd41..43a8efe98 100644 --- a/src/game/Level2.cpp +++ b/src/game/Level2.cpp @@ -94,7 +94,7 @@ bool ChatHandler::HandleMuteCommand(const char* args) else { account_id = objmgr.GetPlayerAccountIdByGUID(guid); - security = objmgr.GetSecurityByAccount(account_id); + security = accmgr.GetSecurity(account_id); } if(security >= m_session->GetSecurity()) @@ -160,7 +160,7 @@ bool ChatHandler::HandleUnmuteCommand(const char* args) else { account_id = objmgr.GetPlayerAccountIdByGUID(guid); - security = objmgr.GetSecurityByAccount(account_id); + security = accmgr.GetSecurity(account_id); } if(security >= m_session->GetSecurity()) diff --git a/src/game/Level3.cpp b/src/game/Level3.cpp index ca00ab0aa..742ddaef8 100644 --- a/src/game/Level3.cpp +++ b/src/game/Level3.cpp @@ -22,6 +22,7 @@ #include "WorldSession.h" #include "World.h" #include "ObjectMgr.h" +#include "AccountMgr.h" #include "PlayerDump.h" #include "SpellMgr.h" #include "Player.h" @@ -711,7 +712,7 @@ bool ChatHandler::HandleSecurityCommand(const char* args) return false; } targetAccountId = objmgr.GetPlayerAccountIdByGUID(targetGUID); - targetSecurity = objmgr.GetSecurityByAccount(targetAccountId); + targetSecurity = accmgr.GetSecurity(targetAccountId); } arg2 = strtok(NULL, " "); @@ -4964,14 +4965,14 @@ bool ChatHandler::HandleLoadPDumpCommand(const char *args) if(!file || !acc) return false; - uint32 account_id = objmgr.GetAccountByAccountName(acc); + uint32 account_id = accmgr.GetId(acc); if(!account_id) { account_id = atoi(acc); if(account_id) { std::string acc_name; - if(!objmgr.GetAccountNameByAccount(account_id,acc_name)) + if(!accmgr.GetName(account_id,acc_name)) return false; } else diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 8b018d0ec..20555a3a1 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -37,6 +37,7 @@ #include "GameEvent.h" #include "Spell.h" #include "Chat.h" +#include "AccountMgr.h" #include "InstanceSaveMgr.h" #include "SpellAuras.h" #include "Util.h" @@ -317,7 +318,7 @@ void ObjectMgr::SendAuctionWonMail( AuctionEntry *auction ) else { bidder_accId = GetPlayerAccountIdByGUID(bidder_guid); - bidder_security = GetSecurityByAccount(bidder_accId); + bidder_security = accmgr.GetSecurity(bidder_accId); if(bidder_security > SEC_PLAYER ) // not do redundant DB requests { @@ -1295,46 +1296,6 @@ uint32 ObjectMgr::GetPlayerAccountIdByGUID(const uint64 &guid) const return 0; } -uint32 ObjectMgr::GetSecurityByAccount(uint32 acc_id) const -{ - QueryResult *result = loginDatabase.PQuery("SELECT gmlevel FROM account WHERE id = '%u'", acc_id); - if(result) - { - uint32 sec = (*result)[0].GetUInt32(); - delete result; - return sec; - } - - return 0; -} - -bool ObjectMgr::GetAccountNameByAccount(uint32 acc_id, std::string &name) const -{ - QueryResult *result = loginDatabase.PQuery("SELECT username FROM account WHERE id = '%u'", acc_id); - if(result) - { - name = (*result)[0].GetCppString(); - delete result; - return true; - } - - return false; -} - -uint32 ObjectMgr::GetAccountByAccountName(std::string name) const -{ - loginDatabase.escape_string(name); - QueryResult *result = loginDatabase.PQuery("SELECT id FROM account WHERE username = '%s'", name.c_str()); - if(result) - { - uint32 id = (*result)[0].GetUInt32(); - delete result; - return id; - } - - return 0; -} - void ObjectMgr::LoadAuctions() { QueryResult *result = CharacterDatabase.Query("SELECT COUNT(*) FROM auctionhouse"); diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h index 2b7072524..a1711faa0 100644 --- a/src/game/ObjectMgr.h +++ b/src/game/ObjectMgr.h @@ -391,9 +391,6 @@ class ObjectMgr bool GetPlayerNameByGUID(const uint64 &guid, std::string &name) const; uint32 GetPlayerTeamByGUID(const uint64 &guid) const; uint32 GetPlayerAccountIdByGUID(const uint64 &guid) const; - uint32 GetSecurityByAccount(uint32 acc_id) const; - bool GetAccountNameByAccount(uint32 acc_id, std::string &name) const; - uint32 GetAccountByAccountName(std::string name) const; uint32 GetNearestTaxiNode( float x, float y, float z, uint32 mapid ); void GetTaxiPath( uint32 source, uint32 destination, uint32 &path, uint32 &cost); diff --git a/src/mangosd/CliRunnable.cpp b/src/mangosd/CliRunnable.cpp index ce4eb7ee6..637c8d30b 100644 --- a/src/mangosd/CliRunnable.cpp +++ b/src/mangosd/CliRunnable.cpp @@ -166,14 +166,14 @@ void CliLoadPlayerDump(char*command,pPrintf zprintf) return; } - uint32 account_id = objmgr.GetAccountByAccountName(acc); + uint32 account_id = accmgr.GetId(acc); if(!account_id) { account_id = atoi(acc); if(account_id) { std::string acc_name; - if(!objmgr.GetAccountNameByAccount(account_id,acc_name)) + if(!accmgr.GetName(account_id,acc_name)) { zprintf("Failed to load the character! Account not exist.\r\n"); return;