예제 #1
0
void RemoveAllEvents(int event_type)
{
	MoveEvents();
	RemoveEvent(event_type);
}
예제 #2
0
void RemoveAllEvents(int event_type)
{
    RemoveThreadsafeEvent(event_type);
    RemoveEvent(event_type);
}
예제 #3
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;
    }

}
예제 #4
0
파일: cbase.cpp 프로젝트: paralin/hl2sdk
//-----------------------------------------------------------------------------
// Purpose: fires off any events in the queue who's fire time is (or before) the present time
//-----------------------------------------------------------------------------
void CEventQueue::ServiceEvents( void )
{
	if (!CBaseEntity::Debug_ShouldStep())
	{
		return;
	}

	EventQueuePrioritizedEvent_t *pe = m_Events.m_pNext;

	while ( pe != NULL && pe->m_flFireTime <= gpGlobals->curtime )
	{
		MDLCACHE_CRITICAL_SECTION();

		bool targetFound = false;

		// find the targets
		if ( pe->m_iTarget != NULL_STRING )
		{
			// In the context the event, the searching entity is also the caller
			CBaseEntity *pSearchingEntity = pe->m_pCaller;
			CBaseEntity *target = NULL;
			while ( 1 )
			{
				target = gEntList.FindEntityByName( target, pe->m_iTarget, pSearchingEntity, pe->m_pActivator, pe->m_pCaller );
				if ( !target )
					break;

				// pump the action into the target
				target->AcceptInput( STRING(pe->m_iTargetInput), pe->m_pActivator, pe->m_pCaller, pe->m_VariantValue, pe->m_iOutputID );
				targetFound = true;
			}
		}

		// direct pointer
		if ( pe->m_pEntTarget != NULL )
		{
			pe->m_pEntTarget->AcceptInput( STRING(pe->m_iTargetInput), pe->m_pActivator, pe->m_pCaller, pe->m_VariantValue, pe->m_iOutputID );
			targetFound = true;
		}

		if ( !targetFound )
		{
			// See if we can find a target if we treat the target as a classname
			if ( pe->m_iTarget != NULL_STRING )
			{
				CBaseEntity *target = NULL;
				while ( 1 )
				{
					target = gEntList.FindEntityByClassname( target, STRING(pe->m_iTarget) );
					if ( !target )
						break;

					// pump the action into the target
					target->AcceptInput( STRING(pe->m_iTargetInput), pe->m_pActivator, pe->m_pCaller, pe->m_VariantValue, pe->m_iOutputID );
					targetFound = true;
				}
			}
		}

		if ( !targetFound )
		{
			const char *pClass ="", *pName = "";
			
			// might be NULL
			if ( pe->m_pCaller )
			{
				pClass = STRING(pe->m_pCaller->m_iClassname);
				pName = STRING(pe->m_pCaller->GetEntityName());
			}
			
			char szBuffer[256];
			Q_snprintf( szBuffer, sizeof(szBuffer), "unhandled input: (%s) -> (%s), from (%s,%s); target entity not found\n", STRING(pe->m_iTargetInput), STRING(pe->m_iTarget), pClass, pName );
			DevMsg( 2, szBuffer );
			ADD_DEBUG_HISTORY( HISTORY_ENTITY_IO, szBuffer );
		}

		// remove the event from the list (remembering that the queue may have been added to)
		RemoveEvent( pe );
		delete pe;

		//
		// If we are in debug mode, exit the loop if we have fired the correct number of events.
		//
		if (CBaseEntity::Debug_IsPaused())
		{
			if (!CBaseEntity::Debug_Step())
			{
				break;
			}
		}

		// restart the list (to catch any new items have probably been added to the queue)
		pe = m_Events.m_pNext;	
	}
}
예제 #5
0
BOOLEAN	DequeAllGameEvents( BOOLEAN fExecute )
{
	EVENT					*pEvent;
	UINT32				uiQueueSize, cnt;
	BOOLEAN				fCompleteLoop = FALSE;
	// First dequeue all primary events


	while( EventQueueSize( PRIMARY_EVENT_QUEUE ) > 0 )
	{
		// Get Event
		if ( RemoveEvent( &pEvent, 0, PRIMARY_EVENT_QUEUE) == FALSE )
		{
			return( FALSE );
		}

		if ( fExecute )
		{
			// Check if event has a delay and add to secondary queue if so
			if ( pEvent->usDelay > 0 )
			{
				AddGameEventToQueue( pEvent->uiEvent, pEvent->usDelay, pEvent->pData, SECONDARY_EVENT_QUEUE );
			}
			else
			{
				ExecuteGameEvent( pEvent );
			}
		}

		// Delete event
		FreeEvent( pEvent );

	};

	// NOW CHECK SECONDARY QUEUE FOR ANY EXPRIED EVENTS
	// Get size of queue
	uiQueueSize = EventQueueSize( SECONDARY_EVENT_QUEUE );

	for ( cnt = 0; cnt < uiQueueSize; cnt++ )
	{
		if ( PeekEvent( &pEvent, cnt, SECONDARY_EVENT_QUEUE) == FALSE )
		{
			return( FALSE );
		}

		// Check time
		if ( ( GetJA2Clock() - pEvent->TimeStamp ) > pEvent->usDelay )
		{
			if ( fExecute )
			{
				ExecuteGameEvent( pEvent );
			}

			// FLag as expired
			pEvent->uiFlags = EVENT_EXPIRED;

		}

	}

	do
	{
		uiQueueSize = EventQueueSize( SECONDARY_EVENT_QUEUE );

		for ( cnt = 0; cnt < uiQueueSize; cnt++ )
		{
			if ( PeekEvent( &pEvent, cnt, SECONDARY_EVENT_QUEUE) == FALSE )
			{
				return( FALSE );
			}

			// Check time
			if ( pEvent->uiFlags & EVENT_EXPIRED )
			{
				RemoveEvent( &pEvent, cnt, SECONDARY_EVENT_QUEUE );
				FreeEvent( pEvent );
				// Restart loop
				break;

			}

		}

		if ( cnt == uiQueueSize )
		{
			fCompleteLoop = TRUE;
		}

	} while( fCompleteLoop == FALSE );

	return( TRUE );
}