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.

143 lines
4.6 KiB

  1. //====== Copyright �, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: Holds the CGCSession class
  4. //
  5. //=============================================================================
  6. #ifndef GCSESSION_H
  7. #define GCSESSION_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. namespace GCSDK
  12. {
  13. class CGCGSSession;
  14. //-----------------------------------------------------------------------------
  15. // Purpose: Base class for sessions in the GC
  16. //-----------------------------------------------------------------------------
  17. class CGCSession
  18. {
  19. public:
  20. CGCSession( const CSteamID & steamID, CGCSharedObjectCache *pCache );
  21. virtual ~CGCSession();
  22. const CSteamID & GetSteamID() const { return m_steamID; }
  23. const CGCSharedObjectCache *GetSOCache() const { return m_pSOCache; }
  24. CGCSharedObjectCache *GetSOCache() { return m_pSOCache; }
  25. void RemoveSOCache() { m_pSOCache = NULL; }
  26. EOSType GetOSType() const;
  27. bool IsTestSession() const;
  28. uint32 GetIPPublic() const;
  29. bool BIsShuttingDown() const { return m_bIsShuttingDown; }
  30. void SetIsShuttingDown( bool bIsShuttingDown ) { m_bIsShuttingDown = bIsShuttingDown; }
  31. virtual void Dump( bool bFull = true ) const = 0;
  32. virtual void MarkAccess() { }
  33. virtual void Run();
  34. virtual void YieldingSOCacheReloaded() {}
  35. #ifdef DBGFLAG_VALIDATE
  36. virtual void Validate( CValidator &validator, const char *pchName );
  37. #endif // DBGFLAG_VALIDATE
  38. private:
  39. CSteamID m_steamID;
  40. CGCSharedObjectCache *m_pSOCache;
  41. uint32 m_unIPPublic;
  42. EOSType m_osType : 16;
  43. bool m_bIsShuttingDown : 1;
  44. bool m_bIsTestSession : 1;
  45. friend class CGCBase;
  46. };
  47. //-----------------------------------------------------------------------------
  48. // Purpose: Base class for user sessions in the GC
  49. //-----------------------------------------------------------------------------
  50. class CGCUserSession : public CGCSession
  51. {
  52. public:
  53. CGCUserSession( const CSteamID & steamID, CGCSharedObjectCache *pCache ) : CGCSession( steamID, pCache ) { }
  54. virtual ~CGCUserSession();
  55. virtual bool BInit();
  56. const CSteamID &GetSteamIDGS() const { return m_steamIDGS; }
  57. const CSteamID &GetSteamIDGSPrev() const { return m_steamIDGSPrev; }
  58. virtual bool BSetServer( const CSteamID &steamIDGS );
  59. virtual bool BLeaveServer();
  60. virtual void Dump( bool bFull = true ) const;
  61. private:
  62. CSteamID m_steamIDGS;
  63. CSteamID m_steamIDGSPrev;
  64. };
  65. //-----------------------------------------------------------------------------
  66. // Purpose: Base class for gameserver sessions in the GC
  67. //-----------------------------------------------------------------------------
  68. class CGCGSSession : public CGCSession
  69. {
  70. public:
  71. CGCGSSession( const CSteamID & steamID, CGCSharedObjectCache *pCache, uint32 unServerAddr, uint16 usServerPort ) ;
  72. virtual ~CGCGSSession();
  73. uint32 GetAddr() const { return m_unServerAddr; }
  74. uint16 GetPort() const { return m_usServerPort; }
  75. void SetIPAndPort( uint32 unServerAddr, uint16 usServerPort ) { m_unServerAddr = unServerAddr; m_usServerPort = usServerPort; }
  76. int GetUserCount() const { return m_vecUsers.Count(); }
  77. const CSteamID &GetUserID( int nIndex ) const { return m_vecUsers[nIndex]; }
  78. // Manages users on the server. It is very important that these are not
  79. // virtual and not yielding. For custom behavior override the Pre*() hooks below
  80. bool BAddUser( const CSteamID &steamIDUser );
  81. bool BRemoveUser( const CSteamID &steamIDUser );
  82. void RemoveAllUsers();
  83. virtual void Dump( bool bFull = true ) const;
  84. protected:
  85. // Hooks to trigger custom behavior when users are added and removed. It is
  86. // very important that these do not yield. If you need to yield, start a job instead
  87. virtual void PreAddUser( const CSteamID &steamIDUser ) {}
  88. virtual void PostAddUser( const CSteamID &steamIDUser ) {}
  89. virtual void PreRemoveUser( const CSteamID &steamIDUser ) {}
  90. virtual void PostRemoveUser( const CSteamID &steamIDUser ) {}
  91. virtual void PreRemoveAllUsers() {}
  92. virtual void PostRemoveAllUsers() {}
  93. public:
  94. // These are the addresses the server itself told us
  95. uint32 m_unServerPublicIPAddr;
  96. uint32 m_unServerPrivateIPAddr;
  97. uint32 m_unServerPort;
  98. uint16 m_unServerTVPort;
  99. CUtlString m_serverKey;
  100. bool m_bServerHibernating;
  101. int m_serverType;
  102. int m_region;
  103. #ifdef DBGFLAG_VALIDATE
  104. virtual void Validate( CValidator &validator, const char *pchName );
  105. #endif // DBGFLAG_VALIDATE
  106. protected:
  107. CUtlVector<CSteamID> m_vecUsers;
  108. // These are the address of the server as connected to Steam
  109. uint32 m_unServerAddr;
  110. uint16 m_usServerPort;
  111. };
  112. } // namespace GCSDK
  113. #endif // GCSESSION_H