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.

475 lines
18 KiB

  1. //========= Copyright � 1996-2004, Valve LLC, All rights reserved. ============
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #ifndef STEAMCLIENTPUBLIC_H
  8. #define STEAMCLIENTPUBLIC_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. //lint -save -e1931 -e1927 -e1924 -e613 -e726
  13. // This header file defines the interface between the calling application and the code that
  14. // knows how to communicate with the connection manager (CM) from the Steam service
  15. // This header file is intended to be portable; ideally this 1 header file plus a lib or dll
  16. // is all you need to integrate the client library into some other tree. So please avoid
  17. // including or requiring other header files if possible. This header should only describe the
  18. // interface layer, no need to include anything about the implementation.
  19. #include "steamtypes.h"
  20. #ifndef NETADR_H
  21. class netadr_t;
  22. #endif
  23. class ICMInterface; // forward declaration
  24. class ICMCallback; // forward declaration
  25. class IVConnCallback; // forward declaration
  26. extern "C" {
  27. ICMInterface * CreateCMInterface( ICMCallback * pCMCallback ); // global function to create an interface object
  28. typedef ICMInterface * (* LPCREATECMINTERFACEPROC)( ICMCallback * ); // typedef for function pointer (for GetProcAddress)
  29. void DestroyCMInterface( ICMInterface * pCMInterface ); // global function to destroy and free an interface object
  30. typedef void (* LPDESTROYCMINTERFACEPROC)( ICMInterface * ); // typedef for function pointer (for GetProcAddress)
  31. }
  32. // General result codes
  33. enum EResult
  34. {
  35. k_EResultOK = 1, // success
  36. k_EResultFail = 2, // generic failure
  37. k_EResultNoConnection = 3, // no/failed network connection
  38. k_EResultNoConnectionRetry = 4, // no/failed network connection, will retry
  39. k_EResultInvalidPassword = 5, // password/ticket is invalid
  40. k_EResultLoggedInElsewhere = 6, // same user logged in elsewhere
  41. k_EResultInvalidProtocolVer = 7, // protocol version is incorrect
  42. k_EResultInvalidParam = 8, // a parameter is incorrect
  43. k_EResultFileNotFound = 9, // file was not found
  44. k_EResultBusy = 10, // called method busy - action not taken
  45. k_EResultInvalidState = 11, // called object was in an invalid state
  46. k_EResultInvalidName = 12, // name is invalid
  47. k_EResultInvalidEmail = 13, // email is invalud
  48. k_EResultDuplicateName = 14, // name is not unique
  49. k_EResultAccessDenied = 15, // access is denied
  50. k_EResultTimeout = 16, // operation timed out
  51. };
  52. // Result codes to GSHandleClientDeny/Kick
  53. typedef enum
  54. {
  55. k_EDenyInvalidVersion = 1,
  56. k_EDenyGeneric,
  57. k_EDenyNotLoggedOn,
  58. k_EDenyNoLicense,
  59. k_EDenyCheater,
  60. } EDenyReason;
  61. // Server flags.
  62. const uint k_unServerFlagNone = 0;
  63. const uint k_unServerFlagActive = 1;
  64. const uint k_unServerFlagInsecure = 2;
  65. // Steam universes. Each universe is a self-contained Steam instance.
  66. enum EUniverse
  67. {
  68. k_EUniverseInvalid = 0,
  69. k_EUniversePublic = 1,
  70. k_EUniverseTestPublic = 2,
  71. k_EUniverseInternal = 3,
  72. k_EUniverseMax
  73. };
  74. EUniverse EUniverseFromName( const char * pchUniverseName );
  75. const char * PchNameFromEUniverse( EUniverse eUniverse );
  76. // Steam account types
  77. enum EAccountType
  78. {
  79. k_EAccountTypeInvalid = 0,
  80. k_EAccountTypeIndividual = 1, // single user account
  81. k_EAccountTypeMultiseat = 2, // multiseat (e.g. cybercafe) account
  82. k_EAccountTypeGameServer = 3, // game server account
  83. k_EAccountTypeAnonGameServer = 4, // anonomous game server account
  84. k_EAccountTypePending = 5 // pending
  85. };
  86. #pragma pack( push, 1 )
  87. // Steam ID structure (64 bits total)
  88. class CSteamID
  89. {
  90. public:
  91. //-----------------------------------------------------------------------------
  92. // Purpose: Constructor
  93. //-----------------------------------------------------------------------------
  94. CSteamID( )
  95. {
  96. m_unAccountID = 0;
  97. m_EAccountType = k_EAccountTypeInvalid;
  98. m_EUniverse = k_EUniverseInvalid;
  99. m_unAccountInstance = 0;
  100. }
  101. //-----------------------------------------------------------------------------
  102. // Purpose: Constructor
  103. // Input : unAccountID - 32-bit account ID
  104. // eUniverse - Universe this account belongs to
  105. // eAccountType - Type of account
  106. //-----------------------------------------------------------------------------
  107. CSteamID( uint32 unAccountID, EUniverse eUniverse, EAccountType eAccountType )
  108. {
  109. Set( unAccountID, eUniverse, eAccountType );
  110. }
  111. //-----------------------------------------------------------------------------
  112. // Purpose: Constructor
  113. // Input : unAccountID - 32-bit account ID
  114. // unAccountInstance - instance
  115. // eUniverse - Universe this account belongs to
  116. // eAccountType - Type of account
  117. //-----------------------------------------------------------------------------
  118. CSteamID( uint32 unAccountID, unsigned int unAccountInstance, EUniverse eUniverse, EAccountType eAccountType )
  119. {
  120. InstancedSet( unAccountID, unAccountInstance, eUniverse, eAccountType );
  121. }
  122. //-----------------------------------------------------------------------------
  123. // Purpose: Constructor
  124. // Input : ulSteamID - 64-bit representation of a Steam ID
  125. //-----------------------------------------------------------------------------
  126. CSteamID( uint64 ulSteamID )
  127. {
  128. SetFromUint64( ulSteamID );
  129. }
  130. //-----------------------------------------------------------------------------
  131. // Purpose: Sets parameters for steam ID
  132. // Input : unAccountID - 32-bit account ID
  133. // eUniverse - Universe this account belongs to
  134. // eAccountType - Type of account
  135. //-----------------------------------------------------------------------------
  136. void Set( uint32 unAccountID, EUniverse eUniverse, EAccountType eAccountType )
  137. {
  138. m_unAccountID = unAccountID;
  139. m_EUniverse = eUniverse;
  140. m_EAccountType = eAccountType;
  141. m_unAccountInstance = 1;
  142. }
  143. //-----------------------------------------------------------------------------
  144. // Purpose: Sets parameters for steam ID
  145. // Input : unAccountID - 32-bit account ID
  146. // eUniverse - Universe this account belongs to
  147. // eAccountType - Type of account
  148. //-----------------------------------------------------------------------------
  149. void InstancedSet( uint32 unAccountID, uint32 unInstance, EUniverse eUniverse, EAccountType eAccountType )
  150. {
  151. m_unAccountID = unAccountID;
  152. m_EUniverse = eUniverse;
  153. m_EAccountType = eAccountType;
  154. m_unAccountInstance = unInstance;
  155. }
  156. //-----------------------------------------------------------------------------
  157. // Purpose: Initializes a steam ID from its 52 bit parts and universe/type
  158. // Input : ulIdentifier - 52 bits of goodness
  159. //-----------------------------------------------------------------------------
  160. void FullSet( uint64 ulIdentifier, EUniverse eUniverse, EAccountType eAccountType )
  161. {
  162. m_unAccountID = ( ulIdentifier & 0xFFFFFFFF ); // account ID is low 32 bits
  163. m_unAccountInstance = ( ( ulIdentifier >> 32 ) & 0xFFFFF ); // account instance is next 20 bits
  164. m_EUniverse = eUniverse;
  165. m_EAccountType = eAccountType;
  166. }
  167. //-----------------------------------------------------------------------------
  168. // Purpose: Initializes a steam ID from its 64-bit representation
  169. // Input : ulSteamID - 64-bit representation of a Steam ID
  170. //-----------------------------------------------------------------------------
  171. void SetFromUint64( uint64 ulSteamID )
  172. {
  173. m_unAccountID = ( ulSteamID & 0xFFFFFFFF ); // account ID is low 32 bits
  174. m_unAccountInstance = ( ( ulSteamID >> 32 ) & 0xFFFFF ); // account instance is next 20 bits
  175. m_EAccountType = ( EAccountType ) ( ( ulSteamID >> 52 ) & 0xF ); // type is next 4 bits
  176. m_EUniverse = ( EUniverse ) ( ( ulSteamID >> 56 ) & 0xFF ); // universe is next 8 bits
  177. }
  178. //-----------------------------------------------------------------------------
  179. // Purpose: Initializes a steam ID from a Steam2 ID structure
  180. // Input: pTSteamGlobalUserID - Steam2 ID to convert
  181. // eUniverse - universe this ID belongs to
  182. //-----------------------------------------------------------------------------
  183. void SetFromSteam2( TSteamGlobalUserID *pTSteamGlobalUserID, EUniverse eUniverse )
  184. {
  185. m_unAccountID = pTSteamGlobalUserID->m_SteamLocalUserID.Split.Low32bits * 2 +
  186. pTSteamGlobalUserID->m_SteamLocalUserID.Split.High32bits;
  187. m_EUniverse = eUniverse; // set the universe
  188. m_EAccountType = k_EAccountTypeIndividual; // Steam 2 accounts always map to account type of individual
  189. m_unAccountInstance = 1; // individual accounts always have an account instance ID of 1
  190. }
  191. //-----------------------------------------------------------------------------
  192. // Purpose: Converts steam ID to its 64-bit representation
  193. // Output : 64-bit representation of a Steam ID
  194. //-----------------------------------------------------------------------------
  195. uint64 ConvertToUint64( ) const
  196. {
  197. return (uint64) ( ( ( (uint64) m_EUniverse ) << 56 ) + ( ( (uint64) m_EAccountType ) << 52 ) +
  198. ( ( (uint64) m_unAccountInstance ) << 32 ) + m_unAccountID );
  199. }
  200. //-----------------------------------------------------------------------------
  201. // Purpose: Fills out a Steam2 ID structure
  202. // Input: pTSteamGlobalUserID - Steam2 ID to write to
  203. //-----------------------------------------------------------------------------
  204. void ConvertToSteam2( TSteamGlobalUserID *pTSteamGlobalUserID ) const
  205. {
  206. // only individual accounts have any meaning in Steam 2, only they can be mapped
  207. // Assert( m_EAccountType == k_EAccountTypeIndividual );
  208. pTSteamGlobalUserID->m_SteamInstanceID = 0;
  209. pTSteamGlobalUserID->m_SteamLocalUserID.Split.High32bits = m_unAccountID % 2;
  210. pTSteamGlobalUserID->m_SteamLocalUserID.Split.Low32bits = m_unAccountID / 2;
  211. }
  212. //-----------------------------------------------------------------------------
  213. // Purpose: Converts the static parts of a steam ID to a 64-bit representation.
  214. // For multiseat accounts, all instances of that account will have the
  215. // same static account key, so they can be grouped together by the static
  216. // account key.
  217. // Output : 64-bit static account key
  218. //-----------------------------------------------------------------------------
  219. uint64 GetStaticAccountKey( ) const
  220. {
  221. // note we do NOT include the account instance (which is a dynamic property) in the static account key
  222. return (uint64) ( ( ( (uint64) m_EUniverse ) << 56 ) + ((uint64) m_EAccountType << 52 ) + m_unAccountID );
  223. }
  224. //-----------------------------------------------------------------------------
  225. // Purpose: create an anonomous game server login to be filled in by the AM
  226. //-----------------------------------------------------------------------------
  227. void CreateBlankAnonLogon( )
  228. {
  229. m_unAccountID = 0;
  230. m_EAccountType = k_EAccountTypeAnonGameServer;
  231. m_EUniverse = k_EUniversePublic;
  232. m_unAccountInstance = 0;
  233. }
  234. //-----------------------------------------------------------------------------
  235. // Purpose: Is this an anonomous game server login that will be filled in?
  236. //-----------------------------------------------------------------------------
  237. bool BBlankAnonAccount( )
  238. {
  239. return m_unAccountID == 0 &&
  240. m_EAccountType == k_EAccountTypeAnonGameServer &&
  241. m_EUniverse == k_EUniversePublic &&
  242. m_unAccountInstance == 0;
  243. }
  244. //-----------------------------------------------------------------------------
  245. // Purpose: Is this a game server account id?
  246. //-----------------------------------------------------------------------------
  247. bool BGameServerAccount( )
  248. {
  249. return m_EAccountType == k_EAccountTypeGameServer || m_EAccountType == k_EAccountTypeAnonGameServer;
  250. }
  251. // simple accessors
  252. void SetAccountID( uint32 unAccountID ) { m_unAccountID = unAccountID; }
  253. uint32 GetAccountID( ) const { return m_unAccountID; }
  254. uint32 GetUnAccountInstance( ) const { return m_unAccountInstance; }
  255. EAccountType GetEAccountType( ) const { return m_EAccountType; }
  256. EUniverse GetEUniverse( ) const { return m_EUniverse; }
  257. bool IsValid( ) const { return m_EAccountType != k_EAccountTypeInvalid; }
  258. // this set of functions is hidden, will be moved out of class
  259. CSteamID( char *pchSteamID );
  260. void SetFromString( char *pchSteamID );
  261. char * Render( ) const; // renders this steam ID to string
  262. static char * Render( uint64 ulSteamID ); // static method to render a uint64 representation of a steam ID to a string
  263. // DEBUG function
  264. bool BValidExternalSteamID( void );
  265. private:
  266. // 64 bits total
  267. uint32 m_unAccountID : 32; // unique account identifier
  268. unsigned int m_unAccountInstance : 20; // dynamic instance ID (used for multiseat type accounts only)
  269. EAccountType m_EAccountType : 4; // type of account
  270. EUniverse m_EUniverse : 8; // universe this account belongs to
  271. };
  272. #pragma pack( pop )
  273. // ICMCallback
  274. // Anyone who owns a CMInterface object should implement this to receive callbacks.
  275. class ICMCallback
  276. {
  277. public:
  278. ICMCallback( ) { };
  279. virtual ~ICMCallback( ) { };
  280. virtual void OnLogonSuccess( void ) = 0 ;
  281. virtual void OnLogonFailure( EResult eResult ) = 0;
  282. virtual void OnLoggedOff( EResult eResult ) = 0;
  283. // Called during logon to get encrypted user ticket
  284. virtual bool GetEncryptedUserTicket( unsigned int unIPPublic, unsigned int unIPPrivate,
  285. const void * pubEncryptionKey, unsigned int cubEncryptionKey,
  286. void * pubEncryptedTicket, unsigned int cubEncryptedTicketBuf, unsigned int * pcubEncryptedTicketSize ) = 0;
  287. // Called when we receive a VAC challenge
  288. virtual void HandleVACChallenge( int nClientGameID, uint8 *pubChallenge, int cubChallenge ) = 0;
  289. // Called when we receive a VAC kick message
  290. virtual void HandleVACKick( int nClientGameID ) = 0;
  291. // Methods to read/write to owner's persistent storage (e.g. config file)
  292. virtual bool GetValue( const char * pwzName, char * pwzValue, const int cchValue ) = 0;
  293. virtual bool SetValue( const char * pwzName, const char * pwzValue ) = 0;
  294. // called when a GS is getting responses to requests or user status
  295. virtual void GSHandleClientApprove( CSteamID & steamID ) = 0;
  296. virtual void GSHandleClientDeny( CSteamID & steamID, EDenyReason eDenyReason ) = 0;
  297. virtual void GSHandleClientKick( CSteamID & steamID, EDenyReason eDenyReason ) = 0;
  298. #ifdef _SERVER
  299. #ifdef TEST_CODE_ENABLED
  300. virtual void TEST_ReportAuthKey( uint8 * pubAuthKey, uint32 cubAuthKey ) = 0;
  301. virtual void TEST_ReportMsgRecieved( int32 m_EMsg ) = 0;
  302. #endif // TEST_CODE_ENABLED
  303. #endif // _SERVER
  304. };
  305. // CMInterface
  306. // This connects the client to the CM.
  307. class ICMInterface
  308. {
  309. public:
  310. ICMInterface() {};
  311. virtual ~ICMInterface() {};
  312. // Manage ClientGames
  313. virtual int NClientGameIDAdd( int nGameID ) = 0;
  314. virtual void RemoveClientGame( int nClientGameID ) = 0;
  315. virtual void SetClientGameServer( int nClientGameID, uint unIPServer, uint16 usPortServer ) = 0;
  316. // Set CM IP and port -- currently only for debugging!
  317. virtual void SetCMs( const netadr_t *pNetAdrCMs, int nNetAdrCMs ) = 0;
  318. // Log on and off
  319. virtual void LogOff( void ) = 0;
  320. virtual void LogOn( CSteamID & steamID ) = 0;
  321. // Our mainloop
  322. virtual bool BMainLoop( ) = 0;
  323. // Send a VAC response to the CM
  324. virtual bool SendVACResponse( int nClientGameID, uint8 *pubResponse, int cubResponse ) = 0;
  325. // Send an authentication packet to the CM
  326. virtual bool SendAuth( uint8 *pubAuth, int cubAuth ) = 0;
  327. virtual bool BLoggedOn( void ) = 0;
  328. virtual void SetSpewLevel( int nSpewLevel ) = 0;
  329. virtual EUniverse GetEUniverse( ) = 0;
  330. virtual void SetEUniverse( EUniverse eUniverse ) = 0;
  331. // Game Server methods
  332. virtual bool GSSendLogonRequest( CSteamID & steamID ) = 0;
  333. virtual bool GSSendDisconnect( CSteamID & steamID ) = 0;
  334. virtual bool GSSendStatusResponse( CSteamID & steamID, int nSecondsConnected, int nSecondsSinceLast ) = 0;
  335. virtual bool GSSetStatus( int32 uAppIdServed, uint uServerFlags, int cPlayers, int cPlayersMax ) = 0;
  336. #ifdef TEST_CODE_ENABLED
  337. virtual void TEST_SetFakePrivateIP( uint unIPPrivate ) = 0;
  338. virtual void TEST_SendBigMessage( void ) = 0; // send a big (multi-packet) message to the server to test packetization code
  339. virtual bool TEST_BBigMessageResponseReceived( void ) = 0; // returns TRUE if a big test message response has been sent back from the server
  340. virtual void TEST_SetPktLossPct( int nPct ) = 0; // sets a simulated packet loss percentage for testing
  341. virtual void TEST_SetForceTCP( bool bForceTCP ) = 0; // forces client to use TCP connection
  342. virtual void TEST_SetTCPFallback( bool bTCPFallback ) = 0; // causes client to connect over TCP, send a fallback message, and disconnect
  343. virtual int TEST_GetOurConnectionID( ) = 0; // returns our connection ID for this connection
  344. virtual void TEST_HeartBeat( ) = 0; // send a heartbeat to the CM
  345. virtual IVConnCallback * TEST_GetVConnCallback( ) =0; // returns our vconn callback interface
  346. virtual void TEST_FakeDisconnect() = 0;
  347. #endif // TEST_CODE_ENABLED
  348. #ifdef DBGFLAG_VALIDATE
  349. virtual void Validate( CValidator &validator, char *pchName ) = 0; // Validate our internal structures
  350. #endif // DBGFLAG_VALIDATE
  351. };
  352. #ifdef VAC_ENABLED
  353. // IVAC
  354. // This is the wrapper class for all VAC functionaility in the client
  355. class IVAC
  356. {
  357. public:
  358. virtual bool BVACCreateProcess(
  359. PVOID lpVACBlob,
  360. DWORD cbBlobSize,
  361. LPCTSTR lpApplicationName,
  362. LPTSTR lpCommandLine,
  363. LPSECURITY_ATTRIBUTES lpProcessAttributes,
  364. LPSECURITY_ATTRIBUTES lpThreadAttributes,
  365. BOOL bInheritHandles,
  366. DWORD dwCreationFlags,
  367. LPVOID lpEnvironment,
  368. LPCTSTR lpCurrentDirectory,
  369. LPSTARTUPINFO lpStartupInfo,
  370. LPPROCESS_INFORMATION lpProcessInformation,
  371. DWORD nGameID
  372. ) = 0;
  373. virtual void KillAllVAC( void ) = 0;
  374. virtual void ProcessVAC( ICMInterface *pCMInterface ) = 0;
  375. virtual void RealHandleVACChallenge( ICMInterface *pCMInterface, int nClientGameID, uint8 *pubChallenge, int cubChallenge) = 0;
  376. #ifdef DBGFLAG_VALIDATE
  377. virtual void Validate( CValidator &validator, char *pchName ) = 0; // Validate our internal structures
  378. #endif
  379. };
  380. // this is a bogus number picked to be beyond any real steam2 uAppID
  381. const int k_nGameIDNotepad = 65535;
  382. // this is the real steam2 uAppID for Counter-Strike Source
  383. const int k_nGameIDCSS = 240;
  384. IVAC * IVACGet( void );
  385. void ReleaseIVAC( IVAC *pIVAC );
  386. BYTE *PbLoadVacBlob( int *pcbVacBlob );
  387. void FreeVacBlob( BYTE *pbVacBlob );
  388. #ifdef _DEBUG
  389. void SetUseDllForIVAC( void );
  390. #endif // _DEBUG
  391. #endif // VAC_ENABLED
  392. //lint -restore
  393. #endif // STEAMCLIENTPUBLIC_H