Skip to content

Commit

Permalink
[Core/Mail] Replace FindPlayer with FindConnectedPlayer (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
leelf00 authored Aug 27, 2024
1 parent f2b1aae commit 9171809
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 47 deletions.
10 changes: 8 additions & 2 deletions src/server/game/Globals/ObjectAccessor.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* This file is part of the Pandaria 5.4.8 Project. See THANKS file for Copyright information
* This file is part of the Legends of Azeroth Pandaria Project. See THANKS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
Expand Down Expand Up @@ -33,6 +33,7 @@
#include "Pet.h"
#include "Player.h"
#include "Vehicle.h"
#include "Transport.h"
#include "World.h"
#include "WorldPacket.h"
#include <cmath>
Expand All @@ -41,7 +42,8 @@
template<class T>
void HashMapHolder<T>::Insert(T* o)
{
static_assert(std::is_same<Player, T>::value,
static_assert(std::is_same<Player, T>::value
|| std::is_same<Transport, T>::value,
"Only Player can be registered in global HashMapHolder");

std::unique_lock<std::shared_mutex> lock(*GetLock());
Expand Down Expand Up @@ -86,6 +88,7 @@ HashMapHolder<Player>::MapType const& ObjectAccessor::GetPlayers()
}

template class TC_GAME_API HashMapHolder<Player>;
template class TC_GAME_API HashMapHolder<Transport>;

namespace PlayerNameMapHolder
{
Expand Down Expand Up @@ -201,6 +204,9 @@ AreaTrigger* ObjectAccessor::GetAreaTrigger(WorldObject const& u, ObjectGuid con

Unit* ObjectAccessor::GetUnit(WorldObject const& u, ObjectGuid const& guid)
{
if (guid.IsEmpty())
return nullptr;

if (guid.IsPlayer())
return GetPlayer(u, guid);

Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Globals/ObjectAccessor.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* This file is part of the Pandaria 5.4.8 Project. See THANKS file for Copyright information
* This file is part of the Legends of Azeroth Pandaria Project. See THANKS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
Expand Down
81 changes: 37 additions & 44 deletions src/server/game/Mails/Mail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "DatabaseEnv.h"
#include "Mail.h"
#include "Log.h"
#include "World.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "Unit.h"
#include "BattlegroundMgr.h"
#include "Item.h"
#include "AuctionHouseMgr.h"
#include "BattlegroundMgr.h"
#include "BlackMarketMgr.h"
#include "CalendarMgr.h"
#include "DatabaseEnv.h"
#include "GameTime.h"
#include "Item.h"
#include "Language.h"
#include "Log.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "World.h"

MailSender::MailSender(Object* sender, MailStationery stationery) : m_stationery(stationery)
{
Expand Down Expand Up @@ -95,7 +95,7 @@ void MailDraft::prepareItems(Player* receiver, CharacterDatabaseTransaction tran
Loot mailLoot;

// can be empty
mailLoot.FillLoot(NULL, m_mailTemplateId, LootTemplates_Mail, receiver, true, true);
mailLoot.FillLoot(nullptr, m_mailTemplateId, LootTemplates_Mail, receiver, true, true);

uint32 max_slot = mailLoot.GetMaxSlotInLootFor(receiver);
for (uint32 i = 0; m_items.size() < MAX_MAIL_ITEMS && i < max_slot; ++i)
Expand Down Expand Up @@ -132,11 +132,12 @@ void MailDraft::deleteIncludedItems(CharacterDatabaseTransaction trans, bool inD

void MailDraft::SendReturnToSender(uint32 sender_acc, uint32 sender_guid, uint32 receiver_guid, CharacterDatabaseTransaction trans)
{
Player* receiver = ObjectAccessor::FindPlayer(ObjectGuid(HighGuid::Player, receiver_guid));
ObjectGuid receiverGuid(HighGuid::Player, receiver_guid);
Player* receiver = ObjectAccessor::FindConnectedPlayer(receiverGuid);

uint32 rc_account = 0;
if (!receiver)
rc_account = sObjectMgr->GetPlayerAccountIdByGUID(ObjectGuid(HighGuid::Player, receiver_guid));
rc_account = sObjectMgr->GetPlayerAccountIdByGUID(receiverGuid);

if (!receiver && !rc_account) // sender not exist
{
Expand Down Expand Up @@ -182,7 +183,7 @@ void MailDraft::SendMailTo(CharacterDatabaseTransaction trans, MailReceiver cons

uint32 mailId = sObjectMgr->GenerateMailID();

time_t deliver_time = time(NULL) + deliver_delay;
time_t deliver_time = GameTime::GetGameTime() + deliver_delay;

//expire time if COD 3 days, if no COD 30 days, if auction sale pending 1 hour
uint32 expire_delay;
Expand Down Expand Up @@ -236,43 +237,35 @@ void MailDraft::SendMailTo(CharacterDatabaseTransaction trans, MailReceiver cons
{
pReceiver->AddNewMailDeliverTime(deliver_time);

if (pReceiver->IsMailsLoaded())
Mail* m = new Mail;
m->messageID = mailId;
m->mailTemplateId = GetMailTemplateId();
m->subject = GetSubject();
m->body = GetBody();
m->money = GetMoney();
m->COD = GetCOD();

for (MailItemMap::const_iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter)
{
Mail* m = new Mail;
m->messageID = mailId;
m->mailTemplateId = GetMailTemplateId();
m->subject = GetSubject();
m->body = GetBody();
m->money = GetMoney();
m->COD = GetCOD();

for (MailItemMap::const_iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter)
{
Item* item = mailItemIter->second;
m->AddItem(item->GetGUID().GetCounter(), item->GetEntry());
}
Item* item = mailItemIter->second;
m->AddItem(item->GetGUID().GetCounter(), item->GetEntry());
}

m->messageType = sender.GetMailMessageType();
m->stationery = sender.GetStationery();
m->sender = sender.GetSenderId();
m->receiver = receiver.GetPlayerGUIDLow();
m->expire_time = expire_time;
m->deliver_time = deliver_time;
m->checked = checked;
m->state = MAIL_STATE_UNCHANGED;
m->messageType = sender.GetMailMessageType();
m->stationery = sender.GetStationery();
m->sender = sender.GetSenderId();
m->receiver = receiver.GetPlayerGUIDLow();
m->expire_time = expire_time;
m->deliver_time = deliver_time;
m->checked = checked;
m->state = MAIL_STATE_UNCHANGED;

pReceiver->AddMail(m); // to insert new mail to beginning of maillist
pReceiver->AddMail(m); // to insert new mail to beginning of maillist

if (!m_items.empty())
{
for (MailItemMap::iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter)
pReceiver->AddMItem(mailItemIter->second);
}
}
else if (!m_items.empty())
if (!m_items.empty())
{
CharacterDatabaseTransaction temp = CharacterDatabaseTransaction(nullptr);
deleteIncludedItems(temp);
for (MailItemMap::iterator mailItemIter = m_items.begin(); mailItemIter != m_items.end(); ++mailItemIter)
pReceiver->AddMItem(mailItemIter->second);
}
}
else if (!m_items.empty())
Expand Down

0 comments on commit 9171809

Please sign in to comment.