TrinityCore
Loading...
Searching...
No Matches
MailPackets.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 "MailPackets.h"
19#include "GameTime.h"
20#include "Item.h"
21#include "Mail.h"
22#include "Player.h"
23#include "World.h"
24
46
48{
49 data << uint8(att.Position);
50 data << int32(att.AttachID);
51 data << int32(att.ItemID);
52 for (uint8 i = 0; i < MAX_INSPECTED_ENCHANTMENT_SLOT; i++)
53 {
54 data << int32(att.EnchantmentID[i]);
55 data << int32(att.EnchantmentDuration[i]);
56 data << int32(att.EnchantmentCharges[i]);
57 }
58 data << int32(att.RandomPropertiesID);
59 data << int32(att.RandomPropertiesSeed);
60 data << int32(att.Count);
61 data << int32(att.Charges);
62 data << uint32(att.MaxDurability);
63 data << int32(att.Durability);
64 data << bool(att.Unlocked);
65
66 return data;
67}
68
70{
71 MailID = mail->messageID;
72 SenderType = mail->messageType;
73
74 switch (mail->messageType)
75 {
76 case MAIL_NORMAL:
77 SenderCharacter = ObjectGuid::Create<HighGuid::Player>(mail->sender);
78 break;
79 case MAIL_CREATURE:
80 case MAIL_GAMEOBJECT:
81 case MAIL_AUCTION:
82 case MAIL_CALENDAR:
83 AltSenderID = mail->sender;
84 break;
85 }
86
87 Cod = mail->COD;
88 StationeryID = mail->stationery;
89 SentMoney = mail->money;
90 Flags = mail->checked;
91 DaysLeft = float(mail->expire_time - GameTime::GetGameTime()) / float(DAY);
92 MailTemplateID = mail->mailTemplateId;
93 Subject = mail->subject;
94 Body = mail->body;
95
96 for (uint8 i = 0; i < mail->items.size(); i++)
97 if (::Item* item = player->GetMItem(mail->items[i].item_guid))
98 Attachments.emplace_back(item, i);
99}
100
102{
103 return sizeof(uint16) + sizeof(int32) + sizeof(uint8) + (SenderCharacter ? sizeof(uint64) : 0) + (AltSenderID ? sizeof(int32) : 0)
104 + sizeof(uint32) + sizeof(int32) + sizeof(int32) + sizeof(uint32) + sizeof(int32) + sizeof(float) + sizeof(int32)
105 + Subject.length() + 1 + Body.length() + 1 + sizeof(uint8) + Attachments.size() * MailAttachedItem::GetPacketSize();
106}
107
109{
110 data << uint16(entry.GetPacketSize());
111 data << int32(entry.MailID);
112 data << uint8(entry.SenderType);
113 if (entry.SenderCharacter)
114 data << *entry.SenderCharacter;
115 else if (entry.AltSenderID)
116 data << int32(*entry.AltSenderID);
117
118 data << uint32(entry.Cod);
119 data << int32(entry.PackageID);
120 data << int32(entry.StationeryID);
121 data << uint32(entry.SentMoney);
122 data << int32(entry.Flags);
123 data << float(entry.DaysLeft);
124 data << int32(entry.MailTemplateID);
125 data << entry.Subject;
126 data << entry.Body;
127 data << uint8(entry.Attachments.size());
128
130 data << att;
131
132 return data;
133}
134
136{
137 _worldPacket >> Mailbox;
138}
139
141{
142 _worldPacket << int32(0); // TotalNumRecords
143 _worldPacket << uint8(0); // Mails.size()
144}
145
147{
148 _worldPacket.put<int32>(0, TotalNumRecords);
149 _worldPacket.put<uint8>(4, Mails.size());
150
151 return &_worldPacket;
152}
153
155{
156 ++TotalNumRecords;
157 if (Mails.size() >= 50 || _maxPacketSizeReached)
158 return;
159
161 if (_worldPacket.size() + packetEntry.GetPacketSize() >= std::size_t(std::numeric_limits<int16>::max()))
162 {
163 _maxPacketSizeReached = true;
164 return;
165 }
166
167 _worldPacket << Mails.emplace_back(std::move(packetEntry));
168}
169
171{
172 _worldPacket >> Mailbox;
173 _worldPacket >> MailID;
174}
175
177{
178 _worldPacket >> Info.Mailbox;
179 _worldPacket >> Info.Target;
180 _worldPacket >> Info.Subject;
181 _worldPacket >> Info.Body;
182 _worldPacket >> Info.StationeryID;
183 _worldPacket >> Info.PackageID;
184 Info.Attachments.resize(_worldPacket.read<uint8>());
185
186 for (auto& att : Info.Attachments)
187 {
188 _worldPacket >> att.AttachPosition;
189 _worldPacket >> att.ItemGUID;
190 }
191
192 _worldPacket >> Info.SendMoney;
193 _worldPacket >> Info.Cod;
194 _worldPacket.read_skip<uint64>();
195 _worldPacket.read_skip<uint8>();
196}
197
199{
200 _worldPacket >> Mailbox;
201 _worldPacket >> MailID;
202 _worldPacket >> SenderGUID;
203}
204
206{
207 _worldPacket << uint32(MailID);
208 _worldPacket << uint32(Command);
209 _worldPacket << uint32(ErrorCode);
210
211 if (ErrorCode == MAIL_ERR_EQUIP_ERROR)
212 _worldPacket << uint32(BagResult);
213
214 if (Command == MAIL_ITEM_TAKEN)
215 {
216 if (ErrorCode == MAIL_OK || ErrorCode == MAIL_ERR_ITEM_HAS_EXPIRED)
217 {
218 _worldPacket << uint32(AttachID);
219 _worldPacket << uint32(QtyInInventory);
220 }
221 }
222
223 return &_worldPacket;
224}
225
227{
228 _worldPacket >> Mailbox;
229 _worldPacket >> MailID;
230}
231
233{
234 _worldPacket >> Mailbox;
235 _worldPacket >> MailID;
236 _worldPacket >> DeleteReason;
237}
238
240{
241 _worldPacket >> Mailbox;
242 _worldPacket >> MailID;
243 _worldPacket >> AttachID;
244}
245
247{
248 _worldPacket >> Mailbox;
249 _worldPacket >> MailID;
250}
251
253{
254 switch (mail->messageType)
255 {
256 case MAIL_NORMAL:
257 SenderGuid = ObjectGuid::Create<HighGuid::Player>(mail->sender);
258 break;
259 case MAIL_AUCTION:
260 case MAIL_CREATURE:
261 case MAIL_GAMEOBJECT:
262 case MAIL_CALENDAR:
263 AltSenderID = mail->sender;
264 break;
265 }
266
267 TimeLeft = mail->deliver_time - time(nullptr);
268 AltSenderType = mail->messageType;
269 StationeryID = mail->stationery;
270}
271
273{
274 _worldPacket << float(NextMailTime);
275 _worldPacket << int32(Next.size());
276
277 for (auto const& entry : Next)
278 {
279 _worldPacket << entry.SenderGuid;
280 _worldPacket << int32(entry.AltSenderID);
281 _worldPacket << int32(entry.AltSenderType);
282 _worldPacket << int32(entry.StationeryID);
283 _worldPacket << float(entry.TimeLeft);
284 }
285
286 return &_worldPacket;
287}
288
290{
291 _worldPacket << float(Delay);
292
293 return &_worldPacket;
294}
295
297{
298 _worldPacket << PostmasterGUID;
299
300 return &_worldPacket;
301}
@ DAY
Definition Common.h:31
uint8_t uint8
Definition Define.h:135
int32_t int32
Definition Define.h:129
uint64_t uint64
Definition Define.h:132
uint16_t uint16
Definition Define.h:134
uint32_t uint32
Definition Define.h:133
EnchantmentSlot
@ MAX_INSPECTED_ENCHANTMENT_SLOT
@ MAIL_AUCTION
Definition Mail.h:38
@ MAIL_GAMEOBJECT
Definition Mail.h:40
@ MAIL_CREATURE
Definition Mail.h:39
@ MAIL_CALENDAR
Definition Mail.h:41
@ MAIL_NORMAL
Definition Mail.h:37
ByteBuffer & operator<<(ByteBuffer &buf, ObjectGuid const &guid)
@ MAIL_ITEM_TAKEN
@ MAIL_ERR_ITEM_HAS_EXPIRED
@ MAIL_ERR_EQUIP_ERROR
@ MAIL_OK
@ ITEM_FIELD_DURABILITY
@ ITEM_FIELD_MAXDURABILITY
void put(std::size_t pos, T value)
Definition ByteBuffer.h:137
Definition Item.h:62
uint32 GetEnchantmentId(EnchantmentSlot slot) const
Definition Item.h:148
int32 GetSpellCharges(uint8 index=0) const
Definition Item.h:161
uint32 GetEnchantmentDuration(EnchantmentSlot slot) const
Definition Item.h:149
bool IsLocked() const
Definition Item.h:101
int32 GetItemRandomPropertyId() const
Definition Item.h:140
uint32 GetItemSuffixFactor() const
Definition Item.h:141
uint32 GetEnchantmentCharges(EnchantmentSlot slot) const
Definition Item.h:150
uint32 GetCount() const
Definition Item.h:119
LowType GetCounter() const
Definition ObjectGuid.h:156
int32 GetInt32Value(uint16 index) const
Definition Object.cpp:243
uint32 GetUInt32Value(uint16 index) const
Definition Object.cpp:249
uint32 GetEntry() const
Definition Object.h:81
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:78
Item * GetMItem(ObjectGuid::LowType id)
Definition Player.cpp:20572
T & emplace_back(Args &&... args)
size_type size() const
void resize(size_type newSize)
WorldPacket const * Write() override
WorldPacket const * Write() override
void AddMail(::Mail const *mail, Player *player)
WorldPacket const * Write() override
WorldPacket const * Write() override
WorldPacket const * Write() override
WorldPacket _worldPacket
Definition Packet.h:42
@ SMSG_MAIL_LIST_RESULT
Definition Opcodes.h:600
time_t GetGameTime()
Definition GameTime.cpp:42
Definition Mail.h:167
std::array< uint32, MAX_INSPECTED_ENCHANTMENT_SLOT > EnchantmentID
Definition MailPackets.h:51
MailAttachedItem(::Item const *item, uint8 pos)
static constexpr std::size_t GetPacketSize()
Definition MailPackets.h:35
std::array< uint32, MAX_INSPECTED_ENCHANTMENT_SLOT > EnchantmentCharges
Definition MailPackets.h:53
std::array< uint32, MAX_INSPECTED_ENCHANTMENT_SLOT > EnchantmentDuration
Definition MailPackets.h:52
MailListEntry(::Mail const *mail, ::Player *player)
Optional< ObjectGuid > SenderCharacter
Definition MailPackets.h:64
std::vector< MailAttachedItem > Attachments
Definition MailPackets.h:75