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.

101 lines
3.2 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #ifndef SV_RCON_H
  7. #define SV_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 "tier2/socketcreator.h"
  20. #include "igameserverdata.h"
  21. #define RCON_MAX_OUTSTANDING_SENDS 100 // max packets to queue before dropping connection
  22. #define RCON_MAX_RCON_COMMAND_LEN 1024 // max size of an incoming command in bytes
  23. //-----------------------------------------------------------------------------
  24. // container class to handle network streams
  25. //-----------------------------------------------------------------------------
  26. class CRConServer : public ISocketCreatorListener
  27. {
  28. public:
  29. CRConServer( const char *netAddress );
  30. CRConServer();
  31. ~CRConServer();
  32. void SetAddress( const char *netAddress );
  33. void SetPassword( const char *pPassword );
  34. bool HasPassword() const;
  35. bool IsPassword( const char *pPassword ) const;
  36. bool CreateSocket();
  37. void RunFrame();
  38. bool IsConnected();
  39. void FinishRedirect( const char *msg, const netadr_t &adr );
  40. bool HandleFailedRconAuth( const netadr_t &adr );
  41. void SetRequestID( ra_listener_id listener, int iRequestID );
  42. bool BCloseAcceptedSocket( ra_listener_id nIndex );
  43. // Allows a server to request a listening client to connect to it
  44. bool ConnectToListeningClient( const netadr_t &adr, bool bSingleSocket );
  45. // Inherited from ISocketCreatorListener
  46. virtual bool ShouldAcceptSocket( SocketHandle_t hSocket, const netadr_t & netAdr );
  47. virtual void OnSocketAccepted( SocketHandle_t hSocket, const netadr_t & netAdr, void** ppData );
  48. virtual void OnSocketClosed( SocketHandle_t hSocket, const netadr_t & netAdr, void* pData );
  49. private:
  50. struct ConnectedRConSocket_t
  51. {
  52. bool authed;
  53. int lastRequestID;
  54. ra_listener_id listenerID;
  55. CUtlBuffer packetbuffer; // data buffer containing pending incoming data for this connection
  56. CUtlLinkedList< CUtlBuffer > m_OutstandingSends; // packets pending to be send (queued because of WSAEWOULDBLOCK )
  57. };
  58. struct FailedRCon_t
  59. {
  60. int badPasswordCount;
  61. netadr_t adr;
  62. CUtlLinkedList< float > badPasswordTimes;
  63. bool operator==( const FailedRCon_t &rhs ) const { return ( adr.CompareAdr( rhs.adr) == 0 ); }
  64. bool operator<( const FailedRCon_t &rhs ) const;
  65. };
  66. ConnectedRConSocket_t* GetSocketData( int nIndex );
  67. void ProcessAccept();
  68. // NOTE: This function can remove elements. If calling it from a loop,
  69. // always iterate over accepted sockets backwards to avoid problems.
  70. bool SendRCONResponse( int nIndex, const void *data, int len, bool fromQueue = false );
  71. CSocketCreator m_Socket;
  72. CUtlVector< FailedRCon_t > m_failedRcons;
  73. CUtlString m_Password;
  74. netadr_t m_Address;
  75. bool m_bSocketDeleted;
  76. };
  77. inline CRConServer::ConnectedRConSocket_t* CRConServer::GetSocketData( int nIndex )
  78. {
  79. return (ConnectedRConSocket_t*)m_Socket.GetAcceptedSocketData( nIndex );
  80. }
  81. CRConServer & RCONServer();
  82. #ifdef ENABLE_RPT
  83. CRConServer & RPTServer();
  84. #endif // ENABLE_RPT
  85. #endif // SV_RCON_H