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.

193 lines
3.8 KiB

  1. //===== Copyright � 1996-2009, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #ifndef X360_XLSP_CMD_H
  7. #define X360_XLSP_CMD_H
  8. #ifdef _X360
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. struct CXlspDatacenter;
  13. class CXlspTitleServers;
  14. class CXlspConnection;
  15. class CJob;
  16. //
  17. // Datacenter info
  18. //
  19. struct CXlspDatacenter
  20. {
  21. XTITLE_SERVER_INFO m_xsi;
  22. XNQOSINFO m_qos;
  23. char m_szGatewayName[ XTITLE_SERVER_MAX_SERVER_INFO_LEN ];
  24. int m_nMasterServerPortStart;
  25. int m_numMasterServers;
  26. int m_nPingBucket;
  27. bool m_bSupportsPII;
  28. IN_ADDR m_adrSecure;
  29. static int Compare( CXlspDatacenter const *dc1, CXlspDatacenter const *dc2 );
  30. bool ParseServerInfo();
  31. void Destroy();
  32. };
  33. class CXlspTitleServers : public IDormantOperation
  34. {
  35. public:
  36. explicit CXlspTitleServers( int nPingLimit, bool bMustSupportPII );
  37. ~CXlspTitleServers();
  38. public:
  39. bool IsSearchCompleted() const;
  40. CUtlVector< CXlspDatacenter > & GetDatacenters();
  41. void Update();
  42. void Destroy();
  43. public:
  44. virtual bool UpdateDormantOperation();
  45. protected:
  46. bool EnumerateDcs( HANDLE &hEnumerate, XOVERLAPPED &xOverlapped, CUtlBuffer &bufResults );
  47. bool ExecuteQosDcs( HANDLE &hEnumerate, XOVERLAPPED &xOverlapped, CUtlBuffer &bufResults, DWORD &numServers, XNQOS *&pQos );
  48. void ParseDatacentersFromQos( CUtlVector< CXlspDatacenter > &arrDcs, CUtlBuffer &bufResults, XNQOS *&pQos );
  49. protected:
  50. enum State_t
  51. {
  52. STATE_INIT,
  53. STATE_XLSP_ENUMERATE_DCS,
  54. STATE_XLSP_QOS_DCS,
  55. STATE_FINISHED
  56. };
  57. State_t m_eState;
  58. HANDLE m_hEnumerate;
  59. XOVERLAPPED m_xOverlapped;
  60. CUtlBuffer m_bufXlspEnumerateDcs;
  61. DWORD m_numServers;
  62. XNQOS *m_pQos;
  63. float m_flTimeout;
  64. int m_nPingLimit;
  65. bool m_bMustSupportPII;
  66. CJob *m_pCancelOverlappedJob;
  67. CUtlVector< CXlspDatacenter > m_arrDcs;
  68. };
  69. //
  70. // XLSP Connection
  71. //
  72. class CXlspConnection : public IMatchEventsSink
  73. {
  74. public:
  75. explicit CXlspConnection( bool bMustSupportPII );
  76. protected:
  77. virtual ~CXlspConnection();
  78. public:
  79. bool IsConnected() const;
  80. bool HasError() const;
  81. CXlspDatacenter const & GetDatacenter() const;
  82. bool ExecuteCmd( KeyValues *pCommand, int numRetriesAllowed = 0, float flCmdRetryTimeout = 0 );
  83. KeyValues * GetCmdResult() const { return m_pCmdResult; }
  84. virtual void Update();
  85. virtual void Destroy();
  86. public:
  87. void ResolveCmdSystemValues( KeyValues *pCommand );
  88. // IMatchEventsSink
  89. protected:
  90. virtual void OnEvent( KeyValues *pEvent );
  91. protected:
  92. void ConnectXlspDc();
  93. protected:
  94. netadr_t GetXlspDcAddress();
  95. enum State_t
  96. {
  97. STATE_INIT,
  98. STATE_CONNECTING, // INIT -> CONNECTING -> CONNECTED
  99. STATE_CONNECTED,
  100. STATE_RUNNINGCMD, // CONNECTED -> RUNNINGCMD -> CONNECTED
  101. STATE_ERROR
  102. };
  103. State_t m_eState;
  104. //
  105. // XLSP datacenters information
  106. //
  107. CXlspTitleServers *m_pTitleServers;
  108. CXlspDatacenter m_dc;
  109. int m_idCmdReplyId;
  110. CUtlVector< char > m_bufCmdRetry;
  111. int m_numCmdRetriesAllowed;
  112. float m_flCmdRetryTimeout;
  113. KeyValues *m_pCmdResult;
  114. float m_flTimeout;
  115. bool m_bMustSupportPII;
  116. };
  117. class CXlspConnectionCmdBatch
  118. {
  119. public:
  120. CXlspConnectionCmdBatch( CXlspConnection *pConnection, CUtlVector< KeyValues * > &arrCommands, int numRetriesAllowedPerEachCmd = 0, float flCommandTimeout = 0.0f );
  121. protected:
  122. virtual ~CXlspConnectionCmdBatch();
  123. public:
  124. bool IsFinished() const;
  125. bool HasAllResults() const;
  126. CUtlVector< KeyValues * > &GetResults() { return m_arrResults; }
  127. public:
  128. virtual void Update();
  129. virtual void Destroy();
  130. protected:
  131. void RunNextCmd();
  132. protected:
  133. CUtlVector< KeyValues * > m_arrCommands;
  134. CUtlVector< KeyValues * > m_arrResults;
  135. enum State_t
  136. {
  137. STATE_BATCH_WAITING,
  138. STATE_RUNNINGCMD,
  139. STATE_FINISHED
  140. };
  141. State_t m_eState;
  142. int m_iCommand;
  143. CXlspConnection *m_pXlspConn;
  144. int m_numRetriesAllowedPerEachCmd;
  145. float m_flCommandTimeout;
  146. };
  147. #endif // _X360
  148. #endif // X360_XLSP_CMD_H