TrinityCore
Loading...
Searching...
No Matches
CalendarMgr.h
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#ifndef TRINITY_CALENDARMGR_H
19#define TRINITY_CALENDARMGR_H
20
21#include "Common.h"
22#include "DatabaseEnvFwd.h"
23#include "ObjectGuid.h"
24#include <deque>
25#include <map>
26#include <set>
27#include <vector>
28
29class Player;
30class WorldPacket;
31
33{
34 // else
36 // if ( *(_DWORD *)(a1 + 8292) & 0x100 )
38};
39
47
54
61
71
79
93
131
140
141#define CALENDAR_DEFAULT_RESPONSE_TIME 946684800 // 01/01/2000 00:00:00
142
144{
145 public:
146 CalendarInvite(CalendarInvite const& calendarInvite, uint64 inviteId, uint64 eventId) : _inviteId(inviteId), _eventId(eventId),
147 _invitee(calendarInvite.GetInviteeGUID()), _senderGUID(calendarInvite.GetSenderGUID()), _responseTime(calendarInvite.GetResponseTime()),
148 _status(calendarInvite.GetStatus()), _rank(calendarInvite.GetRank()), _note(calendarInvite.GetNote())
149 {
150 }
151
153
154 CalendarInvite(uint64 inviteId, uint64 eventId, ObjectGuid invitee, ObjectGuid senderGUID, time_t responseTime,
155 CalendarInviteStatus status, CalendarModerationRank rank, std::string note) :
156 _inviteId(inviteId), _eventId(eventId), _invitee(invitee), _senderGUID(senderGUID), _responseTime(responseTime),
157 _status(status), _rank(rank), _note(std::move(note)) { }
158
161
164
166
167 void SetInviteId(uint64 inviteId) { _inviteId = inviteId; }
168 uint64 GetInviteId() const { return _inviteId; }
169
170 void SetEventId(uint64 eventId) { _eventId = eventId; }
171 uint64 GetEventId() const { return _eventId; }
172
173 void SetSenderGUID(ObjectGuid guid) { _senderGUID = guid; }
174 ObjectGuid GetSenderGUID() const { return _senderGUID; }
175
176 void SetInvitee(ObjectGuid guid) { _invitee = guid; }
177 ObjectGuid GetInviteeGUID() const { return _invitee; }
178
179 void SetResponseTime(time_t responseTime) { _responseTime = responseTime; }
180 time_t GetResponseTime() const { return _responseTime; }
181
182 void SetNote(std::string const& note) { _note = note; }
183 std::string GetNote() const { return _note; }
184
185 void SetStatus(CalendarInviteStatus status) { _status = status; }
186 CalendarInviteStatus GetStatus() const { return _status; }
187
188 void SetRank(CalendarModerationRank rank) { _rank = rank; }
189 CalendarModerationRank GetRank() const { return _rank; }
190
191 private:
199 std::string _note;
200};
201
203{
204 public:
205 CalendarEvent(CalendarEvent const& calendarEvent, uint64 eventId) : _eventId(eventId), _ownerGUID(calendarEvent.GetOwnerGUID()),
206 _eventGuildId(calendarEvent.GetGuildId()), _eventType(calendarEvent.GetType()), _textureId(calendarEvent.GetTextureId()),
207 _date(calendarEvent.GetDate()), _flags(calendarEvent.GetFlags()), _title(calendarEvent.GetTitle()), _description(calendarEvent.GetDescription()),
208 _lockDate(calendarEvent.GetLockDate()) { }
209
210 CalendarEvent(uint64 eventId, ObjectGuid ownerGUID, ObjectGuid::LowType guildId, CalendarEventType type, int32 textureId,
211 time_t date, uint32 flags, std::string title, std::string description, time_t lockDate) :
212 _eventId(eventId), _ownerGUID(ownerGUID), _eventGuildId(guildId), _eventType(type), _textureId(textureId),
213 _date(date), _flags(flags), _title(std::move(title)), _description(std::move(description)), _lockDate(lockDate) { }
214
215 CalendarEvent() : _eventId(1), _ownerGUID(), _eventGuildId(UI64LIT(0)), _eventType(CALENDAR_TYPE_OTHER), _textureId(-1), _date(0),
216 _flags(0), _title(), _description(), _lockDate(0) { }
217
218 CalendarEvent(CalendarEvent const&) = delete;
220
223
225
226 void SetEventId(uint64 eventId) { _eventId = eventId; }
227 uint64 GetEventId() const { return _eventId; }
228
229 void SetOwnerGUID(ObjectGuid guid) { _ownerGUID = guid; }
230 ObjectGuid GetOwnerGUID() const { return _ownerGUID; }
231
232 void SetGuildId(ObjectGuid::LowType guildId) { _eventGuildId = guildId; }
233 ObjectGuid::LowType GetGuildId() const { return _eventGuildId; }
234
235 void SetTitle(std::string const& title) { _title = title; }
236 std::string GetTitle() const { return _title; }
237
238 void SetDescription(std::string const& description) { _description = description; }
239 std::string GetDescription() const { return _description; }
240
241 void SetType(CalendarEventType eventType) { _eventType = eventType; }
242 CalendarEventType GetType() const { return _eventType; }
243
244 void SetTextureId(int32 textureId) { _textureId = textureId; }
245 int32 GetTextureId() const { return _textureId; }
246
247 void SetDate(time_t date) { _date = date; }
248 time_t GetDate() const { return _date; }
249
250 void SetFlags(uint32 flags) { _flags = flags; }
251 uint32 GetFlags() const { return _flags; }
252
253 bool IsGuildEvent() const { return (_flags & CALENDAR_FLAG_GUILD_EVENT) != 0; }
254 bool IsGuildAnnouncement() const { return (_flags & CALENDAR_FLAG_WITHOUT_INVITES) != 0; }
255 bool IsLocked() const { return (_flags & CALENDAR_FLAG_INVITES_LOCKED) != 0; }
256
257 void SetLockDate(time_t lockDate) { _lockDate = lockDate; }
258 time_t GetLockDate() const { return _lockDate; }
259
260 static bool IsGuildEvent(uint32 flags) { return (flags & CALENDAR_FLAG_GUILD_EVENT) != 0; }
262
263 std::string BuildCalendarMailSubject(ObjectGuid remover) const;
264 std::string BuildCalendarMailBody(Player const* invitee) const;
265
266 private:
272 time_t _date;
274 std::string _title;
275 std::string _description;
276 time_t _lockDate;
277};
278typedef std::vector<CalendarInvite*> CalendarInviteStore;
279typedef std::set<CalendarEvent*> CalendarEventStore;
280typedef std::map<uint64 /* eventID */, CalendarInviteStore > CalendarEventInviteStore;
281
283{
284 private:
285 CalendarMgr();
286 ~CalendarMgr();
287
290
291 std::deque<uint64> _freeEventIds;
292 std::deque<uint64> _freeInviteIds;
295
296 public:
297 CalendarMgr(CalendarMgr const&) = delete;
299
302
303 static CalendarMgr* instance();
304
305 void LoadFromDB();
306
307 CalendarEvent* GetEvent(uint64 eventId) const;
308 CalendarEventStore const& GetEvents() const { return _events; }
309 CalendarEventStore GetEventsCreatedBy(ObjectGuid guid, bool includeGuildEvents = false) const;
310 CalendarEventStore GetPlayerEvents(ObjectGuid guid) const;
311 CalendarEventStore GetGuildEvents(ObjectGuid::LowType guildId) const;
312
313 CalendarInvite* GetInvite(uint64 inviteId) const;
314 CalendarEventInviteStore const& GetInvites() const { return _invites; }
315 CalendarInviteStore GetEventInvites(uint64 eventId) const;
316 CalendarInviteStore GetPlayerInvites(ObjectGuid guid) const;
317
318 void FreeEventId(uint64 id);
319 uint64 GetFreeEventId();
320 void FreeInviteId(uint64 id);
321 uint64 GetFreeInviteId();
322
323 void DeleteOldEvents();
324
325 uint32 GetPlayerNumPending(ObjectGuid guid);
326
327 void AddEvent(CalendarEvent* calendarEvent, CalendarSendEventType sendType);
328 void RemoveEvent(uint64 eventId, ObjectGuid remover);
329 void RemoveEvent(CalendarEvent* calendarEvent, ObjectGuid remover);
330 void UpdateEvent(CalendarEvent* calendarEvent);
331
332 void AddInvite(CalendarEvent* calendarEvent, CalendarInvite* invite, CharacterDatabaseTransaction trans = nullptr);
333 void RemoveInvite(uint64 inviteId, uint64 eventId, ObjectGuid remover);
334 void UpdateInvite(CalendarInvite* invite, CharacterDatabaseTransaction trans = nullptr);
335
336 void RemoveAllPlayerEventsAndInvites(ObjectGuid guid);
337 void RemovePlayerGuildEventsAndSignups(ObjectGuid guid, ObjectGuid::LowType guildId);
338
339 void SendCalendarEvent(ObjectGuid guid, CalendarEvent const& calendarEvent, CalendarSendEventType sendType) const;
340 void SendCalendarEventInvite(CalendarInvite const& invite) const;
341 void SendCalendarEventInviteAlert(CalendarEvent const& calendarEvent, CalendarInvite const& invite) const;
342 void SendCalendarEventInviteRemove(CalendarEvent const& calendarEvent, CalendarInvite const& invite, uint32 flags) const;
343 void SendCalendarEventInviteRemoveAlert(ObjectGuid guid, CalendarEvent const& calendarEvent, CalendarInviteStatus status) const;
344 void SendCalendarEventUpdateAlert(CalendarEvent const& calendarEvent, time_t originalDate) const;
345 void SendCalendarEventStatus(CalendarEvent const& calendarEvent, CalendarInvite const& invite) const;
346 void SendCalendarEventRemovedAlert(CalendarEvent const& calendarEvent) const;
347 void SendCalendarEventModeratorStatusAlert(CalendarEvent const& calendarEvent, CalendarInvite const& invite) const;
348 void SendCalendarClearPendingAction(ObjectGuid guid) const;
349 void SendCalendarCommandResult(ObjectGuid guid, CalendarError err, char const* param = nullptr) const;
350
351 void SendPacketToAllEventRelatives(WorldPacket const* packet, CalendarEvent const& calendarEvent) const;
352 std::vector<Player*> GetAllEventRelatives(CalendarEvent const& calendarEvent) const;
353};
354
355#define sCalendarMgr CalendarMgr::instance()
356
357#endif
std::set< CalendarEvent * > CalendarEventStore
CalendarError
Definition CalendarMgr.h:95
@ CALENDAR_ERROR_INTERNAL
@ CALENDAR_ERROR_INVALID_SIGNUP
@ CALENDAR_ERROR_NO_INVITE
@ CALENDAR_ERROR_SYSTEM_DISABLED
@ CALENDAR_ERROR_EVENT_PASSED
@ CALENDAR_ERROR_NOT_INVITED
@ CALENDAR_ERROR_EVENT_LOCKED
@ CALENDAR_ERROR_ARENA_EVENTS_EXCEEDED
@ CALENDAR_ERROR_OTHER_INVITES_EXCEEDED
@ CALENDAR_ERROR_SELF_INVITES_EXCEEDED
Definition CalendarMgr.h:99
@ CALENDAR_ERROR_NOT_ALLIED
@ CALENDAR_ERROR_PERMISSIONS
@ CALENDAR_ERROR_EVENTS_EXCEEDED
Definition CalendarMgr.h:98
@ CALENDAR_ERROR_NO_GUILD_INVITES
@ CALENDAR_ERROR_INVALID_DATE
@ CALENDAR_ERROR_NEEDS_TITLE
@ CALENDAR_ERROR_RESTRICTED_LEVEL
@ CALENDAR_ERROR_DELETE_CREATOR_FAILED
@ CALENDAR_ERROR_GUILD_EVENTS_EXCEEDED
Definition CalendarMgr.h:97
@ CALENDAR_ERROR_NO_MODERATOR
@ CALENDAR_ERROR_INVITE_WRONG_SERVER
@ CALENDAR_ERROR_ALREADY_INVITED_TO_EVENT_S
@ CALENDAR_ERROR_INVITES_EXCEEDED
@ CALENDAR_ERROR_INVALID_TIME
@ CALENDAR_ERROR_EVENT_WRONG_SERVER
@ CALENDAR_ERROR_RESTRICTED_ACCOUNT
@ CALENDAR_ERROR_IGNORING_YOU_S
@ CALENDAR_ERROR_USER_SQUELCHED
@ CALENDAR_ERROR_PLAYER_NOT_FOUND
@ CALENDAR_OK
Definition CalendarMgr.h:96
@ CALENDAR_ERROR_EVENT_INVALID
@ CALENDAR_ERROR_GUILD_PLAYER_NOT_IN_GUILD
CalendarRepeatType
Definition CalendarMgr.h:73
@ CALENDAR_REPEAT_BIWEEKLY
Definition CalendarMgr.h:76
@ CALENDAR_REPEAT_WEEKLY
Definition CalendarMgr.h:75
@ CALENDAR_REPEAT_NEVER
Definition CalendarMgr.h:74
@ CALENDAR_REPEAT_MONTHLY
Definition CalendarMgr.h:77
CalendarModerationRank
Definition CalendarMgr.h:49
@ CALENDAR_RANK_PLAYER
Definition CalendarMgr.h:50
@ CALENDAR_RANK_MODERATOR
Definition CalendarMgr.h:51
@ CALENDAR_RANK_OWNER
Definition CalendarMgr.h:52
CalendarFlags
Definition CalendarMgr.h:41
@ CALENDAR_FLAG_WITHOUT_INVITES
Definition CalendarMgr.h:44
@ CALENDAR_FLAG_INVITES_LOCKED
Definition CalendarMgr.h:43
@ CALENDAR_FLAG_GUILD_EVENT
Definition CalendarMgr.h:45
@ CALENDAR_FLAG_ALL_ALLOWED
Definition CalendarMgr.h:42
std::vector< CalendarInvite * > CalendarInviteStore
CalendarSendEventType
Definition CalendarMgr.h:56
@ CALENDAR_SENDTYPE_GET
Definition CalendarMgr.h:57
@ CALENDAR_SENDTYPE_COPY
Definition CalendarMgr.h:59
@ CALENDAR_SENDTYPE_ADD
Definition CalendarMgr.h:58
CalendarMailAnswers
Definition CalendarMgr.h:33
@ CALENDAR_EVENT_REMOVED_MAIL_SUBJECT
Definition CalendarMgr.h:35
@ CALENDAR_INVITE_REMOVED_MAIL_SUBJECT
Definition CalendarMgr.h:37
CalendarEventType
Definition CalendarMgr.h:63
@ CALENDAR_TYPE_OTHER
Definition CalendarMgr.h:68
@ CALENDAR_TYPE_HEROIC
Definition CalendarMgr.h:69
@ CALENDAR_TYPE_RAID
Definition CalendarMgr.h:64
@ CALENDAR_TYPE_MEETING
Definition CalendarMgr.h:67
@ CALENDAR_TYPE_PVP
Definition CalendarMgr.h:66
@ CALENDAR_TYPE_DUNGEON
Definition CalendarMgr.h:65
CalendarInviteStatus
Definition CalendarMgr.h:81
@ CALENDAR_STATUS_TENTATIVE
Definition CalendarMgr.h:90
@ CALENDAR_STATUS_NOT_SIGNED_UP
Definition CalendarMgr.h:89
@ CALENDAR_STATUS_STANDBY
Definition CalendarMgr.h:87
@ CALENDAR_STATUS_INVITED
Definition CalendarMgr.h:82
@ CALENDAR_STATUS_ACCEPTED
Definition CalendarMgr.h:83
@ CALENDAR_STATUS_SIGNED_UP
Definition CalendarMgr.h:88
@ CALENDAR_STATUS_REMOVED
Definition CalendarMgr.h:91
@ CALENDAR_STATUS_DECLINED
Definition CalendarMgr.h:84
@ CALENDAR_STATUS_CONFIRMED
Definition CalendarMgr.h:85
@ CALENDAR_STATUS_OUT
Definition CalendarMgr.h:86
std::map< uint64, CalendarInviteStore > CalendarEventInviteStore
CalendarLimits
@ CALENDAR_OLD_EVENTS_DELETION_TIME
@ CALENDAR_MAX_EVENTS
@ CALENDAR_MAX_INVITES
@ CALENDAR_MAX_GUILD_EVENTS
@ CALENDAR_CREATE_EVENT_COOLDOWN
@ MONTH
Definition Common.h:36
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
#define TC_GAME_API
Definition Define.h:129
int32_t int32
Definition Define.h:150
uint64_t uint64
Definition Define.h:153
#define UI64LIT(N)
Definition Define.h:139
uint32_t uint32
Definition Define.h:154
uint16 flags
uint64 _maxInviteId
CalendarEventInviteStore _invites
CalendarEventStore const & GetEvents() const
std::deque< uint64 > _freeEventIds
CalendarEventStore _events
CalendarMgr & operator=(CalendarMgr const &)=delete
CalendarEventInviteStore const & GetInvites() const
CalendarMgr(CalendarMgr &&)=delete
uint64 _maxEventId
std::deque< uint64 > _freeInviteIds
CalendarMgr(CalendarMgr const &)=delete
CalendarMgr & operator=(CalendarMgr &&)=delete
uint64 LowType
Definition ObjectGuid.h:321
STL namespace.
void SetType(CalendarEventType eventType)
bool IsGuildAnnouncement() const
CalendarEvent(CalendarEvent const &calendarEvent, uint64 eventId)
CalendarEventType GetType() const
std::string _description
ObjectGuid GetOwnerGUID() const
CalendarEventType _eventType
bool IsGuildEvent() const
void SetEventId(uint64 eventId)
time_t GetDate() const
uint64 GetEventId() const
void SetDescription(std::string const &description)
ObjectGuid::LowType GetGuildId() const
std::string _title
void SetTitle(std::string const &title)
void SetLockDate(time_t lockDate)
int32 GetTextureId() const
CalendarEvent(CalendarEvent const &)=delete
CalendarEvent & operator=(CalendarEvent const &)=delete
ObjectGuid::LowType _eventGuildId
bool IsLocked() const
void SetGuildId(ObjectGuid::LowType guildId)
ObjectGuid _ownerGUID
CalendarEvent(CalendarEvent &&)=delete
time_t GetLockDate() const
std::string GetTitle() const
void SetTextureId(int32 textureId)
static bool IsGuildEvent(uint32 flags)
std::string GetDescription() const
static bool IsGuildAnnouncement(uint32 flags)
CalendarEvent & operator=(CalendarEvent &&)=delete
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)
void SetDate(time_t date)
void SetOwnerGUID(ObjectGuid guid)
uint32 GetFlags() const
void SetFlags(uint32 flags)
void SetStatus(CalendarInviteStatus status)
CalendarModerationRank GetRank() const
CalendarInvite & operator=(CalendarInvite &&)=delete
void SetRank(CalendarModerationRank rank)
CalendarModerationRank _rank
CalendarInviteStatus GetStatus() const
CalendarInvite(CalendarInvite const &)=delete
uint64 GetInviteId() const
CalendarInvite(CalendarInvite const &calendarInvite, uint64 inviteId, uint64 eventId)
void SetSenderGUID(ObjectGuid guid)
ObjectGuid _senderGUID
void SetResponseTime(time_t responseTime)
void SetNote(std::string const &note)
void SetInvitee(ObjectGuid guid)
std::string GetNote() const
void SetInviteId(uint64 inviteId)
time_t GetResponseTime() const
CalendarInvite & operator=(CalendarInvite const &)=delete
ObjectGuid _invitee
time_t _responseTime
uint64 GetEventId() const
CalendarInvite(uint64 inviteId, uint64 eventId, ObjectGuid invitee, ObjectGuid senderGUID, time_t responseTime, CalendarInviteStatus status, CalendarModerationRank rank, std::string note)
CalendarInvite(CalendarInvite &&)=delete
ObjectGuid GetSenderGUID() const
CalendarInviteStatus _status
ObjectGuid GetInviteeGUID() const
std::string _note
void SetEventId(uint64 eventId)