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
70
78
92
130
139
140#define CALENDAR_DEFAULT_RESPONSE_TIME 946684800 // 01/01/2000 00:00:00
141
143{
144 public:
145 CalendarInvite(CalendarInvite const& calendarInvite, uint64 inviteId, uint64 eventId)
146 {
147 _inviteId = inviteId;
148 _eventId = eventId;
149 _invitee = calendarInvite.GetInviteeGUID();
150 _senderGUID = calendarInvite.GetSenderGUID();
151 _responseTime = calendarInvite.GetResponseTime();
152 _status = calendarInvite.GetStatus();
153 _rank = calendarInvite.GetRank();
154 _note = calendarInvite.GetNote();
155 }
156
158
159 CalendarInvite(uint64 inviteId, uint64 eventId, ObjectGuid invitee, ObjectGuid senderGUID, time_t statusTime,
160 CalendarInviteStatus status, CalendarModerationRank rank, std::string note) :
161 _inviteId(inviteId), _eventId(eventId), _invitee(invitee), _senderGUID(senderGUID), _responseTime(statusTime),
162 _status(status), _rank(rank), _note(std::move(note)) { }
163
166
169
171
172 void SetInviteId(uint64 inviteId) { _inviteId = inviteId; }
173 uint64 GetInviteId() const { return _inviteId; }
174
175 void SetEventId(uint64 eventId) { _eventId = eventId; }
176 uint64 GetEventId() const { return _eventId; }
177
178 void SetSenderGUID(ObjectGuid guid) { _senderGUID = guid; }
179 ObjectGuid GetSenderGUID() const { return _senderGUID; }
180
181 void SetInvitee(ObjectGuid guid) { _invitee = guid; }
182 ObjectGuid GetInviteeGUID() const { return _invitee; }
183
184 void SetResponseTime(time_t statusTime) { _responseTime = statusTime; }
185 time_t GetResponseTime() const { return _responseTime; }
186
187 void SetNote(std::string const& note) { _note = note; }
188 std::string GetNote() const { return _note; }
189
190 void SetStatus(CalendarInviteStatus status) { _status = status; }
191 CalendarInviteStatus GetStatus() const { return _status; }
192
193 void SetRank(CalendarModerationRank rank) { _rank = rank; }
194 CalendarModerationRank GetRank() const { return _rank; }
195
196 private:
204 std::string _note;
205};
206
208{
209 public:
210 CalendarEvent(CalendarEvent const& calendarEvent, uint64 eventId)
211 {
212 _eventId = eventId;
213 _ownerGUID = calendarEvent.GetOwnerGUID();
214 _eventGuildId = calendarEvent.GetGuildId();
215 _eventType = calendarEvent.GetType();
216 _textureId = calendarEvent.GetTextureId();
217 _date = calendarEvent.GetDate();
218 _flags = calendarEvent.GetFlags();
219 _title = calendarEvent.GetTitle();
220 _description = calendarEvent.GetDescription();
221 _lockDate = calendarEvent.GetLockDate();
222 }
223
224 CalendarEvent(uint64 eventId, ObjectGuid ownerGUID, ObjectGuid::LowType guildId, CalendarEventType type, int32 textureId,
225 time_t date, uint32 flags, std::string title, std::string description, time_t lockDate) :
226 _eventId(eventId), _ownerGUID(ownerGUID), _eventGuildId(guildId), _eventType(type), _textureId(textureId),
227 _date(date), _flags(flags), _title(std::move(title)), _description(std::move(description)), _lockDate(lockDate) { }
228
229 CalendarEvent() : _eventId(1), _ownerGUID(), _eventGuildId(UI64LIT(0)), _eventType(CALENDAR_TYPE_OTHER), _textureId(-1), _date(0),
230 _flags(0), _title(), _description(), _lockDate(0) { }
231
232 CalendarEvent(CalendarEvent const&) = delete;
234
237
239
240 void SetEventId(uint64 eventId) { _eventId = eventId; }
241 uint64 GetEventId() const { return _eventId; }
242
243 void SetOwnerGUID(ObjectGuid guid) { _ownerGUID = guid; }
244 ObjectGuid GetOwnerGUID() const { return _ownerGUID; }
245
246 void SetGuildId(ObjectGuid::LowType guildId) { _eventGuildId = guildId; }
247 ObjectGuid::LowType GetGuildId() const { return _eventGuildId; }
248
249 void SetTitle(std::string const& title) { _title = title; }
250 std::string GetTitle() const { return _title; }
251
252 void SetDescription(std::string const& description) { _description = description; }
253 std::string GetDescription() const { return _description; }
254
255 void SetType(CalendarEventType eventType) { _eventType = eventType; }
256 CalendarEventType GetType() const { return _eventType; }
257
258 void SetTextureId(int32 textureId) { _textureId = textureId; }
259 int32 GetTextureId() const { return _textureId; }
260
261 void SetDate(time_t date) { _date = date; }
262 time_t GetDate() const { return _date; }
263
264 void SetFlags(uint32 flags) { _flags = flags; }
265 uint32 GetFlags() const { return _flags; }
266
267 bool IsGuildEvent() const { return (_flags & CALENDAR_FLAG_GUILD_EVENT) != 0; }
268 bool IsGuildAnnouncement() const { return (_flags & CALENDAR_FLAG_WITHOUT_INVITES) != 0; }
269 bool IsLocked() const { return (_flags & CALENDAR_FLAG_INVITES_LOCKED) != 0; }
270
271 void SetLockDate(time_t lockDate) { _lockDate = lockDate; }
272 time_t GetLockDate() const { return _lockDate; }
273
274 static bool IsGuildEvent(uint32 flags) { return (flags & CALENDAR_FLAG_GUILD_EVENT) != 0; }
276
277 std::string BuildCalendarMailSubject(ObjectGuid remover) const;
278 std::string BuildCalendarMailBody(Player const* invitee) const;
279
280 private:
286 time_t _date;
288 std::string _title;
289 std::string _description;
290 time_t _lockDate;
291};
292typedef std::vector<CalendarInvite*> CalendarInviteStore;
293typedef std::set<CalendarEvent*> CalendarEventStore;
294typedef std::map<uint64 /* eventId */, CalendarInviteStore > CalendarEventInviteStore;
295
297{
298 private:
299 CalendarMgr();
300 ~CalendarMgr();
301
304
305 std::deque<uint64> _freeEventIds;
306 std::deque<uint64> _freeInviteIds;
309
310 public:
311 CalendarMgr(CalendarMgr const&) = delete;
313
316
317 static CalendarMgr* instance();
318
319 void LoadFromDB();
320
321 CalendarEvent* GetEvent(uint64 eventId) const;
322 CalendarEventStore const& GetEvents() const { return _events; }
323 CalendarEventStore GetEventsCreatedBy(ObjectGuid guid, bool includeGuildEvents = false) const;
324 CalendarEventStore GetPlayerEvents(ObjectGuid guid) const;
325 CalendarEventStore GetGuildEvents(ObjectGuid::LowType guildId) const;
326
327 CalendarInvite* GetInvite(uint64 inviteId) const;
328 CalendarEventInviteStore const& GetInvites() const { return _invites; }
329 CalendarInviteStore GetEventInvites(uint64 eventId) const;
330 CalendarInviteStore GetPlayerInvites(ObjectGuid guid) const;
331
332 void FreeEventId(uint64 id);
333 uint64 GetFreeEventId();
334 void FreeInviteId(uint64 id);
335 uint64 GetFreeInviteId();
336
337 void DeleteOldEvents();
338
339 uint32 GetPlayerNumPending(ObjectGuid guid);
340
341 void AddEvent(CalendarEvent* calendarEvent, CalendarSendEventType sendType);
342 void RemoveEvent(uint64 eventId, ObjectGuid remover);
343 void RemoveEvent(CalendarEvent* calendarEvent, ObjectGuid remover);
344 void UpdateEvent(CalendarEvent* calendarEvent);
345
346 void AddInvite(CalendarEvent* calendarEvent, CalendarInvite* invite, CharacterDatabaseTransaction trans = nullptr);
347 void RemoveInvite(uint64 inviteId, uint64 eventId, ObjectGuid remover);
348 void UpdateInvite(CalendarInvite* invite, CharacterDatabaseTransaction trans = nullptr);
349
350 void RemoveAllPlayerEventsAndInvites(ObjectGuid guid);
351 void RemovePlayerGuildEventsAndSignups(ObjectGuid guid, ObjectGuid::LowType guildId);
352
353 void SendCalendarEvent(ObjectGuid guid, CalendarEvent const& calendarEvent, CalendarSendEventType sendType) const;
354 void SendCalendarEventInvite(CalendarInvite const& invite) const;
355 void SendCalendarEventInviteAlert(CalendarEvent const& calendarEvent, CalendarInvite const& invite) const;
356 void SendCalendarEventInviteRemove(CalendarEvent const& calendarEvent, CalendarInvite const& invite, uint32 flags) const;
357 void SendCalendarEventInviteRemoveAlert(ObjectGuid guid, CalendarEvent const& calendarEvent, CalendarInviteStatus status) const;
358 void SendCalendarEventUpdateAlert(CalendarEvent const& calendarEvent, time_t originalDate) const;
359 void SendCalendarEventStatus(CalendarEvent const& calendarEvent, CalendarInvite const& invite) const;
360 void SendCalendarEventRemovedAlert(CalendarEvent const& calendarEvent) const;
361 void SendCalendarEventModeratorStatusAlert(CalendarEvent const& calendarEvent, CalendarInvite const& invite) const;
362 void SendCalendarClearPendingAction(ObjectGuid guid) const;
363 void SendCalendarCommandResult(ObjectGuid guid, CalendarError err, char const* param = nullptr) const;
364
365 void SendPacketToAllEventRelatives(WorldPacket const* packet, CalendarEvent const& calendarEvent) const;
366 std::vector<Player*> GetAllEventRelatives(CalendarEvent const& calendarEvent) const;
367};
368
369#define sCalendarMgr CalendarMgr::instance()
370
371#endif
std::set< CalendarEvent * > CalendarEventStore
CalendarError
Definition CalendarMgr.h:94
@ 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
Definition CalendarMgr.h:99
@ CALENDAR_ERROR_SELF_INVITES_EXCEEDED
Definition CalendarMgr.h:98
@ CALENDAR_ERROR_NOT_ALLIED
@ CALENDAR_ERROR_PERMISSIONS
@ CALENDAR_ERROR_EVENTS_EXCEEDED
Definition CalendarMgr.h:97
@ 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:96
@ 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:95
@ CALENDAR_ERROR_EVENT_INVALID
@ CALENDAR_ERROR_GUILD_PLAYER_NOT_IN_GUILD
CalendarRepeatType
Definition CalendarMgr.h:72
@ CALENDAR_REPEAT_BIWEEKLY
Definition CalendarMgr.h:75
@ CALENDAR_REPEAT_WEEKLY
Definition CalendarMgr.h:74
@ CALENDAR_REPEAT_NEVER
Definition CalendarMgr.h:73
@ CALENDAR_REPEAT_MONTHLY
Definition CalendarMgr.h:76
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_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:80
@ CALENDAR_STATUS_TENTATIVE
Definition CalendarMgr.h:89
@ CALENDAR_STATUS_NOT_SIGNED_UP
Definition CalendarMgr.h:88
@ CALENDAR_STATUS_STANDBY
Definition CalendarMgr.h:86
@ CALENDAR_STATUS_INVITED
Definition CalendarMgr.h:81
@ CALENDAR_STATUS_ACCEPTED
Definition CalendarMgr.h:82
@ CALENDAR_STATUS_SIGNED_UP
Definition CalendarMgr.h:87
@ CALENDAR_STATUS_REMOVED
Definition CalendarMgr.h:90
@ CALENDAR_STATUS_DECLINED
Definition CalendarMgr.h:83
@ CALENDAR_STATUS_CONFIRMED
Definition CalendarMgr.h:84
@ CALENDAR_STATUS_OUT
Definition CalendarMgr.h:85
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:33
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
#define TC_GAME_API
Definition Define.h:114
int32_t int32
Definition Define.h:129
uint64_t uint64
Definition Define.h:132
#define UI64LIT(N)
Definition Define.h:118
uint32_t uint32
Definition Define.h:133
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
uint32 LowType
Definition ObjectGuid.h:142
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
CalendarInvite(uint64 inviteId, uint64 eventId, ObjectGuid invitee, ObjectGuid senderGUID, time_t statusTime, CalendarInviteStatus status, CalendarModerationRank rank, std::string note)
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 SetNote(std::string const &note)
void SetInvitee(ObjectGuid guid)
std::string GetNote() const
void SetResponseTime(time_t statusTime)
void SetInviteId(uint64 inviteId)
time_t GetResponseTime() const
CalendarInvite & operator=(CalendarInvite const &)=delete
ObjectGuid _invitee
time_t _responseTime
uint64 GetEventId() const
CalendarInvite(CalendarInvite &&)=delete
ObjectGuid GetSenderGUID() const
CalendarInviteStatus _status
ObjectGuid GetInviteeGUID() const
std::string _note
void SetEventId(uint64 eventId)