mirror of
https://github.com/mangosfour/server.git
synced 2025-12-14 07:37:01 +00:00
[10969] Some cleanups in MailDraft API
* Use Set* names for cases when function replace old value by new (instead Add*) * Prevent hidden MailDraft copy create becase if draft have items its can't be just shared and need preoprtly cloned, but item close is high price operation (guid use, DB tiuched and etc) So this must be explictly operation. In next commits will be added clone function for this. * Some MailDraft overwrite by assign cases rewrited to more clean way.
This commit is contained in:
parent
22115a8d04
commit
231c6d77ce
8 changed files with 39 additions and 31 deletions
|
|
@ -128,7 +128,7 @@ void WorldSession::SendAuctionOutbiddedMail(AuctionEntry *auction, uint32 newPri
|
||||||
newPrice, auction->GetAuctionOutBid(), auction->item_template);
|
newPrice, auction->GetAuctionOutBid(), auction->item_template);
|
||||||
|
|
||||||
MailDraft(msgAuctionOutbiddedSubject.str(), "") // TODO: fix body
|
MailDraft(msgAuctionOutbiddedSubject.str(), "") // TODO: fix body
|
||||||
.AddMoney(auction->bid)
|
.SetMoney(auction->bid)
|
||||||
.SendMailTo(MailReceiver(oldBidder, oldBidder_guid), auction, MAIL_CHECK_MASK_COPIED);
|
.SendMailTo(MailReceiver(oldBidder, oldBidder_guid), auction, MAIL_CHECK_MASK_COPIED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -150,7 +150,7 @@ void WorldSession::SendAuctionCancelledToBidderMail( AuctionEntry* auction )
|
||||||
msgAuctionCancelledSubject << auction->item_template << ":0:" << AUCTION_CANCELLED_TO_BIDDER << ":0:0";
|
msgAuctionCancelledSubject << auction->item_template << ":0:" << AUCTION_CANCELLED_TO_BIDDER << ":0:0";
|
||||||
|
|
||||||
MailDraft(msgAuctionCancelledSubject.str(), "") // TODO: fix body
|
MailDraft(msgAuctionCancelledSubject.str(), "") // TODO: fix body
|
||||||
.AddMoney(auction->bid)
|
.SetMoney(auction->bid)
|
||||||
.SendMailTo(MailReceiver(bidder, bidder_guid), auction, MAIL_CHECK_MASK_COPIED);
|
.SendMailTo(MailReceiver(bidder, bidder_guid), auction, MAIL_CHECK_MASK_COPIED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -234,7 +234,7 @@ void AuctionHouseMgr::SendAuctionSuccessfulMail( AuctionEntry * auction )
|
||||||
}
|
}
|
||||||
|
|
||||||
MailDraft(msgAuctionSuccessfulSubject.str(), auctionSuccessfulBody.str())
|
MailDraft(msgAuctionSuccessfulSubject.str(), auctionSuccessfulBody.str())
|
||||||
.AddMoney(profit)
|
.SetMoney(profit)
|
||||||
.SendMailTo(MailReceiver(owner, owner_guid), auction, MAIL_CHECK_MASK_COPIED, HOUR);
|
.SendMailTo(MailReceiver(owner, owner_guid), auction, MAIL_CHECK_MASK_COPIED, HOUR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1763,14 +1763,10 @@ bool ChatHandler::HandleSendMailCommand(char* args)
|
||||||
if (!msgText)
|
if (!msgText)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// msgSubject, msgText isn't NUL after prev. check
|
|
||||||
std::string subject = msgSubject;
|
|
||||||
std::string text = msgText;
|
|
||||||
|
|
||||||
// from console show nonexistent sender
|
// from console show nonexistent sender
|
||||||
MailSender sender(MAIL_NORMAL, m_session ? m_session->GetPlayer()->GetObjectGuid().GetCounter() : 0, MAIL_STATIONERY_GM);
|
MailSender sender(MAIL_NORMAL, m_session ? m_session->GetPlayer()->GetObjectGuid().GetCounter() : 0, MAIL_STATIONERY_GM);
|
||||||
|
|
||||||
MailDraft(subject, text)
|
MailDraft(msgSubject, msgText)
|
||||||
.SendMailTo(MailReceiver(target, target_guid),sender);
|
.SendMailTo(MailReceiver(target, target_guid),sender);
|
||||||
|
|
||||||
std::string nameLink = playerLink(target_name);
|
std::string nameLink = playerLink(target_name);
|
||||||
|
|
|
||||||
|
|
@ -6514,10 +6514,6 @@ bool ChatHandler::HandleSendItemsCommand(char* args)
|
||||||
if (!msgText)
|
if (!msgText)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// msgSubject, msgText isn't NUL after prev. check
|
|
||||||
std::string subject = msgSubject;
|
|
||||||
std::string text = msgText;
|
|
||||||
|
|
||||||
// extract items
|
// extract items
|
||||||
typedef std::pair<uint32,uint32> ItemPair;
|
typedef std::pair<uint32,uint32> ItemPair;
|
||||||
typedef std::list< ItemPair > ItemPairs;
|
typedef std::list< ItemPair > ItemPairs;
|
||||||
|
|
@ -6575,7 +6571,7 @@ bool ChatHandler::HandleSendItemsCommand(char* args)
|
||||||
MailSender sender(MAIL_NORMAL, m_session ? m_session->GetPlayer()->GetObjectGuid().GetCounter() : 0, MAIL_STATIONERY_GM);
|
MailSender sender(MAIL_NORMAL, m_session ? m_session->GetPlayer()->GetObjectGuid().GetCounter() : 0, MAIL_STATIONERY_GM);
|
||||||
|
|
||||||
// fill mail
|
// fill mail
|
||||||
MailDraft draft(subject, text);
|
MailDraft draft(msgSubject, msgText);
|
||||||
|
|
||||||
for(ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
|
for(ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
|
||||||
{
|
{
|
||||||
|
|
@ -6619,15 +6615,11 @@ bool ChatHandler::HandleSendMoneyCommand(char* args)
|
||||||
if (money <= 0)
|
if (money <= 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// msgSubject, msgText isn't NUL after prev. check
|
|
||||||
std::string subject = msgSubject;
|
|
||||||
std::string text = msgText;
|
|
||||||
|
|
||||||
// from console show nonexistent sender
|
// from console show nonexistent sender
|
||||||
MailSender sender(MAIL_NORMAL, m_session ? m_session->GetPlayer()->GetObjectGuid().GetCounter() : 0, MAIL_STATIONERY_GM);
|
MailSender sender(MAIL_NORMAL, m_session ? m_session->GetPlayer()->GetObjectGuid().GetCounter() : 0, MAIL_STATIONERY_GM);
|
||||||
|
|
||||||
MailDraft(subject, text)
|
MailDraft(msgSubject, msgText)
|
||||||
.AddMoney(money)
|
.SetMoney(money)
|
||||||
.SendMailTo(MailReceiver(receiver, receiver_guid),sender);
|
.SendMailTo(MailReceiver(receiver, receiver_guid),sender);
|
||||||
|
|
||||||
std::string nameLink = playerLink(receiver_name);
|
std::string nameLink = playerLink(receiver_name);
|
||||||
|
|
|
||||||
|
|
@ -272,8 +272,8 @@ void WorldSession::HandleSendMail(WorldPacket & recv_data )
|
||||||
|
|
||||||
// will delete item or place to receiver mail list
|
// will delete item or place to receiver mail list
|
||||||
draft
|
draft
|
||||||
.AddMoney(money)
|
.SetMoney(money)
|
||||||
.AddCOD(COD)
|
.SetCOD(COD)
|
||||||
.SendMailTo(MailReceiver(receive, rc), pl, body.empty() ? MAIL_CHECK_MASK_COPIED : MAIL_CHECK_MASK_HAS_BODY, deliver_delay);
|
.SendMailTo(MailReceiver(receive, rc), pl, body.empty() ? MAIL_CHECK_MASK_COPIED : MAIL_CHECK_MASK_HAS_BODY, deliver_delay);
|
||||||
|
|
||||||
CharacterDatabase.BeginTransaction();
|
CharacterDatabase.BeginTransaction();
|
||||||
|
|
@ -389,9 +389,11 @@ void WorldSession::HandleMailReturnToSender(WorldPacket & recv_data )
|
||||||
// send back only to existing players and simple drop for other cases
|
// send back only to existing players and simple drop for other cases
|
||||||
if (m->messageType == MAIL_NORMAL && m->sender)
|
if (m->messageType == MAIL_NORMAL && m->sender)
|
||||||
{
|
{
|
||||||
MailDraft draft(m->subject, m->body);
|
MailDraft draft;
|
||||||
if (m->mailTemplateId)
|
if (m->mailTemplateId)
|
||||||
draft = MailDraft(m->mailTemplateId, false); // items already included
|
draft.SetMailTemplate(m->mailTemplateId, false);// items already included
|
||||||
|
else
|
||||||
|
draft.SetSubjectAndBody(m->subject, m->body);
|
||||||
|
|
||||||
if(m->HasItems())
|
if(m->HasItems())
|
||||||
{
|
{
|
||||||
|
|
@ -404,7 +406,7 @@ void WorldSession::HandleMailReturnToSender(WorldPacket & recv_data )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
draft.AddMoney(m->money).SendReturnToSender(GetAccountId(), m->receiverGuid, ObjectGuid(HIGHGUID_PLAYER, m->sender));
|
draft.SetMoney(m->money).SendReturnToSender(GetAccountId(), m->receiverGuid, ObjectGuid(HIGHGUID_PLAYER, m->sender));
|
||||||
}
|
}
|
||||||
|
|
||||||
delete m; // we can deallocate old mail
|
delete m; // we can deallocate old mail
|
||||||
|
|
@ -484,7 +486,7 @@ void WorldSession::HandleMailTakeItem(WorldPacket & recv_data )
|
||||||
if(sender || sender_accId)
|
if(sender || sender_accId)
|
||||||
{
|
{
|
||||||
MailDraft(m->subject, "")
|
MailDraft(m->subject, "")
|
||||||
.AddMoney(m->COD)
|
.SetMoney(m->COD)
|
||||||
.SendMailTo(MailReceiver(sender, sender_guid), _player, MAIL_CHECK_MASK_COD_PAYMENT);
|
.SendMailTo(MailReceiver(sender, sender_guid), _player, MAIL_CHECK_MASK_COD_PAYMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,8 @@ enum MailAuctionAnswers
|
||||||
class MailSender
|
class MailSender
|
||||||
{
|
{
|
||||||
public: // Constructors
|
public: // Constructors
|
||||||
|
MailSender() : m_messageType(MAIL_NORMAL), m_senderId(0), m_stationery(MAIL_STATIONERY_DEFAULT) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new MailSender object.
|
* Creates a new MailSender object.
|
||||||
*
|
*
|
||||||
|
|
@ -181,6 +183,12 @@ class MailDraft
|
||||||
typedef std::map<uint32, Item*> MailItemMap;
|
typedef std::map<uint32, Item*> MailItemMap;
|
||||||
|
|
||||||
public: // Constructors
|
public: // Constructors
|
||||||
|
/**
|
||||||
|
* Creates a new blank MailDraft object
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
MailDraft()
|
||||||
|
: m_mailTemplateId(0), m_mailTemplateItemsNeed(false), m_money(0), m_COD(0) {}
|
||||||
/**
|
/**
|
||||||
* Creates a new MailDraft object using mail template id.
|
* Creates a new MailDraft object using mail template id.
|
||||||
*
|
*
|
||||||
|
|
@ -211,23 +219,31 @@ class MailDraft
|
||||||
/// Returns the Cost of delivery of this MailDraft.
|
/// Returns the Cost of delivery of this MailDraft.
|
||||||
uint32 GetCOD() const { return m_COD; }
|
uint32 GetCOD() const { return m_COD; }
|
||||||
public: // modifiers
|
public: // modifiers
|
||||||
|
|
||||||
|
// this two modifiers expected to be applied in normal case to blank draft and exclusively, it will work and with mixed cases but this will be not normal way use.
|
||||||
|
MailDraft& SetSubjectAndBody(std::string subject, std::string body) { m_subject = subject; m_body = body; return *this; }
|
||||||
|
MailDraft& SetMailTemplate(uint16 mailTemplateId, bool need_items = true) { m_mailTemplateId = mailTemplateId, m_mailTemplateItemsNeed = need_items; return *this; }
|
||||||
|
|
||||||
MailDraft& AddItem(Item* item);
|
MailDraft& AddItem(Item* item);
|
||||||
/**
|
/**
|
||||||
* Modifies the amount of money in a MailDraft.
|
* Modifies the amount of money in a MailDraft.
|
||||||
*
|
*
|
||||||
* @param money The amount of money included in this MailDraft.
|
* @param money The amount of money included in this MailDraft.
|
||||||
*/
|
*/
|
||||||
MailDraft& AddMoney(uint32 money) { m_money = money; return *this; }
|
MailDraft& SetMoney(uint32 money) { m_money = money; return *this; }
|
||||||
/**
|
/**
|
||||||
* Modifies the cost of delivery of the MailDraft.
|
* Modifies the cost of delivery of the MailDraft.
|
||||||
*
|
*
|
||||||
* @param COD the amount to which the cod should be set.
|
* @param COD the amount to which the cod should be set.
|
||||||
*/
|
*/
|
||||||
MailDraft& AddCOD(uint32 COD) { m_COD = COD; return *this; }
|
MailDraft& SetCOD(uint32 COD) { m_COD = COD; return *this; }
|
||||||
public: // finishers
|
public: // finishers
|
||||||
void SendReturnToSender(uint32 sender_acc, ObjectGuid sender_guid, ObjectGuid receiver_guid);
|
void SendReturnToSender(uint32 sender_acc, ObjectGuid sender_guid, ObjectGuid receiver_guid);
|
||||||
void SendMailTo(MailReceiver const& receiver, MailSender const& sender, MailCheckMask checked = MAIL_CHECK_MASK_NONE, uint32 deliver_delay = 0);
|
void SendMailTo(MailReceiver const& receiver, MailSender const& sender, MailCheckMask checked = MAIL_CHECK_MASK_NONE, uint32 deliver_delay = 0);
|
||||||
private:
|
private:
|
||||||
|
MailDraft(MailDraft const&); // trap decl, no body, mail draft must cloned only explicitly...
|
||||||
|
MailDraft& operator=(MailDraft const&); // trap decl, no body, ...because items clone is high price operation
|
||||||
|
|
||||||
void deleteIncludedItems(bool inDB = false);
|
void deleteIncludedItems(bool inDB = false);
|
||||||
void prepareItems(Player* receiver); ///< called from SendMailTo for generate mailTemplateBase items
|
void prepareItems(Player* receiver); ///< called from SendMailTo for generate mailTemplateBase items
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4233,9 +4233,11 @@ void Player::DeleteFromDB(ObjectGuid playerguid, uint32 accountId, bool updateRe
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
MailDraft draft(subject, body);
|
MailDraft draft;
|
||||||
if (mailTemplateId)
|
if (mailTemplateId)
|
||||||
draft = MailDraft(mailTemplateId, false); // items already included
|
draft.SetMailTemplate(mailTemplateId, false);// items already included
|
||||||
|
else
|
||||||
|
draft.SetSubjectAndBody(subject, body);
|
||||||
|
|
||||||
if (has_items)
|
if (has_items)
|
||||||
{
|
{
|
||||||
|
|
@ -4278,7 +4280,7 @@ void Player::DeleteFromDB(ObjectGuid playerguid, uint32 accountId, bool updateRe
|
||||||
|
|
||||||
uint32 pl_account = sObjectMgr.GetPlayerAccountIdByGUID(playerguid);
|
uint32 pl_account = sObjectMgr.GetPlayerAccountIdByGUID(playerguid);
|
||||||
|
|
||||||
draft.AddMoney(money).SendReturnToSender(pl_account, playerguid, ObjectGuid(HIGHGUID_PLAYER, sender));
|
draft.SetMoney(money).SendReturnToSender(pl_account, playerguid, ObjectGuid(HIGHGUID_PLAYER, sender));
|
||||||
}
|
}
|
||||||
while (resultMail->NextRow());
|
while (resultMail->NextRow());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "10968"
|
#define REVISION_NR "10969"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue