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.

159 lines
4.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef SESSION_H
  7. #define SESSION_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "engine/imatchmaking.h"
  12. #include "ixboxsystem.h"
  13. #include "const.h"
  14. #include "net.h"
  15. // valid session states
  16. enum SESSION_STATE
  17. {
  18. SESSION_STATE_NONE,
  19. SESSION_STATE_CREATING,
  20. SESSION_STATE_MIGRATING,
  21. SESSION_STATE_IDLE,
  22. SESSION_STATE_WAITING_FOR_REGISTRATION,
  23. SESSION_STATE_REGISTERING,
  24. SESSION_STATE_REGISTERED,
  25. SESSION_STATE_STARTING,
  26. SESSION_STATE_IN_GAME,
  27. SESSION_STATE_ENDING,
  28. SESSION_STATE_FINISHED,
  29. SESSION_STATE_DELETING
  30. };
  31. // slot types for the session
  32. enum SLOTS
  33. {
  34. SLOTS_TOTALPUBLIC,
  35. SLOTS_TOTALPRIVATE,
  36. SLOTS_FILLEDPUBLIC,
  37. SLOTS_FILLEDPRIVATE,
  38. SLOTS_LAST
  39. };
  40. class CClientInfo
  41. {
  42. public:
  43. uint64 m_id; // machine id
  44. netadr_t m_adr; // IP and Port
  45. XNADDR m_xnaddr; // XNADDR
  46. XUID m_xuids[MAX_PLAYERS_PER_CLIENT]; // XUIDs
  47. bool m_bInvited; // use private slots
  48. bool m_bRegistered; // registered for arbitration
  49. bool m_bMigrated; // successfully completed migration
  50. bool m_bModified; // completed session modification
  51. bool m_bReportedStats; // reported session stats to Live
  52. bool m_bLoaded; // map load is complete
  53. byte m_cVoiceState[MAX_PLAYERS_PER_CLIENT]; // has voice permission
  54. char m_cPlayers; // number of players on this client
  55. char m_iControllers[MAX_PLAYERS_PER_CLIENT]; // the controller (user index) for each player
  56. char m_iTeam[MAX_PLAYERS_PER_CLIENT]; // each player's team
  57. char m_szGamertags[MAX_PLAYERS_PER_CLIENT][MAX_PLAYER_NAME_LENGTH];
  58. char mutable m_numPrivateSlotsUsed; // number of private slots used by this client if invited
  59. CClientInfo()
  60. {
  61. Clear();
  62. }
  63. void Clear()
  64. {
  65. Q_memset( this, 0, sizeof( CClientInfo ) );
  66. Q_memset( &m_iTeam, -1, sizeof( m_iTeam ) );
  67. }
  68. };
  69. class CMatchmaking;
  70. class CSession
  71. {
  72. public:
  73. CSession();
  74. ~CSession();
  75. void ResetSession();
  76. void SetParent( CMatchmaking *pParent );
  77. void RunFrame();
  78. bool CreateSession();
  79. void CancelCreateSession();
  80. void DestroySession();
  81. void RegisterForArbitration();
  82. bool MigrateHost();
  83. void JoinLocal( const CClientInfo *pClient );
  84. void JoinRemote( const CClientInfo *pClient );
  85. void RemoveLocal( const CClientInfo *pClient );
  86. void RemoveRemote( const CClientInfo *pClient );
  87. // Accessors
  88. HANDLE GetSessionHandle();
  89. void SetSessionInfo( XSESSION_INFO *pInfo );
  90. void SetNewSessionInfo( XSESSION_INFO *pInfo );
  91. void GetSessionInfo( XSESSION_INFO *pInfo );
  92. void GetNewSessionInfo( XSESSION_INFO *pInfo );
  93. void SetSessionNonce( int64 nonce );
  94. uint64 GetSessionNonce();
  95. XNKID GetSessionId();
  96. void SetSessionSlots( unsigned int nSlot, unsigned int nPlayers );
  97. uint GetSessionSlots( unsigned int nSlot );
  98. void SetSessionFlags( uint flags );
  99. uint GetSessionFlags();
  100. int GetPlayerCount();
  101. void SetFlag( uint dwFlag );
  102. void SetIsHost( bool bHost );
  103. void SetIsSystemLink( bool bSystemLink );
  104. void SetOwnerId( uint id );
  105. bool IsHost();
  106. bool IsFull();
  107. bool IsArbitrated();
  108. bool IsSystemLink();
  109. void SwitchToState( SESSION_STATE newState );
  110. void SetContext( const uint nContextId, const uint nContextValue, const bool bAsync = true );
  111. void SetProperty( const uint nPropertyId, const uint cbValue, const void *pvValue, const bool bAsync = true );
  112. XSESSION_REGISTRATION_RESULTS *GetRegistrationResults() { return m_pRegistrationResults; }
  113. private:
  114. // Update functions
  115. void UpdateCreating();
  116. void UpdateMigrating();
  117. void UpdateRegistering();
  118. void SendNotification( SESSION_NOTIFY notification );
  119. void UpdateSlots( const CClientInfo *pClient, bool bAddPlayers );
  120. double GetTime();
  121. HANDLE m_hSession; // Session handle
  122. bool m_bIsHost; // Is hosting
  123. bool m_bIsArbitrated; // Is Arbitrated
  124. bool m_bUsingQoS; // Is the QoS listener enabled
  125. bool m_bIsSystemLink; // Is this a system link session
  126. XSESSION_INFO m_SessionInfo; // Session ID, key, and host address
  127. XSESSION_INFO m_NewSessionInfo; // Session ID, key, and host address
  128. uint64 m_SessionNonce; // Nonce of the session
  129. uint m_nSessionFlags; // Session creation flags
  130. uint m_nOwnerId; // Which player created the session
  131. uint m_SessionState;
  132. double m_fOperationStartTime;
  133. CMatchmaking *m_pParent;
  134. AsyncHandle_t m_hCreateHandle;
  135. AsyncHandle_t m_hMigrateHandle;
  136. AsyncHandle_t m_hRegisterHandle;
  137. XSESSION_REGISTRATION_RESULTS *m_pRegistrationResults;
  138. // public/private slots for the session
  139. uint m_nPlayerSlots[SLOTS_LAST];
  140. };
  141. #endif // SESSION_H