[7915] Implement more stricted checks and limitations at loading creature addon data.
[getmangos.git] / src / game / Mail.h
blob7f7398da8f195b2bdfdba4750cfd50fbb638254f
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #ifndef MANGOS_MAIL_H
19 #define MANGOS_MAIL_H
21 #include "Common.h"
22 #include <map>
24 class Item;
26 #define MAIL_BODY_ITEM_TEMPLATE 8383 // - plain letter, A Dusty Unsent Letter: 889
27 #define MAX_MAIL_ITEMS 12
29 enum MailCheckMask
31 MAIL_CHECK_MASK_NONE = 0,
32 MAIL_CHECK_MASK_READ = 1,
33 MAIL_CHECK_MASK_AUCTION = 4,
34 MAIL_CHECK_MASK_COD_PAYMENT = 8,
35 MAIL_CHECK_MASK_RETURNED = 16
38 enum MailMessageType
40 MAIL_NORMAL = 0,
41 MAIL_AUCTION = 2,
42 MAIL_CREATURE = 3, // client send CMSG_CREATURE_QUERY on this mailmessagetype
43 MAIL_GAMEOBJECT = 4, // client send CMSG_GAMEOBJECT_QUERY on this mailmessagetype
44 MAIL_ITEM = 5, // client send CMSG_ITEM_QUERY on this mailmessagetype
47 enum MailState
49 MAIL_STATE_UNCHANGED = 1,
50 MAIL_STATE_CHANGED = 2,
51 MAIL_STATE_DELETED = 3
54 enum MailAuctionAnswers
56 AUCTION_OUTBIDDED = 0,
57 AUCTION_WON = 1,
58 AUCTION_SUCCESSFUL = 2,
59 AUCTION_EXPIRED = 3,
60 AUCTION_CANCELLED_TO_BIDDER = 4,
61 AUCTION_CANCELED = 5,
62 AUCTION_SALE_PENDING = 6
65 // gathered from Stationery.dbc
66 enum MailStationery
68 MAIL_STATIONERY_UNKNOWN = 0x01,
69 MAIL_STATIONERY_NORMAL = 0x29,
70 MAIL_STATIONERY_GM = 0x3D,
71 MAIL_STATIONERY_AUCTION = 0x3E,
72 MAIL_STATIONERY_VAL = 0x40,
73 MAIL_STATIONERY_CHR = 0x41
76 struct MailItemInfo
78 uint32 item_guid;
79 uint32 item_template;
82 struct MailItem
84 MailItem() : item_slot(0), item_guidlow(0), item_template(0), item(NULL) {}
86 uint8 item_slot; // slot in mail
87 uint32 item_guidlow; // item guid (low part)
88 uint32 item_template; // item entry
89 Item *item; // item pointer
91 void deleteItem(bool inDB = false);
94 typedef std::map<uint32, MailItem> MailItemMap;
96 class MailItemsInfo
98 public:
99 MailItemMap::const_iterator begin() const { return i_MailItemMap.begin(); }
100 MailItemMap::const_iterator end() const { return i_MailItemMap.end(); }
101 MailItemMap::iterator begin() { return i_MailItemMap.begin(); }
102 MailItemMap::iterator end() { return i_MailItemMap.end(); }
104 void AddItem(uint32 guidlow, uint32 _template, Item *item, uint8 slot = 0)
106 MailItem mailItem;
107 mailItem.item_slot = slot;
108 mailItem.item_guidlow = guidlow;
109 mailItem.item_template = _template;
110 mailItem.item = item;
111 i_MailItemMap[guidlow] = mailItem;
114 void AddItem(uint32 guidlow, uint8 slot = 0)
116 MailItem mailItem;
117 mailItem.item_guidlow = guidlow;
118 mailItem.item_slot = slot;
119 i_MailItemMap[guidlow] = mailItem;
122 uint8 size() const { return i_MailItemMap.size(); }
123 bool empty() const { return i_MailItemMap.empty(); }
125 void deleteIncludedItems(bool inDB = false)
127 for(MailItemMap::iterator mailItemIter = begin(); mailItemIter != end(); ++mailItemIter)
129 MailItem& mailItem = mailItemIter->second;
130 mailItem.deleteItem(inDB);
133 private:
134 MailItemMap i_MailItemMap; // Keep the items in a map to avoid duplicate guids (which can happen), store only low part of guid
137 struct Mail
139 uint32 messageID;
140 uint8 messageType;
141 uint8 stationery;
142 uint16 mailTemplateId;
143 uint32 sender;
144 uint32 receiver;
145 std::string subject;
146 uint32 itemTextId;
147 std::vector<MailItemInfo> items;
148 std::vector<uint32> removedItems;
149 time_t expire_time;
150 time_t deliver_time;
151 uint32 money;
152 uint32 COD;
153 uint32 checked;
154 MailState state;
156 void AddItem(uint32 itemGuidLow, uint32 item_template)
158 MailItemInfo mii;
159 mii.item_guid = itemGuidLow;
160 mii.item_template = item_template;
161 items.push_back(mii);
164 void AddAllItems(MailItemsInfo& pMailItemsInfo)
166 for(MailItemMap::iterator mailItemIter = pMailItemsInfo.begin(); mailItemIter != pMailItemsInfo.end(); ++mailItemIter)
168 MailItem& mailItem = mailItemIter->second;
169 AddItem(mailItem.item_guidlow, mailItem.item_template);
173 bool RemoveItem(uint32 item_guid)
175 for(std::vector<MailItemInfo>::iterator itr = items.begin(); itr != items.end(); ++itr)
177 if(itr->item_guid == item_guid)
179 items.erase(itr);
180 return true;
183 return false;
186 bool HasItems() const { return !items.empty(); }
188 #endif