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.

125 lines
5.6 KiB

  1. //====== Copyright Valve Corporation, All rights reserved. ====================
  2. //
  3. // Purpose: misc networking utilities
  4. //
  5. //=============================================================================
  6. #ifndef ISTEAMNETWORKINGUTILS
  7. #define ISTEAMNETWORKINGUTILS
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "steamnetworkingtypes.h"
  12. struct SteamDatagramRelayAuthTicket;
  13. //-----------------------------------------------------------------------------
  14. /// Misc networking utilities for checking the local networking environment
  15. /// and estimating pings.
  16. class ISteamNetworkingUtils
  17. {
  18. public:
  19. /// Fetch current timestamp. These values never go backwards, and
  20. /// the initial value is low enough that practically speaking it's
  21. /// not necessary to worry about the value wrapping around.
  22. virtual SteamNetworkingMicroseconds GetLocalTimestamp() = 0;
  23. /// Check if the ping data of sufficient recency is available, and if
  24. /// it's too old, start refreshing it.
  25. ///
  26. /// Games that use the ping location information will typically
  27. /// want to call this at boot time, to make sure all prerequisites
  28. /// are ready. Especially since the first measurement might take
  29. /// slightly longer than subsequent measurements.
  30. ///
  31. /// Returns true if sufficiently recent data is already available.
  32. ///
  33. /// Returns false if sufficiently recent data is not available. In this
  34. /// case, ping measurement is initiated, if it is not already active.
  35. /// (You cannot restart a measurement already in progress.)
  36. ///
  37. /// A FIXME event will be posted when measurement is completed.
  38. virtual bool CheckPingDataUpToDate( float flMaxAgeSeconds ) = 0;
  39. /// Return location info for the current host. Returns the approximate
  40. /// age of the data, in seconds, or -1 if no data is available.
  41. /// Note that this might return an age older than the age of your game's
  42. /// process, if the data was obtained before you game started.
  43. ///
  44. /// This always return the most up-to-date information we have available
  45. /// right now, even if we are in the middle of re-calculating ping times.
  46. virtual float GetLocalPingLocation( SteamNetworkPingLocation_t &result ) = 0;
  47. /// Return true if we are taking ping measurements to update our ping
  48. /// location or select optimal routing. Ping measurement typically takes
  49. /// a few seconds, perhaps up to 10 seconds.
  50. virtual bool IsPingMeasurementInProgress() = 0;
  51. /// Estimate the round-trip latency between two arbitrary locations, in
  52. /// milliseconds. This is a conservative estimate, based on routing through
  53. /// the relay network. For most basic connections based on SteamID,
  54. /// this ping time will be pretty accurate, since it will be based on the
  55. /// route likely to be actually used.
  56. ///
  57. /// If a direct IP route is used (perhaps via NAT traversal), then the route
  58. /// will be different, and the ping time might be better. Or it might actually
  59. /// be a bit worse! Standard IP routing is frequently suboptimal!
  60. ///
  61. /// but even in this case, the estimate obtained using this method is a
  62. /// reasonable upper bound on the ping time. (Also it has the advantage
  63. /// of returning immediately and not sending any packets.)
  64. ///
  65. /// In a few cases we might not able to estimate the route. In this case
  66. /// a negative value is returned. k_nSteamNetworkingPing_Failed means
  67. /// the reason was because of some networking difficulty. (Failure to
  68. /// ping, etc) k_nSteamNetworkingPing_Unknown is returned if we cannot
  69. /// currently answer the question for some other reason.
  70. virtual int EstimatePingTimeBetweenTwoLocations( const SteamNetworkPingLocation_t &location1, const SteamNetworkPingLocation_t &location2 ) = 0;
  71. /// Same as EstimatePingTime, but assumes that one location is the local host.
  72. /// This is a bit faster, especially if you need to calculate a bunch of
  73. /// these in a loop to find the fastest one.
  74. ///
  75. /// In rare cases this might return a slightly different estimate than combining
  76. /// GetLocalPingLocation with EstimatePingTimeBetweenTwoLocations. That's because
  77. /// this function uses a slightly more complete description
  78. virtual int EstimatePingTimeFromLocalHost( const SteamNetworkPingLocation_t &remoteLocation ) = 0;
  79. // FIXME:
  80. //
  81. // Check current internet connection status
  82. //
  83. // Low level ticket stuff. I need to get some advice and talk through how this should work
  84. // or how best to tuck it away and make it transparent.
  85. //
  86. virtual bool ReceivedTicket( const void *pvTicket, int cbTicket, SteamDatagramRelayAuthTicket *pOutParsedTicket ) = 0;
  87. virtual bool HasTicketForServer( CSteamID steamID ) = 0;
  88. virtual uint32 GetIPForServerSteamIDFromTicket( CSteamID steamID ) = 0;
  89. //
  90. // Low level network config stuff I haven't figure out how best to tuck away.
  91. // Dota and CSGO use it because we have gameservers in the datacenter, and
  92. // we need this information to do region selection. But most games won't
  93. // need it.
  94. //
  95. /// Fetch directly measured ping time from local host to a particular network PoP.
  96. /// Most games will not need to call this.
  97. virtual int GetPingToDataCenter( SteamNetworkingPOPID popID, SteamNetworkingPOPID *pViaRelayPoP ) = 0;
  98. virtual int GetDirectPingToPOP( SteamNetworkingPOPID popID ) = 0;
  99. /// Get number of network PoPs in the config
  100. virtual int GetPOPCount() = 0;
  101. /// Get list of all POP IDs
  102. virtual int GetPOPList( SteamNetworkingPOPID *list, int nListSz ) = 0;
  103. };
  104. #define STEAMNETWORKINGUTILS_VERSION "SteamNetworkingUtils001"
  105. /// Get ISteamNetworkingUtils object. This will eventually go in Steam_api.h with all the rest of its kin
  106. STEAMDATAGRAMLIB_INTERFACE ISteamNetworkingUtils *SteamNetworkingUtils();
  107. #endif // ISTEAMNETWORKINGUTILS