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.

99 lines
2.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: defines a RCon class used to send rcon commands to remote servers
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #ifndef RCON_H
  8. #define RCON_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "server.h"
  13. #include "netadr.h"
  14. class CSocket;
  15. class IResponse;
  16. typedef struct
  17. {
  18. char queued[1024];
  19. } queue_requests_t;
  20. class CRcon
  21. {
  22. public:
  23. CRcon(IResponse *target,serveritem_t &server, const char *password);
  24. ~CRcon();
  25. // resets the state of the object, will cause it to get the challenge id again
  26. void Reset();
  27. // send an rcon command to a server
  28. void SendRcon(const char *cmd);
  29. // does nothing
  30. void Refresh();
  31. bool IsRefreshing();
  32. serveritem_t &GetServer();
  33. void RunFrame();
  34. // return the response from the server
  35. const char *RconResponse();
  36. // called when the message handler gets a packet back
  37. void UpdateServer(netadr_t *adr, int challenge,const char *resp);
  38. // returns the challenge id
  39. bool Challenge();
  40. // returns if a new rcon result is waiting
  41. bool NewRcon();
  42. // returns if the password failed
  43. bool PasswordFail();
  44. // called when a bad password is used
  45. void BadPassword(const char *info);
  46. // returns whether this rcon is disabled (due to bad passwords)
  47. bool Disabled();
  48. //set the password to use in the rcon request
  49. void SetPassword(const char *newPass);
  50. private:
  51. // sends the actual request
  52. void RconRequest(const char *command, int challenge);
  53. // requests a challenge value from the server
  54. void GetChallenge();
  55. serveritem_t m_Server;
  56. CSocket *m_pQuery; // Game server query socket
  57. IResponse *m_pResponseTarget;
  58. bool m_bIsRefreshing; // whether we are currently performing an rcon command
  59. bool m_bChallenge; // whether we are currently GETTING a challenge id
  60. bool m_bNewRcon; // whether an rcon response is waiting to be picked up
  61. bool m_bPasswordFail; // whether the password failed
  62. bool m_bDisable; // whether rcon is disabled due to password failures
  63. bool m_bGotChallenge; // whether we have a valid challenge id stored away
  64. CUtlVector<queue_requests_t> requests;
  65. char m_sPassword[100];
  66. char m_sCmd[1024];
  67. char m_sRconResponse[2048];
  68. int m_iChallenge;
  69. float m_fQuerySendTime;
  70. };
  71. #endif // RCON_H