Team Fortress 2 Source Code as on 22/4/2020
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.

98 lines
3.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Holds the CGCClient class
  4. //
  5. //=============================================================================
  6. #ifndef GCCLIENT_H
  7. #define GCCLIENT_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "steam/steam_api.h"
  12. #include "jobmgr.h"
  13. #include "sharedobject.h"
  14. class ISteamGameCoordinator;
  15. struct GCMessageAvailable_t;
  16. class CTestEvent;
  17. namespace GCSDK
  18. {
  19. //-----------------------------------------------------------------------------
  20. // Purpose: base for CGCMsgHandler
  21. // used only by CGCMsgHandler, shouldn't be used directly
  22. //-----------------------------------------------------------------------------
  23. class CGCClient
  24. {
  25. public:
  26. CGCClient( ISteamGameCoordinator *pSteamGameCoordinator = NULL, bool bGameserver = false );
  27. virtual ~CGCClient( );
  28. bool BInit( ISteamGameCoordinator *pSteamGameCoordinator );
  29. void Uninit( );
  30. bool BMainLoop( uint64 ulLimitMicroseconds, uint64 ulFrameTimeMicroseconds = 0 );
  31. CJobMgr &GetJobMgr() { return m_JobMgr; }
  32. bool BSendMessage( uint32 unMsgType, const uint8 *pubData, uint32 cubData );
  33. bool BSendMessage( const CGCMsgBase& msg );
  34. bool BSendMessage( const CProtoBufMsgBase& msg );
  35. /// Locate a given shared object from the cache
  36. CSharedObject *FindSharedObject( const CSteamID & ownerID, const CSharedObject & soIndex );
  37. /// Find a shared object cache for the specified user. Optionally, the cache will be
  38. /// created if it doesn't not currently exist.
  39. CGCClientSharedObjectCache *FindSOCache( const CSteamID & steamID, bool bCreateIfMissing = true );
  40. /// Adds a listener to the shared object cache for the specified Steam ID.
  41. ///
  42. /// @see CGCClientSharedObjectCache::AddListener
  43. void AddSOCacheListener( const CSteamID &ownerID, ISharedObjectListener *pListener );
  44. /// Removes a listener for the shared object cache for the specified Steam ID.
  45. /// Returns true if we were listening and were successfully removed, false
  46. /// otherwise
  47. ///
  48. /// @see CGCClientSharedObjectCache::RemoveListener
  49. bool RemoveSOCacheListener( const CSteamID &ownerID, ISharedObjectListener *pListener );
  50. void OnGCMessageAvailable( GCMessageAvailable_t *pCallback );
  51. ISteamGameCoordinator *GetSteamGameCoordinator() { return m_pSteamGameCoordinator; }
  52. virtual void Test_AddEvent( CTestEvent *pEvent ) {}
  53. virtual void Test_CacheSubscribed( const CSteamID & steamID ) {}
  54. void NotifySOCacheUnsubscribed( const CSteamID & ownerID );
  55. void Dump();
  56. #ifdef DBGFLAG_VALIDATE
  57. static void ValidateStatics( CValidator &validator );
  58. #endif
  59. protected:
  60. ISteamGameCoordinator *m_pSteamGameCoordinator;
  61. CUtlMemory<uint8> m_memMsg;
  62. // local job handling
  63. CJobMgr m_JobMgr;
  64. // Shared object caches
  65. CUtlMap<CSteamID, CGCClientSharedObjectCache *> m_mapSOCache;
  66. // Steam callback for getting notified about messages available. Not part of the class
  67. // in Steam builds because we use the TestClientManager instead of steam_api.dll in Steam
  68. #ifndef STEAM
  69. CCallback< CGCClient, GCMessageAvailable_t, false > m_callbackGCMessageAvailable;
  70. #endif
  71. };
  72. } // namespace GCSDK
  73. #endif // GCCLIENT_H