CalendarEvent* CalendarMgr::CheckPermisions(uint64 eventId, uint64 guid, uint64 inviteId, CalendarRanks minRank) { if (CalendarEvent* calendarEvent = GetEvent(eventId)) if (CalendarInvite* invite = GetInvite(inviteId)) if (calendarEvent->HasInvite(inviteId) && invite->GetEventId() == calendarEvent->GetEventId() && invite->GetInvitee() == guid && invite->GetRank() >= minRank) return calendarEvent; return NULL; }
uint32 CalendarMgr::GetPlayerNumPending(uint64 guid) { if (!guid) return 0; CalendarPlayerinviteIdMap::const_iterator itr = _playerInvites.find(guid); if (itr == _playerInvites.end()) return 0; uint32 pendingNum = 0; for (CalendarinviteIdList::const_iterator it = itr->second.begin(); it != itr->second.end(); ++it) if (CalendarInvite* invite = GetInvite(*it)) if (invite->GetRank() != CALENDAR_RANK_OWNER && invite->GetStatus() != CALENDAR_STATUS_CONFIRMED && invite->GetStatus() != CALENDAR_STATUS_8 && invite->GetStatus() != CALENDAR_STATUS_9) // FIXME Check the proper value ++pendingNum; return pendingNum; }
CalendarEvent* CalendarMgr::CheckPermisions(uint64 eventId, Player* player, uint64 inviteId, CalendarModerationRank minRank) { if (!player) return NULL; // CALENDAR_ERROR_INTERNAL CalendarEvent* calendarEvent = GetEvent(eventId); if (!calendarEvent) { player->GetSession()->SendCalendarCommandResult(CALENDAR_ERROR_EVENT_INVALID); return NULL; } CalendarInvite* invite = GetInvite(inviteId); if (!invite) { player->GetSession()->SendCalendarCommandResult(CALENDAR_ERROR_NO_INVITE); return NULL; } if (!calendarEvent->HasInvite(inviteId)) { player->GetSession()->SendCalendarCommandResult(CALENDAR_ERROR_NOT_INVITED); return NULL; } if (invite->GetEventId() != calendarEvent->GetEventId() || invite->GetInvitee() != player->GetGUID()) { player->GetSession()->SendCalendarCommandResult(CALENDAR_ERROR_INTERNAL); return NULL; } if (invite->GetRank() < minRank) { player->GetSession()->SendCalendarCommandResult(CALENDAR_ERROR_PERMISSIONS); return NULL; } return calendarEvent; }
bool CalendarMgr::RemoveEvent(uint64 eventId) { CalendarEventMap::iterator itr = _events.find(eventId); if (itr == _events.end()) { sLog->outError("CalendarMgr::removeEvent: Event [" UI64FMTD "] does not exist", eventId); return false; } _events.erase(itr); bool val = true; CalendarinviteIdList const& invites = itr->second.GetInviteIdList(); for (CalendarinviteIdList::const_iterator itr = invites.begin(); itr != invites.end(); ++itr) { CalendarInvite* invite = GetInvite(*itr); if (!invite || !RemovePlayerEvent(invite->GetInvitee(), eventId)) val = false; } return val; }
void CalendarMgr::LoadFromDB() { uint32 oldMSTime = getMSTime(); uint32 count = 0; _maxEventId = 0; _maxInviteId = 0; // 0 1 2 3 4 5 6 7 8 if (QueryResult result = CharacterDatabase.Query("SELECT id, creator, title, description, type, dungeon, eventtime, flags, time2 FROM calendar_events")) do { Field* fields = result->Fetch(); uint64 eventId = fields[0].GetUInt64(); ObjectGuid creatorGUID = ObjectGuid(HighGuid::Player, fields[1].GetUInt32()); std::string title = fields[2].GetString(); std::string description = fields[3].GetString(); CalendarEventType type = CalendarEventType(fields[4].GetUInt8()); int32 dungeonId = fields[5].GetInt32(); uint32 eventTime = fields[6].GetUInt32(); uint32 flags = fields[7].GetUInt32(); uint32 timezoneTime = fields[8].GetUInt32(); ObjectGuid::LowType guildId = 0; if (flags & CALENDAR_FLAG_GUILD_EVENT || flags & CALENDAR_FLAG_WITHOUT_INVITES) guildId = sCharacterCache->GetCharacterGuildIdByGuid(creatorGUID); CalendarEvent* calendarEvent = new CalendarEvent(eventId, creatorGUID, guildId, type, dungeonId, time_t(eventTime), flags, time_t(timezoneTime), title, description); _events.insert(calendarEvent); _maxEventId = std::max(_maxEventId, eventId); ++count; } while (result->NextRow()); TC_LOG_INFO("server.loading", ">> Loaded %u calendar events in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); count = 0; oldMSTime = getMSTime(); // 0 1 2 3 4 5 6 7 if (QueryResult result = CharacterDatabase.Query("SELECT id, event, invitee, sender, status, statustime, `rank`, text FROM calendar_invites")) do { Field* fields = result->Fetch(); uint64 inviteId = fields[0].GetUInt64(); uint64 eventId = fields[1].GetUInt64(); ObjectGuid invitee = ObjectGuid(HighGuid::Player, fields[2].GetUInt32()); ObjectGuid senderGUID = ObjectGuid(HighGuid::Player, fields[3].GetUInt32()); CalendarInviteStatus status = CalendarInviteStatus(fields[4].GetUInt8()); uint32 statusTime = fields[5].GetUInt32(); CalendarModerationRank rank = CalendarModerationRank(fields[6].GetUInt8()); std::string text = fields[7].GetString(); CalendarInvite* invite = new CalendarInvite(inviteId, eventId, invitee, senderGUID, time_t(statusTime), status, rank, text); _invites[eventId].push_back(invite); _maxInviteId = std::max(_maxInviteId, inviteId); ++count; } while (result->NextRow()); TC_LOG_INFO("server.loading", ">> Loaded %u calendar invites in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); for (uint64 i = 1; i < _maxEventId; ++i) if (!GetEvent(i)) _freeEventIds.push_back(i); for (uint64 i = 1; i < _maxInviteId; ++i) if (!GetInvite(i)) _freeInviteIds.push_back(i); }
void CalendarMgr::LoadFromDB() { uint32 count = 0; _maxEventId = 0; _maxInviteId = 0; // 0 1 2 3 4 5 6 7 8 if (QueryResult result = CharacterDatabase.Query("SELECT id, creator, title, description, type, dungeon, eventtime, flags, time2 FROM calendar_events")) do { Field* fields = result->Fetch(); uint64 eventId = fields[0].GetUInt64(); uint64 creatorGUID = MAKE_NEW_GUID(fields[1].GetUInt32(), 0, HIGHGUID_PLAYER); std::string title = fields[2].GetString(); std::string description = fields[3].GetString(); CalendarEventType type = CalendarEventType(fields[4].GetUInt8()); int32 dungeonId = fields[5].GetInt32(); uint32 eventTime = fields[6].GetUInt32(); uint32 flags = fields[7].GetUInt32(); uint32 timezoneTime = fields[8].GetUInt32(); uint32 guildId = 0; if (flags & CALENDAR_FLAG_GUILD_EVENT || flags & CALENDAR_FLAG_WITHOUT_INVITES) guildId = Player::GetGuildIdFromDB(creatorGUID); CalendarEvent* calendarEvent = new CalendarEvent(eventId, creatorGUID, guildId, type, dungeonId, time_t(eventTime), flags, time_t(timezoneTime), title, description); _events.insert(calendarEvent); _maxEventId = std::max(_maxEventId, eventId); ++count; } while (result->NextRow()); sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded %u calendar events", count); count = 0; // 0 1 2 3 4 5 6 7 if (QueryResult result = CharacterDatabase.Query("SELECT id, event, invitee, sender, status, statustime, rank, text FROM calendar_invites")) do { Field* fields = result->Fetch(); uint64 inviteId = fields[0].GetUInt64(); uint64 eventId = fields[1].GetUInt64(); uint64 invitee = MAKE_NEW_GUID(fields[2].GetUInt32(), 0, HIGHGUID_PLAYER); uint64 senderGUID = MAKE_NEW_GUID(fields[3].GetUInt32(), 0, HIGHGUID_PLAYER); CalendarInviteStatus status = CalendarInviteStatus(fields[4].GetUInt8()); uint32 statusTime = fields[5].GetUInt32(); CalendarModerationRank rank = CalendarModerationRank(fields[6].GetUInt8()); std::string text = fields[7].GetString(); CalendarInvite* invite = new CalendarInvite(inviteId, eventId, invitee, senderGUID, time_t(statusTime), status, rank, text); _invites[eventId].push_back(invite); _maxInviteId = std::max(_maxInviteId, inviteId); ++count; } while (result->NextRow()); sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded %u calendar invites", count); for (uint64 i = 1; i < _maxEventId; ++i) if (!GetEvent(i)) _freeEventIds.push_back(i); for (uint64 i = 1; i < _maxInviteId; ++i) if (!GetInvite(i)) _freeInviteIds.push_back(i); }
void CalendarMgr::AddAction(CalendarAction const& action) { switch (action.GetAction()) { case CALENDAR_ACTION_ADD_EVENT: { if (AddEvent(action.Event) && AddInvite(action.Invite)) { SendCalendarEventInviteAlert(action.Event, action.Invite); SendCalendarEvent(action.Event, CALENDAR_SENDTYPE_ADD); } break; } case CALENDAR_ACTION_MODIFY_EVENT: { uint64 eventId = action.Event.GetEventId(); CalendarEvent* calendarEvent = CheckPermisions(eventId, action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_MODERATOR); if (!calendarEvent) return; calendarEvent->SetEventId(action.Event.GetEventId()); calendarEvent->SetType(action.Event.GetType()); calendarEvent->SetFlags(action.Event.GetFlags()); calendarEvent->SetTime(action.Event.GetTime()); calendarEvent->SetTimeZoneTime(action.Event.GetTimeZoneTime()); calendarEvent->SetRepeatable(action.Event.GetRepeatable()); calendarEvent->SetDungeonId(action.Event.GetDungeonId()); calendarEvent->SetTitle(action.Event.GetTitle()); calendarEvent->SetDescription(action.Event.GetDescription()); calendarEvent->SetMaxInvites(action.Event.GetMaxInvites()); CalendarinviteIdList const& invites = calendarEvent->GetInviteIdList(); for (CalendarinviteIdList::const_iterator itr = invites.begin(); itr != invites.end(); ++itr) if (CalendarInvite* invite = GetInvite(*itr)) SendCalendarEventUpdateAlert(invite->GetInvitee(), *calendarEvent, CALENDAR_SENDTYPE_ADD); break; } case CALENDAR_ACTION_COPY_EVENT: { CalendarEvent* calendarEvent = CheckPermisions(action.Event.GetEventId(), action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_OWNER); if (!calendarEvent) return; uint64 eventId = GetFreeEventId(); CalendarEvent newEvent(eventId); newEvent.SetType(calendarEvent->GetType()); newEvent.SetFlags(calendarEvent->GetFlags()); newEvent.SetTime(action.Event.GetTime()); newEvent.SetTimeZoneTime(calendarEvent->GetTimeZoneTime()); newEvent.SetRepeatable(calendarEvent->GetRepeatable()); newEvent.SetDungeonId(calendarEvent->GetDungeonId()); newEvent.SetTitle(calendarEvent->GetTitle()); newEvent.SetDescription(calendarEvent->GetDescription()); newEvent.SetMaxInvites(calendarEvent->GetMaxInvites()); newEvent.SetCreatorGUID(calendarEvent->GetCreatorGUID()); newEvent.SetGuildId(calendarEvent->GetGuildId()); CalendarinviteIdList const invites = calendarEvent->GetInviteIdList(); for (CalendarinviteIdList::const_iterator itr = invites.begin(); itr != invites.end(); ++itr) if (CalendarInvite* invite = GetInvite(*itr)) { uint64 inviteId = GetFreeInviteId(); CalendarInvite newInvite(inviteId); newInvite.SetEventId(eventId); newInvite.SetSenderGUID(action.GetGUID()); newInvite.SetInvitee(invite->GetInvitee()); newInvite.SetStatus(invite->GetStatus()); newInvite.SetStatusTime(invite->GetStatusTime()); newInvite.SetText(invite->GetText()); newInvite.SetRank(invite->GetRank()); if (AddInvite(newInvite)) { SendCalendarEventInviteAlert(newEvent, newInvite); newEvent.AddInvite(inviteId); } } if (AddEvent(newEvent)) SendCalendarEvent(newEvent, CALENDAR_SENDTYPE_COPY); break; } case CALENDAR_ACTION_REMOVE_EVENT: { uint64 eventId = action.Event.GetEventId(); uint32 flags = action.Event.GetFlags(); sLog->outError("CalendarMgr::AddAction:: Flags %u", flags); // FIXME - Use of Flags here! CalendarEvent* calendarEvent = CheckPermisions(eventId, action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_OWNER); if (!calendarEvent) return; CalendarinviteIdList const& inviteIds = calendarEvent->GetInviteIdList(); for (CalendarinviteIdList::const_iterator it = inviteIds.begin(); it != inviteIds.end(); ++it) if (uint64 invitee = RemoveInvite(*it)) SendCalendarEventRemovedAlert(invitee, *calendarEvent); RemoveEvent(eventId); break; } case CALENDAR_ACTION_ADD_EVENT_INVITE: { uint64 eventId = action.Invite.GetEventId(); CalendarEvent* calendarEvent = CheckPermisions(eventId, action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_MODERATOR); if (!calendarEvent) return; if (AddInvite(action.Invite)) { calendarEvent->AddInvite(action.Invite.GetInviteId()); SendCalendarEventInvite(action.Invite, (!(calendarEvent->GetFlags() & CALENDAR_FLAG_INVITES_LOCKED) && !action.Invite.GetStatusTime())); SendCalendarEventInviteAlert(*calendarEvent, action.Invite); } break; } case CALENDAR_ACTION_SIGNUP_TO_EVENT: { uint64 eventId = action.Event.GetEventId(); CalendarEvent* calendarEvent = GetEvent(eventId); CheckPermisions(eventId, action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_MODERATOR); if (!calendarEvent || !(calendarEvent->GetFlags() & CALENDAR_FLAG_GUILD_ONLY) || !calendarEvent->GetGuildId() || calendarEvent->GetGuildId() != action.GetExtraData()) return; uint8 status = action.Invite.GetStatus(); if (status == CALENDAR_STATUS_INVITED) status = CALENDAR_STATUS_CONFIRMED; else if (status == CALENDAR_STATUS_ACCEPTED) status = CALENDAR_STATUS_8; CalendarInvite newInvite(GetFreeInviteId()); newInvite.SetStatus(status); newInvite.SetStatusTime(uint32(time(NULL))); newInvite.SetEventId(eventId); newInvite.SetInvitee(action.GetGUID()); newInvite.SetSenderGUID(action.GetGUID()); if (AddInvite(newInvite)) SendCalendarEventInvite(newInvite, false); break; } case CALENDAR_ACTION_MODIFY_EVENT_INVITE: { uint64 eventId = action.Invite.GetEventId(); uint64 inviteId = action.Invite.GetInviteId(); CalendarEvent* calendarEvent; if (action.GetInviteId() != action.Invite.GetInviteId()) calendarEvent = CheckPermisions(eventId, action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_MODERATOR); else calendarEvent = GetEvent(eventId); CalendarInvite* invite = GetInvite(inviteId); if (!calendarEvent || !invite || !calendarEvent->HasInvite(inviteId)) return; invite->SetStatus(action.Invite.GetStatus()); SendCalendarEventStatus(invite->GetSenderGUID(), *calendarEvent, *invite); break; } case CALENDAR_ACTION_MODIFY_MODERATOR_EVENT_INVITE: { uint64 eventId = action.Invite.GetEventId(); uint64 inviteId = action.Invite.GetInviteId(); CalendarEvent* calendarEvent; if (action.GetInviteId() != action.Invite.GetInviteId()) calendarEvent = CheckPermisions(eventId, action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_OWNER); else calendarEvent = GetEvent(eventId); CalendarInvite* invite = GetInvite(inviteId); if (!calendarEvent || !invite || !calendarEvent->HasInvite(inviteId)) return; sLog->outError("SPP: CALENDAR_ACTION_MODIFY_MODERATOR_EVENT_INVITE: All OK"); invite->SetStatus(action.Invite.GetStatus()); SendCalendarEventModeratorStatusAlert(*invite); break; } case CALENDAR_ACTION_REMOVE_EVENT_INVITE: { uint64 eventId = action.Invite.GetEventId(); uint64 inviteId = action.Invite.GetInviteId(); CalendarEvent* calendarEvent = CheckPermisions(eventId, action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_MODERATOR); if (!calendarEvent) return; if (uint64 invitee = RemoveInvite(inviteId)) { SendCalendarEventInviteRemoveAlert(invitee, *calendarEvent, CALENDAR_STATUS_9); SendCalendarEventInviteRemove(action.GetGUID(), action.Invite, calendarEvent->GetFlags()); } break; } default: break; } }