// remove invit from an event and inform client // some check done before so it may fail and raison is sent to client // require valid eventId/inviteId and correct right for the remover. bool CalendarMgr::RemoveInvite(uint64 eventId, uint64 inviteId, ObjectGuid const& removerGuid) { Player* remover = sObjectMgr.GetPlayer(removerGuid); CalendarEventStore::iterator citr = m_EventStore.find(eventId); if (citr == m_EventStore.end()) { SendCalendarCommandResult(remover, CALENDAR_ERROR_EVENT_INVALID); return false; } CalendarEvent& event = citr->second; return event.RemoveInviteById(inviteId, remover); }
// remove event by its id // some check done before so it may fail and raison is sent to client void CalendarMgr::RemoveEvent(uint64 eventId, Player* remover) { CalendarEventStore::iterator citr = m_EventStore.find(eventId); if (citr == m_EventStore.end()) { SendCalendarCommandResult(remover, CALENDAR_ERROR_EVENT_INVALID); return; } if (remover->GetObjectGuid() != citr->second.CreatorGuid) { // only creator can remove his event SendCalendarCommandResult(remover, CALENDAR_ERROR_PERMISSIONS); return; } SendCalendarEventRemovedAlert(&citr->second); CharacterDatabase.PExecute("DELETE FROM calendar_events WHERE eventId=" UI64FMTD, eventId); // explicitly remove all invite and send mail to all invitee citr->second.RemoveAllInvite(remover->GetObjectGuid()); m_EventStore.erase(citr); }
// copy event to another date (all invitee is copied too but their status are reseted) void CalendarMgr::CopyEvent(uint64 eventId, time_t newTime, ObjectGuid const& guid) { Player* player = sObjectMgr.GetPlayer(guid); CalendarEvent* event = GetEventById(eventId); if (!event) { SendCalendarCommandResult(player, CALENDAR_ERROR_EVENT_INVALID); return; } CalendarEvent* newEvent = AddEvent(guid, event->Title, event->Description, event->Type, event->Repeatable, CALENDAR_MAX_INVITES, event->DungeonId, newTime, event->UnknownTime, event->Flags); if (!newEvent) return; if (newEvent->IsGuildAnnouncement()) AddInvite(newEvent, guid, guid, CALENDAR_STATUS_CONFIRMED, CALENDAR_RANK_OWNER, "", time(NULL)); else { // copy all invitees, set new owner as the one who make the copy, set invitees status to invited CalendarInviteMap const* cInvMap = event->GetInviteMap(); CalendarInviteMap::const_iterator ci_itr = cInvMap->begin(); while (ci_itr != cInvMap->end()) { const CalendarInvite* invite = ci_itr->second; if (invite->InviteeGuid == guid) { AddInvite(newEvent, guid, invite->InviteeGuid, CALENDAR_STATUS_CONFIRMED, CALENDAR_RANK_OWNER, "", time(NULL)); } else { CalendarModerationRank rank = CALENDAR_RANK_PLAYER; // copy moderator rank if (invite->Rank == CALENDAR_RANK_MODERATOR) rank = CALENDAR_RANK_MODERATOR; AddInvite(newEvent, guid, invite->InviteeGuid, CALENDAR_STATUS_INVITED, rank, "", time(NULL)); } ++ci_itr; } } SendCalendarEvent(player, newEvent, CALENDAR_SENDTYPE_COPY); }
CalendarEventStore::iterator CalendarMgr::RemoveEvent(uint64 eventId, uint64 remover) { CalendarEventStore::iterator current; CalendarEvent* calendarEvent = GetEvent(eventId, ¤t); if (!calendarEvent) { SendCalendarCommandResult(remover, CALENDAR_ERROR_EVENT_INVALID); return _events.end(); } SendCalendarEventRemovedAlert(*calendarEvent); SQLTransaction trans = CharacterDatabase.BeginTransaction(); PreparedStatement* stmt; MailDraft mail(calendarEvent->BuildCalendarMailSubject(remover), calendarEvent->BuildCalendarMailBody()); CalendarInviteStore& eventInvites = _invites[eventId]; for (size_t i = 0; i < eventInvites.size(); ++i) { CalendarInvite* invite = eventInvites[i]; stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CALENDAR_INVITE); stmt->setUInt64(0, invite->GetInviteId()); trans->Append(stmt); // guild events only? check invite status here? // When an event is deleted, all invited (accepted/declined? - verify) guildies are notified via in-game mail. (wowwiki) if (remover && invite->GetInviteeGUID() != remover) mail.SendMailTo(trans, MailReceiver(invite->GetInviteeGUID()), calendarEvent, MAIL_CHECK_MASK_COPIED); delete invite; } _invites.erase(eventId); stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CALENDAR_EVENT); stmt->setUInt64(0, eventId); trans->Append(stmt); CharacterDatabase.CommitTransaction(trans); delete calendarEvent; current = _events.erase(current); return current; }
void CalendarMgr::RemoveEvent(uint64 eventId, uint64 remover) { CalendarEvent* calendarEvent = GetEvent(eventId); if (!calendarEvent) { SendCalendarCommandResult(remover, CALENDAR_ERROR_EVENT_INVALID); return; } SendCalendarEventRemovedAlert(*calendarEvent); SQLTransaction trans = CharacterDatabase.BeginTransaction(); PreparedStatement* stmt; MailDraft mail(calendarEvent->BuildCalendarMailSubject(remover), calendarEvent->BuildCalendarMailBody()); std::vector<CalendarInvite*>::iterator itr = _invites[eventId].begin(); while (itr != _invites[eventId].end()) { stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CALENDAR_INVITE); stmt->setUInt64(0, (*itr)->GetInviteId()); trans->Append(stmt); // guild events only? check invite status here? // When an event is deleted, all invited (accepted/declined? - verify) guildies are notified via in-game mail. (wowwiki) if (remover && (*itr)->GetInviteeGUID() != remover) mail.SendMailTo(trans, MailReceiver((*itr)->GetInviteeGUID()), calendarEvent, MAIL_CHECK_MASK_COPIED); delete *itr; _invites[eventId].erase(itr); } _invites.erase(eventId); stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CALENDAR_EVENT); stmt->setUInt64(0, eventId); trans->Append(stmt); CharacterDatabase.CommitTransaction(trans); delete calendarEvent; _events.erase(calendarEvent); }
// Add invit to an event and inform client // some check done before so it may fail and raison is sent to client // return value is the CalendarInvite pointer on success CalendarInvite* CalendarMgr::AddInvite(CalendarEvent* event, ObjectGuid const& senderGuid, ObjectGuid const& inviteeGuid, CalendarInviteStatus status, CalendarModerationRank rank, std::string text, time_t statusTime) { Player* sender = sObjectMgr.GetPlayer(senderGuid); if (!event || !sender) return NULL; std::string name; sObjectMgr.GetPlayerNameByGUID(inviteeGuid, name); // check if invitee is not already invited if (event->GetInviteByGuid(inviteeGuid)) { SendCalendarCommandResult(sender, CALENDAR_ERROR_ALREADY_INVITED_TO_EVENT_S, name.c_str()); return NULL; } // check if player can still have new invite (except for event creator) if (!event->IsGuildAnnouncement() && event->CreatorGuid != inviteeGuid) { if (!CanAddInviteTo(inviteeGuid)) { SendCalendarCommandResult(sender, CALENDAR_ERROR_OTHER_INVITES_EXCEEDED_S, name.c_str()); return NULL; } } CalendarInvite* invite = new CalendarInvite(event, GetNewInviteId(), senderGuid, inviteeGuid, statusTime, status, rank, text); if (!event->IsGuildAnnouncement()) SendCalendarEventInvite(invite); if (!event->IsGuildEvent() || invite->InviteeGuid == event->CreatorGuid) SendCalendarEventInviteAlert(invite); if (event->IsGuildAnnouncement()) { // no need to realy add invite for announcements delete invite; return NULL; } DEBUG_FILTER_LOG(LOG_FILTER_CALENDAR, "Add Invite> eventId[" UI64FMTD "], senderGuid[%s], inviteGuid[%s], Status[%u], rank[%u], text[%s], time[%u]", event->EventId, senderGuid.GetString().c_str(), inviteeGuid.GetString().c_str(), uint32(status), uint32(rank), text.c_str(), uint32(statusTime)); if (!event->AddInvite(invite)) { sLog.outError("CalendarEvent::AddInvite > Fail adding invite!"); delete invite; return NULL; } CharacterDatabase.PExecute("INSERT INTO calendar_invites VALUES (" UI64FMTD ", " UI64FMTD ", %u, %u, %u, %u, %u)", invite->InviteId, event->EventId, inviteeGuid.GetCounter(), senderGuid.GetCounter(), uint32(status), uint32(statusTime), uint32(rank)); return invite; }
// add single event to main events store // some check done before so it may fail and raison is sent to client // return value is the CalendarEvent pointer on success CalendarEvent* CalendarMgr::AddEvent(ObjectGuid const& guid, std::string title, std::string description, uint32 type, uint32 repeatable, uint32 maxInvites, int32 dungeonId, time_t eventTime, time_t unkTime, uint32 flags) { Player* player = sObjectMgr.GetPlayer(guid); if (!player) return NULL; if (title.empty()) { SendCalendarCommandResult(player, CALENDAR_ERROR_NEEDS_TITLE); return NULL; } if (eventTime < time(NULL)) { SendCalendarCommandResult(player, CALENDAR_ERROR_INVALID_DATE); return NULL; } uint32 guildId = 0; if ((flags & CALENDAR_FLAG_GUILD_EVENT) || (flags & CALENDAR_FLAG_GUILD_ANNOUNCEMENT)) { guildId = player->GetGuildId(); if (!guildId) { SendCalendarCommandResult(player, CALENDAR_ERROR_GUILD_PLAYER_NOT_IN_GUILD); return NULL; } if (!CanAddGuildEvent(guildId)) { SendCalendarCommandResult(player, CALENDAR_ERROR_GUILD_EVENTS_EXCEEDED); return NULL; } } else { if (!CanAddEvent(guid)) { SendCalendarCommandResult(player, CALENDAR_ERROR_EVENTS_EXCEEDED); return NULL; } } uint64 nId = GetNewEventId(); DEBUG_FILTER_LOG(LOG_FILTER_CALENDAR, "CalendarMgr::AddEvent> ID(" UI64FMTD "), '%s', Desc > '%s', type=%u, repeat=%u, maxInvites=%u, dungeonId=%d, flags=%u", nId, title.c_str(), description.c_str(), type, repeatable, maxInvites, dungeonId, flags); CalendarEvent& newEvent = m_EventStore[nId]; newEvent.EventId = nId; newEvent.CreatorGuid = guid; newEvent.Title = title; newEvent.Description = description; newEvent.Type = (CalendarEventType) type; newEvent.Repeatable = (CalendarRepeatType) repeatable; newEvent.DungeonId = dungeonId; newEvent.EventTime = eventTime; newEvent.Flags = flags; newEvent.GuildId = guildId; CharacterDatabase.escape_string(title); CharacterDatabase.escape_string(description); CharacterDatabase.PExecute("INSERT INTO calendar_events VALUES (" UI64FMTD ", %u, %u, %u, %u, %d, %u, '%s', '%s')", nId, guid.GetCounter(), guildId, type, flags, dungeonId, uint32(eventTime), title.c_str(), description.c_str()); return &newEvent; }