示例#1
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.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;
    }

}
示例#2
0
// 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();
}