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()); 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; _events.erase(calendarEvent); }
void WorldSession::HandleCalendarCopyEvent(WorldPacket& recvData) { ObjectGuid guid = _player->GetGUID(); uint64 eventId; uint64 inviteId; uint32 eventTime; recvData >> eventId >> inviteId; recvData.ReadPackedTime(eventTime); TC_LOG_DEBUG("network", "CMSG_CALENDAR_COPY_EVENT [%s], EventId [" UI64FMTD "] inviteId [" UI64FMTD "] Time: %u", guid.ToString().c_str(), eventId, inviteId, eventTime); // prevent events in the past // To Do: properly handle timezones and remove the "- time_t(86400L)" hack if (time_t(eventTime) < (time(NULL) - time_t(86400L))) { recvData.rfinish(); return; } if (CalendarEvent* oldEvent = sCalendarMgr->GetEvent(eventId)) { CalendarEvent* newEvent = new CalendarEvent(*oldEvent, sCalendarMgr->GetFreeEventId()); newEvent->SetEventTime(time_t(eventTime)); sCalendarMgr->AddEvent(newEvent, CALENDAR_SENDTYPE_COPY); CalendarInviteStore invites = sCalendarMgr->GetEventInvites(eventId); SQLTransaction trans; if (invites.size() > 1) trans = CharacterDatabase.BeginTransaction(); for (CalendarInviteStore::const_iterator itr = invites.begin(); itr != invites.end(); ++itr) sCalendarMgr->AddInvite(newEvent, new CalendarInvite(**itr, sCalendarMgr->GetFreeInviteId(), newEvent->GetEventId()), trans); if (invites.size() > 1) CharacterDatabase.CommitTransaction(trans); // should we change owner when somebody makes a copy of event owned by another person? } else sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_EVENT_INVALID); }
bool CalendarMgr::AddEvent(CalendarEvent const& newEvent) { uint64 eventId = newEvent.GetEventId(); if (_events.find(eventId) != _events.end()) { sLog->outError("CalendarMgr::addEvent: Event [" UI64FMTD "] exists", eventId); return false; } _events[eventId] = newEvent; return true; }
// remove all events and invite of player related to a specific guild // used when player quit a guild void CalendarMgr::RemoveGuildCalendar(ObjectGuid const& playerGuid, uint32 GuildId) { CalendarEventStore::iterator itr = m_EventStore.begin(); while (itr != m_EventStore.end()) { CalendarEvent* event = &itr->second; if (event->CreatorGuid == playerGuid && (event->IsGuildEvent() || event->IsGuildAnnouncement())) { // all invite will be automaticaly deleted m_EventStore.erase(itr++); // itr already incremented so go recheck event owner continue; } // event not owned by playerGuid but an guild invite can still be found if (event->GuildId != GuildId || !(event->IsGuildEvent() || event->IsGuildAnnouncement())) { ++itr; continue; } event->RemoveInviteByGuid(playerGuid); ++itr; } }
// Iterate over the list of events foreach (const CalendarEvent &event, events2) { // Copy the data into a model entry QVariantMap entry; entry["myType"] = QVariant(trUtf8("tomorrow")); entry["eventId"] = event.id(); entry["accountId"] = event.accountId(); entry["subject"] = event.subject().replace('&', "&").replace('<', "<").replace('>', ">").replace('"', """); entry["order"] = order++; entry["startTime"] = event.startTime(); entry["endTime"] = event.endTime(); entry["timeString"] = ""; entry["account"] = event.accountId(); std::stringstream keyStream; keyStream << event.accountId() << event.folderId(); std::string key = keyStream.str(); entry["color24"] = QString::number(accountColor[key], 16); qDebug() << "FMI ######### key:" << QString::fromStdString(key) << "=" << accountColor[key]; qDebug() << "FMI ######### id:" << event.id() << " subject" << event.subject() << " startTime:" << event.startTime().toString(Qt::DefaultLocaleShortDate); entries.append(entry); }
// fill all player invites in provided CalendarInvitesList void CalendarMgr::GetPlayerInvitesList(ObjectGuid const& guid, CalendarInvitesList& calInvList) { for (CalendarEventStore::iterator itr = m_EventStore.begin(); itr != m_EventStore.end(); ++itr) { CalendarEvent* event = &itr->second; if (event->IsGuildAnnouncement()) continue; CalendarInviteMap const* cInvMap = event->GetInviteMap(); CalendarInviteMap::const_iterator ci_itr = cInvMap->begin(); while (ci_itr != cInvMap->end()) { if (ci_itr->second->InviteeGuid == guid) { calInvList.push_back(ci_itr->second); break; } ++ci_itr; } } }
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; }
void CalendarMgr::SendCalendarEventUpdateAlert(CalendarEvent const& calendarEvent, time_t oldEventTime) { WorldPacket data(SMSG_CALENDAR_EVENT_UPDATED_ALERT, 1 + 8 + 4 + 4 + 4 + 1 + 4 + calendarEvent.GetTitle().size() + calendarEvent.GetDescription().size() + 1 + 4 + 4); data << uint8(1); // unk data << uint64(calendarEvent.GetEventId()); data.AppendPackedTime(oldEventTime); data << uint32(calendarEvent.GetFlags()); data.AppendPackedTime(calendarEvent.GetEventTime()); data << uint8(calendarEvent.GetType()); data << int32(calendarEvent.GetDungeonId()); data << calendarEvent.GetTitle(); data << calendarEvent.GetDescription(); data << uint8(CALENDAR_REPEAT_NEVER); // repeatable data << uint32(CALENDAR_MAX_INVITES); data << uint32(0); // unk SendPacketToAllEventRelatives(data, calendarEvent); }
// check if an invitee have not reached invite limit bool CalendarMgr::CanAddInviteTo(ObjectGuid const& guid) { uint32 totalInvites = 0; for (CalendarEventStore::iterator itr = m_EventStore.begin(); itr != m_EventStore.end(); ++itr) { CalendarEvent* event = &itr->second; if (event->IsGuildAnnouncement()) continue; CalendarInviteMap const* cInvMap = event->GetInviteMap(); CalendarInviteMap::const_iterator ci_itr = cInvMap->begin(); while (ci_itr != cInvMap->end()) { if ((ci_itr->second->InviteeGuid == guid) && (++totalInvites >= CALENDAR_MAX_INVITES)) return false; ++ci_itr; } } return true; }
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()); data << uint8(invite.GetStatus()); data << uint8(invite.GetRank()); data << calendarEvent.GetCreatorGUID().WriteAsPacked(); data << invite.GetSenderGUID().WriteAsPacked(); if (calendarEvent.IsGuildEvent() || calendarEvent.IsGuildAnnouncement()) { if (Guild* guild = sGuildMgr->GetGuildById(calendarEvent.GetGuildId())) guild->BroadcastPacket(&data); } else if (Player* player = ObjectAccessor::FindConnectedPlayer(invite.GetInviteeGUID())) player->SendDirectMessage(&data); }
void WorldSession::HandleCalendarAddEvent(WorldPacket& recvData) { uint64 guid = _player->GetGUID(); std::string title; std::string description; uint8 type; uint8 repeatable; uint32 maxInvites; int32 dungeonId; uint32 eventPackedTime; uint32 unkPackedTime; uint32 flags; recvData >> title >> description >> type >> repeatable >> maxInvites >> dungeonId; recvData.ReadPackedTime(eventPackedTime); recvData.ReadPackedTime(unkPackedTime); recvData >> flags; CalendarEvent* calendarEvent = new CalendarEvent(sCalendarMgr->GetFreeEventId(), guid, 0, CalendarEventType(type), dungeonId, time_t(eventPackedTime), flags, time_t(unkPackedTime), title, description); if (calendarEvent->IsGuildEvent() || calendarEvent->IsGuildAnnouncement()) if (Player* creator = ObjectAccessor::FindPlayer(guid)) calendarEvent->SetGuildId(creator->GetGuildId()); if (calendarEvent->IsGuildAnnouncement()) { // 946684800 is 01/01/2000 00:00:00 - default response time CalendarInvite* invite = new CalendarInvite(0, calendarEvent->GetEventId(), 0, guid, 946684800, CALENDAR_STATUS_NOT_SIGNED_UP, CALENDAR_RANK_PLAYER, ""); sCalendarMgr->AddInvite(calendarEvent, invite); } else { uint32 inviteCount; recvData >> inviteCount; for (uint32 i = 0; i < inviteCount; ++i) { uint64 invitee = 0; uint8 status = 0; uint8 rank = 0; recvData.readPackGUID(invitee); recvData >> status >> rank; // 946684800 is 01/01/2000 00:00:00 - default response time CalendarInvite* invite = new CalendarInvite(sCalendarMgr->GetFreeInviteId(), calendarEvent->GetEventId(), invitee, guid, 946684800, CalendarInviteStatus(status), CalendarModerationRank(rank), ""); sCalendarMgr->AddInvite(calendarEvent, invite); } } sCalendarMgr->AddEvent(calendarEvent, CALENDAR_SENDTYPE_ADD); }
void CalendarMgr::SendPacketToAllEventRelatives(WorldPacket& packet, CalendarEvent const& calendarEvent) { // Send packet to all guild members if (calendarEvent.IsGuildEvent() || calendarEvent.IsGuildAnnouncement()) if (Guild* guild = sGuildMgr->GetGuildById(calendarEvent.GetGuildId())) guild->BroadcastPacket(&packet); // Send packet to all invitees if event is non-guild, in other case only to non-guild invitees (packet was broadcasted for them) CalendarInviteStore invites = _invites[calendarEvent.GetEventId()]; for (CalendarInviteStore::iterator itr = invites.begin(); itr != invites.end(); ++itr) if (Player* player = ObjectAccessor::FindConnectedPlayer((*itr)->GetInviteeGUID())) if (!calendarEvent.IsGuildEvent() || player->GetGuildId() != calendarEvent.GetGuildId()) player->SendDirectMessage(&packet); }
void WorldSession::HandleCalendarAddEvent(WorldPackets::Calendar::CalendarAddEvent& calendarAddEvent) { ObjectGuid guid = _player->GetGUID(); // prevent events in the past // To Do: properly handle timezones and remove the "- time_t(86400L)" hack if (calendarAddEvent.EventInfo.Time < (time(NULL) - time_t(86400L))) return; CalendarEvent* calendarEvent = new CalendarEvent(sCalendarMgr->GetFreeEventId(), guid, UI64LIT(0), CalendarEventType(calendarAddEvent.EventInfo.EventType), calendarAddEvent.EventInfo.TextureID, calendarAddEvent.EventInfo.Time, calendarAddEvent.EventInfo.Flags, calendarAddEvent.EventInfo.Title, calendarAddEvent.EventInfo.Description, time_t(0)); if (calendarEvent->IsGuildEvent() || calendarEvent->IsGuildAnnouncement()) if (Player* creator = ObjectAccessor::FindPlayer(guid)) calendarEvent->SetGuildId(creator->GetGuildId()); if (calendarEvent->IsGuildAnnouncement()) { CalendarInvite invite(0, calendarEvent->GetEventId(), ObjectGuid::Empty, guid, CALENDAR_DEFAULT_RESPONSE_TIME, CALENDAR_STATUS_NOT_SIGNED_UP, CALENDAR_RANK_PLAYER, ""); // WARNING: By passing pointer to a local variable, the underlying method(s) must NOT perform any kind // of storage of the pointer as it will lead to memory corruption sCalendarMgr->AddInvite(calendarEvent, &invite); } else { SQLTransaction trans; if (calendarAddEvent.EventInfo.Invites.size() > 1) trans = CharacterDatabase.BeginTransaction(); for (uint32 i = 0; i < calendarAddEvent.EventInfo.Invites.size(); ++i) { CalendarInvite* invite = new CalendarInvite(sCalendarMgr->GetFreeInviteId(), calendarEvent->GetEventId(), calendarAddEvent.EventInfo.Invites[i].Guid, guid, CALENDAR_DEFAULT_RESPONSE_TIME, CalendarInviteStatus(calendarAddEvent.EventInfo.Invites[i].Status), CalendarModerationRank(calendarAddEvent.EventInfo.Invites[i].Moderator), ""); sCalendarMgr->AddInvite(calendarEvent, invite, trans); } if (calendarAddEvent.EventInfo.Invites.size() > 1) CharacterDatabase.CommitTransaction(trans); } sCalendarMgr->AddEvent(calendarEvent, CALENDAR_SENDTYPE_ADD); }
//! [2] void EventEditor::loadEvent(const EventKey &eventKey) { m_eventKey = eventKey; // Load the event from the persistent storage const CalendarEvent event = m_calendarService->event(m_eventKey.accountId(), m_eventKey.eventId()); // Update the properties with the data from the event m_subject = event.subject(); m_location = event.location(); m_startTime = event.startTime(); m_endTime = event.endTime(); m_folderId = event.folderId(); m_accountId = event.accountId(); // Emit the change notifications emit subjectChanged(); emit locationChanged(); emit startTimeChanged(); emit endTimeChanged(); emit folderIdChanged(); emit accountIdChanged(); }
void CalendarMgr::SendCalendarEvent(ObjectGuid guid, CalendarEvent const& calendarEvent, CalendarSendEventType sendType) { Player* player = ObjectAccessor::FindConnectedPlayer(guid); if (!player) return; CalendarInviteStore const& eventInviteeList = _invites[calendarEvent.GetEventId()]; WorldPacket data(SMSG_CALENDAR_SEND_EVENT, 60 + eventInviteeList.size() * 32); data << uint8(sendType); data << calendarEvent.GetCreatorGUID().WriteAsPacked(); data << uint64(calendarEvent.GetEventId()); data << calendarEvent.GetTitle(); data << calendarEvent.GetDescription(); data << uint8(calendarEvent.GetType()); data << uint8(CALENDAR_REPEAT_NEVER); // repeatable data << uint32(CALENDAR_MAX_INVITES); data << int32(calendarEvent.GetDungeonId()); data << uint32(calendarEvent.GetFlags()); data.AppendPackedTime(calendarEvent.GetEventTime()); data.AppendPackedTime(calendarEvent.GetTimeZoneTime()); data << uint32(calendarEvent.GetGuildId()); data << uint32(eventInviteeList.size()); for (CalendarInviteStore::const_iterator itr = eventInviteeList.begin(); itr != eventInviteeList.end(); ++itr) { CalendarInvite const* calendarInvite = (*itr); ObjectGuid inviteeGuid = calendarInvite->GetInviteeGUID(); Player* invitee = ObjectAccessor::FindPlayer(inviteeGuid); uint8 inviteeLevel = invitee ? invitee->getLevel() : sCharacterCache->GetCharacterLevelByGuid(inviteeGuid); ObjectGuid::LowType inviteeGuildId = invitee ? invitee->GetGuildId() : sCharacterCache->GetCharacterGuildIdByGuid(inviteeGuid); data << inviteeGuid.WriteAsPacked(); data << uint8(inviteeLevel); data << uint8(calendarInvite->GetStatus()); data << uint8(calendarInvite->GetRank()); data << uint8(calendarEvent.IsGuildEvent() && calendarEvent.GetGuildId() == inviteeGuildId); data << uint64(calendarInvite->GetInviteId()); data.AppendPackedTime(calendarInvite->GetStatusTime()); data << calendarInvite->GetText(); } player->SendDirectMessage(&data); }
bool CalendarEvent::operator==(const CalendarEvent &other) const { // Storing a QDateTime to QSettings seems to lose time zone information. Lets ignore the time zone when // comparing or we'll never find ourselves again. QDateTime thisStartTime = m_startTime; if (other.startTime().timeSpec() == Qt::TimeZone) thisStartTime.setTimeZone(other.startTime().timeZone()); QDateTime thisEndTime = m_endTime; if (other.endTime().timeSpec() == Qt::TimeZone) thisEndTime.setTimeZone(other.endTime().timeZone()); QDateTime thisReminder = m_reminder; if (other.reminder().timeSpec() == Qt::TimeZone) thisReminder.setTimeZone(other.reminder().timeZone()); return m_id == other.id() && m_title == other.title() && m_description == other.description() && thisStartTime == other.startTime() && thisEndTime == other.endTime() && thisReminder == other.reminder() && m_location == other.location() && m_calendar == other.calendar() && m_comment == other.comment() && m_guests == other.guests() && m_recurring == other.recurring() && m_isAllDay == other.isAllDay(); }
// load all events and their related invites from invite void CalendarMgr::LoadCalendarsFromDB() { // in case of reload (not yet implemented) m_MaxInviteId = 0; m_MaxEventId = 0; m_EventStore.clear(); sLog.outString("Loading Calendar Events..."); // 0 1 2 3 4 5 6 7 8 QueryResult* eventsQuery = CharacterDatabase.Query("SELECT eventId, creatorGuid, guildId, type, flags, dungeonId, eventTime, title, description FROM calendar_events ORDER BY eventId"); if (!eventsQuery) { BarGoLink bar(1); bar.step(); sLog.outString(); sLog.outString(">> calendar_events table is empty!"); } else { BarGoLink bar(eventsQuery->GetRowCount()); do { Field* field = eventsQuery->Fetch(); bar.step(); uint64 eventId = field[0].GetUInt64(); CalendarEvent& newEvent = m_EventStore[eventId]; newEvent.EventId = eventId; newEvent.CreatorGuid = ObjectGuid(HIGHGUID_PLAYER, field[1].GetUInt32()); newEvent.GuildId = field[2].GetUInt32(); newEvent.Type = CalendarEventType(field[3].GetUInt8()); newEvent.Flags = field[4].GetUInt32(); newEvent.DungeonId = field[5].GetInt32(); newEvent.EventTime = time_t(field[6].GetUInt32()); newEvent.Title = field[7].GetCppString(); newEvent.Description = field[8].GetCppString(); m_MaxEventId = std::max(eventId, m_MaxEventId); } while (eventsQuery->NextRow()); sLog.outString(); sLog.outString(">> Loaded %u events!", uint32(eventsQuery->GetRowCount())); delete eventsQuery; } sLog.outString("Loading Calendar invites..."); // 0 1 2 3 4 5 6 QueryResult* invitesQuery = CharacterDatabase.Query("SELECT inviteId, eventId, inviteeGuid, senderGuid, status, lastUpdateTime, rank FROM calendar_invites ORDER BY inviteId"); if (!invitesQuery) { BarGoLink bar(1); bar.step(); sLog.outString(); if (m_MaxEventId) // An Event was loaded before { // delete all events (no event exist without at least one invite) m_EventStore.clear(); m_MaxEventId = 0; CharacterDatabase.DirectExecute("TRUNCATE TABLE calendar_events"); sLog.outString(">> calendar_invites table is empty, cleared calendar_events table!"); } else sLog.outString(">> calendar_invite table is empty!"); } else { if (m_MaxEventId) { uint64 totalInvites = 0; uint32 deletedInvites = 0; BarGoLink bar(invitesQuery->GetRowCount()); do { Field* field = invitesQuery->Fetch(); uint64 inviteId = field[0].GetUInt64(); uint64 eventId = field[1].GetUInt64(); ObjectGuid inviteeGuid = ObjectGuid(HIGHGUID_PLAYER, field[2].GetUInt32()); ObjectGuid senderGuid = ObjectGuid(HIGHGUID_PLAYER, field[3].GetUInt32()); CalendarInviteStatus status = CalendarInviteStatus(field[4].GetUInt8()); time_t lastUpdateTime = time_t(field[5].GetUInt32()); CalendarModerationRank rank = CalendarModerationRank(field[6].GetUInt8()); CalendarEvent* event = GetEventById(eventId); if (!event) { // delete invite CharacterDatabase.PExecute("DELETE FROM calendar_invites WHERE inviteId =" UI64FMTD, field[0].GetUInt64()); ++deletedInvites; continue; } CalendarInvite* invite = new CalendarInvite(event, inviteId, senderGuid, inviteeGuid, lastUpdateTime, status, rank, ""); event->AddInvite(invite); ++totalInvites; m_MaxInviteId = std::max(inviteId, m_MaxInviteId); } while (invitesQuery->NextRow()); sLog.outString(); sLog.outString(">> Loaded " UI64FMTD " invites! %s", totalInvites, (deletedInvites != 0) ? "(deleted some invites without corresponding event!)" : ""); } else { // delete all invites (no invites exist without events) CharacterDatabase.DirectExecute("TRUNCATE TABLE calendar_invites"); sLog.outString(">> calendar_invites table is cleared! (invites without events found)"); } delete invitesQuery; } sLog.outString(); }
void CalendarMgr::SendCalendarEvent(uint64 guid, CalendarEvent const& calendarEvent, CalendarSendEventType sendType) { Player* player = ObjectAccessor::FindPlayer(guid); if (!player) return; std::vector<CalendarInvite*> const& eventInviteeList = _invites[calendarEvent.GetEventId()]; WorldPacket data(SMSG_CALENDAR_SEND_EVENT, 60 + eventInviteeList.size() * 32); data << uint8(sendType); data.appendPackGUID(calendarEvent.GetCreatorGUID()); data << uint64(calendarEvent.GetEventId()); data << calendarEvent.GetTitle(); data << calendarEvent.GetDescription(); data << uint8(calendarEvent.GetType()); data << uint8(CALENDAR_REPEAT_NEVER); // repeatable data << uint32(CALENDAR_MAX_INVITES); data << int32(calendarEvent.GetDungeonId()); data << uint32(calendarEvent.GetFlags()); data.AppendPackedTime(calendarEvent.GetEventTime()); data.AppendPackedTime(calendarEvent.GetTimeZoneTime()); Guild* guild = sGuildMgr->GetGuildById(calendarEvent.GetGuildId()); data << uint64(guild ? guild->GetGUID() : 0); data << uint32(eventInviteeList.size()); for (std::vector<CalendarInvite*>::const_iterator itr = eventInviteeList.begin(); itr != eventInviteeList.end(); ++itr) { CalendarInvite const* calendarInvite = (*itr); uint64 inviteeGuid = calendarInvite->GetInviteeGUID(); Player* invitee = ObjectAccessor::FindPlayer(inviteeGuid); uint8 inviteeLevel = invitee ? invitee->getLevel() : Player::GetLevelFromDB(inviteeGuid); uint32 inviteeGuildId = invitee ? invitee->GetGuildId() : Player::GetGuildIdFromDB(inviteeGuid); data.appendPackGUID(inviteeGuid); data << uint8(inviteeLevel); data << uint8(calendarInvite->GetStatus()); data << uint8(calendarInvite->GetRank()); data << uint8(calendarEvent.IsGuildEvent() && calendarEvent.GetGuildId() == inviteeGuildId); data << uint64(calendarInvite->GetInviteId()); data.AppendPackedTime(calendarInvite->GetStatusTime()); data << calendarInvite->GetText(); } player->SendDirectMessage(&data); }
void WorldSession::HandleCalendarGetCalendar(WorldPacket& /*recvData*/) { uint64 guid = _player->GetGUID(); sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_GET_CALENDAR [" UI64FMTD "]", guid); time_t currTime = time(NULL); WorldPacket data(SMSG_CALENDAR_SEND_CALENDAR, 1000); // Average size if no instance CalendarInviteStore invites = sCalendarMgr->GetPlayerInvites(guid); data << uint32(invites.size()); for (CalendarInviteStore::const_iterator itr = invites.begin(); itr != invites.end(); ++itr) { data << uint64((*itr)->GetEventId()); data << uint64((*itr)->GetInviteId()); data << uint8((*itr)->GetStatus()); data << uint8((*itr)->GetRank()); if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent((*itr)->GetEventId())) { data << uint8(calendarEvent->IsGuildEvent()); data.appendPackGUID(calendarEvent->GetCreatorGUID()); } else { data << uint8(0); data.appendPackGUID((*itr)->GetSenderGUID()); } } CalendarEventStore playerEvents = sCalendarMgr->GetPlayerEvents(guid); data << uint32(playerEvents.size()); for (CalendarEventStore::const_iterator itr = playerEvents.begin(); itr != playerEvents.end(); ++itr) { CalendarEvent* calendarEvent = *itr; data << uint64(calendarEvent->GetEventId()); data << calendarEvent->GetTitle(); data << uint32(calendarEvent->GetType()); data.AppendPackedTime(calendarEvent->GetEventTime()); data << uint32(calendarEvent->GetFlags()); data << int32(calendarEvent->GetDungeonId()); data.appendPackGUID(calendarEvent->GetCreatorGUID()); } data << uint32(currTime); // server time data.AppendPackedTime(currTime); // zone time ByteBuffer dataBuffer; uint32 boundCounter = 0; for (uint8 i = 0; i < MAX_DIFFICULTY; ++i) { BoundInstancesMap const& m_boundInstances = sInstanceSaveMgr->PlayerGetBoundInstances(_player->GetGUIDLow(), Difficulty(i)); for (BoundInstancesMap::const_iterator itr = m_boundInstances.begin(); itr != m_boundInstances.end(); ++itr) { if (itr->second.perm) { InstanceSave const* save = itr->second.save; time_t resetTime = itr->second.extended ? save->GetExtendedResetTime() : save->GetResetTime(); dataBuffer << uint32(save->GetMapId()); dataBuffer << uint32(save->GetDifficulty()); dataBuffer << uint32(resetTime >= currTime ? resetTime-currTime : 0); dataBuffer << uint64(MAKE_NEW_GUID(save->GetInstanceId(), 0, HIGHGUID_INSTANCE)); // instance save id as unique instance copy id ++boundCounter; } } } data << uint32(boundCounter); data.append(dataBuffer); // pussywizard uint32 relationTime = sWorld->getIntConfig(CONFIG_INSTANCE_RESET_TIME_RELATIVE_TIMESTAMP) + sWorld->getIntConfig(CONFIG_INSTANCE_RESET_TIME_HOUR) * HOUR; // set point in time (default 29.12.2005) + X hours data << uint32(relationTime); // Reuse variables boundCounter = 0; std::set<uint32> sentMaps; dataBuffer.clear(); 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); dataBuffer << int32(mapId); time_t period = sInstanceSaveMgr->GetExtendedResetTimeFor(mapId, (Difficulty)PAIR32_HIPART(itr->first)) - itr->second; dataBuffer << int32(period); // pussywizard: reset time period dataBuffer << int32(0); // pussywizard: reset time offset, needed for other than 7-day periods if not aligned with relationTime ++boundCounter; } data << uint32(boundCounter); data.append(dataBuffer); // TODO: Fix this, how we do know how many and what holidays to send? data << uint32(sGameEventMgr->modifiedHolidays.size()); for (uint32 entry : sGameEventMgr->modifiedHolidays) { HolidaysEntry const* holiday = sHolidaysStore.LookupEntry(entry); 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 -- WritePackedTime ? 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 WorldSession::HandleCalendarGetCalendar(WorldPacket& /*recvData*/) { uint64 guid = _player->GetGUID(); sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_GET_CALENDAR [" UI64FMTD "]", guid); time_t currTime = time(NULL); WorldPacket data(SMSG_CALENDAR_SEND_CALENDAR, 1000); // Average size if no instance std::vector<CalendarInvite*> invites = sCalendarMgr->GetPlayerInvites(guid); data << uint32(invites.size()); for (std::vector<CalendarInvite*>::const_iterator itr = invites.begin(); itr != invites.end(); ++itr) { data << uint64((*itr)->GetEventId()); data << uint64((*itr)->GetInviteId()); data << uint8((*itr)->GetStatus()); data << uint8((*itr)->GetRank()); if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent((*itr)->GetEventId())) { data << uint8(calendarEvent->IsGuildEvent()); data.appendPackGUID(calendarEvent->GetCreatorGUID()); } else { data << uint8(0); data.appendPackGUID((*itr)->GetSenderGUID()); } } CalendarEventStore playerEvents = sCalendarMgr->GetPlayerEvents(guid); data << uint32(playerEvents.size()); for (CalendarEventStore::const_iterator itr = playerEvents.begin(); itr != playerEvents.end(); ++itr) { CalendarEvent* calendarEvent = *itr; data << uint64(calendarEvent->GetEventId()); data << calendarEvent->GetTitle(); data << uint32(calendarEvent->GetType()); data.AppendPackedTime(calendarEvent->GetEventTime()); data << uint32(calendarEvent->GetFlags()); data << int32(calendarEvent->GetDungeonId()); Guild* guild = sGuildMgr->GetGuildById(calendarEvent->GetGuildId()); data << uint64(guild ? guild->GetGUID() : 0); data.appendPackGUID(calendarEvent->GetCreatorGUID()); } data << uint32(currTime); // server time data.AppendPackedTime(currTime); // zone time ByteBuffer dataBuffer; uint32 boundCounter = 0; for (uint8 i = 0; i < MAX_DIFFICULTY; ++i) { Player::BoundInstancesMap boundInstances = _player->GetBoundInstances(Difficulty(i)); for (Player::BoundInstancesMap::const_iterator itr = boundInstances.begin(); itr != boundInstances.end(); ++itr) { if (itr->second.perm) { InstanceSave const* save = itr->second.save; dataBuffer << uint32(save->GetMapId()); dataBuffer << uint32(save->GetDifficulty()); dataBuffer << uint32(save->GetResetTime() - currTime); dataBuffer << uint64(save->GetInstanceId()); // instance save id as unique instance copy id ++boundCounter; } } } data << uint32(boundCounter); data.append(dataBuffer); data << uint32(1135753200); // Constant date, unk (28.12.2005 07:00) // Reuse variables boundCounter = 0; std::set<uint32> sentMaps; dataBuffer.clear(); 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); dataBuffer << int32(mapId); dataBuffer << int32(itr->second - currTime); dataBuffer << int32(0); // Never seen anything else in sniffs - still unknown ++boundCounter; } data << uint32(boundCounter); data.append(dataBuffer); // 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 -- WritePackedTime ? 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 WorldSession::HandleCalendarAddEvent(WorldPacket& recvData) { uint64 guid = _player->GetGUID(); std::string title; std::string description; uint8 type; int32 dungeonId; uint32 eventPackedTime; uint32 maxInvites; // always 100, necesary? Not find the way how to change it uint32 flags; uint32 inviteeCount; uint16 descriptionLength, titleLength; recvData >> maxInvites >> flags >> dungeonId; recvData.ReadPackedTime(eventPackedTime); recvData >> type; inviteeCount = recvData.ReadBits(22); descriptionLength = recvData.ReadBits(11); std::list<CalendarInvitePacketInfo> calendarInviteList; for (uint32 i = 0; i < inviteeCount; i++) { CalendarInvitePacketInfo info; info.Guid[7] = recvData.ReadBit(); info.Guid[2] = recvData.ReadBit(); info.Guid[6] = recvData.ReadBit(); info.Guid[3] = recvData.ReadBit(); info.Guid[5] = recvData.ReadBit(); info.Guid[1] = recvData.ReadBit(); info.Guid[0] = recvData.ReadBit(); info.Guid[4] = recvData.ReadBit(); calendarInviteList.push_back(info); } titleLength = recvData.ReadBits(8); for (std::list<CalendarInvitePacketInfo>::iterator iter = calendarInviteList.begin(); iter != calendarInviteList.end(); ++iter) { recvData.ReadByteSeq(iter->Guid[4]); recvData.ReadByteSeq(iter->Guid[2]); recvData.ReadByteSeq(iter->Guid[3]); recvData.ReadByteSeq(iter->Guid[1]); recvData.ReadByteSeq(iter->Guid[0]); recvData.ReadByteSeq(iter->Guid[6]); recvData.ReadByteSeq(iter->Guid[7]); recvData >> iter->Status; recvData.ReadByteSeq(iter->Guid[5]); recvData >> iter->ModerationRank; } title = recvData.ReadString(titleLength); description = recvData.ReadString(descriptionLength); CalendarEvent* calendarEvent = new CalendarEvent(sCalendarMgr->GetFreeEventId(), guid, 0, CalendarEventType(type), dungeonId, time_t(eventPackedTime), flags, title, description); if (calendarEvent->IsGuildEvent() || calendarEvent->IsGuildAnnouncement()) if (Player* creator = ObjectAccessor::FindPlayer(guid)) calendarEvent->SetGuildId(creator->GetGuildId()); if (calendarEvent->IsGuildAnnouncement()) { // DEFAULT_STATUS_TIME is 01/01/2000 00:00:00 - default response time CalendarInvite* invite = new CalendarInvite(0, calendarEvent->GetEventId(), 0, guid, DEFAULT_STATUS_TIME, CALENDAR_STATUS_NOT_SIGNED_UP, CALENDAR_RANK_PLAYER, ""); sCalendarMgr->AddInvite(calendarEvent, invite); } else { for (std::list<CalendarInvitePacketInfo>::const_iterator iter = calendarInviteList.begin(); iter != calendarInviteList.end(); ++iter) { // DEFAULT_STATUS_TIME is 01/01/2000 00:00:00 - default response time CalendarInvite* invite = new CalendarInvite(sCalendarMgr->GetFreeInviteId(), calendarEvent->GetEventId(), (uint64)iter->Guid, guid, DEFAULT_STATUS_TIME, CalendarInviteStatus(iter->Status), CalendarModerationRank(iter->ModerationRank), ""); sCalendarMgr->AddInvite(calendarEvent, invite); } } sCalendarMgr->AddEvent(calendarEvent, CALENDAR_SENDTYPE_ADD); }
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 CalendarThreadWrapper::addToCalendar() { const QString viaStation = m_result->viaStation(); QSettings settings(FAHRPLAN_SETTINGS_NAMESPACE, "fahrplan2"); QString calendarEntryTitle; QString calendarEntryDesc; if (viaStation.isEmpty()) calendarEntryTitle = tr("%1 to %2").arg(m_result->departureStation(), m_result->arrivalStation()); else calendarEntryTitle = tr("%1 via %3 to %2").arg(m_result->departureStation(), m_result->arrivalStation(), viaStation); if (!m_result->info().isEmpty()) calendarEntryDesc.append(m_result->info()).append("\n"); const bool compactFormat = settings.value("compactCalendarEntries", false).toBool(); for (int i=0; i < m_result->itemcount(); i++) { JourneyDetailResultItem *item = m_result->getItem(i); if (!compactFormat && !item->train().isEmpty()) calendarEntryDesc.append("--- ").append(item->train()).append(" ---\n"); calendarEntryDesc.append(formatStation(item->departureDateTime(), item->departureStation(), item->departureInfo())); calendarEntryDesc.append("\n"); if (compactFormat && !item->train().isEmpty()) calendarEntryDesc.append("--- ").append(item->train()).append(" ---\n"); calendarEntryDesc.append(formatStation(item->arrivalDateTime(), item->arrivalStation(), item->arrivalInfo())); calendarEntryDesc.append("\n"); if (!item->info().isEmpty()) { calendarEntryDesc.append(item->info()).append("\n"); } if (!compactFormat) calendarEntryDesc.append("\n"); } if (!compactFormat) calendarEntryDesc.append( tr("-- \nAdded by Fahrplan. Please, re-check the information before your journey.")); #ifdef BUILD_FOR_BLACKBERRY CalendarService service; QPair<AccountId, FolderId> folder; settings.beginGroup("Calendar"); folder.first = settings.value("AccountId", -1).toInt(); if (folder.first >= 0) folder.second = settings.value("FolderId", -1).toInt(); if ((folder.first < 0) || (folder.second < 0)) folder = service.defaultCalendarFolder(); CalendarEvent event; event.setAccountId(folder.first); event.setFolderId(folder.second); event.setSubject(calendarEntryTitle); event.setStartTime(m_result->departureDateTime()); event.setEndTime(m_result->arrivalDateTime()); event.setBody(calendarEntryDesc); event.setReminder(-1); emit addCalendarEntryComplete(service.createEvent(event) == Result::Success); #elif defined(BUILD_FOR_HARMATTAN) || defined(BUILD_FOR_MAEMO_5) || defined(BUILD_FOR_SYMBIAN) QOrganizerManager defaultManager; QOrganizerEvent event; event.setDisplayLabel(calendarEntryTitle); event.setStartDateTime(m_result->departureDateTime()); event.setEndDateTime(m_result->arrivalDateTime()); event.setDescription(calendarEntryDesc); QString id = settings.value("Calendar/CollectionId").toString(); if (!id.isEmpty()) { QOrganizerCollectionId collectionId = QOrganizerCollectionId::fromString(id); if (!collectionId.isNull()) event.setCollectionId(collectionId); } emit addCalendarEntryComplete(defaultManager.saveItem(&event)); #else emit addCalendarEntryComplete(false); #endif QThread::currentThread()->exit(0); // Move back to GUI thread so the deleteLater() callback works (it requires // an event loop which is still alive) moveToThread(QCoreApplication::instance()->thread()); }
void WorldSession::HandleCalendarAddEvent(WorldPacket& recvData) { ObjectGuid guid = _player->GetGUID(); std::string title; std::string description; uint8 type; uint8 repeatable; uint32 maxInvites; int32 dungeonId; uint32 eventPackedTime; uint32 unkPackedTime; uint32 flags; recvData >> title >> description >> type >> repeatable >> maxInvites >> dungeonId; recvData.ReadPackedTime(eventPackedTime); recvData.ReadPackedTime(unkPackedTime); recvData >> flags; // prevent events in the past // To Do: properly handle timezones and remove the "- time_t(86400L)" hack if (time_t(eventPackedTime) < (time(NULL) - time_t(86400L))) { recvData.rfinish(); return; } CalendarEvent* calendarEvent = new CalendarEvent(sCalendarMgr->GetFreeEventId(), guid, 0, CalendarEventType(type), dungeonId, time_t(eventPackedTime), flags, time_t(unkPackedTime), title, description); if (calendarEvent->IsGuildEvent() || calendarEvent->IsGuildAnnouncement()) if (Player* creator = ObjectAccessor::FindPlayer(guid)) calendarEvent->SetGuildId(creator->GetGuildId()); if (calendarEvent->IsGuildAnnouncement()) { // 946684800 is 01/01/2000 00:00:00 - default response time CalendarInvite invite(0, calendarEvent->GetEventId(), ObjectGuid::Empty, guid, 946684800, CALENDAR_STATUS_NOT_SIGNED_UP, CALENDAR_RANK_PLAYER, ""); // WARNING: By passing pointer to a local variable, the underlying method(s) must NOT perform any kind // of storage of the pointer as it will lead to memory corruption sCalendarMgr->AddInvite(calendarEvent, &invite); } else { // client limits the amount of players to be invited to 100 const uint32 MaxPlayerInvites = 100; uint32 inviteCount; ObjectGuid invitee[MaxPlayerInvites]; uint8 status[MaxPlayerInvites]; uint8 rank[MaxPlayerInvites]; memset(status, 0, sizeof(status)); memset(rank, 0, sizeof(rank)); try { recvData >> inviteCount; for (uint32 i = 0; i < inviteCount && i < MaxPlayerInvites; ++i) { recvData >> invitee[i].ReadAsPacked(); recvData >> status[i] >> rank[i]; } } catch (ByteBufferException const&) { delete calendarEvent; calendarEvent = NULL; throw; } SQLTransaction trans; if (inviteCount > 1) trans = CharacterDatabase.BeginTransaction(); for (uint32 i = 0; i < inviteCount && i < MaxPlayerInvites; ++i) { // 946684800 is 01/01/2000 00:00:00 - default response time CalendarInvite* invite = new CalendarInvite(sCalendarMgr->GetFreeInviteId(), calendarEvent->GetEventId(), invitee[i], guid, 946684800, CalendarInviteStatus(status[i]), CalendarModerationRank(rank[i]), ""); sCalendarMgr->AddInvite(calendarEvent, invite, trans); } if (inviteCount > 1) CharacterDatabase.CommitTransaction(trans); } sCalendarMgr->AddEvent(calendarEvent, CALENDAR_SENDTYPE_ADD); }
void CalendarMgr::SendCalendarEvent(CalendarEvent const& calendarEvent, CalendarSendEventType type) { if (Player* player = ObjectAccessor::FindPlayer(calendarEvent.GetCreatorGUID())) player->GetSession()->SendCalendarEvent(calendarEvent, type); }
void WorldSession::HandleCalendarGetCalendar(WorldPacket& /*recvData*/) { uint64 guid = _player->GetGUID(); TC_LOG_DEBUG("network", "CMSG_CALENDAR_GET_CALENDAR [" UI64FMTD "]", guid); time_t currTime = time(NULL); uint32 counter = 0; CalendarInviteStore invites = sCalendarMgr->GetPlayerInvites(guid); CalendarEventStore playerEvents = sCalendarMgr->GetPlayerEvents(guid); ResetTimeByMapDifficultyMap const& resets = sInstanceSaveMgr->GetResetTimeMap(); ByteBuffer lockoutInfoBuffer; ByteBuffer invitesInfoBuffer; ByteBuffer eventsInfoBuffer; WorldPacket data(SMSG_CALENDAR_SEND_CALENDAR, 1000); // Average size if no instance size_t resetPos = data.bitwpos(); data.WriteBits(0, 20); // Reset placeholder data.WriteBits(0, 16); // Holidays -> f**k that shit... Necessary to find out when this should be sent size_t lockoutPos = data.bitwpos(); data.WriteBits(0, 20); // Lockout placeholder for (uint8 i = 0; i < MAX_DIFFICULTY; ++i) { Player::BoundInstancesMap boundInstances = _player->GetBoundInstances(Difficulty(i)); for (Player::BoundInstancesMap::const_iterator itr = boundInstances.begin(); itr != boundInstances.end(); ++itr) { if (itr->second.perm) { InstanceSave const* save = itr->second.save; ObjectGuid guid = save->GetInstanceId(); data.WriteBit(guid[6]); data.WriteBit(guid[7]); data.WriteBit(guid[2]); data.WriteBit(guid[1]); data.WriteBit(guid[5]); data.WriteBit(guid[4]); data.WriteBit(guid[0]); data.WriteBit(guid[3]); lockoutInfoBuffer << uint32(save->GetDifficulty()); lockoutInfoBuffer.WriteByteSeq(guid[3]); lockoutInfoBuffer.WriteByteSeq(guid[0]); lockoutInfoBuffer.WriteByteSeq(guid[1]); lockoutInfoBuffer.WriteByteSeq(guid[5]); lockoutInfoBuffer << uint32(save->GetResetTime() - currTime); lockoutInfoBuffer << uint32(save->GetMapId()); lockoutInfoBuffer.WriteByteSeq(guid[2]); lockoutInfoBuffer.WriteByteSeq(guid[7]); lockoutInfoBuffer.WriteByteSeq(guid[6]); lockoutInfoBuffer.WriteByteSeq(guid[4]); ++counter; } } } data.WriteBits(invites.size(), 19); for (CalendarInviteStore::const_iterator itr = invites.begin(); itr != invites.end(); ++itr) { CalendarEvent* calendarEvent = sCalendarMgr->GetEvent((*itr)->GetEventId()); ObjectGuid guid = (*itr)->GetSenderGUID(); data.WriteBit(guid[1]); data.WriteBit(guid[2]); data.WriteBit(guid[6]); data.WriteBit(guid[7]); data.WriteBit(guid[3]); data.WriteBit(guid[0]); data.WriteBit(guid[4]); data.WriteBit(guid[5]); invitesInfoBuffer.WriteByteSeq(guid[2]); invitesInfoBuffer << uint64((*itr)->GetInviteId()); invitesInfoBuffer << uint8((*itr)->GetStatus()); invitesInfoBuffer.WriteByteSeq(guid[6]); invitesInfoBuffer.WriteByteSeq(guid[3]); invitesInfoBuffer.WriteByteSeq(guid[4]); invitesInfoBuffer.WriteByteSeq(guid[1]); invitesInfoBuffer.WriteByteSeq(guid[0]); invitesInfoBuffer << uint64((*itr)->GetEventId()); invitesInfoBuffer.WriteByteSeq(guid[7]); invitesInfoBuffer.WriteByteSeq(guid[5]); invitesInfoBuffer << uint8((*itr)->GetRank()); invitesInfoBuffer << uint8((calendarEvent && calendarEvent->IsGuildEvent() && calendarEvent->GetGuildId() == _player->GetGuildId()) ? 1 : 0); } data.WriteBits(playerEvents.size(), 19); for (CalendarEventStore::const_iterator itr = playerEvents.begin(); itr != playerEvents.end(); ++itr) { CalendarEvent* calendarEvent = *itr; Guild* guild = sGuildMgr->GetGuildById(calendarEvent->GetGuildId()); ObjectGuid guildGuid = guild ? guild->GetGUID() : 0; ObjectGuid creatorGuid = calendarEvent->GetCreatorGUID(); data.WriteBit(creatorGuid[2]); data.WriteBit(guildGuid[1]); data.WriteBit(guildGuid[7]); data.WriteBit(creatorGuid[4]); data.WriteBit(guildGuid[5]); data.WriteBit(guildGuid[6]); data.WriteBit(guildGuid[3]); data.WriteBit(guildGuid[4]); data.WriteBit(creatorGuid[7]); data.WriteBits(calendarEvent->GetTitle().size(), 8); data.WriteBit(creatorGuid[1]); data.WriteBit(guildGuid[2]); data.WriteBit(guildGuid[0]); data.WriteBit(creatorGuid[0]); data.WriteBit(creatorGuid[3]); data.WriteBit(creatorGuid[6]); data.WriteBit(creatorGuid[5]); eventsInfoBuffer.WriteByteSeq(creatorGuid[5]); eventsInfoBuffer.WriteByteSeq(guildGuid[3]); eventsInfoBuffer.WriteString(calendarEvent->GetTitle()); eventsInfoBuffer.WriteByteSeq(guildGuid[7]); eventsInfoBuffer << int32(calendarEvent->GetDungeonId()); eventsInfoBuffer.WriteByteSeq(creatorGuid[0]); eventsInfoBuffer.WriteByteSeq(creatorGuid[4]); eventsInfoBuffer.WriteByteSeq(guildGuid[2]); eventsInfoBuffer.WriteByteSeq(creatorGuid[7]); eventsInfoBuffer.WriteByteSeq(creatorGuid[2]); eventsInfoBuffer.AppendPackedTime(calendarEvent->GetEventTime()); eventsInfoBuffer.WriteByteSeq(creatorGuid[3]); eventsInfoBuffer.WriteByteSeq(creatorGuid[1]); eventsInfoBuffer.WriteByteSeq(guildGuid[6]); eventsInfoBuffer.WriteByteSeq(guildGuid[1]); eventsInfoBuffer.WriteByteSeq(creatorGuid[6]); eventsInfoBuffer << uint32(calendarEvent->GetFlags()); eventsInfoBuffer.WriteByteSeq(guildGuid[4]); eventsInfoBuffer.WriteByteSeq(guildGuid[5]); eventsInfoBuffer.WriteByteSeq(guildGuid[0]); eventsInfoBuffer << uint64(calendarEvent->GetEventId()); eventsInfoBuffer << uint8(calendarEvent->GetType()); } data.FlushBits(); data.PutBits(lockoutPos, counter, 20); data.append(eventsInfoBuffer); data.append(lockoutInfoBuffer); data.append(invitesInfoBuffer); data.AppendPackedTime(currTime); // zone time counter = 0; std::set<uint32> sentMaps; 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 << int32(mapId); data << int32(itr->second - currTime); data << int32(0); // offset => found it different only once counter++; } data.PutBits(resetPos, counter, 20); data << uint32(1135753200); // Constant date, unk (28.12.2005 07:00) data << uint32(currTime); // server time SendPacket(&data); }
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; } }
//! [3] void EventEditor::saveEvent() { if (m_mode == CreateMode) { // Create a new event object CalendarEvent event; event.setAccountId(m_accountId); event.setFolderId(m_folderId); event.setSubject(m_subject); event.setLocation(m_location); event.setStartTime(m_startTime); event.setEndTime(m_endTime); // Save the event to persistent storage m_calendarService->createEvent(event); } else if (m_mode == EditMode) { // Load the event from persistent storage CalendarEvent event = m_calendarService->event(m_eventKey.accountId(), m_eventKey.eventId()); event.setSubject(m_subject); event.setLocation(m_location); event.setStartTime(m_startTime); event.setEndTime(m_endTime); // Save the updated event back to persistent storage m_calendarService->updateEvent(event); } }
void CalendarEvent::diff(const CalendarEvent &other) const { QDateTime thisStartTime = m_startTime; if (other.startTime().timeSpec() == Qt::TimeZone) thisStartTime.setTimeZone(other.startTime().timeZone()); QDateTime thisEndTime = m_endTime; if (other.endTime().timeSpec() == Qt::TimeZone) thisEndTime.setTimeZone(other.endTime().timeZone()); QDateTime thisReminder = m_reminder; if (other.reminder().timeSpec() == Qt::TimeZone) thisReminder.setTimeZone(other.reminder().timeZone()); if (m_id != other.id()) qDebug() << "id: " << m_id << " <> " << other.id(); if (m_title != other.title()) qDebug() << "title: " << m_title << " <> " << other.title(); if (m_description != other.description()) qDebug() << "description: " << m_description << " <> " << other.description(); if (thisStartTime != other.startTime()) qDebug() << "startTime: " << thisStartTime << " <> " << other.startTime(); if (thisEndTime != other.endTime()) qDebug() << "endTime: " << thisEndTime << " <> " << other.endTime(); if (thisReminder != other.reminder()) qDebug() << "reminder: " << thisReminder << " <> " << other.reminder(); if (m_location != other.location()) qDebug() << "location: " << m_location << " <> " << other.location(); if (m_calendar != other.calendar()) qDebug() << "calendar: " << m_calendar << " <> " << other.calendar(); if (m_comment != other.comment()) qDebug() << "comment: " << m_comment << " <> " << other.comment(); if (m_guests != other.guests()) qDebug() << "guests: " << m_guests << " <> " << other.guests(); if (m_recurring != other.recurring()) qDebug() << "recurring: " << m_recurring << " <> " << other.recurring(); if (m_isAllDay != other.isAllDay()) qDebug() << "isAllDay: " << m_isAllDay << " <> " << other.isAllDay(); }