core/EventManager.cpp
changeset 2883 1d7b415cef73
parent 2708 023e747a3bb1
child 3099 1b7bf8509625
     1.1 --- a/core/EventManager.cpp	Sat Dec 19 12:57:26 2009 -0800
     1.2 +++ b/core/EventManager.cpp	Sat Dec 19 18:16:41 2009 -0800
     1.3 @@ -1,5 +1,5 @@
     1.4  /**
     1.5 - * vim: set ts=4 :
     1.6 + * vim: set ts=4 sw=4 tw=99 noet :
     1.7   * =============================================================================
     1.8   * SourceMod
     1.9   * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
    1.10 @@ -42,6 +42,20 @@
    1.11  const ParamType GAMEEVENT_PARAMS[] = {Param_Cell, Param_String, Param_Cell};
    1.12  typedef List<EventHook *> EventHookList;
    1.13  
    1.14 +class EventForwardFilter : public IForwardFilter
    1.15 +{
    1.16 +	EventInfo *pEventInfo;
    1.17 +public:
    1.18 +	EventForwardFilter(EventInfo *pEventInfo) : pEventInfo(pEventInfo)
    1.19 +	{
    1.20 +	}
    1.21 +
    1.22 +	void Preprocess(IPluginFunction *fun, FwdParamInfo *params)
    1.23 +	{
    1.24 +		params[2].val = pEventInfo->bDontBroadcast ? 1 : 0;
    1.25 +	}
    1.26 +};
    1.27 +
    1.28  EventManager::EventManager() : m_EventType(0)
    1.29  {
    1.30  	/* Create an event lookup trie */
    1.31 @@ -327,6 +341,7 @@
    1.32  
    1.33  		pInfo->pEvent = pEvent;
    1.34  		pInfo->pOwner = pContext->GetIdentity();
    1.35 +		pInfo->bDontBroadcast = false;
    1.36  
    1.37  		return pInfo;
    1.38  	}
    1.39 @@ -365,6 +380,7 @@
    1.40  	IChangeableForward *pForward;
    1.41  	const char *name;
    1.42  	cell_t res = Pl_Continue;
    1.43 +	bool broadcast = bDontBroadcast;
    1.44  
    1.45  	/* The engine accepts NULL without crashing, so to prevent a crash in SM we ignore these */
    1.46  	if (!pEvent)
    1.47 @@ -390,10 +406,16 @@
    1.48  			HandleSecurity sec(NULL, g_pCoreIdent);
    1.49  			Handle_t hndl = g_HandleSys.CreateHandle(m_EventType, &info, NULL, g_pCoreIdent, NULL);
    1.50  
    1.51 +			info.bDontBroadcast = bDontBroadcast;
    1.52 +
    1.53 +			EventForwardFilter filter(&info);
    1.54 +
    1.55  			pForward->PushCell(hndl);
    1.56  			pForward->PushString(name);
    1.57  			pForward->PushCell(bDontBroadcast);
    1.58 -			pForward->Execute(&res, NULL);
    1.59 +			pForward->Execute(&res, &filter);
    1.60 +
    1.61 +			broadcast = info.bDontBroadcast;
    1.62  
    1.63  			g_HandleSys.FreeHandle(hndl, &sec);
    1.64  		}
    1.65 @@ -414,6 +436,9 @@
    1.66  		m_EventStack.push(NULL);
    1.67  	}
    1.68  
    1.69 +	if (broadcast != bDontBroadcast)
    1.70 +		RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, true, &IGameEventManager2::FireEvent, (pEvent, broadcast));
    1.71 +
    1.72  	RETURN_META_VALUE(MRES_IGNORED, true);
    1.73  }
    1.74  
    1.75 @@ -441,6 +466,7 @@
    1.76  		{
    1.77  			if (pHook->postCopy)
    1.78  			{
    1.79 +				info.bDontBroadcast = bDontBroadcast;
    1.80  				info.pEvent = m_EventCopies.front();
    1.81  				info.pOwner = NULL;
    1.82  				hndl = g_HandleSys.CreateHandle(m_EventType, &info, NULL, g_pCoreIdent, NULL);