[11730] Move empty guid check into GetPlayerAccountIdByGUID code.

This cleanup small code and let catch some missing check cases
when 0 guid attempt searched by real DB query.

This also make function call more safe if it used with non-player guid by
some reason.
This commit is contained in:
VladimirMangos 2011-07-10 05:28:53 +04:00
parent 35e8af7195
commit 8e48e44c22
5 changed files with 13 additions and 10 deletions

View file

@ -155,7 +155,7 @@ void WorldSession::SendAuctionOutbiddedMail(AuctionEntry *auction)
Player *oldBidder = sObjectMgr.GetPlayer(oldBidder_guid);
uint32 oldBidder_accId = 0;
if(!oldBidder && oldBidder_guid)
if(!oldBidder)
oldBidder_accId = sObjectMgr.GetPlayerAccountIdByGUID(oldBidder_guid);
// old bidder exist
@ -180,7 +180,7 @@ void WorldSession::SendAuctionCancelledToBidderMail(AuctionEntry* auction)
Player *bidder = sObjectMgr.GetPlayer(bidder_guid);
uint32 bidder_accId = 0;
if (!bidder && bidder_guid)
if (!bidder)
bidder_accId = sObjectMgr.GetPlayerAccountIdByGUID(bidder_guid);
// bidder exist
@ -409,7 +409,7 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket & recv_data)
// impossible have online own another character (use this for speedup check in case online owner)
Player* auction_owner = sObjectMgr.GetPlayer(ownerGuid);
if (!auction_owner && ownerGuid && sObjectMgr.GetPlayerAccountIdByGUID(ownerGuid) == pl->GetSession()->GetAccountId())
if (!auction_owner && sObjectMgr.GetPlayerAccountIdByGUID(ownerGuid) == pl->GetSession()->GetAccountId())
{
// you cannot bid your another character auction:
SendAuctionCommandResult(NULL, AUCTION_BID_PLACED, AUCTION_ERR_BID_OWN);

View file

@ -104,7 +104,7 @@ void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry *auction)
}
else
{
bidder_accId = bidder_guid ? sObjectMgr.GetPlayerAccountIdByGUID(bidder_guid) : 0;
bidder_accId = sObjectMgr.GetPlayerAccountIdByGUID(bidder_guid);
bidder_security = bidder_accId ? sAccountMgr.GetSecurity(bidder_accId) : SEC_PLAYER;
if (bidder_security > SEC_PLAYER) // not do redundant DB requests
@ -122,13 +122,13 @@ void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry *auction)
else if (ownerGuid && !sObjectMgr.GetPlayerNameByGUID(ownerGuid, owner_name))
owner_name = sObjectMgr.GetMangosStringForDBCLocale(LANG_UNKNOWN);
uint32 owner_accid = ownerGuid ? sObjectMgr.GetPlayerAccountIdByGUID(ownerGuid) : 0;
uint32 owner_accid = sObjectMgr.GetPlayerAccountIdByGUID(ownerGuid);
sLog.outCommand(bidder_accId,"GM %s (Account: %u) won item in auction (Entry: %u Count: %u) and pay money: %u. Original owner %s (Account: %u)",
bidder_name.c_str(), bidder_accId, auction->itemTemplate, auction->itemCount, auction->bid, owner_name.c_str(), owner_accid);
}
}
else if (!bidder && bidder_guid)
else if (!bidder)
bidder_accId = sObjectMgr.GetPlayerAccountIdByGUID(bidder_guid);
if (auction_owner)
@ -183,7 +183,7 @@ void AuctionHouseMgr::SendAuctionSuccessfulMail(AuctionEntry * auction)
Player *owner = sObjectMgr.GetPlayer(owner_guid);
uint32 owner_accId = 0;
if (!owner && owner_guid)
if (!owner)
owner_accId = sObjectMgr.GetPlayerAccountIdByGUID(owner_guid);
// owner exist

View file

@ -514,7 +514,7 @@ void WorldSession::HandleMailTakeItem(WorldPacket & recv_data )
sender_accId = sender->GetSession()->GetAccountId();
sender_name = sender->GetName();
}
else
else if (sender_guid)
{
// can be calculated early
sender_accId = sObjectMgr.GetPlayerAccountIdByGUID(sender_guid);
@ -525,7 +525,7 @@ void WorldSession::HandleMailTakeItem(WorldPacket & recv_data )
sLog.outCommand(GetAccountId(), "GM %s (Account: %u) receive mail item: %s (Entry: %u Count: %u) and send COD money: %u to player: %s (Account: %u)",
GetPlayerName(), GetAccountId(), it->GetProto()->Name1, it->GetEntry(), it->GetCount(), m->COD, sender_name.c_str(), sender_accId);
}
else if(!sender)
else if (!sender)
sender_accId = sObjectMgr.GetPlayerAccountIdByGUID(sender_guid);
// check player existence

View file

@ -1657,6 +1657,9 @@ Team ObjectMgr::GetPlayerTeamByGUID(ObjectGuid guid) const
uint32 ObjectMgr::GetPlayerAccountIdByGUID(ObjectGuid guid) const
{
if (!guid.IsPlayer())
return 0;
// prevent DB access for online player
if(Player* player = GetPlayer(guid))
return player->GetSession()->GetAccountId();

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11729"
#define REVISION_NR "11730"
#endif // __REVISION_NR_H__