void CalendarMgr::SendCalendarEventInviteAlert(CalendarEvent const& calendarEvent, CalendarInvite const& invite) { WorldPacket data(SMSG_CALENDAR_EVENT_INVITE_ALERT); data << uint64(calendarEvent.GetEventId()); data << calendarEvent.GetTitle(); data.AppendPackedTime(calendarEvent.GetEventTime()); data << uint32(calendarEvent.GetFlags()); data << uint32(calendarEvent.GetType()); data << int32(calendarEvent.GetDungeonId()); data << uint64(invite.GetInviteId()); Guild* guild = sGuildMgr->GetGuildById(calendarEvent.GetGuildId()); data << uint64(guild ? guild->GetGUID() : 0); data << uint8(invite.GetStatus()); data << uint8(invite.GetRank()); data.appendPackGUID(calendarEvent.GetCreatorGUID()); data.appendPackGUID(invite.GetSenderGUID()); if (calendarEvent.IsGuildEvent() || calendarEvent.IsGuildAnnouncement()) { if (Guild* guild = sGuildMgr->GetGuildById(calendarEvent.GetGuildId())) guild->BroadcastPacket(&data); } else if (Player* player = ObjectAccessor::FindPlayer(invite.GetInviteeGUID())) player->SendDirectMessage(&data); }
void CalendarMgr::SendCalendarEventInvite(CalendarInvite const& invite) { CalendarEvent* calendarEvent = GetEvent(invite.GetEventId()); time_t statusTime = invite.GetStatusTime(); bool hasStatusTime = statusTime != 946684800; // 01/01/2000 00:00:00 ObjectGuid invitee = invite.GetInviteeGUID(); Player* player = ObjectAccessor::FindConnectedPlayer(invitee); uint8 level = player ? player->getLevel() : sCharacterCache->GetCharacterLevelByGuid(invitee); WorldPacket data(SMSG_CALENDAR_EVENT_INVITE, 8 + 8 + 8 + 1 + 1 + 1 + (4) + 1); data << invitee.WriteAsPacked(); data << uint64(invite.GetEventId()); data << uint64(invite.GetInviteId()); data << uint8(level); data << uint8(invite.GetStatus()); data << uint8(hasStatusTime); if (hasStatusTime) data.AppendPackedTime(statusTime); data << uint8(invite.GetSenderGUID() != invite.GetInviteeGUID()); // false only if the invite is sign-up if (!calendarEvent) // Pre-invite { if (Player* playerSender = ObjectAccessor::FindConnectedPlayer(invite.GetSenderGUID())) playerSender->SendDirectMessage(&data); } else { if (calendarEvent->GetCreatorGUID() != invite.GetInviteeGUID()) // correct? SendPacketToAllEventRelatives(data, *calendarEvent); } }
void CalendarMgr::SendCalendarEventModeratorStatusAlert(CalendarEvent const& calendarEvent, CalendarInvite const& invite) { WorldPacket data(SMSG_CALENDAR_EVENT_MODERATOR_STATUS_ALERT, 8 + 8 + 1 + 1); data << invite.GetInviteeGUID().WriteAsPacked(); data << uint64(invite.GetEventId()); data << uint8(invite.GetRank()); data << uint8(1); // Unk boolean - Display to client? SendPacketToAllEventRelatives(data, calendarEvent); }
void CalendarMgr::SendCalendarEventInviteRemove(CalendarEvent const& calendarEvent, CalendarInvite const& invite, uint32 flags) { WorldPacket data(SMSG_CALENDAR_EVENT_INVITE_REMOVED, 8 + 4 + 4 + 1); data << invite.GetInviteeGUID().WriteAsPacked(); data << uint64(invite.GetEventId()); data << uint32(flags); data << uint8(1); // FIXME SendPacketToAllEventRelatives(data, calendarEvent); }
void CalendarMgr::SendCalendarEventStatus(CalendarEvent const& calendarEvent, CalendarInvite const& invite) { WorldPacket data(SMSG_CALENDAR_EVENT_STATUS, 8 + 8 + 4 + 4 + 1 + 1 + 4); data << invite.GetInviteeGUID().WriteAsPacked(); data << uint64(calendarEvent.GetEventId()); data.AppendPackedTime(calendarEvent.GetEventTime()); data << uint32(calendarEvent.GetFlags()); data << uint8(invite.GetStatus()); data << uint8(invite.GetRank()); data.AppendPackedTime(invite.GetStatusTime()); SendPacketToAllEventRelatives(data, calendarEvent); }
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; }
bool CalendarMgr::AddInvite(CalendarInvite const& newInvite) { uint64 inviteId = newInvite.GetInviteId(); if (!inviteId) { sLog->outError("CalendarMgr::addInvite: Cant add Invite 0"); return false; } if (_invites.find(inviteId) != _invites.end()) { sLog->outError("CalendarMgr::addInvite: Invite [" UI64FMTD "] exists", inviteId); return false; } _invites[inviteId] = newInvite; uint64 guid = newInvite.GetInvitee(); bool inviteAdded = AddPlayerInvite(guid, inviteId); bool eventAdded = AddPlayerEvent(guid, newInvite.GetEventId()); return eventAdded && inviteAdded; }
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 WorldSession::HandleCalendarGetCalendar(WorldPacket& /*recvData*/) { uint64 guid = _player->GetGUID(); sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_GET_CALENDAR [" UI64FMTD "]", guid); time_t cur_time = time_t(time(NULL)); sLog->outDebug(LOG_FILTER_NETWORKIO, "SMSG_CALENDAR_SEND_CALENDAR [" UI64FMTD "]", guid); WorldPacket data(SMSG_CALENDAR_SEND_CALENDAR, 1000); // Impossible to get the correct size without doing a double iteration of some elements CalendarInviteIdList const& invites = sCalendarMgr->GetPlayerInvites(guid); data << uint32(invites.size()); for (CalendarInviteIdList::const_iterator it = invites.begin(); it != invites.end(); ++it) { CalendarInvite* invite = sCalendarMgr->GetInvite(*it); CalendarEvent* calendarEvent = invite ? sCalendarMgr->GetEvent(invite->GetEventId()) : NULL; if (calendarEvent) { data << uint64(invite->GetEventId()); data << uint64(invite->GetInviteId()); data << uint8(invite->GetStatus()); data << uint8(invite->GetRank()); data << uint8(calendarEvent->GetGuildId() != 0); data.appendPackGUID(calendarEvent->GetCreatorGUID()); } else { sLog->outError("SMSG_CALENDAR_SEND_CALENDAR: No Invite found with id [" UI64FMTD "]", *it); data << uint64(0) << uint64(0) << uint8(0) << uint8(0); data.appendPackGUID(0); } } CalendarEventIdList const& events = sCalendarMgr->GetPlayerEvents(guid); data << uint32(events.size()); for (CalendarEventIdList::const_iterator it = events.begin(); it != events.end(); ++it) { if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(*it)) { data << uint64(*it); data << calendarEvent->GetTitle().c_str(); data << uint32(calendarEvent->GetType()); data << uint32(calendarEvent->GetTime()); data << uint32(calendarEvent->GetFlags()); data << uint32(calendarEvent->GetDungeonId()); data.appendPackGUID(calendarEvent->GetCreatorGUID()); } else { sLog->outError("SMSG_CALENDAR_SEND_CALENDAR: No Event found with id [" UI64FMTD "]", *it); data << uint64(0) << uint8(0) << uint32(0) << uint32(0) << uint32(0) << uint32(0); data.appendPackGUID(0); } } data << uint32(cur_time); // server time data << uint32(secsToTimeBitFields(cur_time)); // server time uint32 counter = 0; size_t p_counter = data.wpos(); data << uint32(counter); // instance save count for (uint8 i = 0; i < MAX_DIFFICULTY; ++i) for (Player::BoundInstancesMap::const_iterator itr = _player->_boundInstances[i].begin(); itr != _player->_boundInstances[i].end(); ++itr) if (itr->second.perm) { InstanceSave const* save = itr->second.save; data << uint32(save->GetMapId()); data << uint32(save->GetDifficulty()); data << uint32(save->GetResetTime() - cur_time); data << uint64(save->GetInstanceId()); // instance save id as unique instance copy id ++counter; } data.put<uint32>(p_counter, counter); data << uint32(1135753200); // unk (28.12.2005 07:00) counter = 0; p_counter = data.wpos(); data << uint32(counter); // raid reset count std::set<uint32> sentMaps; ResetTimeByMapDifficultyMap const& resets = sInstanceSaveMgr->GetResetTimeMap(); for (ResetTimeByMapDifficultyMap::const_iterator itr = resets.begin(); itr != resets.end(); ++itr) { uint32 mapId = PAIR32_LOPART(itr->first); if (sentMaps.find(mapId) != sentMaps.end()) continue; MapEntry const* mapEntry = sMapStore.LookupEntry(mapId); if (!mapEntry || !mapEntry->IsRaid()) continue; sentMaps.insert(mapId); data << uint32(mapId); data << uint32(itr->second - cur_time); data << uint32(mapEntry->unk_time); ++counter; } data.put<uint32>(p_counter, counter); // TODO: Fix this, how we do know how many and what holidays to send? uint32 holidayCount = 0; data << uint32(holidayCount); for (uint32 i = 0; i < holidayCount; ++i) { HolidaysEntry const* holiday = sHolidaysStore.LookupEntry(666); data << uint32(holiday->Id); // m_ID data << uint32(holiday->Region); // m_region, might be looping data << uint32(holiday->Looping); // m_looping, might be region data << uint32(holiday->Priority); // m_priority data << uint32(holiday->CalendarFilterType); // m_calendarFilterType for (uint8 j = 0; j < MAX_HOLIDAY_DATES; ++j) data << uint32(holiday->Date[j]); // 26 * m_date for (uint8 j = 0; j < MAX_HOLIDAY_DURATIONS; ++j) data << uint32(holiday->Duration[j]); // 10 * m_duration for (uint8 j = 0; j < MAX_HOLIDAY_FLAGS; ++j) data << uint32(holiday->CalendarFlags[j]); // 10 * m_calendarFlags data << holiday->TextureFilename; // m_textureFilename (holiday name) } SendPacket(&data); }
void CalendarMgr::SendCalendarEventModeratorStatusAlert(CalendarInvite const& invite) { if (Player* player = ObjectAccessor::FindPlayer(invite.GetInvitee())) player->GetSession()->SendCalendarEventModeratorStatusAlert(invite); }
void CalendarMgr::SendCalendarEventInviteAlert(CalendarEvent const& calendarEvent, CalendarInvite const& invite) { if (Player* player = ObjectAccessor::FindPlayer(invite.GetInvitee())) player->GetSession()->SendCalendarEventInviteAlert(calendarEvent, invite); }
void CalendarMgr::SendCalendarEventInvite(CalendarInvite const& invite, bool pending) { if (Player* player = ObjectAccessor::FindPlayer(invite.GetSenderGUID())) player->GetSession()->SendCalendarEventInvite(invite, pending); }
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; } }