Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
PlayerMail.cpp
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#include "Player.h"
7#include "Item.h"
8#include "Mail.h"
9#include "WorldPacket.h"
10#include "WorldSession.h"
11
13{
14 for (PlayerMails::iterator itr = m_mail.begin(); itr != m_mail.end(); ++itr)
15 {
16 if ((*itr)->messageID == id)
17 {
18 //do not delete item, because Player::removeMail() is called when returning mail to sender.
19 m_mail.erase(itr);
20 return;
21 }
22 }
23}
24
25void Player::SendMailResult(uint32 mailId, MailResponseType mailAction, MailResponseResult mailError, uint32 equipError, uint32 item_guid, uint32 item_count)
26{
27 WorldPacket data(SMSG_SEND_MAIL_RESULT, 4 + 4 + 4 + 4 + 4 + 4);
28 data << uint32(mailId);
29 data << uint32(equipError);
30 data << uint32(mailError);
31 data << uint32(mailAction);
32 data << uint32(item_guid);
33 data << uint32(item_count);
34
35 GetSession()->SendPacket(&data);
36}
37
39{
40 // deliver undelivered mail
42 data << float(0);
43 GetSession()->SendPacket(&data);
44}
45
47{
48 // calculate next delivery time (min. from non-delivered mails
49 // and recalculate unReadMail
50 time_t cTime = time(NULL);
52 unReadMails = 0;
53 for (PlayerMails::iterator itr = m_mail.begin(); itr != m_mail.end(); ++itr)
54 {
55 if ((*itr)->deliver_time > cTime)
56 {
57 if (!m_nextMailDelivereTime || m_nextMailDelivereTime > (*itr)->deliver_time)
58 m_nextMailDelivereTime = (*itr)->deliver_time;
59 }
60 else if (((*itr)->checked & MAIL_CHECK_MASK_READ) == 0)
62 }
63}
64
65void Player::AddNewMailDeliverTime(time_t deliver_time)
66{
67 if (deliver_time <= time(NULL)) // ready now
68 {
71 }
72 else // not ready and no have ready mails
73 {
75 m_nextMailDelivereTime = deliver_time;
76 }
77}
78
80{
81 for (PlayerMails::iterator itr = m_mail.begin(); itr != m_mail.end(); ++itr)
82 if ((*itr)->messageID == id)
83 return (*itr);
84
85 return NULL;
86}
87
89{
90 ItemMap::const_iterator itr = mMitems.find(id);
91 return itr != mMitems.end() ? itr->second : NULL;
92}
93
95{
96 ASSERT(it);
97 //ASSERT deleted, because items can be added before loading
98 mMitems[it->GetGUIDLow()] = it;
99}
100
102{
103 return mMitems.erase(id) ? true : false;
104}
std::uint32_t uint32
Definition Define.h:77
#define ASSERT
Definition Errors.h:29
@ MAIL_CHECK_MASK_READ
Definition Mail.h:35
MailResponseType
MailResponseResult
Definition Item.h:202
uint32 GetGUIDLow() const
Definition Object.h:120
void AddNewMailDeliverTime(time_t deliver_time)
ItemMap mMitems
Definition Player.h:2029
void UpdateNextMailTimeAndUnreads()
void AddMItem(Item *it)
uint8 unReadMails
Definition Player.h:2024
bool RemoveMItem(uint32 id)
void RemoveMail(uint32 id)
void SendNewMail()
void SendMailResult(uint32 mailId, MailResponseType mailAction, MailResponseResult mailError, uint32 equipError=0, uint32 item_guid=0, uint32 item_count=0)
WorldSession * GetSession() const
Definition Player.h:2417
time_t m_nextMailDelivereTime
Definition Player.h:2025
PlayerMails m_mail
Definition Player.h:3402
Item * GetMItem(uint32 id)
Mail * GetMail(uint32 id)
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
@ SMSG_RECEIVED_MAIL
Definition Opcodes.h:931
@ SMSG_SEND_MAIL_RESULT
Definition Opcodes.h:946
Definition Mail.h:156