Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
3.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: wrapper for GameEvent manager legacy support
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. // GameEventManager.cpp: implementation of the CGameEventManager class.
  9. //
  10. //////////////////////////////////////////////////////////////////////
  11. #include "GameEventManager.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. class CGameEventManagerOld : public IGameEventManager
  15. {
  16. public: // IGameEventManager wrapper
  17. int LoadEventsFromFile( const char * filename ) { return g_GameEventManager.LoadEventsFromFile( filename ); }
  18. KeyValues *GetEvent(const char * name);
  19. void Reset() { g_GameEventManager.Reset(); }
  20. bool AddListener( IGameEventListener * listener, const char * event, bool bIsServerSide );
  21. bool AddListener( IGameEventListener * listener, bool bIsServerSide );
  22. void RemoveListener(IGameEventListener * listener);
  23. bool FireEvent( KeyValues * event );
  24. bool FireEventClientOnly( KeyValues * event );
  25. bool FireEventServerOnly( KeyValues * event );
  26. bool SerializeKeyValues( KeyValues *event, bf_write *buf, CGameEvent *eventtype = NULL );
  27. KeyValues * UnserializeKeyValue( bf_read *msg ); // create new KeyValues, must be deleted
  28. protected:
  29. bool FireEventIntern( KeyValues * event, bool bServerSide, bool bClientSide );
  30. };
  31. static CGameEventManagerOld s_GameEventManagerOld;
  32. // Expose CVEngineServer to the engine.
  33. EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CGameEventManagerOld, IGameEventManager, INTERFACEVERSION_GAMEEVENTSMANAGER, s_GameEventManagerOld );
  34. bool CGameEventManagerOld::AddListener( IGameEventListener * listener, const char * event, bool bIsServerSide )
  35. {
  36. CGameEventDescriptor *descriptor = g_GameEventManager.GetEventDescriptor( event );
  37. if ( !descriptor )
  38. return false;
  39. if ( bIsServerSide )
  40. {
  41. return g_GameEventManager.AddListener( listener, descriptor, CGameEventManager::SERVERSIDE_OLD );
  42. }
  43. else
  44. {
  45. return g_GameEventManager.AddListener( listener, descriptor, CGameEventManager::CLIENTSIDE_OLD );
  46. }
  47. }
  48. bool CGameEventManagerOld::AddListener( IGameEventListener * listener, bool bIsServerSide )
  49. {
  50. if ( bIsServerSide )
  51. {
  52. return g_GameEventManager.AddListenerAll( listener, CGameEventManager::SERVERSIDE_OLD );
  53. }
  54. else
  55. {
  56. return g_GameEventManager.AddListenerAll( listener, CGameEventManager::CLIENTSIDE_OLD );
  57. }
  58. }
  59. void CGameEventManagerOld::RemoveListener(IGameEventListener * listener)
  60. {
  61. g_GameEventManager.RemoveListenerOld( listener );
  62. }
  63. KeyValues *CGameEventManagerOld::GetEvent(const char * name)
  64. {
  65. CGameEventDescriptor *event = g_GameEventManager.GetEventDescriptor( name );
  66. if ( !event )
  67. return NULL;
  68. return event->keys;
  69. }
  70. bool CGameEventManagerOld::FireEvent( KeyValues * event )
  71. {
  72. return FireEventIntern( event, false, false );
  73. }
  74. bool CGameEventManagerOld::FireEventClientOnly( KeyValues * event )
  75. {
  76. return FireEventIntern( event, false, true );
  77. }
  78. bool CGameEventManagerOld::FireEventServerOnly( KeyValues * event )
  79. {
  80. return FireEventIntern( event, true, false );
  81. }
  82. bool CGameEventManagerOld::FireEventIntern( KeyValues *keys, bool bServerSideOnly, bool bClientSideOnly )
  83. {
  84. if ( !keys )
  85. return false;
  86. CGameEvent *event = (CGameEvent*) g_GameEventManager.CreateEvent( keys->GetName() );
  87. if ( !event )
  88. return false;
  89. event->m_pDataKeys->deleteThis();
  90. event->m_pDataKeys = keys;
  91. if ( bClientSideOnly )
  92. {
  93. return g_GameEventManager.FireEventClientSide( event );
  94. }
  95. else
  96. {
  97. return g_GameEventManager.FireEvent( event, bServerSideOnly );
  98. }
  99. }
  100. bool CGameEventManagerOld::SerializeKeyValues( KeyValues* event, bf_write* buf, CGameEvent* eventtype )
  101. {
  102. DevMsg("SerializeKeyValues:: not supported\n");
  103. return false;
  104. }
  105. KeyValues *CGameEventManagerOld::UnserializeKeyValue( bf_read *buf)
  106. {
  107. DevMsg("UnserializeKeyValue:: not supported\n");
  108. return NULL;
  109. }