Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
Mail.h
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#ifndef SKYFIRE_MAIL_H
7#define SKYFIRE_MAIL_H
8
9#include "Common.h"
10#include <map>
11
12struct AuctionEntry;
14struct CalendarEvent;
15class Item;
16class Object;
17class Player;
18
19#define MAIL_BODY_ITEM_TEMPLATE 8383 // - plain letter, A Dusty Unsent Letter: 889
20#define MAX_MAIL_ITEMS 12
21
23{
26 MAIL_CREATURE = 3, // client send CMSG_CREATURE_QUERY on this mailmessagetype
27 MAIL_GAMEOBJECT = 4, // client send CMSG_GAMEOBJECT_QUERY on this mailmessagetype
30};
31
41
42// gathered from Stationery.dbc
53
61
63{
65 MAIL_SHOW_DELETE = 0x0002, // forced show delete button instead return button
66 MAIL_SHOW_AUCTION = 0x0004, // from old comment
67 MAIL_SHOW_UNK2 = 0x0008, // unknown, COD will be shown even without that flag
69};
70
72{
73public: // Constructors
74 MailSender(MailMessageType messageType, uint32 sender_guidlow_or_entry, MailStationery stationery = MAIL_STATIONERY_DEFAULT)
75 : m_messageType(messageType), m_senderId(sender_guidlow_or_entry), m_stationery(stationery)
76 {
77 }
80 MailSender(AuctionEntry* sender);
82 MailSender(Player* sender);
83public: // Accessors
85 uint32 GetSenderId() const { return m_senderId; }
87private:
89 uint32 m_senderId; // player low guid or other object entry
91};
92
94{
95public: // Constructors
96 explicit MailReceiver(uint32 receiver_lowguid) : m_receiver(NULL), m_receiver_lowguid(receiver_lowguid) { }
97 MailReceiver(Player* receiver);
98 MailReceiver(Player* receiver, uint32 receiver_lowguid);
99public: // Accessors
100 Player* GetPlayer() const { return m_receiver; }
102private:
105};
106
108{
109 typedef std::map<uint32, Item*> MailItemMap;
110
111public: // Constructors
112 explicit MailDraft(uint16 mailTemplateId, bool need_items = true)
113 : m_mailTemplateId(mailTemplateId), m_mailTemplateItemsNeed(need_items), m_money(0), m_COD(0)
114 { }
115 MailDraft(std::string const& subject, std::string const& body)
116 : m_mailTemplateId(0), m_mailTemplateItemsNeed(false), m_subject(subject), m_body(body), m_money(0), m_COD(0) { }
117public: // Accessors
119 std::string const& GetSubject() const { return m_subject; }
120 uint64 GetMoney() const { return m_money; }
121 uint64 GetCOD() const { return m_COD; }
122 std::string const& GetBody() const { return m_body; }
123
124public: // modifiers
125 MailDraft& AddItem(Item* item);
126 MailDraft& AddMoney(uint64 money) { m_money = money; return *this; }
127 MailDraft& AddCOD(uint32 COD) { m_COD = COD; return *this; }
128
129public: // finishers
130 void SendReturnToSender(uint32 sender_acc, uint32 sender_guid, uint32 receiver_guid, SQLTransaction& trans);
131 void SendMailTo(SQLTransaction& trans, MailReceiver const& receiver, MailSender const& sender, MailCheckMask checked = MAIL_CHECK_MASK_NONE, uint32 deliver_delay = 0);
132
133private:
134 void deleteIncludedItems(SQLTransaction& trans, bool inDB = false);
135 void prepareItems(Player* receiver, SQLTransaction& trans); // called from SendMailTo for generate mailTemplateBase items
136
139 std::string m_subject;
140 std::string m_body;
141
142 MailItemMap m_items; // Keep the items in a map to avoid duplicate guids (which can happen), store only low part of guid
143
146};
147
153typedef std::vector<MailItemInfo> MailItemInfoVec;
154
155struct Mail
156{
159
164 uint32 sender; // TODO: change to uint64 and store full guids
166 std::string subject;
167 std::string body;
168 std::vector<MailItemInfo> items;
169 std::vector<uint32> removedItems;
176
177 void AddItem(uint32 itemGuidLow, uint32 item_template)
178 {
179 MailItemInfo mii;
180 mii.item_guid = itemGuidLow;
181 mii.item_template = item_template;
182 items.push_back(mii);
183 }
184
185 bool RemoveItem(uint32 item_guid)
186 {
187 for (MailItemInfoVec::iterator itr = items.begin(); itr != items.end(); ++itr)
188 {
189 if (itr->item_guid == item_guid)
190 {
191 items.erase(itr);
192 return true;
193 }
194 }
195 return false;
196 }
197
198 bool HasItems() const { return !items.empty(); }
199};
200
201#endif
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
std::uint64_t uint64
Definition Define.h:76
std::uint16_t uint16
Definition Define.h:78
MailShowFlags
Definition Mail.h:63
@ MAIL_SHOW_UNK2
Definition Mail.h:67
@ MAIL_SHOW_UNK0
Definition Mail.h:64
@ MAIL_SHOW_DELETE
Definition Mail.h:65
@ MAIL_SHOW_RETURN
Definition Mail.h:68
@ MAIL_SHOW_AUCTION
Definition Mail.h:66
MailCheckMask
Definition Mail.h:33
@ MAIL_CHECK_MASK_HAS_BODY
Definition Mail.h:39
@ MAIL_CHECK_MASK_READ
Definition Mail.h:35
@ MAIL_CHECK_MASK_COD_PAYMENT
This mail was copied. Do not allow making a copy of items in mail.
Definition Mail.h:38
@ MAIL_CHECK_MASK_RETURNED
Definition Mail.h:36
@ MAIL_CHECK_MASK_NONE
Definition Mail.h:34
@ MAIL_CHECK_MASK_COPIED
This mail was returned. Do not allow returning mail back again.
Definition Mail.h:37
MailState
Definition Mail.h:55
@ MAIL_STATE_UNCHANGED
Definition Mail.h:57
@ MAIL_STATE_NONE
Definition Mail.h:56
@ MAIL_STATE_DELETED
Definition Mail.h:59
@ MAIL_STATE_CHANGED
Definition Mail.h:58
std::vector< MailItemInfo > MailItemInfoVec
Definition Mail.h:153
MailStationery
Definition Mail.h:44
@ MAIL_STATIONERY_TEST
Definition Mail.h:45
@ MAIL_STATIONERY_GM
Definition Mail.h:47
@ MAIL_STATIONERY_CHR
Definition Mail.h:50
@ MAIL_STATIONERY_ORP
Definition Mail.h:51
@ MAIL_STATIONERY_DEFAULT
Definition Mail.h:46
@ MAIL_STATIONERY_VAL
Definition Mail.h:49
@ MAIL_STATIONERY_AUCTION
Definition Mail.h:48
MailMessageType
Definition Mail.h:23
@ MAIL_AUCTION
Definition Mail.h:25
@ MAIL_BLACKMARKET
Definition Mail.h:29
@ MAIL_GAMEOBJECT
Definition Mail.h:27
@ MAIL_CREATURE
Definition Mail.h:26
@ MAIL_CALENDAR
Definition Mail.h:28
@ MAIL_NORMAL
Definition Mail.h:24
Skyfire::AutoPtr< Transaction, Skyfire::Mutex > SQLTransaction
Definition Transaction.h:42
Definition Item.h:202
uint64 GetCOD() const
Definition Mail.h:121
uint64 m_money
Definition Mail.h:144
MailItemMap m_items
Definition Mail.h:142
std::string const & GetSubject() const
Definition Mail.h:119
void deleteIncludedItems(SQLTransaction &trans, bool inDB=false)
Definition Mail.cpp:101
uint16 m_mailTemplateId
Definition Mail.h:137
MailDraft(uint16 mailTemplateId, bool need_items=true)
Definition Mail.h:112
MailDraft & AddCOD(uint32 COD)
Definition Mail.h:127
void SendReturnToSender(uint32 sender_acc, uint32 sender_guid, uint32 receiver_guid, SQLTransaction &trans)
Definition Mail.cpp:120
std::map< uint32, Item * > MailItemMap
Definition Mail.h:109
MailDraft(std::string const &subject, std::string const &body)
Definition Mail.h:115
void SendMailTo(SQLTransaction &trans, MailReceiver const &receiver, MailSender const &sender, MailCheckMask checked=MAIL_CHECK_MASK_NONE, uint32 deliver_delay=0)
Definition Mail.cpp:162
std::string m_subject
Definition Mail.h:139
bool m_mailTemplateItemsNeed
Definition Mail.h:138
uint16 GetMailTemplateId() const
Definition Mail.h:118
uint64 m_COD
Definition Mail.h:145
void prepareItems(Player *receiver, SQLTransaction &trans)
Definition Mail.cpp:75
MailDraft & AddItem(Item *item)
Definition Mail.cpp:70
std::string const & GetBody() const
Definition Mail.h:122
std::string m_body
Definition Mail.h:140
MailDraft & AddMoney(uint64 money)
Definition Mail.h:126
uint64 GetMoney() const
Definition Mail.h:120
Player * GetPlayer() const
Definition Mail.h:100
Player * m_receiver
Definition Mail.h:103
MailReceiver(uint32 receiver_lowguid)
Definition Mail.h:96
uint32 GetPlayerGUIDLow() const
Definition Mail.h:101
uint32 m_receiver_lowguid
Definition Mail.h:104
uint32 GetSenderId() const
Definition Mail.h:85
uint32 m_senderId
Definition Mail.h:89
MailSender(MailMessageType messageType, uint32 sender_guidlow_or_entry, MailStationery stationery=MAIL_STATIONERY_DEFAULT)
Definition Mail.h:74
MailStationery m_stationery
Definition Mail.h:90
MailMessageType m_messageType
Definition Mail.h:88
MailMessageType GetMailMessageType() const
Definition Mail.h:84
MailStationery GetStationery() const
Definition Mail.h:86
bool HasItems() const
Definition Mail.h:198
uint8 messageType
Definition Mail.h:161
uint32 messageID
Definition Mail.h:160
std::vector< uint32 > removedItems
Definition Mail.h:169
uint64 money
Definition Mail.h:172
uint64 COD
Definition Mail.h:173
time_t expire_time
Definition Mail.h:170
uint32 sender
Definition Mail.h:164
uint32 receiver
Definition Mail.h:165
uint8 stationery
Definition Mail.h:162
std::string subject
Definition Mail.h:166
std::string body
Definition Mail.h:167
std::vector< MailItemInfo > items
Definition Mail.h:168
time_t deliver_time
Definition Mail.h:171
Mail()
Definition Mail.h:157
bool RemoveItem(uint32 item_guid)
Definition Mail.h:185
uint32 checked
Definition Mail.h:174
MailState state
Definition Mail.h:175
void AddItem(uint32 itemGuidLow, uint32 item_template)
Definition Mail.h:177
uint16 mailTemplateId
Definition Mail.h:163
uint32 item_guid
Definition Mail.h:150
uint32 item_template
Definition Mail.h:151