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.

112 lines
2.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #ifndef SERVERLIST_H
  8. #define SERVERLIST_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "server.h"
  13. #include "netadr.h"
  14. #include "serverinfo.h"
  15. #include "iresponse.h"
  16. #include "utlrbtree.h"
  17. class CSocket;
  18. class IServerRefreshResponse;
  19. // holds a single query - definition needs to be public
  20. struct query_t
  21. {
  22. netadr_t addr;
  23. int serverID;
  24. float sendTime;
  25. };
  26. //-----------------------------------------------------------------------------
  27. // Purpose: Handles a list of servers, and can refresh them
  28. //-----------------------------------------------------------------------------
  29. class CServerList: public IResponse
  30. {
  31. public:
  32. CServerList(IServerRefreshResponse *gameList);
  33. ~CServerList();
  34. // Handles a frame of networking
  35. void RunFrame();
  36. // gets a server from the list by id, range [0, ServerCount)
  37. serveritem_t &GetServer(unsigned int serverID);
  38. // returns the number of servers
  39. int ServerCount();
  40. // adds a new server to the list, returning a handle to the server
  41. unsigned int AddNewServer(serveritem_t &server);
  42. // starts a refresh
  43. void StartRefresh();
  44. // stops all refreshing
  45. void StopRefresh();
  46. // clears all servers from the list
  47. void Clear();
  48. // marks a server to be refreshed
  49. void AddServerToRefreshList(unsigned int serverID);
  50. // returns true if servers are currently being refreshed
  51. bool IsRefreshing();
  52. // returns the number of servers not yet pinged
  53. int RefreshListRemaining();
  54. // implementation of IRconResponse interface
  55. // called when the server has successfully responded to an info command
  56. virtual void ServerResponded();
  57. // called when a server response has timed out
  58. virtual void ServerFailedToRespond();
  59. private:
  60. // Run query logic for this frame
  61. void QueryFrame();
  62. // recalculates a servers ping, from the last few ping times
  63. int CalculateAveragePing(serveritem_t &server);
  64. IServerRefreshResponse *m_pResponseTarget;
  65. enum
  66. {
  67. MAX_QUERY_SOCKETS = 255,
  68. };
  69. // holds the list of all the currently active queries
  70. CUtlRBTree<query_t, unsigned short> m_Queries;
  71. // list of all known servers
  72. CUtlVector<CServerInfo *> m_Servers;
  73. // list of servers to be refreshed, in order... this would be more optimal as a queue
  74. CUtlVector<int> m_RefreshList;
  75. int m_iUpdateSerialNumber; // serial number of current update so we don't get results overlapping between different server list updates
  76. bool m_bQuerying; // Is refreshing taking place?
  77. int m_nMaxActive; // Max # of simultaneous sockets to use for querying
  78. int m_nMaxRampUp; // increasing number of sockets to use
  79. int m_nRampUpSpeed; // amount to ramp up each frame
  80. int m_nInvalidServers; // number of servers marked as 'no not refresh'
  81. int m_nRefreshedServers; // count of servers refreshed
  82. };
  83. #endif // SERVERLIST_H