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.

116 lines
3.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: steam state machine that handles authenticating steam users
  4. //
  5. //=============================================================================//
  6. #ifndef STEAMUAUTHSERVER_H
  7. #define STEAMUAUTHSERVER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "baseclient.h"
  12. #include "utlvector.h"
  13. #include "netadr.h"
  14. #include "utlstring.h"
  15. #include "steam/steam_gameserver.h"
  16. class CSteam3Server : public CSteamGameServerAPIContext
  17. {
  18. public:
  19. CSteam3Server();
  20. ~CSteam3Server();
  21. #if !defined(NO_STEAM)
  22. STEAM_GAMESERVER_CALLBACK( CSteam3Server, OnLogonSuccess, SteamServersConnected_t, m_CallbackLogonSuccess );
  23. STEAM_GAMESERVER_CALLBACK( CSteam3Server, OnLogonFailure, SteamServerConnectFailure_t, m_CallbackLogonFailure );
  24. STEAM_GAMESERVER_CALLBACK( CSteam3Server, OnLoggedOff, SteamServersDisconnected_t, m_CallbackLoggedOff );
  25. // game server callbacks
  26. STEAM_GAMESERVER_CALLBACK( CSteam3Server, OnGSPolicyResponse, GSPolicyResponse_t, m_CallbackGSPolicyResponse );
  27. STEAM_GAMESERVER_CALLBACK( CSteam3Server, OnValidateAuthTicketResponse, ValidateAuthTicketResponse_t, m_CallbackValidateAuthTicketResponse );
  28. STEAM_GAMESERVER_CALLBACK( CSteam3Server, OnComputeNewPlayerCompatibilityResponse, ComputeNewPlayerCompatibilityResult_t, m_CallbackPlayerCompatibilityResponse );
  29. #endif
  30. // CSteam3 stuff
  31. enum EServerType {
  32. eServerTypeNormal,
  33. // Don't register a game port, use hltv system's port as query port
  34. eServerTypeTVRelay
  35. };
  36. void Activate( EServerType serverType );
  37. void NotifyOfLevelChange();
  38. void NotifyOfServerNameChange();
  39. void SendUpdatedServerDetails();
  40. void Shutdown();
  41. bool NotifyClientConnect( CBaseClient *client, uint32 unUserID, netadr_t & adr, const void *pvCookie, uint32 ucbCookie );
  42. bool NotifyLocalClientConnect( CBaseClient *client ); // Used for local player on listen server and bots.
  43. void NotifyClientDisconnect( CBaseClient *client );
  44. void RunFrame();
  45. bool BSecure() { return SteamGameServer() && SteamGameServer()->BSecure(); }
  46. bool BIsActive() { return SteamGameServer() && ( m_eServerMode >= eServerModeNoAuthentication ); }
  47. bool BLanOnly() const { return m_eServerMode == eServerModeNoAuthentication; }
  48. bool BWantsSecure() { return m_eServerMode == eServerModeAuthenticationAndSecure; }
  49. bool BLoggedOn() { return SteamGameServer() && SteamGameServer()->BLoggedOn(); }
  50. bool CompareUserID( const USERID_t & id1, const USERID_t & id2 );
  51. const CSteamID& GetGSSteamID();
  52. uint16 GetQueryPort() const { return m_QueryPort; }
  53. // Fetch public IP. Might return 0 if we don't know
  54. uint32 GetPublicIP() { return SteamGameServer() ? SteamGameServer()->GetPublicIP() : 0; }
  55. bool IsMasterServerUpdaterSharingGameSocket();
  56. /// Select Steam account name / password to use
  57. void SetAccount( const char *pszToken )
  58. {
  59. m_sAccountToken = pszToken;
  60. }
  61. void UpdateGroupSteamID( bool bForce );
  62. /// What account name was selected?
  63. const char *GetAccountToken() const { return m_sAccountToken.String(); }
  64. private:
  65. bool CheckForDuplicateSteamID( const CBaseClient *client );
  66. CBaseClient *ClientFindFromSteamID( CSteamID & steamIDFind );
  67. void OnValidateAuthTicketResponseHelper( CBaseClient *cl, EAuthSessionResponse eAuthSessionResponse );
  68. EServerMode GetCurrentServerMode();
  69. EServerMode m_eServerMode;
  70. EServerType m_eServerType;
  71. bool m_bMasterServerUpdaterSharingGameSocket;
  72. bool m_bLogOnFinished;
  73. bool m_bLoggedOn;
  74. bool m_bLogOnResult; // if true, show logon result
  75. bool m_bHasActivePlayers; // player stats updates are only sent if active players are available
  76. CSteamID m_SteamIDGS;
  77. CSteamID m_steamIDLanOnly;
  78. bool m_bActive;
  79. bool m_bWantsSecure;
  80. bool m_bInitialized;
  81. bool m_bWantsPersistentAccountLogon;
  82. // The port that we are listening for queries on.
  83. uint32 m_unIP;
  84. uint16 m_usPort;
  85. uint16 m_QueryPort;
  86. CUtlString m_sAccountToken;
  87. CSteamID m_SteamIDGroupForBlocking;
  88. };
  89. // singleton accessor
  90. CSteam3Server &Steam3Server();
  91. #endif