TrinityCore
Loading...
Searching...
No Matches
MailHandler.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "WorldSession.h"
19#include "AccountMgr.h"
20#include "BattlenetAccountMgr.h"
21#include "CharacterCache.h"
22#include "DatabaseEnv.h"
23#include "DB2Stores.h"
24#include "GossipDef.h"
25#include "GameTime.h"
26#include "Guild.h"
27#include "GuildMgr.h"
28#include "Item.h"
29#include "Language.h"
30#include "Log.h"
31#include "Mail.h"
32#include "MailPackets.h"
33#include "ObjectAccessor.h"
34#include "ObjectMgr.h"
35#include "Player.h"
36#include "World.h"
37
39{
40 if (guid == _player->GetGUID())
41 {
43 {
44 TC_LOG_WARN("cheat", "{} attempted to open mailbox by using a cheat.", _player->GetName());
45 return false;
46 }
47 }
48 else if (guid.IsGameObject())
49 {
51 return false;
52 }
53 else if (guid.IsAnyTypeCreature())
54 {
56 return false;
57 }
58 else
59 return false;
60
61 return true;
62}
63
65{
66 if (sendMail.Info.Attachments.size() > MAX_CLIENT_MAIL_ITEMS) // client limit
67 {
69 return;
70 }
71
72 if (!CanOpenMailBox(sendMail.Info.Mailbox))
73 return;
74
75 if (sendMail.Info.Target.empty())
76 return;
77
78 Player* player = _player;
79
80 if (player->GetLevel() < sWorld->getIntConfig(CONFIG_MAIL_LEVEL_REQ))
81 {
83 return;
84 }
85
86 ObjectGuid receiverGuid;
87 if (normalizePlayerName(sendMail.Info.Target))
88 receiverGuid = sCharacterCache->GetCharacterGuidByName(sendMail.Info.Target);
89
90 if (!receiverGuid)
91 {
92 TC_LOG_INFO("network", "Player {} is sending mail to {} (GUID: non-existing!) with subject {} "
93 "and body {} includes {} items, {} copper and {} COD copper with StationeryID = {}",
94 GetPlayerInfo(), sendMail.Info.Target, std::string_view(sendMail.Info.Subject), std::string_view(sendMail.Info.Body),
95 sendMail.Info.Attachments.size(), sendMail.Info.SendMoney, sendMail.Info.Cod, sendMail.Info.StationeryID);
97 return;
98 }
99
100 if (sendMail.Info.SendMoney < 0)
101 {
103 TC_LOG_WARN("cheat", "Player {} attempted to send mail to {} ({}) with negative money value (SendMoney: {})",
104 GetPlayerInfo(), sendMail.Info.Target, receiverGuid.ToString(), sendMail.Info.SendMoney);
105 return;
106 }
107
108 if (sendMail.Info.Cod < 0)
109 {
111 TC_LOG_WARN("cheat", "Player {} attempted to send mail to {} ({}) with negative COD value (Cod: {})",
112 GetPlayerInfo(), sendMail.Info.Target, receiverGuid.ToString(), sendMail.Info.Cod);
113 return;
114 }
115
116 TC_LOG_INFO("network", "Player {} is sending mail to {} ({}) with subject {} and body {} "
117 "including {} items, {} copper and {} COD copper with StationeryID = {}",
118 GetPlayerInfo(), sendMail.Info.Target, receiverGuid.ToString(), std::string_view(sendMail.Info.Subject),
119 std::string_view(sendMail.Info.Body), sendMail.Info.Attachments.size(), sendMail.Info.SendMoney, sendMail.Info.Cod, sendMail.Info.StationeryID);
120
121 if (player->GetGUID() == receiverGuid)
122 {
124 return;
125 }
126
127 uint32 cost = !sendMail.Info.Attachments.empty() ? 30 * sendMail.Info.Attachments.size() : 30; // price hardcoded in client
128
129 int64 reqmoney = cost + sendMail.Info.SendMoney;
130
131 // Check for overflow
132 if (reqmoney < sendMail.Info.SendMoney)
133 {
135 return;
136 }
137
138 auto mailCountCheckContinuation = [this, player, receiverGuid, mailInfo = std::move(sendMail.Info), reqmoney, cost](Team receiverTeam, uint64 mailsCount, uint8 receiverLevel, uint32 receiverAccountId, uint32 receiverBnetAccountId) mutable
139 {
140 if (_player != player)
141 return;
142
143 if (!player->HasEnoughMoney(reqmoney) && !player->IsGameMaster())
144 {
146 return;
147 }
148
149 // do not allow to have more than 100 mails in mailbox.. mails count is in opcode uint8!!! - so max can be 255..
150 if (mailsCount > 100)
151 {
153 return;
154 }
155
156 // test the receiver's Faction... or all items are account bound
157 bool accountBound = !mailInfo.Attachments.empty();
158 for (WorldPackets::Mail::SendMail::StructSendMail::MailAttachment const& att : mailInfo.Attachments)
159 {
160 if (Item* item = player->GetItemByGuid(att.ItemGUID))
161 {
162 ItemTemplate const* itemProto = item->GetTemplate();
163 if (!itemProto || !itemProto->HasFlag(ITEM_FLAG_IS_BOUND_TO_ACCOUNT))
164 {
165 accountBound = false;
166 break;
167 }
168 }
169 }
170
171 if (!accountBound && player->GetTeam() != receiverTeam && !HasPermission(rbac::RBAC_PERM_TWO_SIDE_INTERACTION_MAIL))
172 {
174 return;
175 }
176
177 if (receiverLevel < sWorld->getIntConfig(CONFIG_MAIL_LEVEL_REQ))
178 {
180 return;
181 }
182
183 std::vector<Item*> items;
184
185 for (WorldPackets::Mail::SendMail::StructSendMail::MailAttachment const& att : mailInfo.Attachments)
186 {
187 if (att.ItemGUID.IsEmpty())
188 {
190 return;
191 }
192
193 Item* item = player->GetItemByGuid(att.ItemGUID);
194
195 // prevent sending bag with items (cheat: can be placed in bag after adding equipped empty bag to mail)
196 if (!item)
197 {
199 return;
200 }
201
202 // handle empty bag before CanBeTraded, since that func already has that check
203 if (item->IsNotEmptyBag())
204 {
206 return;
207 }
208
209 if (!item->CanBeTraded(true))
210 {
212 return;
213 }
214
215 if (item->IsBoundAccountWide() && item->IsSoulBound() && GetAccountId() != receiverAccountId)
216 {
217 if (!item->IsBattlenetAccountBound() || !GetBattlenetAccountId() || GetBattlenetAccountId() != receiverBnetAccountId)
218 {
220 return;
221 }
222 }
223
224 if (item->GetTemplate()->HasFlag(ITEM_FLAG_CONJURED) || *item->m_itemData->Expiration)
225 {
227 return;
228 }
229
230 if (mailInfo.Cod && item->IsWrapped())
231 {
233 return;
234 }
235
236 items.push_back(item);
237 }
238
239 player->SendMailResult(0, MAIL_SEND, MAIL_OK);
240
241 player->ModifyMoney(-reqmoney);
243
244 bool needItemDelay = false;
245
246 MailDraft draft(mailInfo.Subject, mailInfo.Body);
247
248 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
249
250 if (!mailInfo.Attachments.empty() || mailInfo.SendMoney > 0)
251 {
253 if (!mailInfo.Attachments.empty())
254 {
255 for (Item* item : items)
256 {
257 if (log)
258 {
259 sLog->OutCommand(GetAccountId(), "GM {} ({}) (Account: {}) mail item: {} (Entry: {} Count: {}) "
260 "to: {} ({}) (Account: {})", GetPlayerName(), _player->GetGUID().ToString(), GetAccountId(),
261 item->GetNameForLocaleIdx(sWorld->GetDefaultDbcLocale()), item->GetEntry(), item->GetCount(),
262 mailInfo.Target, receiverGuid.ToString(), receiverAccountId);
263 }
264
265 item->SetNotRefundable(GetPlayer()); // makes the item no longer refundable
266 player->MoveItemFromInventory(item->GetBagSlot(), item->GetSlot(), true);
267
268 item->DeleteFromInventoryDB(trans); // deletes item from character's inventory
269 item->SetOwnerGUID(receiverGuid);
270 item->SetState(ITEM_CHANGED);
271 item->SaveToDB(trans); // recursive and not have transaction guard into self, item not in inventory and can be save standalone
272
273 draft.AddItem(item);
274 }
275
276 // if item send to character at another account, then apply item delivery delay
277 needItemDelay = GetAccountId() != receiverAccountId;
278 }
279
280 if (log && mailInfo.SendMoney > 0)
281 {
282 sLog->OutCommand(GetAccountId(), "GM {} ({}) (Account: {}) mail money: {} to: {} ({}) (Account: {})",
283 GetPlayerName(), _player->GetGUID().ToString(), GetAccountId(), mailInfo.SendMoney, mailInfo.Target, receiverGuid.ToString(), receiverAccountId);
284 }
285 }
286
287 // If theres is an item, there is a one hour delivery delay if sent to another account's character.
288 uint32 deliver_delay = needItemDelay ? sWorld->getIntConfig(CONFIG_MAIL_DELIVERY_DELAY) : 0;
289
290 // Mail sent between guild members arrives instantly
291 if (Guild* guild = sGuildMgr->GetGuildById(player->GetGuildId()))
292 if (guild->IsMember(receiverGuid))
293 deliver_delay = 0;
294
295 // don't ask for COD if there are no items
296 if (mailInfo.Attachments.empty())
297 mailInfo.Cod = 0;
298
299 MailCheckMask mailFlags = mailInfo.Body.empty() ? MAIL_CHECK_MASK_COPIED : MAIL_CHECK_MASK_HAS_BODY;
300
301 if (player->IsGameMaster())
303
304 // will delete item or place to receiver mail list
305 draft
306 .AddMoney(mailInfo.SendMoney)
307 .AddCOD(mailInfo.Cod)
308 .SendMailTo(trans, MailReceiver(ObjectAccessor::FindConnectedPlayer(receiverGuid), receiverGuid.GetCounter()), MailSender(player), mailFlags, deliver_delay);
309
310 player->SaveInventoryAndGoldToDB(trans);
311 CharacterDatabase.CommitTransaction(trans);
312 };
313
314 if (Player* receiver = ObjectAccessor::FindConnectedPlayer(receiverGuid))
315 {
316 mailCountCheckContinuation(receiver->GetTeam(), receiver->GetMailSize(), receiver->GetLevel(), receiver->GetSession()->GetAccountId(), receiver->GetSession()->GetBattlenetAccountId());
317 }
318 else
319 {
321 stmt->setUInt64(0, receiverGuid.GetCounter());
322
324 .WithChainingPreparedCallback([continuation = std::move(mailCountCheckContinuation), receiverGuid](QueryCallback& queryCallback, PreparedQueryResult mailCountResult) mutable
325 {
326 if (CharacterCacheEntry const* characterInfo = sCharacterCache->GetCharacterCacheByGuid(receiverGuid))
327 queryCallback.WithPreparedCallback([continuation = std::move(continuation), characterInfo, mailCountResult](PreparedQueryResult bnetAccountResult) mutable
328 {
329 continuation(Player::TeamForRace(characterInfo->Race), mailCountResult ? (*mailCountResult)[0].GetUInt64() : UI64LIT(0),
330 characterInfo->Level, characterInfo->AccountId, bnetAccountResult ? (*bnetAccountResult)[0].GetUInt32() : 0);
331 }).SetNextQuery(Battlenet::AccountMgr::GetIdByGameAccountAsync(characterInfo->AccountId));
332 }));
333 }
334}
335
336//called when mail is read
338{
339 if (!CanOpenMailBox(markAsRead.Mailbox))
340 return;
341
342 Player* player = _player;
343 Mail* m = player->GetMail(markAsRead.MailID);
344 if (m && m->state != MAIL_STATE_DELETED)
345 {
346 if (player->unReadMails)
347 --player->unReadMails;
349 player->m_mailsUpdated = true;
351 }
352}
353
354//called when client deletes mail
356{
357 if (!CanOpenMailBox(_player->PlayerTalkClass->GetInteractionData().SourceGuid))
358 return;
359
360 Mail* m = _player->GetMail(mailDelete.MailID);
361 Player* player = _player;
362 player->m_mailsUpdated = true;
363 if (m)
364 {
365 // delete shouldn't show up for COD mails
366 if (m->COD)
367 {
369 return;
370 }
371
373 }
374 player->SendMailResult(mailDelete.MailID, MAIL_DELETED, MAIL_OK);
375}
376
378{
379 if (!CanOpenMailBox(_player->PlayerTalkClass->GetInteractionData().SourceGuid))
380 return;
381
382 Player* player = _player;
383 Mail* m = player->GetMail(returnToSender.MailID);
384 if (!m || m->state == MAIL_STATE_DELETED || m->deliver_time > GameTime::GetGameTime() || m->sender != returnToSender.SenderGUID.GetCounter())
385 {
387 return;
388 }
389 //we can return mail now, so firstly delete the old one
390 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
391
393 stmt->setUInt64(0, returnToSender.MailID);
394 trans->Append(stmt);
395
396 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_MAIL_ITEM_BY_ID);
397 stmt->setUInt64(0, returnToSender.MailID);
398 trans->Append(stmt);
399
400 player->RemoveMail(returnToSender.MailID);
401
402 // only return mail if the player exists (and delete if not existing)
403 if (m->messageType == MAIL_NORMAL && m->sender)
404 {
405 MailDraft draft(m->subject, m->body);
406 if (m->mailTemplateId)
407 draft = MailDraft(m->mailTemplateId, false); // items already included
408
409 if (m->HasItems())
410 {
411 for (MailItemInfoVec::iterator itr2 = m->items.begin(); itr2 != m->items.end(); ++itr2)
412 {
413 if (Item* item = player->GetMItem(itr2->item_guid))
414 draft.AddItem(item);
415 player->RemoveMItem(itr2->item_guid);
416 }
417 }
418 draft.AddMoney(m->money).SendReturnToSender(GetAccountId(), m->receiver, m->sender, trans);
419 }
420
421 CharacterDatabase.CommitTransaction(trans);
422
423 delete m; //we can deallocate old mail
424 player->SendMailResult(returnToSender.MailID, MAIL_RETURNED_TO_SENDER, MAIL_OK);
425}
426
427//called when player takes item attached in mail
429{
430 if (!CanOpenMailBox(takeItem.Mailbox))
431 return;
432
433 Player* player = _player;
434
435 Mail* m = player->GetMail(takeItem.MailID);
437 {
439 return;
440 }
441
442 // verify that the mail has the item to avoid cheaters taking COD items without paying
443 if (std::ranges::find(m->items, ObjectGuid::LowType(takeItem.AttachID), &MailItemInfo::item_guid) == m->items.end())
444 {
446 return;
447 }
448
449 // prevent cheating with skip client money check
450 if (!player->HasEnoughMoney(m->COD))
451 {
453 return;
454 }
455
456 Item* it = player->GetMItem(takeItem.AttachID);
457
458 ItemPosCountVec dest;
459 uint8 msg = _player->CanStoreItem(NULL_BAG, NULL_SLOT, dest, it, false);
460 if (msg == EQUIP_ERR_OK)
461 {
462 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
463 m->RemoveItem(takeItem.AttachID);
464 m->removedItems.push_back(takeItem.AttachID);
465
466 if (m->COD > 0) //if there is COD, take COD money from player and send them to sender by mail
467 {
468 ObjectGuid sender_guid = ObjectGuid::Create<HighGuid::Player>(m->sender);
469 Player* receiver = ObjectAccessor::FindConnectedPlayer(sender_guid);
470
471 uint32 sender_accId = 0;
472
474 {
475 std::string sender_name;
476 if (receiver)
477 {
478 sender_accId = receiver->GetSession()->GetAccountId();
479 sender_name = receiver->GetName();
480 }
481 else
482 {
483 // can be calculated early
484 sender_accId = sCharacterCache->GetCharacterAccountIdByGuid(sender_guid);
485
486 if (!sCharacterCache->GetCharacterNameByGuid(sender_guid, sender_name))
487 sender_name = sObjectMgr->GetTrinityStringForDBCLocale(LANG_UNKNOWN);
488 }
489 sLog->OutCommand(GetAccountId(), "GM {} (Account: {}) receiver mail item: {} (Entry: {} Count: {}) and send COD money: {} to player: {} (Account: {})",
490 GetPlayerName(), GetAccountId(), it->GetNameForLocaleIdx(sWorld->GetDefaultDbcLocale()), it->GetEntry(), it->GetCount(), m->COD, sender_name, sender_accId);
491 }
492 else if (!receiver)
493 sender_accId = sCharacterCache->GetCharacterAccountIdByGuid(sender_guid);
494
495 // check player existence
496 if (receiver || sender_accId)
497 {
498 MailDraft(m->subject, "")
499 .AddMoney(m->COD)
501 }
502
503 player->ModifyMoney(-int64(m->COD));
504 }
505 m->COD = 0;
507 player->m_mailsUpdated = true;
508 player->RemoveMItem(it->GetGUID().GetCounter());
509
510 uint32 count = it->GetCount(); // save counts before store and possible merge with deleting
511 it->SetState(ITEM_UNCHANGED); // need to set this state, otherwise item cannot be removed later, if neccessary
512 player->MoveItemToInventory(dest, it, true);
513
514 player->SaveInventoryAndGoldToDB(trans);
515 player->_SaveMail(trans);
516 CharacterDatabase.CommitTransaction(trans);
517
518 player->SendMailResult(takeItem.MailID, MAIL_ITEM_TAKEN, MAIL_OK, 0, takeItem.AttachID, count);
519 }
520 else
522}
523
525{
526 if (!CanOpenMailBox(takeMoney.Mailbox))
527 return;
528
529 Player* player = _player;
530
531 Mail* m = player->GetMail(takeMoney.MailID);
532 if ((!m || m->state == MAIL_STATE_DELETED || m->deliver_time > GameTime::GetGameTime()) ||
533 (takeMoney.Money > 0 && m->money != uint64(takeMoney.Money)))
534 {
536 return;
537 }
538
539 if (!player->ModifyMoney(m->money, false))
540 {
542 return;
543 }
544
545 m->money = 0;
547 player->m_mailsUpdated = true;
548
549 player->SendMailResult(takeMoney.MailID, MAIL_MONEY_TAKEN, MAIL_OK);
550
551 // save money and mail to prevent cheating
552 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
553 player->SaveInventoryAndGoldToDB(trans);
554 player->_SaveMail(trans);
555 CharacterDatabase.CommitTransaction(trans);
556}
557
558//called when player lists his received mails
560{
561 if (!CanOpenMailBox(getList.Mailbox))
562 return;
563
564 Player* player = _player;
565
567 time_t curTime = GameTime::GetGameTime();
568
569 for (Mail* m : player->GetMails())
570 {
571 // skip deleted or not delivered (deliver delay not expired) mails
572 if (m->state == MAIL_STATE_DELETED || curTime < m->deliver_time)
573 continue;
574
575 // max. 100 mails can be sent
576 if (response.Mails.size() < 100)
577 response.Mails.emplace_back(m, player);
578
579 ++response.TotalNumRecords;
580 }
581
582 player->PlayerTalkClass->GetInteractionData().StartInteraction(getList.Mailbox, PlayerInteractionType::MailInfo);
583 SendPacket(response.Write());
584
585 // recalculate m_nextMailDelivereTime and unReadMails
587}
588
589//used when player copies mail body to his inventory
591{
592 if (!CanOpenMailBox(createTextItem.Mailbox))
593 return;
594
595 Player* player = _player;
596
597 Mail* m = player->GetMail(createTextItem.MailID);
598 if (!m || (m->body.empty() && !m->mailTemplateId) || m->state == MAIL_STATE_DELETED || m->deliver_time > GameTime::GetGameTime() || (m->checked & MAIL_CHECK_MASK_COPIED))
599 {
601 return;
602 }
603
605 if (!bodyItem)
606 return;
607
608 // in mail template case we need create new item text
609 if (m->mailTemplateId)
610 {
611 MailTemplateEntry const* mailTemplateEntry = sMailTemplateStore.LookupEntry(m->mailTemplateId);
612 ASSERT(mailTemplateEntry);
613 bodyItem->SetText(mailTemplateEntry->Body[GetSessionDbcLocale()]);
614 }
615 else
616 bodyItem->SetText(m->body);
617
618 if (m->messageType == MAIL_NORMAL)
619 bodyItem->SetCreator(ObjectGuid::Create<HighGuid::Player>(m->sender));
620
622
623 ItemPosCountVec dest;
624 uint8 msg = _player->CanStoreItem(NULL_BAG, NULL_SLOT, dest, bodyItem, false);
625 if (msg == EQUIP_ERR_OK)
626 {
629 player->m_mailsUpdated = true;
630
631 player->StoreItem(dest, bodyItem, true);
632 player->SendMailResult(createTextItem.MailID, MAIL_MADE_PERMANENT, MAIL_OK);
633 }
634 else
635 {
636 player->SendMailResult(createTextItem.MailID, MAIL_MADE_PERMANENT, MAIL_ERR_EQUIP_ERROR, msg);
637 delete bodyItem;
638 }
639}
640
642{
644
645 if (_player->unReadMails > 0)
646 {
647 result.NextMailTime = 0.0f;
648
649 time_t now = GameTime::GetGameTime();
650 std::set<ObjectGuid::LowType> sentSenders;
651
652 for (Mail* mail : _player->GetMails())
653 {
654 if (mail->checked & MAIL_CHECK_MASK_READ)
655 continue;
656
657 // already delivered
658 if (now < mail->deliver_time)
659 continue;
660
661 // only send each mail sender once
662 if (sentSenders.count(mail->sender))
663 continue;
664
665 result.Next.emplace_back(mail);
666
667 sentSenders.insert(mail->sender);
668
669 // do not send more than 2 mails
670 if (sentSenders.size() > 2)
671 break;
672 }
673 }
674 else
675 result.NextMailTime = -DAY;
676
677 SendPacket(result.Write());
678}
#define sCharacterCache
@ CHAR_DEL_MAIL_BY_ID
@ CHAR_DEL_MAIL_ITEM_BY_ID
@ CHAR_SEL_MAIL_COUNT
@ DAY
Definition Common.h:34
DB2Storage< MailTemplateEntry > sMailTemplateStore("MailTemplate.db2", &MailTemplateLoadInfo::Instance)
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
std::shared_ptr< PreparedResultSet > PreparedQueryResult
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
uint8_t uint8
Definition Define.h:156
int64_t int64
Definition Define.h:149
uint64_t uint64
Definition Define.h:153
uint32_t uint32
Definition Define.h:154
#define ASSERT
Definition Errors.h:72
#define sGuildMgr
Definition GuildMgr.h:76
@ EQUIP_ERR_TOO_MUCH_GOLD
@ EQUIP_ERR_MAIL_BOUND_ITEM
Definition ItemDefines.h:99
@ EQUIP_ERR_DESTROY_NONEMPTY_BAG
Definition ItemDefines.h:58
@ EQUIP_ERR_OK
Definition ItemDefines.h:26
@ EQUIP_ERR_NOT_SAME_ACCOUNT
@ ITEM_FIELD_FLAG_READABLE
@ ITEM_FLAG_IS_BOUND_TO_ACCOUNT
@ ITEM_FLAG_CONJURED
@ ITEM_CHANGED
Definition Item.h:47
@ ITEM_UNCHANGED
Definition Item.h:46
@ LANG_UNKNOWN
Definition Language.h:77
@ LANG_MAIL_RECEIVER_REQ
Definition Language.h:1175
@ LANG_MAIL_SENDER_REQ
Definition Language.h:1174
#define TC_LOG_INFO(filterType__, message__,...)
Definition Log.h:176
#define sLog
Definition Log.h:156
#define TC_LOG_WARN(filterType__, message__,...)
Definition Log.h:179
@ MAIL_STATE_DELETED
Definition Mail.h:91
@ MAIL_STATE_CHANGED
Definition Mail.h:90
#define MAIL_BODY_ITEM_TEMPLATE
Definition Mail.h:34
#define MAX_CLIENT_MAIL_ITEMS
Definition Mail.h:35
MailCheckMask
Definition Mail.h:52
@ MAIL_CHECK_MASK_HAS_BODY
This mail has body text.
Definition Mail.h:58
@ MAIL_CHECK_MASK_READ
This mail was read.
Definition Mail.h:54
@ MAIL_CHECK_MASK_COD_PAYMENT
This mail is payable on delivery.
Definition Mail.h:57
@ MAIL_CHECK_MASK_COPIED
This mail was copied. Do not allow making a copy of items in mail.
Definition Mail.h:56
@ MAIL_CHECK_MASK_NOT_RETURNABLE
This mail cannot be returned even if mail was not returned before.
Definition Mail.h:63
@ MAIL_NORMAL
Definition Mail.h:40
bool normalizePlayerName(std::string &name)
#define sObjectMgr
Definition ObjectMgr.h:1873
std::vector< ItemPosCount > ItemPosCountVec
Definition Player.h:827
@ GAMEOBJECT_TYPE_MAILBOX
@ MAIL_MONEY_TAKEN
@ MAIL_DELETED
@ MAIL_RETURNED_TO_SENDER
@ MAIL_MADE_PERMANENT
@ MAIL_ITEM_TAKEN
@ MAIL_SEND
@ MAIL_ERR_NOT_ENOUGH_MONEY
@ MAIL_ERR_NOT_YOUR_TEAM
@ MAIL_ERR_CANT_SEND_WRAPPED_COD
@ MAIL_ERR_RECIPIENT_CAP_REACHED
@ MAIL_ERR_EQUIP_ERROR
@ MAIL_ERR_RECIPIENT_NOT_FOUND
@ MAIL_OK
@ MAIL_ERR_TOO_MANY_ATTACHMENTS
@ MAIL_ERR_MAIL_ATTACHMENT_INVALID
@ MAIL_ERR_INTERNAL_ERROR
@ MAIL_ERR_CANNOT_SEND_TO_SELF
@ UNIT_NPC_FLAG_MAILBOX
@ UNIT_NPC_FLAG_2_NONE
@ NULL_BAG
Definition Unit.h:63
@ NULL_SLOT
Definition Unit.h:64
ObjectGuid const & GetGUID() const
Definition BaseEntity.h:163
Definition Guild.h:329
Definition Item.h:185
void SetState(ItemUpdateState state, Player *forplayer=nullptr)
Definition Item.cpp:1258
void SetItemFlag(ItemFieldFlags flags)
Definition Item.h:224
bool IsWrapped() const
Definition Item.h:266
void SetText(std::string const &text)
Definition Item.h:321
bool IsBoundAccountWide() const
Definition Item.h:234
bool CanBeTraded(bool mail=false, bool trade=false) const
Definition Item.cpp:1342
ItemTemplate const * GetTemplate() const
Definition Item.cpp:1233
UF::UpdateField< UF::ItemData, uint32(WowCS::EntityFragment::CGObject), TYPEID_ITEM > m_itemData
Definition Item.h:464
bool IsSoulBound() const
Definition Item.h:233
bool IsBattlenetAccountBound() const
Definition Item.h:235
void SetCreator(ObjectGuid guid)
Definition Item.h:208
std::string GetNameForLocaleIdx(LocaleConstant locale) const override
Definition Item.cpp:565
bool IsNotEmptyBag() const
Definition Item.cpp:576
uint32 GetCount() const
Definition Item.h:289
static Item * CreateItem(uint32 itemEntry, uint32 count, ItemContext context, Player const *player=nullptr, bool addDefaultBonuses=true)
Definition Item.cpp:1721
void SendMailTo(CharacterDatabaseTransaction trans, MailReceiver const &receiver, MailSender const &sender, MailCheckMask checked=MAIL_CHECK_MASK_NONE, uint32 deliver_delay=0)
Definition Mail.cpp:195
MailDraft & AddCOD(uint64 COD)
Definition Mail.h:152
void SendReturnToSender(uint32 sender_acc, ObjectGuid::LowType sender_guid, ObjectGuid::LowType receiver_guid, CharacterDatabaseTransaction trans)
Definition Mail.cpp:152
MailDraft & AddItem(Item *item)
Definition Mail.cpp:99
MailDraft & AddMoney(uint64 money)
Definition Mail.h:151
LowType GetCounter() const
Definition ObjectGuid.h:336
std::string ToString() const
bool IsGameObject() const
Definition ObjectGuid.h:372
bool IsAnyTypeCreature() const
Definition ObjectGuid.h:368
uint64 LowType
Definition ObjectGuid.h:321
uint32 GetEntry() const
Definition Object.h:89
void UpdateNextMailTimeAndUnreads()
Definition Player.cpp:2550
bool ModifyMoney(int64 amount, bool sendError=true)
Definition Player.cpp:24800
Creature * GetNPCIfCanInteractWith(ObjectGuid const &guid, NPCFlags npcFlags, NPCFlags2 npcFlags2) const
Definition Player.cpp:1814
Item * GetMItem(ObjectGuid::LowType id)
Definition Player.cpp:22395
void SendMailResult(uint64 mailId, MailResponseType mailAction, MailResponseResult mailError, uint32 equipError=0, ObjectGuid::LowType itemGuid=UI64LIT(0), uint32 itemCount=0) const
Definition Player.cpp:2530
InventoryResult CanStoreItem(uint8 bag, uint8 slot, ItemPosCountVec &dest, Item *pItem, bool swap=false) const
Definition Player.cpp:9975
void SaveInventoryAndGoldToDB(CharacterDatabaseTransaction trans)
Definition Player.cpp:20790
GameObject * GetGameObjectIfCanInteractWith(ObjectGuid const &guid) const
Definition Player.cpp:1871
uint8 unReadMails
Definition Player.h:1927
bool m_mailsUpdated
Definition Player.h:1879
Item * StoreItem(ItemPosCountVec const &pos, Item *pItem, bool update)
Definition Player.cpp:11365
WorldSession * GetSession() const
Definition Player.h:2256
PlayerMails const & GetMails() const
Definition Player.h:1919
void MoveItemFromInventory(uint8 bag, uint8 slot, bool update)
Definition Player.cpp:11993
void UpdateCriteria(CriteriaType type, uint64 miscValue1=0, uint64 miscValue2=0, uint64 miscValue3=0, WorldObject *ref=nullptr)
Definition Player.cpp:27532
void MoveItemToInventory(ItemPosCountVec const &dest, Item *pItem, bool update, bool in_characterInventoryDB=false)
Definition Player.cpp:12011
void _SaveMail(CharacterDatabaseTransaction trans)
Definition Player.cpp:21129
ObjectGuid::LowType GetGuildId() const
Definition Player.h:2147
bool RemoveMItem(ObjectGuid::LowType id)
Definition Player.cpp:22408
bool IsGameMaster() const
Definition Player.h:1293
Mail * GetMail(uint64 id)
Definition Player.cpp:3475
Item * GetItemByGuid(ObjectGuid guid) const
Definition Player.cpp:9522
void RemoveMail(uint64 id)
Definition Player.cpp:2512
std::unique_ptr< PlayerMenu > PlayerTalkClass
Definition Player.h:2556
Team GetTeam() const
Definition Player.h:2406
bool HasEnoughMoney(uint64 amount) const
Definition Player.h:1892
void setUInt64(uint8 index, uint64 value)
uint8 GetLevel() const
Definition Unit.h:769
std::string const & GetName() const
Definition Object.h:342
WorldPacket const * Write() override
std::vector< MailListEntry > Mails
Definition MailPackets.h:85
WorldPacket const * Write() override
std::vector< MailNextTimeEntry > Next
char const * GetTrinityString(uint32 entry) const
void SendNotification(char const *format,...) ATTR_PRINTF(2
LocaleConstant GetSessionDbcLocale() const
std::string GetPlayerInfo() const
void HandleSendMail(WorldPackets::Mail::SendMail &sendMail)
Player * GetPlayer() const
bool CanOpenMailBox(ObjectGuid guid)
void HandleMailDelete(WorldPackets::Mail::MailDelete &mailDelete)
QueryCallbackProcessor & GetQueryProcessor()
void HandleMailTakeItem(WorldPackets::Mail::MailTakeItem &takeItem)
void HandleQueryNextMailTime(WorldPackets::Mail::MailQueryNextMailTime &queryNextMailTime)
void HandleMailMarkAsRead(WorldPackets::Mail::MailMarkAsRead &markAsRead)
bool HasPermission(uint32 permissionId)
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
uint32 GetBattlenetAccountId() const
void HandleMailReturnToSender(WorldPackets::Mail::MailReturnToSender &returnToSender)
uint32 GetAccountId() const
Player * _player
void HandleMailCreateTextItem(WorldPackets::Mail::MailCreateTextItem &createTextItem)
void HandleMailTakeMoney(WorldPackets::Mail::MailTakeMoney &takeMoney)
void HandleGetMailList(WorldPackets::Mail::MailGetList &getList)
std::string const & GetPlayerName() const
#define sWorld
Definition World.h:919
@ CONFIG_MAIL_LEVEL_REQ
Definition World.h:327
@ CONFIG_MAIL_DELIVERY_DELAY
Definition World.h:294
TC_GAME_API QueryCallback GetIdByGameAccountAsync(uint32 gameAccountId)
time_t GetGameTime()
Definition GameTime.cpp:52
TC_GAME_API Player * FindConnectedPlayer(ObjectGuid const &)
@ RBAC_PERM_TWO_SIDE_INTERACTION_MAIL
Definition RBAC.h:80
@ RBAC_PERM_COMMAND_MAILBOX
Definition RBAC.h:651
@ RBAC_PERM_LOG_GM_TRADE
Definition RBAC.h:64
bool HasFlag(ItemFlags flag) const
ObjectGuid::LowType item_guid
Definition Mail.h:175
LocalizedString Body
Definition Mail.h:181
bool HasItems() const
Definition Mail.h:220
ObjectGuid::LowType receiver
Definition Mail.h:187
uint8 messageType
Definition Mail.h:183
uint64 money
Definition Mail.h:194
uint64 COD
Definition Mail.h:195
ObjectGuid::LowType sender
Definition Mail.h:186
std::string subject
Definition Mail.h:188
std::vector< ObjectGuid::LowType > removedItems
Definition Mail.h:191
std::string body
Definition Mail.h:189
std::vector< MailItemInfo > items
Definition Mail.h:190
bool RemoveItem(ObjectGuid::LowType item_guid)
Definition Mail.h:207
time_t deliver_time
Definition Mail.h:193
uint32 checked
Definition Mail.h:196
MailState state
Definition Mail.h:197
uint16 mailTemplateId
Definition Mail.h:185
String< 2000, Strings::NoHyperlinks > Body
String< 256, Strings::NoHyperlinks > Subject
std::vector< MailAttachment > Attachments