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.

95 lines
2.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #ifndef REMOTESERVER_H
  8. #define REMOTESERVER_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "UtlLinkedList.h"
  13. #include "igameserverdata.h"
  14. class IServerDataResponse;
  15. //-----------------------------------------------------------------------------
  16. // Purpose: Configures and installs the connection to the game server (remote or local)
  17. //-----------------------------------------------------------------------------
  18. class CRemoteServer
  19. {
  20. public:
  21. CRemoteServer();
  22. ~CRemoteServer();
  23. // setup this object
  24. void Initialize();
  25. // remote connection
  26. void ConnectRemoteGameServer(unsigned int ip, unsigned short port, const char *password);
  27. // request a cvar/data from the server
  28. void RequestValue(IServerDataResponse *requester, const char *variable);
  29. // sets a value
  30. void SetValue(const char *variable, const char *value);
  31. // sends a custom command
  32. void SendCommand(const char *commandString);
  33. // changes the current password on the server
  34. // responds with "PasswordChange" "true" or "PasswordChange" "false"
  35. void ChangeAccessPassword(IServerDataResponse *requester, const char *newPassword);
  36. // process any return values, firing any IServerDataResponse items
  37. // returns true if any items were fired
  38. bool ProcessServerResponse();
  39. // Adds a constant watches for a particular message. Used to handle
  40. // information channels from the server->client (map changed, player joined, etc.)
  41. void AddServerMessageHandler(IServerDataResponse *handler, const char *watch);
  42. // removes a requester from the list to guarantee the pointer won't be used
  43. void RemoveServerDataResponseTarget(IServerDataResponse *invalidRequester);
  44. private:
  45. int m_iCurrentRequestID;
  46. ra_listener_id m_ListenerID;
  47. bool m_bInitialized;
  48. // list of all the currently waiting response handlers
  49. struct ResponseHandler_t
  50. {
  51. int requestID;
  52. IServerDataResponse *handler;
  53. };
  54. CUtlLinkedList<ResponseHandler_t, int> m_ResponseHandlers;
  55. // list of constant response handlers
  56. struct MessageHandler_t
  57. {
  58. char messageName[32];
  59. IServerDataResponse *handler;
  60. };
  61. CUtlLinkedList<MessageHandler_t, int> m_MessageHandlers;
  62. };
  63. //-----------------------------------------------------------------------------
  64. // Purpose: callback interface
  65. //-----------------------------------------------------------------------------
  66. class IServerDataResponse
  67. {
  68. public:
  69. // called when the server has returned a requested value
  70. virtual void OnServerDataResponse(const char *value, const char *response) = 0;
  71. };
  72. // singleton accessor
  73. extern CRemoteServer &RemoteServer();
  74. #endif // REMOTESERVER_H