@@ -113,6 +113,7 @@ extern void InitCommands();
113113extern void ClearAllCommands ();
114114extern PLUGIN_RESULT DispatchClientCommand (edict_t *pEntity, const CCommand &command);
115115extern CConVarChangedListenerManager* GetOnConVarChangedListenerManager ();
116+ extern CServerOutputListenerManager* GetOnServerOutputListenerManager ();
116117
117118// -----------------------------------------------------------------------------
118119// The plugin is a static singleton that is exported as an interface
@@ -188,100 +189,13 @@ bool GetInterfaces( InterfaceHelper_t* pInterfaceList, CreateInterfaceFn factory
188189}
189190
190191
191- // -----------------------------------------------------------------------------
192- // Server output hook.
193- // -----------------------------------------------------------------------------
194- #if defined(ENGINE_ORANGEBOX) || defined(ENGINE_BMS) || defined(ENGINE_GMOD)
195- SpewRetval_t SP_SpewOutput ( SpewType_t spewType, const tchar *pMsg )
196- {
197- bool block = false ;
198-
199- // Only filter outputs from the main thread. See issues #400 and #404.
200- if (ThreadInMainThread ()) {
201- extern CListenerManager* GetOnServerOutputListenerManager ();
202-
203- for (int i = 0 ; i < GetOnServerOutputListenerManager ()->m_vecCallables .Count (); i++)
204- {
205- BEGIN_BOOST_PY ()
206- object return_value = GetOnServerOutputListenerManager ()->m_vecCallables [i](
207- (MessageSeverity) spewType,
208- pMsg);
209-
210- if (!return_value.is_none () && extract<OutputReturn>(return_value) == OUTPUT_BLOCK)
211- block = true ;
212-
213- END_BOOST_PY_NORET ()
214- }
215- }
216-
217- if (!block && g_SourcePythonPlugin.m_pOldSpewOutputFunc )
218- return g_SourcePythonPlugin.m_pOldSpewOutputFunc (spewType, pMsg);
219-
220- return SPEW_CONTINUE;
221- }
222- #else
223- class SPLoggingListener : public ILoggingListener
224- {
225- public:
226- virtual void Log ( const LoggingContext_t *pContext, const tchar *pMessage )
227- {
228- bool block = false ;
229-
230- // Only filter outputs from the main thread. See issues #400 and #404.
231- if (ThreadInMainThread ()) {
232- extern CListenerManager* GetOnServerOutputListenerManager ();
233-
234- for (int i = 0 ; i < GetOnServerOutputListenerManager ()->m_vecCallables .Count (); i++)
235- {
236- BEGIN_BOOST_PY ()
237- object return_value = GetOnServerOutputListenerManager ()->m_vecCallables [i](
238- (MessageSeverity) pContext->m_Severity ,
239- pMessage);
240-
241- if (!return_value.is_none () && extract<OutputReturn>(return_value) == OUTPUT_BLOCK)
242- block = true ;
243-
244- END_BOOST_PY_NORET ()
245- }
246- }
247-
248- if (!block)
249- {
250- // Restore the old logging state before SP has been loaded
251- LoggingSystem_PopLoggingState (false );
252-
253- // Resend the log message. Our listener won't get called anymore
254- LoggingSystem_LogDirect (
255- pContext->m_ChannelID ,
256- pContext->m_Severity ,
257- pContext->m_Color ,
258- pMessage);
259-
260- // Create a new logging state with only our listener being active
261- #if defined(ENGINE_LEFT4DEAD2)
262- LoggingSystem_PushLoggingState (false );
263- #else
264- LoggingSystem_PushLoggingState (false , true );
265- #endif
266- LoggingSystem_RegisterLoggingListener (this );
267-
268- }
269- }
270- } g_LoggingListener;
271-
272- #endif
273-
274192// -----------------------------------------------------------------------------
275193// Purpose: constructor/destructor
276194// -----------------------------------------------------------------------------
277195CSourcePython::CSourcePython ()
278196{
279197 m_iClientCommandIndex = 0 ;
280198 m_pOldMDLCacheNotifier = NULL ;
281-
282- #if defined(ENGINE_ORANGEBOX) || defined(ENGINE_BMS) || defined(ENGINE_GMOD)
283- m_pOldSpewOutputFunc = NULL ;
284- #endif
285199}
286200
287201CSourcePython::~CSourcePython ()
@@ -336,22 +250,6 @@ bool CSourcePython::Load( CreateInterfaceFn interfaceFactory, CreateInterfaceFn
336250 return false ;
337251 }
338252
339- #if defined(ENGINE_ORANGEBOX) || defined(ENGINE_BMS) || defined(ENGINE_GMOD)
340- DevMsg (1 , MSG_PREFIX " Retrieving old output function...\n " );
341- m_pOldSpewOutputFunc = GetSpewOutputFunc ();
342-
343- DevMsg (1 , MSG_PREFIX " Setting new output function...\n " );
344- SpewOutputFunc (SP_SpewOutput);
345- #else
346- DevMsg (1 , MSG_PREFIX " Registering logging listener...\n " );
347- #if defined(ENGINE_LEFT4DEAD2)
348- LoggingSystem_PushLoggingState (false );
349- #else
350- LoggingSystem_PushLoggingState (false , true );
351- #endif
352- LoggingSystem_RegisterLoggingListener (&g_LoggingListener);
353- #endif
354-
355253 // TODO: Don't hardcode the 64 bytes offset
356254#ifdef ENGINE_LEFT4DEAD2
357255 #define CACHE_NOTIFY_OFFSET 68
@@ -383,17 +281,6 @@ void CSourcePython::Unload( void )
383281{
384282 Msg (MSG_PREFIX " Unloading...\n " );
385283
386- #if defined(ENGINE_ORANGEBOX) || defined(ENGINE_BMS) || defined(ENGINE_GMOD)
387- if (m_pOldSpewOutputFunc)
388- {
389- DevMsg (1 , MSG_PREFIX " Restoring old output function...\n " );
390- SpewOutputFunc (m_pOldSpewOutputFunc);
391- }
392- #else
393- DevMsg (1 , MSG_PREFIX " Restoring old logging state...\n " );
394- LoggingSystem_PopLoggingState (false );
395- #endif
396-
397284 DevMsg (1 , MSG_PREFIX " Resetting cache notifier...\n " );
398285 modelcache->SetCacheNotify (m_pOldMDLCacheNotifier);
399286
@@ -403,6 +290,9 @@ void CSourcePython::Unload( void )
403290 DevMsg (1 , MSG_PREFIX " Clearing convar changed listener...\n " );
404291 GetOnConVarChangedListenerManager ()->clear ();
405292
293+ DevMsg (1 , MSG_PREFIX " Clearing server output listeners...\n " );
294+ GetOnServerOutputListenerManager ()->clear ();
295+
406296 DevMsg (1 , MSG_PREFIX " Unhooking all functions...\n " );
407297 GetHookManager ()->UnhookAllFunctions ();
408298
0 commit comments