TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CalendarMgr.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
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_CALENDARMGR_H
19 #define TRINITY_CALENDARMGR_H
20 
21 #include "Common.h"
22 #include "DatabaseEnv.h"
23 #include "WorldPacket.h"
24 #include "ObjectGuid.h"
25 
27 {
28  // else
30  // if ( *(_DWORD *)(a1 + 8292) & 0x100 )
32 };
33 
35 {
40 };
41 
43 {
47 };
48 
50 {
54 };
55 
57 {
64 };
65 
67 {
72 };
73 
75 {
85  CALENDAR_STATUS_REMOVED = 9 // correct name?
86 };
87 
89 {
107 
118 
124 };
125 
126 #define CALENDAR_MAX_EVENTS 30
127 #define CALENDAR_MAX_GUILD_EVENTS 100
128 #define CALENDAR_MAX_INVITES 100
129 #define CALENDAR_DEFAULT_RESPONSE_TIME 946684800 // 01/01/2000 00:00:00
130 
132 {
133  public:
134  CalendarInvite(CalendarInvite const& calendarInvite, uint64 inviteId, uint64 eventId)
135  {
136  _inviteId = inviteId;
137  _eventId = eventId;
138  _invitee = calendarInvite.GetInviteeGUID();
139  _senderGUID = calendarInvite.GetSenderGUID();
140  _responseTime = calendarInvite.GetResponseTime();
141  _status = calendarInvite.GetStatus();
142  _rank = calendarInvite.GetRank();
143  _note = calendarInvite.GetNote();
144  }
145 
146  CalendarInvite() : _inviteId(1), _eventId(0), _invitee(), _senderGUID(), _responseTime(0),
147  _status(CALENDAR_STATUS_INVITED), _rank(CALENDAR_RANK_PLAYER), _note("") { }
148 
149  CalendarInvite(uint64 inviteId, uint64 eventId, ObjectGuid invitee, ObjectGuid senderGUID, time_t responseTime,
150  CalendarInviteStatus status, CalendarModerationRank rank, std::string note) :
151  _inviteId(inviteId), _eventId(eventId), _invitee(invitee), _senderGUID(senderGUID), _responseTime(responseTime),
152  _status(status), _rank(rank), _note(note) { }
153 
154  ~CalendarInvite();
155 
156  void SetInviteId(uint64 inviteId) { _inviteId = inviteId; }
157  uint64 GetInviteId() const { return _inviteId; }
158 
159  void SetEventId(uint64 eventId) { _eventId = eventId; }
160  uint64 GetEventId() const { return _eventId; }
161 
162  void SetSenderGUID(ObjectGuid guid) { _senderGUID = guid; }
163  ObjectGuid GetSenderGUID() const { return _senderGUID; }
164 
165  void SetInvitee(ObjectGuid guid) { _invitee = guid; }
166  ObjectGuid GetInviteeGUID() const { return _invitee; }
167 
168  void SetResponseTime(time_t responseTime) { _responseTime = responseTime; }
169  time_t GetResponseTime() const { return _responseTime; }
170 
171  void SetNote(std::string const& note) { _note = note; }
172  std::string GetNote() const { return _note; }
173 
174  void SetStatus(CalendarInviteStatus status) { _status = status; }
175  CalendarInviteStatus GetStatus() const { return _status; }
176 
177  void SetRank(CalendarModerationRank rank) { _rank = rank; }
178  CalendarModerationRank GetRank() const { return _rank; }
179 
180  private:
188  std::string _note;
189 };
190 
192 {
193  public:
194  CalendarEvent(CalendarEvent const& calendarEvent, uint64 eventId)
195  {
196  _eventId = eventId;
197  _ownerGUID = calendarEvent.GetOwnerGUID();
198  _eventGuildId = calendarEvent.GetGuildId();
199  _eventType = calendarEvent.GetType();
200  _textureId = calendarEvent.GetTextureId();
201  _date = calendarEvent.GetDate();
202  _flags = calendarEvent.GetFlags();
203  _title = calendarEvent.GetTitle();
204  _description = calendarEvent.GetDescription();
205  _lockDate = calendarEvent.GetLockDate();
206  }
207 
208  CalendarEvent(uint64 eventId, ObjectGuid ownerGUID, ObjectGuid::LowType guildId, CalendarEventType type, int32 textureId,
209  time_t date, uint32 flags, std::string title, std::string description, time_t lockDate) :
210  _eventId(eventId), _ownerGUID(ownerGUID), _eventGuildId(guildId), _eventType(type), _textureId(textureId),
211  _date(date), _flags(flags), _title(title), _description(description), _lockDate(lockDate) { }
212 
213  CalendarEvent() : _eventId(1), _ownerGUID(), _eventGuildId(UI64LIT(0)), _eventType(CALENDAR_TYPE_OTHER), _textureId(-1), _date(0),
214  _flags(0), _title(""), _description(""), _lockDate(0) { }
215 
216  ~CalendarEvent();
217 
218  void SetEventId(uint64 eventId) { _eventId = eventId; }
219  uint64 GetEventId() const { return _eventId; }
220 
221  void SetOwnerGUID(ObjectGuid guid) { _ownerGUID = guid; }
222  ObjectGuid GetOwnerGUID() const { return _ownerGUID; }
223 
224  void SetGuildId(ObjectGuid::LowType guildId) { _eventGuildId = guildId; }
225  ObjectGuid::LowType GetGuildId() const { return _eventGuildId; }
226 
227  void SetTitle(std::string const& title) { _title = title; }
228  std::string GetTitle() const { return _title; }
229 
230  void SetDescription(std::string const& description) { _description = description; }
231  std::string GetDescription() const { return _description; }
232 
233  void SetType(CalendarEventType eventType) { _eventType = eventType; }
234  CalendarEventType GetType() const { return _eventType; }
235 
236  void SetTextureId(int32 textureId) { _textureId = textureId; }
237  int32 GetTextureId() const { return _textureId; }
238 
239  void SetDate(time_t date) { _date = date; }
240  time_t GetDate() const { return _date; }
241 
242  void SetFlags(uint32 flags) { _flags = flags; }
243  uint32 GetFlags() const { return _flags; }
244 
245  bool IsGuildEvent() const { return (_flags & CALENDAR_FLAG_GUILD_EVENT) != 0; }
246  bool IsGuildAnnouncement() const { return (_flags & CALENDAR_FLAG_WITHOUT_INVITES) != 0; }
247  bool IsLocked() const { return (_flags & CALENDAR_FLAG_INVITES_LOCKED) != 0; }
248 
249  void SetLockDate(time_t lockDate) { _lockDate = lockDate; }
250  time_t GetLockDate() const { return _lockDate; }
251 
252  std::string BuildCalendarMailSubject(ObjectGuid remover) const;
253  std::string BuildCalendarMailBody() const;
254 
255  private:
261  time_t _date;
263  std::string _title;
264  std::string _description;
265  time_t _lockDate;
266 };
267 typedef std::vector<CalendarInvite*> CalendarInviteStore;
268 typedef std::set<CalendarEvent*> CalendarEventStore;
269 typedef std::map<uint64 /* eventID */, CalendarInviteStore > CalendarEventInviteStore;
270 
272 {
273  private:
274  CalendarMgr();
275  ~CalendarMgr();
276 
279 
280  std::deque<uint64> _freeEventIds;
281  std::deque<uint64> _freeInviteIds;
284 
285  public:
286  static CalendarMgr* instance();
287 
288  void LoadFromDB();
289 
290  CalendarEvent* GetEvent(uint64 eventId) const;
291  CalendarEventStore const& GetEvents() const { return _events; }
292  CalendarEventStore GetPlayerEvents(ObjectGuid guid);
293 
294  CalendarInvite* GetInvite(uint64 inviteId) const;
295  CalendarEventInviteStore const& GetInvites() const { return _invites; }
296  CalendarInviteStore const& GetEventInvites(uint64 eventId);
297  CalendarInviteStore GetPlayerInvites(ObjectGuid guid);
298 
299  void FreeEventId(uint64 id);
300  uint64 GetFreeEventId();
301  void FreeInviteId(uint64 id);
302  uint64 GetFreeInviteId();
303 
304  uint32 GetPlayerNumPending(ObjectGuid guid);
305 
306  void AddEvent(CalendarEvent* calendarEvent, CalendarSendEventType sendType);
307  void RemoveEvent(uint64 eventId, ObjectGuid remover);
308  void UpdateEvent(CalendarEvent* calendarEvent);
309 
310  void AddInvite(CalendarEvent* calendarEvent, CalendarInvite* invite);
311  void AddInvite(CalendarEvent* calendarEvent, CalendarInvite* invite, SQLTransaction& trans);
312  void RemoveInvite(uint64 inviteId, uint64 eventId, ObjectGuid remover);
313  void UpdateInvite(CalendarInvite* invite);
314  void UpdateInvite(CalendarInvite* invite, SQLTransaction& trans);
315 
316  void RemoveAllPlayerEventsAndInvites(ObjectGuid guid);
317  void RemovePlayerGuildEventsAndSignups(ObjectGuid guid, ObjectGuid::LowType guildId);
318 
319  void SendCalendarEvent(ObjectGuid guid, CalendarEvent const& calendarEvent, CalendarSendEventType sendType);
320  void SendCalendarEventInvite(CalendarInvite const& invite);
321  void SendCalendarEventInviteAlert(CalendarEvent const& calendarEvent, CalendarInvite const& invite);
322  void SendCalendarEventInviteRemove(CalendarEvent const& calendarEvent, CalendarInvite const& invite, uint32 flags);
323  void SendCalendarEventInviteRemoveAlert(ObjectGuid guid, CalendarEvent const& calendarEvent, CalendarInviteStatus status);
324  void SendCalendarEventUpdateAlert(CalendarEvent const& calendarEvent, time_t originalDate);
325  void SendCalendarEventStatus(CalendarEvent const& calendarEvent, CalendarInvite const& invite);
326  void SendCalendarEventRemovedAlert(CalendarEvent const& calendarEvent);
327  void SendCalendarEventModeratorStatusAlert(CalendarEvent const& calendarEvent, CalendarInvite const& invite);
328  void SendCalendarClearPendingAction(ObjectGuid guid);
329  void SendCalendarCommandResult(ObjectGuid guid, CalendarError err, char const* param = NULL);
330 
331  void SendPacketToAllEventRelatives(WorldPacket const* packet, CalendarEvent const& calendarEvent);
332 };
333 
334 #define sCalendarMgr CalendarMgr::instance()
335 
336 #endif
std::string _note
Definition: CalendarMgr.h:188
Definition: CalendarMgr.h:36
ObjectGuid GetInviteeGUID() const
Definition: CalendarMgr.h:166
Definition: CalendarMgr.h:63
Definition: CalendarMgr.h:69
Definition: CalendarMgr.h:98
Definition: CalendarMgr.h:84
time_t _date
Definition: CalendarMgr.h:261
CalendarEvent(CalendarEvent const &calendarEvent, uint64 eventId)
Definition: CalendarMgr.h:194
CalendarError
Definition: CalendarMgr.h:88
Definition: CalendarMgr.h:271
uint32 _flags
Definition: CalendarMgr.h:262
CalendarModerationRank _rank
Definition: CalendarMgr.h:187
ObjectGuid _ownerGUID
Definition: CalendarMgr.h:257
Definition: CalendarMgr.h:29
Definition: CalendarMgr.h:45
uint64 _maxInviteId
Definition: CalendarMgr.h:283
std::deque< uint64 > _freeInviteIds
Definition: CalendarMgr.h:281
Definition: CalendarMgr.h:117
Definition: CalendarMgr.h:53
void SetLockDate(time_t lockDate)
Definition: CalendarMgr.h:249
Definition: CalendarMgr.h:38
std::string _description
Definition: CalendarMgr.h:264
std::string GetTitle() const
Definition: CalendarMgr.h:228
Definition: CalendarMgr.h:99
void SetStatus(CalendarInviteStatus status)
Definition: CalendarMgr.h:174
uint64 _eventId
Definition: CalendarMgr.h:182
void LoadFromDB()
Definition: AddonMgr.cpp:40
Definition: CalendarMgr.h:101
CalendarEventType
Definition: CalendarMgr.h:56
time_t _lockDate
Definition: CalendarMgr.h:265
CalendarFlags
Definition: CalendarMgr.h:34
Definition: CalendarMgr.h:104
Definition: CalendarMgr.h:114
Definition: CalendarMgr.h:90
Definition: CalendarMgr.h:103
Definition: CalendarMgr.h:119
Definition: CalendarMgr.h:121
#define UI64LIT(N)
Definition: Define.h:138
Definition: CalendarMgr.h:93
Definition: CalendarMgr.h:111
arena_t NULL
Definition: jemalloc_internal.h:624
std::deque< uint64 > _freeEventIds
Definition: CalendarMgr.h:280
Definition: CalendarMgr.h:108
CalendarEventStore _events
Definition: CalendarMgr.h:277
CalendarEventType GetType() const
Definition: CalendarMgr.h:234
Definition: CalendarMgr.h:106
time_t _responseTime
Definition: CalendarMgr.h:185
CalendarRepeatType
Definition: CalendarMgr.h:66
uint64 LowType
Definition: ObjectGuid.h:199
void SetOwnerGUID(ObjectGuid guid)
Definition: CalendarMgr.h:221
Definition: CalendarMgr.h:62
CalendarModerationRank
Definition: CalendarMgr.h:42
time_t GetResponseTime() const
Definition: CalendarMgr.h:169
ObjectGuid::LowType _eventGuildId
Definition: CalendarMgr.h:258
ObjectGuid::LowType GetGuildId() const
Definition: CalendarMgr.h:225
CalendarInvite(uint64 inviteId, uint64 eventId, ObjectGuid invitee, ObjectGuid senderGUID, time_t responseTime, CalendarInviteStatus status, CalendarModerationRank rank, std::string note)
Definition: CalendarMgr.h:149
Definition: CalendarMgr.h:82
Definition: CalendarMgr.h:83
int32 GetTextureId() const
Definition: CalendarMgr.h:237
uint64 _eventId
Definition: CalendarMgr.h:256
Definition: CalendarMgr.h:97
Definition: CalendarMgr.h:60
std::set< CalendarEvent * > CalendarEventStore
Definition: CalendarMgr.h:268
Definition: CalendarMgr.h:70
CalendarInvite()
Definition: CalendarMgr.h:146
Definition: CalendarMgr.h:109
Definition: CalendarMgr.h:110
void SetTitle(std::string const &title)
Definition: CalendarMgr.h:227
uint64 GetEventId() const
Definition: CalendarMgr.h:219
CalendarInviteStatus _status
Definition: CalendarMgr.h:186
Definition: CalendarMgr.h:58
std::vector< CalendarInvite * > CalendarInviteStore
Definition: CalendarMgr.h:267
Definition: CalendarMgr.h:39
std::string GetNote() const
Definition: CalendarMgr.h:172
Definition: CalendarMgr.h:79
Definition: CalendarMgr.h:77
uint64 GetInviteId() const
Definition: CalendarMgr.h:157
void SetSenderGUID(ObjectGuid guid)
Definition: CalendarMgr.h:162
std::string GetDescription() const
Definition: CalendarMgr.h:231
Definition: CalendarMgr.h:46
void SetGuildId(ObjectGuid::LowType guildId)
Definition: CalendarMgr.h:224
Definition: CalendarMgr.h:80
CalendarEventType _eventType
Definition: CalendarMgr.h:259
Definition: CalendarMgr.h:191
Definition: CalendarMgr.h:68
Definition: CalendarMgr.h:113
Definition: CalendarMgr.h:71
Definition: CalendarMgr.h:96
uint64 _maxEventId
Definition: CalendarMgr.h:282
Definition: CalendarMgr.h:100
Definition: CalendarMgr.h:59
uint64 GetEventId() const
Definition: CalendarMgr.h:160
CalendarEventStore const & GetEvents() const
Definition: CalendarMgr.h:291
void SetResponseTime(time_t responseTime)
Definition: CalendarMgr.h:168
int32_t int32
Definition: Define.h:146
void SetNote(std::string const &note)
Definition: CalendarMgr.h:171
uint32_t uint32
Definition: Define.h:150
void SetInvitee(ObjectGuid guid)
Definition: CalendarMgr.h:165
uint64_t uint64
Definition: Define.h:149
std::string _title
Definition: CalendarMgr.h:263
Definition: CalendarMgr.h:122
void SetEventId(uint64 eventId)
Definition: CalendarMgr.h:159
Definition: CalendarMgr.h:123
void SetFlags(uint32 flags)
Definition: CalendarMgr.h:242
ObjectGuid GetSenderGUID() const
Definition: CalendarMgr.h:163
Definition: CalendarMgr.h:115
bool IsGuildAnnouncement() const
Definition: CalendarMgr.h:246
CalendarEvent()
Definition: CalendarMgr.h:213
ObjectGuid _senderGUID
Definition: CalendarMgr.h:184
CalendarMailAnswers
Definition: CalendarMgr.h:26
ObjectGuid _invitee
Definition: CalendarMgr.h:183
void SetDate(time_t date)
Definition: CalendarMgr.h:239
Definition: CalendarMgr.h:81
Definition: CalendarMgr.h:94
void SetDescription(std::string const &description)
Definition: CalendarMgr.h:230
void SetType(CalendarEventType eventType)
Definition: CalendarMgr.h:233
#define TC_GAME_API
Definition: Define.h:134
time_t GetDate() const
Definition: CalendarMgr.h:240
Definition: CalendarMgr.h:120
void SetRank(CalendarModerationRank rank)
Definition: CalendarMgr.h:177
Definition: CalendarMgr.h:37
bool IsGuildEvent() const
Definition: CalendarMgr.h:245
CalendarEventInviteStore _invites
Definition: CalendarMgr.h:278
Definition: CalendarMgr.h:102
CalendarEvent(uint64 eventId, ObjectGuid ownerGUID, ObjectGuid::LowType guildId, CalendarEventType type, int32 textureId, time_t date, uint32 flags, std::string title, std::string description, time_t lockDate)
Definition: CalendarMgr.h:208
Definition: CalendarMgr.h:52
Definition: CalendarMgr.h:116
Definition: CalendarMgr.h:76
bool IsLocked() const
Definition: CalendarMgr.h:247
Definition: CalendarMgr.h:105
Definition: CalendarMgr.h:112
CalendarInviteStatus
Definition: CalendarMgr.h:74
CalendarEventInviteStore const & GetInvites() const
Definition: CalendarMgr.h:295
Definition: CalendarMgr.h:61
std::map< uint64, CalendarInviteStore > CalendarEventInviteStore
Definition: CalendarMgr.h:269
Definition: ObjectGuid.h:189
uint8 flags
Definition: DisableMgr.cpp:44
Definition: CalendarMgr.h:44
void SetInviteId(uint64 inviteId)
Definition: CalendarMgr.h:156
CalendarInviteStatus GetStatus() const
Definition: CalendarMgr.h:175
CalendarSendEventType
Definition: CalendarMgr.h:49
Definition: CalendarMgr.h:51
Definition: CalendarMgr.h:131
Definition: CalendarMgr.h:78
uint64 _inviteId
Definition: CalendarMgr.h:181
void SetTextureId(int32 textureId)
Definition: CalendarMgr.h:236
time_t GetLockDate() const
Definition: CalendarMgr.h:250
Definition: CalendarMgr.h:85
CalendarInvite(CalendarInvite const &calendarInvite, uint64 inviteId, uint64 eventId)
Definition: CalendarMgr.h:134
Definition: CalendarMgr.h:92
Definition: CalendarMgr.h:31
CalendarModerationRank GetRank() const
Definition: CalendarMgr.h:178
Definition: WorldPacket.h:26
int32 _textureId
Definition: CalendarMgr.h:260
uint32 GetFlags() const
Definition: CalendarMgr.h:243
Definition: CalendarMgr.h:95
Definition: CalendarMgr.h:91
ObjectGuid GetOwnerGUID() const
Definition: CalendarMgr.h:222
void SetEventId(uint64 eventId)
Definition: CalendarMgr.h:218
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58