TrinityCore
Loading...
Searching...
No Matches
Mail.h
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#ifndef TRINITY_MAIL_H
19#define TRINITY_MAIL_H
20
21#include "Common.h"
22#include "DatabaseEnvFwd.h"
23#include "EnumFlag.h"
24#include "ObjectGuid.h"
25#include <map>
26
27struct CalendarEvent;
30class Item;
31class Object;
32class Player;
33
34#define MAIL_BODY_ITEM_TEMPLATE 8383 // - plain letter, A Dusty Unsent Letter: 889
35#define MAX_CLIENT_MAIL_ITEMS 12 // max number of items a player is allowed to attach
36#define MAX_MAIL_ITEMS 16
37
39{
42 MAIL_CREATURE = 3, // client send CMSG_CREATURE_QUERY on this mailmessagetype
43 MAIL_GAMEOBJECT = 4, // client send CMSG_GAMEOBJECT_QUERY on this mailmessagetype
46 MAIL_COMMERCE_AUCTION = 7, // wow token auction
48 MAIL_ARTISANS_CONSORTIUM = 9 // crafting orders
49};
50
72
74
75// gathered from Stationery.dbc
86
93
95{
96 public: // Constructors
97 MailSender(MailMessageType messageType, ObjectGuid::LowType sender_guidlow_or_entry, MailStationery stationery = MAIL_STATIONERY_DEFAULT)
98 : m_messageType(messageType), m_senderId(sender_guidlow_or_entry), m_stationery(stationery)
99 {
100 }
102 MailSender(CalendarEvent* sender);
103 MailSender(AuctionHouseObject const* sender);
105 MailSender(Player* sender);
106 MailSender(uint32 senderEntry);
107 public: // Accessors
108 MailMessageType GetMailMessageType() const { return m_messageType; }
109 ObjectGuid::LowType GetSenderId() const { return m_senderId; }
110 MailStationery GetStationery() const { return m_stationery; }
111 private:
113 ObjectGuid::LowType m_senderId; // player low guid or other object entry
115};
116
118{
119 public: // Constructors
120 explicit MailReceiver(ObjectGuid::LowType receiver_lowguid) : m_receiver(nullptr), m_receiver_lowguid(receiver_lowguid) { }
121 MailReceiver(Player* receiver);
122 MailReceiver(Player* receiver, ObjectGuid::LowType receiver_lowguid);
123 MailReceiver(Player* receiver, ObjectGuid receiverGuid);
124 public: // Accessors
125 Player* GetPlayer() const { return m_receiver; }
126 ObjectGuid::LowType GetPlayerGUIDLow() const { return m_receiver_lowguid; }
127 private:
130};
131
133{
134 typedef std::map<ObjectGuid::LowType, Item*> MailItemMap;
135
136 public: // Constructors
137 explicit MailDraft(uint16 mailTemplateId, bool need_items = true)
138 : m_mailTemplateId(mailTemplateId), m_mailTemplateItemsNeed(need_items), m_money(0), m_COD(0)
139 { }
140 MailDraft(std::string const& subject, std::string const& body)
141 : m_mailTemplateId(0), m_mailTemplateItemsNeed(false), m_subject(subject), m_body(body), m_money(0), m_COD(0) { }
142 public: // Accessors
143 uint16 GetMailTemplateId() const { return m_mailTemplateId; }
144 std::string const& GetSubject() const { return m_subject; }
145 uint64 GetMoney() const { return m_money; }
146 uint64 GetCOD() const { return m_COD; }
147 std::string const& GetBody() const { return m_body; }
148
149 public: // modifiers
150 MailDraft& AddItem(Item* item);
151 MailDraft& AddMoney(uint64 money) { m_money = money; return *this; }
152 MailDraft& AddCOD(uint64 COD) { m_COD = COD; return *this; }
153
154 public: // finishers
155 void SendReturnToSender(uint32 sender_acc, ObjectGuid::LowType sender_guid, ObjectGuid::LowType receiver_guid, CharacterDatabaseTransaction trans);
156 void SendMailTo(CharacterDatabaseTransaction trans, MailReceiver const& receiver, MailSender const& sender, MailCheckMask checked = MAIL_CHECK_MASK_NONE, uint32 deliver_delay = 0);
157
158 private:
159 void deleteIncludedItems(CharacterDatabaseTransaction trans, bool inDB = false);
160 void prepareItems(Player* receiver, CharacterDatabaseTransaction trans); // called from SendMailTo for generate mailTemplateBase items
161
164 std::string m_subject;
165 std::string m_body;
166
167 MailItemMap m_items; // Keep the items in a map to avoid duplicate guids (which can happen), store only low part of guid
168
171};
172
178typedef std::vector<MailItemInfo> MailItemInfoVec;
179
180struct Mail
181{
186 ObjectGuid::LowType sender; // TODO: change to uint64 and store full guids
188 std::string subject;
189 std::string body;
190 std::vector<MailItemInfo> items;
191 std::vector<ObjectGuid::LowType> removedItems;
198
199 void AddItem(ObjectGuid::LowType itemGuidLow, uint32 item_template)
200 {
201 MailItemInfo mii;
202 mii.item_guid = itemGuidLow;
203 mii.item_template = item_template;
204 items.push_back(mii);
205 }
206
208 {
209 for (MailItemInfoVec::iterator itr = items.begin(); itr != items.end(); ++itr)
210 {
211 if (itr->item_guid == item_guid)
212 {
213 items.erase(itr);
214 return true;
215 }
216 }
217 return false;
218 }
219
220 bool HasItems() const { return !items.empty(); }
221};
222
223#endif
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
#define TC_GAME_API
Definition Define.h:129
uint8_t uint8
Definition Define.h:156
uint64_t uint64
Definition Define.h:153
uint16_t uint16
Definition Define.h:155
uint32_t uint32
Definition Define.h:154
#define DEFINE_ENUM_FLAG(enumType)
Definition EnumFlag.h:26
MailState
Definition Mail.h:88
@ MAIL_STATE_DELETED
Definition Mail.h:91
@ MAIL_STATE_CHANGED
Definition Mail.h:90
@ MAIL_STATE_UNCHANGED
Definition Mail.h:89
MailCheckMask
Definition Mail.h:52
@ MAIL_CHECK_MASK_COMMERCE
WoW Token mail.
Definition Mail.h:70
@ MAIL_CHECK_MASK_NOT_DELETABLE_WITH_ATTACHMENTS
This mail cannot be deleted without taking attachments first.
Definition Mail.h:65
@ MAIL_CHECK_MASK_UNK_12
Definition Mail.h:66
@ MAIL_CHECK_MASK_HAS_BODY
This mail has body text.
Definition Mail.h:58
@ MAIL_CHECK_MASK_UNK_5
Definition Mail.h:59
@ MAIL_CHECK_MASK_READ
This mail was read.
Definition Mail.h:54
@ MAIL_CHECK_MASK_AUCTION_WON
This mail is delivering won auction items.
Definition Mail.h:60
@ MAIL_CHECK_MASK_UNK_13
Definition Mail.h:67
@ MAIL_CHECK_MASK_COD_PAYMENT
This mail is payable on delivery.
Definition Mail.h:57
@ MAIL_CHECK_MASK_RETURNED
This mail was returned. Do not allow returning mail back again.
Definition Mail.h:55
@ MAIL_CHECK_MASK_NONE
Definition Mail.h:53
@ MAIL_CHECK_MASK_RESTORED_ITEM
This mail contains recovered items.
Definition Mail.h:68
@ 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_CALENDAR_INVITE
This mail is related to calendar invite.
Definition Mail.h:62
@ MAIL_CHECK_MASK_NOT_COPYABLE
This mail cannot be copied.
Definition Mail.h:69
@ MAIL_CHECK_MASK_NOT_RETURNABLE
This mail cannot be returned even if mail was not returned before.
Definition Mail.h:63
@ MAIL_CHECK_MASK_AUCTION
This mail came from auction house.
Definition Mail.h:64
@ MAIL_CHECK_MASK_UNK_7
Definition Mail.h:61
std::vector< MailItemInfo > MailItemInfoVec
Definition Mail.h:178
MailStationery
Definition Mail.h:77
@ MAIL_STATIONERY_TEST
Definition Mail.h:78
@ MAIL_STATIONERY_GM
Definition Mail.h:80
@ MAIL_STATIONERY_CHR
Definition Mail.h:83
@ MAIL_STATIONERY_ORP
Definition Mail.h:84
@ MAIL_STATIONERY_DEFAULT
Definition Mail.h:79
@ MAIL_STATIONERY_VAL
Definition Mail.h:82
@ MAIL_STATIONERY_AUCTION
Definition Mail.h:81
MailMessageType
Definition Mail.h:39
@ MAIL_AUCTION
Definition Mail.h:41
@ MAIL_BLACKMARKET
Definition Mail.h:45
@ MAIL_GAMEOBJECT
Definition Mail.h:43
@ MAIL_CREATURE
Definition Mail.h:42
@ MAIL_COMMERCE_AUCTION
Definition Mail.h:46
@ MAIL_AUCTION_2
Definition Mail.h:47
@ MAIL_CALENDAR
Definition Mail.h:44
@ MAIL_NORMAL
Definition Mail.h:40
@ MAIL_ARTISANS_CONSORTIUM
Definition Mail.h:48
Definition Item.h:185
uint64 GetCOD() const
Definition Mail.h:146
uint64 m_money
Definition Mail.h:169
MailItemMap m_items
Definition Mail.h:167
std::string const & GetSubject() const
Definition Mail.h:144
std::map< ObjectGuid::LowType, Item * > MailItemMap
Definition Mail.h:134
MailDraft & AddCOD(uint64 COD)
Definition Mail.h:152
uint16 m_mailTemplateId
Definition Mail.h:162
MailDraft(uint16 mailTemplateId, bool need_items=true)
Definition Mail.h:137
MailDraft(std::string const &subject, std::string const &body)
Definition Mail.h:140
std::string m_subject
Definition Mail.h:164
bool m_mailTemplateItemsNeed
Definition Mail.h:163
uint16 GetMailTemplateId() const
Definition Mail.h:143
uint64 m_COD
Definition Mail.h:170
std::string const & GetBody() const
Definition Mail.h:147
std::string m_body
Definition Mail.h:165
MailDraft & AddMoney(uint64 money)
Definition Mail.h:151
uint64 GetMoney() const
Definition Mail.h:145
Player * GetPlayer() const
Definition Mail.h:125
ObjectGuid::LowType GetPlayerGUIDLow() const
Definition Mail.h:126
Player * m_receiver
Definition Mail.h:128
ObjectGuid::LowType m_receiver_lowguid
Definition Mail.h:129
MailReceiver(ObjectGuid::LowType receiver_lowguid)
Definition Mail.h:120
MailStationery m_stationery
Definition Mail.h:114
ObjectGuid::LowType GetSenderId() const
Definition Mail.h:109
MailSender(MailMessageType messageType, ObjectGuid::LowType sender_guidlow_or_entry, MailStationery stationery=MAIL_STATIONERY_DEFAULT)
Definition Mail.h:97
MailMessageType m_messageType
Definition Mail.h:112
MailMessageType GetMailMessageType() const
Definition Mail.h:108
MailStationery GetStationery() const
Definition Mail.h:110
ObjectGuid::LowType m_senderId
Definition Mail.h:113
uint64 LowType
Definition ObjectGuid.h:321
ObjectGuid::LowType item_guid
Definition Mail.h:175
uint32 item_template
Definition Mail.h:176
Definition Mail.h:181
uint64 messageID
Definition Mail.h:182
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
time_t expire_time
Definition Mail.h:192
uint8 stationery
Definition Mail.h:184
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
void AddItem(ObjectGuid::LowType itemGuidLow, uint32 item_template)
Definition Mail.h:199
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