mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-24 06:06:23 +00:00
fix(Calendar/Packets): add additional validation when creating events (#2799)
This commit is contained in:
@@ -14,7 +14,9 @@
|
||||
|
||||
CalendarInvite::~CalendarInvite()
|
||||
{
|
||||
sCalendarMgr->FreeInviteId(_inviteId);
|
||||
// Free _inviteId only if it's a real invite and not just a pre-invite or guild announcement
|
||||
if (_inviteId != 0 && _eventId != 0)
|
||||
sCalendarMgr->FreeInviteId(_inviteId);
|
||||
}
|
||||
|
||||
CalendarEvent::~CalendarEvent()
|
||||
@@ -141,15 +143,25 @@ void CalendarMgr::AddInvite(CalendarEvent* calendarEvent, CalendarInvite* invite
|
||||
}
|
||||
}
|
||||
|
||||
CalendarEventStore::iterator CalendarMgr::RemoveEvent(uint64 eventId, uint64 remover)
|
||||
void CalendarMgr::RemoveEvent(uint64 eventId, uint64 remover)
|
||||
{
|
||||
CalendarEventStore::iterator current;
|
||||
CalendarEvent* calendarEvent = GetEvent(eventId, ¤t);
|
||||
CalendarEvent* calendarEvent = GetEvent(eventId);
|
||||
|
||||
if (!calendarEvent)
|
||||
{
|
||||
SendCalendarCommandResult(remover, CALENDAR_ERROR_EVENT_INVALID);
|
||||
return _events.end();
|
||||
return;
|
||||
}
|
||||
|
||||
RemoveEvent(calendarEvent, remover);
|
||||
}
|
||||
|
||||
void CalendarMgr::RemoveEvent(CalendarEvent* calendarEvent, uint64 remover)
|
||||
{
|
||||
if (!calendarEvent)
|
||||
{
|
||||
SendCalendarCommandResult(remover, CALENDAR_ERROR_EVENT_INVALID);
|
||||
return;
|
||||
}
|
||||
|
||||
SendCalendarEventRemovedAlert(*calendarEvent);
|
||||
@@ -158,7 +170,7 @@ CalendarEventStore::iterator CalendarMgr::RemoveEvent(uint64 eventId, uint64 rem
|
||||
PreparedStatement* stmt;
|
||||
MailDraft mail(calendarEvent->BuildCalendarMailSubject(remover), calendarEvent->BuildCalendarMailBody());
|
||||
|
||||
CalendarInviteStore& eventInvites = _invites[eventId];
|
||||
CalendarInviteStore& eventInvites = _invites[calendarEvent->GetEventId()];
|
||||
for (size_t i = 0; i < eventInvites.size(); ++i)
|
||||
{
|
||||
CalendarInvite* invite = eventInvites[i];
|
||||
@@ -174,16 +186,16 @@ CalendarEventStore::iterator CalendarMgr::RemoveEvent(uint64 eventId, uint64 rem
|
||||
delete invite;
|
||||
}
|
||||
|
||||
_invites.erase(eventId);
|
||||
_invites.erase(calendarEvent->GetEventId());
|
||||
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CALENDAR_EVENT);
|
||||
stmt->setUInt64(0, eventId);
|
||||
stmt->setUInt64(0, calendarEvent->GetEventId());
|
||||
trans->Append(stmt);
|
||||
CharacterDatabase.CommitTransaction(trans);
|
||||
|
||||
delete calendarEvent;
|
||||
current = _events.erase(current);
|
||||
return current;
|
||||
_events.erase(calendarEvent);
|
||||
return;
|
||||
}
|
||||
|
||||
void CalendarMgr::RemoveInvite(uint64 inviteId, uint64 eventId, uint64 /*remover*/)
|
||||
@@ -260,12 +272,13 @@ void CalendarMgr::RemoveAllPlayerEventsAndInvites(uint64 guid)
|
||||
{
|
||||
for (CalendarEventStore::const_iterator itr = _events.begin(); itr != _events.end();)
|
||||
{
|
||||
if ((*itr)->GetCreatorGUID() == guid)
|
||||
CalendarEvent* event = *itr;
|
||||
++itr;
|
||||
if (event->GetCreatorGUID() == guid)
|
||||
{
|
||||
itr = RemoveEvent((*itr)->GetEventId(), 0); // don't send mail if removing a character
|
||||
RemoveEvent(event, 0);
|
||||
continue;
|
||||
}
|
||||
++itr;
|
||||
}
|
||||
|
||||
CalendarInviteStore playerInvites = GetPlayerInvites(guid);
|
||||
@@ -275,15 +288,9 @@ void CalendarMgr::RemoveAllPlayerEventsAndInvites(uint64 guid)
|
||||
|
||||
void CalendarMgr::RemovePlayerGuildEventsAndSignups(uint64 guid, uint32 guildId)
|
||||
{
|
||||
for (CalendarEventStore::const_iterator itr = _events.begin(); itr != _events.end();)
|
||||
{
|
||||
for (CalendarEventStore::const_iterator itr = _events.begin(); itr != _events.end(); ++itr)
|
||||
if ((*itr)->GetCreatorGUID() == guid && ((*itr)->IsGuildEvent() || (*itr)->IsGuildAnnouncement()))
|
||||
{
|
||||
itr = RemoveEvent((*itr)->GetEventId(), guid);
|
||||
continue;
|
||||
}
|
||||
++itr;
|
||||
}
|
||||
RemoveEvent((*itr)->GetEventId(), guid);
|
||||
|
||||
CalendarInviteStore playerInvites = GetPlayerInvites(guid);
|
||||
for (CalendarInviteStore::const_iterator itr = playerInvites.begin(); itr != playerInvites.end(); ++itr)
|
||||
@@ -292,17 +299,13 @@ void CalendarMgr::RemovePlayerGuildEventsAndSignups(uint64 guid, uint32 guildId)
|
||||
RemoveInvite((*itr)->GetInviteId(), (*itr)->GetEventId(), guid);
|
||||
}
|
||||
|
||||
CalendarEvent* CalendarMgr::GetEvent(uint64 eventId, CalendarEventStore::iterator* it)
|
||||
CalendarEvent* CalendarMgr::GetEvent(uint64 eventId)
|
||||
{
|
||||
for (CalendarEventStore::iterator itr = _events.begin(); itr != _events.end(); ++itr)
|
||||
if ((*itr)->GetEventId() == eventId)
|
||||
{
|
||||
if (it)
|
||||
*it = itr;
|
||||
return *itr;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CalendarInvite* CalendarMgr::GetInvite(uint64 inviteId) const
|
||||
@@ -315,7 +318,7 @@ CalendarInvite* CalendarMgr::GetInvite(uint64 inviteId) const
|
||||
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
||||
sLog->outDebug(LOG_FILTER_UNITS, "CalendarMgr::GetInvite: [" UI64FMTD "] not found!", inviteId);
|
||||
#endif
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CalendarMgr::FreeEventId(uint64 id)
|
||||
@@ -354,6 +357,44 @@ uint64 CalendarMgr::GetFreeInviteId()
|
||||
return inviteId;
|
||||
}
|
||||
|
||||
void CalendarMgr::DeleteOldEvents()
|
||||
{
|
||||
time_t oldEventsTime = time(nullptr) - CALENDAR_OLD_EVENTS_DELETION_TIME;
|
||||
|
||||
for (CalendarEventStore::const_iterator itr = _events.begin(); itr != _events.end();)
|
||||
{
|
||||
CalendarEvent* event = *itr;
|
||||
++itr;
|
||||
if (event->GetEventTime() < oldEventsTime)
|
||||
RemoveEvent(event, 0);
|
||||
}
|
||||
}
|
||||
|
||||
CalendarEventStore CalendarMgr::GetEventsCreatedBy(uint64 guid, bool includeGuildEvents)
|
||||
{
|
||||
CalendarEventStore result;
|
||||
for (CalendarEventStore::const_iterator itr = _events.begin(); itr != _events.end(); ++itr)
|
||||
if ((*itr)->GetCreatorGUID() == guid && (includeGuildEvents || (!(*itr)->IsGuildEvent() && !(*itr)->IsGuildAnnouncement())))
|
||||
result.insert(*itr);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
CalendarEventStore CalendarMgr::GetGuildEvents(uint32 guildId)
|
||||
{
|
||||
CalendarEventStore result;
|
||||
|
||||
if (!guildId)
|
||||
return result;
|
||||
|
||||
for (CalendarEventStore::const_iterator itr = _events.begin(); itr != _events.end(); ++itr)
|
||||
if ((*itr)->IsGuildEvent() || (*itr)->IsGuildAnnouncement())
|
||||
if ((*itr)->GetGuildId() == guildId)
|
||||
result.insert(*itr);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
CalendarEventStore CalendarMgr::GetPlayerEvents(uint64 guid)
|
||||
{
|
||||
CalendarEventStore events;
|
||||
@@ -365,9 +406,10 @@ CalendarEventStore CalendarMgr::GetPlayerEvents(uint64 guid)
|
||||
events.insert(event);
|
||||
|
||||
if (Player* player = ObjectAccessor::FindPlayerInOrOutOfWorld(guid))
|
||||
for (CalendarEventStore::const_iterator itr = _events.begin(); itr != _events.end(); ++itr)
|
||||
if ((*itr)->GetGuildId() == player->GetGuildId())
|
||||
events.insert(*itr);
|
||||
if (player->GetGuildId())
|
||||
for (CalendarEventStore::const_iterator itr = _events.begin(); itr != _events.end(); ++itr)
|
||||
if ((*itr)->GetGuildId() == player->GetGuildId())
|
||||
events.insert(*itr);
|
||||
|
||||
return events;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user