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.

144 lines
3.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #ifndef CL_RCON_H
  7. #define CL_RCON_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "sv_main.h"
  12. #include "netmessages.h"
  13. #include "net.h"
  14. #include "client.h"
  15. #include "utlvector.h"
  16. #include "utllinkedlist.h"
  17. #include "netadr.h"
  18. #include "sv_remoteaccess.h"
  19. #include "sv_rcon.h"
  20. #include "socketcreator.h"
  21. #include "igameserverdata.h"
  22. #include "ivprofexport.h"
  23. // memdbgon must be the last include file in a .cpp file!!!
  24. #include "tier0/memdbgon.h"
  25. abstract_class IVProfData
  26. {
  27. public:
  28. virtual void OnRemoteGroupData( const void *data, int len ) = 0;
  29. virtual void OnRemoteData( const void *data, int len ) = 0;
  30. };
  31. //-----------------------------------------------------------------------------
  32. // Used to display client perf data in showbudget
  33. //-----------------------------------------------------------------------------
  34. class CRConVProfExport : public IVProfExport, public IVProfData
  35. {
  36. // Inherited from IVProfExport
  37. public:
  38. virtual void AddListener();
  39. virtual void RemoveListener();
  40. virtual void PauseProfile();
  41. virtual void ResumeProfile();
  42. virtual void SetBudgetFlagsFilter( int filter );
  43. virtual int GetNumBudgetGroups();
  44. virtual void GetBudgetGroupInfos( CExportedBudgetGroupInfo *pInfos );
  45. virtual void GetBudgetGroupTimes( float times[MAX_BUDGETGROUP_TIMES] );
  46. // Inherited from IVProfData
  47. public:
  48. virtual void OnRemoteGroupData( const void *data, int len );
  49. virtual void OnRemoteData( const void *data, int len );
  50. // Other public methods
  51. public:
  52. CRConVProfExport();
  53. private:
  54. void CleanupGroupData();
  55. CUtlVector< CExportedBudgetGroupInfo > m_Info;
  56. CUtlVector<float> m_Times; // Times from the most recent snapshot.
  57. };
  58. class CRConClient : public ISocketCreatorListener
  59. {
  60. public:
  61. CRConClient();
  62. ~CRConClient();
  63. void SetAddress( const netadr_t & netAdr );
  64. // Connects to the address specified by SetAddress
  65. bool ConnectSocket();
  66. void Disconnect() { CloseSocket(); }
  67. // Creates a listen server, connects to remote machines that connect to it
  68. void CreateListenSocket( const netadr_t &netAdr );
  69. void CloseListenSocket();
  70. void RunFrame();
  71. void SendCmd( const char *msg );
  72. bool IsConnected() const;
  73. bool IsAuthenticated() const { return m_bAuthenticated; }
  74. void RegisterVProfDataCallback( IVProfData *callback );
  75. void StopVProfData();
  76. void StartVProfData();
  77. void TakeScreenshot();
  78. void GrabConsoleLog();
  79. void SetPassword( const char *pPassword );
  80. void SetRemoteFileDirectory( const char *pDir );
  81. // Inherited from ISocketCreatorListener
  82. virtual bool ShouldAcceptSocket( SocketHandle_t hSocket, const netadr_t & netAdr );
  83. virtual void OnSocketAccepted( SocketHandle_t hSocket, const netadr_t & netAdr, void** ppData );
  84. virtual void OnSocketClosed( SocketHandle_t hSocket, const netadr_t & netAdr, void* pData );
  85. private:
  86. SocketHandle_t GetSocketHandle() const;
  87. void CloseSocket();
  88. void Authenticate();
  89. void ParseReceivedData();
  90. void SendQueuedData();
  91. void SendResponse( CUtlBuffer &response, bool bAutoAuthenticate = true );
  92. void BuildResponse( CUtlBuffer &response, ServerDataRequestType_t msg, const char *pString1, const char *pString2 );
  93. void SaveRemoteScreenshot( const void* pBuffer, int nBufLen );
  94. void SaveRemoteConsoleLog( const void* pBuffer, int nBufLen );
  95. CRConVProfExport m_VProfExport;
  96. CSocketCreator m_Socket;
  97. netadr_t m_Address;
  98. int m_iAuthRequestID;
  99. int m_iReqID;
  100. bool m_bAuthenticated;
  101. CUtlBuffer m_RecvBuffer;
  102. CUtlBuffer m_SendBuffer;
  103. CUtlString m_Password;
  104. CUtlString m_RemoteFileDir;
  105. int m_nScreenShotIndex;
  106. int m_nConsoleLogIndex;
  107. };
  108. inline SocketHandle_t CRConClient::GetSocketHandle() const
  109. {
  110. return m_Socket.GetAcceptedSocketHandle( 0 );
  111. }
  112. CRConClient & RCONClient();
  113. #ifdef ENABLE_RPT
  114. CRConClient & RPTClient(); // used in remote perf testing
  115. #endif // ENABLE_RPT
  116. #endif // CL_RCON_H