Example #1
0
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;
}
Example #2
0
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;
}
Example #3
0
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;
}
Example #4
0
void CalendarMgr::SendCalendarEventModeratorStatusAlert(CalendarInvite const& invite)
{
    if (Player* player = ObjectAccessor::FindPlayer(invite.GetInvitee()))
        player->GetSession()->SendCalendarEventModeratorStatusAlert(invite);
}
Example #5
0
void CalendarMgr::SendCalendarEventInviteAlert(CalendarEvent const& calendarEvent, CalendarInvite const& invite)
{
    if (Player* player = ObjectAccessor::FindPlayer(invite.GetInvitee()))
        player->GetSession()->SendCalendarEventInviteAlert(calendarEvent, invite);
}
Example #6
0
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.GetPlayer(), 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.GetPlayer(), 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.GetPlayer()->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();
            // FIXME - Use of Flags here!

            CalendarEvent* calendarEvent = CheckPermisions(eventId, action.GetPlayer(), 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.GetPlayer(), 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.GetPlayer(), action.GetInviteId(), CALENDAR_RANK_MODERATOR);

            if (!calendarEvent || !(calendarEvent->GetFlags() & CALENDAR_FLAG_GUILD_ONLY)
                || !calendarEvent->GetGuildId() || calendarEvent->GetGuildId() != action.GetExtraData())
                return;

            CalendarInviteStatus 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.GetPlayer()->GetGUID());
            newInvite.SetSenderGUID(action.GetPlayer()->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 = NULL;
            if (action.GetInviteId() != action.Invite.GetInviteId())
                calendarEvent = CheckPermisions(eventId, action.GetPlayer(), 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 = NULL;
            if (action.GetInviteId() != action.Invite.GetInviteId())
                calendarEvent = CheckPermisions(eventId, action.GetPlayer(), action.GetInviteId(), CALENDAR_RANK_OWNER);
            else
                calendarEvent = GetEvent(eventId);

            CalendarInvite* invite = GetInvite(inviteId);

            if (!calendarEvent || !invite || !calendarEvent->HasInvite(inviteId))
                return;

            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.GetPlayer(), action.GetInviteId(), CALENDAR_RANK_MODERATOR);
            if (!calendarEvent)
                return;

            // already checked in CheckPermisions
            CalendarInvite* invite = GetInvite(inviteId);
            if (!invite)
                return;

            if (calendarEvent->GetCreatorGUID() == invite->GetInvitee())
            {
                action.GetPlayer()->GetSession()->SendCalendarCommandResult(CALENDAR_ERROR_DELETE_CREATOR_FAILED);
                return;
            }

            if (uint64 invitee = RemoveInvite(inviteId))
            {
                SendCalendarEventInviteRemoveAlert(invitee, *calendarEvent, CALENDAR_STATUS_9);
                SendCalendarEventInviteRemove(action.GetPlayer()->GetGUID(), action.Invite, calendarEvent->GetFlags());
            }
            break;
        }
        default:
            break;
    }
}