Rise
The Vieneo Province
Loading...
Searching...
No Matches
isteamnetworkingutils.h
Go to the documentation of this file.
1//====== Copyright Valve Corporation, All rights reserved. ====================
2//
3// Purpose: misc networking utilities
4//
5//=============================================================================
6
7#ifndef ISTEAMNETWORKINGUTILS
8#define ISTEAMNETWORKINGUTILS
9#pragma once
10
12#include "steam_api_common.h"
13
14struct SteamDatagramRelayAuthTicket;
16
17//-----------------------------------------------------------------------------
21{
22public:
23 //
24 // Efficient message sending
25 //
26
41 virtual SteamNetworkingMessage_t *AllocateMessage( int cbAllocateBuffer ) = 0;
42
43 //
44 // Access to Steam Datagram Relay (SDR) network
45 //
46
47 //
48 // Initialization and status check
49 //
50
71 inline void InitRelayNetworkAccess();
72
82
83 //
84 // "Ping location" functions
85 //
86 // We use the ping times to the valve relays deployed worldwide to
87 // generate a "marker" that describes the location of an Internet host.
88 // Given two such markers, we can estimate the network latency between
89 // two hosts, without sending any packets. The estimate is based on the
90 // optimal route that is found through the Valve network. If you are
91 // using the Valve network to carry the traffic, then this is precisely
92 // the ping you want. If you are not, then the ping time will probably
93 // still be a reasonable estimate.
94 //
95 // This is extremely useful to select peers for matchmaking!
96 //
97 // The markers can also be converted to a string, so they can be transmitted.
98 // We have a separate library you can use on your app's matchmaking/coordinating
99 // server to manipulate these objects. (See steamdatagram_gamecoordinator.h)
100
111
135
144 virtual int EstimatePingTimeFromLocalHost( const SteamNetworkPingLocation_t &remoteLocation ) = 0;
145
150 virtual void ConvertPingLocationToString( const SteamNetworkPingLocation_t &location, char *pszBuf, int cchBufSize ) = 0;
151
154 virtual bool ParsePingLocationString( const char *pszString, SteamNetworkPingLocation_t &result ) = 0;
155
174 virtual bool CheckPingDataUpToDate( float flMaxAgeSeconds ) = 0;
175
176 //
177 // List of Valve data centers, and ping times to them. This might
178 // be useful to you if you are use our hosting, or just need to measure
179 // latency to a cloud data center where we are running relays.
180 //
181
184 virtual int GetPingToDataCenter( SteamNetworkingPOPID popID, SteamNetworkingPOPID *pViaRelayPoP ) = 0;
185
187 virtual int GetDirectPingToPOP( SteamNetworkingPOPID popID ) = 0;
188
190 virtual int GetPOPCount() = 0;
191
194 virtual int GetPOPList( SteamNetworkingPOPID *list, int nListSz ) = 0;
195
196 //
197 // Misc
198 //
199
218
243
244 //
245 // Fake IP
246 //
247 // Useful for interfacing with code that assumes peers are identified using an IPv4 address
248 //
249
255
268 virtual EResult GetRealIdentityForFakeIP( const SteamNetworkingIPAddr &fakeIP, SteamNetworkingIdentity *pOutRealIdentity ) = 0;
269
270 //
271 // Set and get configuration values, see ESteamNetworkingConfigValue for individual descriptions.
272 //
273
274 // Shortcuts for common cases. (Implemented as inline functions below)
277 bool SetGlobalConfigValueString( ESteamNetworkingConfigValue eValue, const char *val );
282
283 //
284 // Set global callbacks. If you do not want to use Steam's callback dispatch mechanism and you
285 // want to use the same callback on all (or most) listen sockets and connections, then
286 // simply install these callbacks first thing, and you are good to go.
287 // See ISteamNetworkingSockets::RunCallbacks
288 //
295
306 virtual bool SetConfigValue( ESteamNetworkingConfigValue eValue, ESteamNetworkingConfigScope eScopeType, intptr_t scopeObj,
307 ESteamNetworkingConfigDataType eDataType, const void *pArg ) = 0;
308
313 bool SetConfigValueStruct( const SteamNetworkingConfigValue_t &opt, ESteamNetworkingConfigScope eScopeType, intptr_t scopeObj );
314
323 ESteamNetworkingConfigDataType *pOutDataType, void *pResult, size_t *cbResult ) = 0;
324
329 ESteamNetworkingConfigScope *pOutScope ) = 0;
330
340
341 //
342 // String conversions. You'll usually access these using the respective
343 // inline methods.
344 //
345 virtual void SteamNetworkingIPAddr_ToString( const SteamNetworkingIPAddr &addr, char *buf, size_t cbBuf, bool bWithPort ) = 0;
346 virtual bool SteamNetworkingIPAddr_ParseString( SteamNetworkingIPAddr *pAddr, const char *pszStr ) = 0;
348 virtual void SteamNetworkingIdentity_ToString( const SteamNetworkingIdentity &identity, char *buf, size_t cbBuf ) = 0;
349 virtual bool SteamNetworkingIdentity_ParseString( SteamNetworkingIdentity *pIdentity, const char *pszStr ) = 0;
350
351protected:
352 ~ISteamNetworkingUtils(); // Silence some warnings
353};
354#define STEAMNETWORKINGUTILS_INTERFACE_VERSION "SteamNetworkingUtils004"
355
356// Global accessors
357// Using standalone lib
358#ifdef STEAMNETWORKINGSOCKETS_STANDALONELIB
359
360 // Standalone lib
361 static_assert( STEAMNETWORKINGUTILS_INTERFACE_VERSION[22] == '4', "Version mismatch" );
362 STEAMNETWORKINGSOCKETS_INTERFACE ISteamNetworkingUtils *SteamNetworkingUtils_LibV4();
363 inline ISteamNetworkingUtils *SteamNetworkingUtils_Lib() { return SteamNetworkingUtils_LibV4(); }
364
365 #ifndef STEAMNETWORKINGSOCKETS_STEAMAPI
366 inline ISteamNetworkingUtils *SteamNetworkingUtils() { return SteamNetworkingUtils_LibV4(); }
367 #endif
368#endif
369
370// Using Steamworks SDK
371#ifdef STEAMNETWORKINGSOCKETS_STEAMAPI
373 /* Prefer user version of the interface. But if it isn't found, then use
374 gameserver one. Yes, this is a completely terrible hack */
378 "global",
380 )
381
382 #ifndef STEAMNETWORKINGSOCKETS_STANDALONELIB
383 inline ISteamNetworkingUtils *SteamNetworkingUtils() { return SteamNetworkingUtils_SteamAPI(); }
384 #endif
385#endif
386
421
422#ifndef API_GEN
423
427{
429 inline const char *c_str() const { return buf; }
430private:
432};
433
436{
437 SteamNetworkingIPAddrRender( const SteamNetworkingIPAddr &x, bool bWithPort = true ) { x.ToString( buf, sizeof(buf), bWithPort ); }
438 inline const char *c_str() const { return buf; }
439private:
441};
442
443#endif
444
446//
447// Internal stuff
448
453inline bool ISteamNetworkingUtils::SetGlobalConfigValuePtr( ESteamNetworkingConfigValue eValue, void *val ) { return SetConfigValue( eValue, k_ESteamNetworkingConfig_Global, 0, k_ESteamNetworkingConfig_Ptr, &val ); } // Note: passing pointer to pointer.
463
465{
466 // Locate the argument. Strings are a special case, since the
467 // "value" (the whole string buffer) doesn't fit in the struct
468 // NOTE: for pointer values, we pass a pointer to the pointer,
469 // we do not pass the pointer directly.
470 const void *pVal = ( opt.m_eDataType == k_ESteamNetworkingConfig_String ) ? (const void *)opt.m_val.m_string : (const void *)&opt.m_val;
471 return SetConfigValue( opt.m_eValue, eScopeType, scopeObj, opt.m_eDataType, pVal );
472}
473
474// How to get helper functions.
475#if defined( STEAMNETWORKINGSOCKETS_STATIC_LINK ) || defined(STEAMNETWORKINGSOCKETS_FOREXPORT) || defined( STEAMNETWORKINGSOCKETS_STANDALONELIB )
476
477 // Call direct to static functions
478 STEAMNETWORKINGSOCKETS_INTERFACE void SteamNetworkingIPAddr_ToString( const SteamNetworkingIPAddr *pAddr, char *buf, size_t cbBuf, bool bWithPort );
479 STEAMNETWORKINGSOCKETS_INTERFACE bool SteamNetworkingIPAddr_ParseString( SteamNetworkingIPAddr *pAddr, const char *pszStr );
480 STEAMNETWORKINGSOCKETS_INTERFACE ESteamNetworkingFakeIPType SteamNetworkingIPAddr_GetFakeIPType( const SteamNetworkingIPAddr *pAddr );
481 STEAMNETWORKINGSOCKETS_INTERFACE void SteamNetworkingIdentity_ToString( const SteamNetworkingIdentity *pIdentity, char *buf, size_t cbBuf );
482 STEAMNETWORKINGSOCKETS_INTERFACE bool SteamNetworkingIdentity_ParseString( SteamNetworkingIdentity *pIdentity, size_t sizeofIdentity, const char *pszStr );
483 inline void SteamNetworkingIPAddr::ToString( char *buf, size_t cbBuf, bool bWithPort ) const { SteamNetworkingIPAddr_ToString( this, buf, cbBuf, bWithPort ); }
484 inline bool SteamNetworkingIPAddr::ParseString( const char *pszStr ) { return SteamNetworkingIPAddr_ParseString( this, pszStr ); }
485 inline ESteamNetworkingFakeIPType SteamNetworkingIPAddr::GetFakeIPType() const { return SteamNetworkingIPAddr_GetFakeIPType( this ); }
486 inline void SteamNetworkingIdentity::ToString( char *buf, size_t cbBuf ) const { SteamNetworkingIdentity_ToString( this, buf, cbBuf ); }
487 inline bool SteamNetworkingIdentity::ParseString( const char *pszStr ) { return SteamNetworkingIdentity_ParseString( this, sizeof(*this), pszStr ); }
488
489#elif defined( STEAMNETWORKINGSOCKETS_STEAMAPI )
490 // Using steamworks SDK - go through SteamNetworkingUtils()
491 inline void SteamNetworkingIPAddr::ToString( char *buf, size_t cbBuf, bool bWithPort ) const { SteamNetworkingUtils()->SteamNetworkingIPAddr_ToString( *this, buf, cbBuf, bWithPort ); }
492 inline bool SteamNetworkingIPAddr::ParseString( const char *pszStr ) { return SteamNetworkingUtils()->SteamNetworkingIPAddr_ParseString( this, pszStr ); }
493 inline ESteamNetworkingFakeIPType SteamNetworkingIPAddr::GetFakeIPType() const { return SteamNetworkingUtils()->SteamNetworkingIPAddr_GetFakeIPType( *this ); }
494 inline void SteamNetworkingIdentity::ToString( char *buf, size_t cbBuf ) const { SteamNetworkingUtils()->SteamNetworkingIdentity_ToString( *this, buf, cbBuf ); }
495 inline bool SteamNetworkingIdentity::ParseString( const char *pszStr ) { return SteamNetworkingUtils()->SteamNetworkingIdentity_ParseString( this, pszStr ); }
496#else
497 #error "Invalid config"
498#endif
499
500#endif // ISTEAMNETWORKINGUTILS
bool SetConfigValueStruct(const SteamNetworkingConfigValue_t &opt, ESteamNetworkingConfigScope eScopeType, intptr_t scopeObj)
virtual bool CheckPingDataUpToDate(float flMaxAgeSeconds)=0
bool SetConnectionConfigValueFloat(HSteamNetConnection hConn, ESteamNetworkingConfigValue eValue, float val)
virtual int EstimatePingTimeFromLocalHost(const SteamNetworkPingLocation_t &remoteLocation)=0
virtual ESteamNetworkingConfigValue IterateGenericEditableConfigValues(ESteamNetworkingConfigValue eCurrent, bool bEnumerateDevVars)=0
bool SetGlobalConfigValueFloat(ESteamNetworkingConfigValue eValue, float val)
virtual SteamNetworkingMessage_t * AllocateMessage(int cbAllocateBuffer)=0
virtual ESteamNetworkingGetConfigValueResult GetConfigValue(ESteamNetworkingConfigValue eValue, ESteamNetworkingConfigScope eScopeType, intptr_t scopeObj, ESteamNetworkingConfigDataType *pOutDataType, void *pResult, size_t *cbResult)=0
bool SetGlobalConfigValuePtr(ESteamNetworkingConfigValue eValue, void *val)
bool SetGlobalCallback_FakeIPResult(FnSteamNetworkingFakeIPResult fnCallback)
bool SetConnectionConfigValueInt32(HSteamNetConnection hConn, ESteamNetworkingConfigValue eValue, int32 val)
virtual bool SteamNetworkingIPAddr_ParseString(SteamNetworkingIPAddr *pAddr, const char *pszStr)=0
virtual void SteamNetworkingIdentity_ToString(const SteamNetworkingIdentity &identity, char *buf, size_t cbBuf)=0
virtual int GetPOPList(SteamNetworkingPOPID *list, int nListSz)=0
virtual void ConvertPingLocationToString(const SteamNetworkPingLocation_t &location, char *pszBuf, int cchBufSize)=0
virtual const char * GetConfigValueInfo(ESteamNetworkingConfigValue eValue, ESteamNetworkingConfigDataType *pOutDataType, ESteamNetworkingConfigScope *pOutScope)=0
bool IsFakeIPv4(uint32 nIPv4)
virtual int GetDirectPingToPOP(SteamNetworkingPOPID popID)=0
Get direct ping time to the relays at the data center.
bool SetGlobalCallback_MessagesSessionRequest(FnSteamNetworkingMessagesSessionRequest fnCallback)
virtual ESteamNetworkingFakeIPType SteamNetworkingIPAddr_GetFakeIPType(const SteamNetworkingIPAddr &addr)=0
virtual bool SetConfigValue(ESteamNetworkingConfigValue eValue, ESteamNetworkingConfigScope eScopeType, intptr_t scopeObj, ESteamNetworkingConfigDataType eDataType, const void *pArg)=0
bool SetGlobalCallback_SteamRelayNetworkStatusChanged(FnSteamRelayNetworkStatusChanged fnCallback)
bool SetGlobalConfigValueString(ESteamNetworkingConfigValue eValue, const char *val)
virtual float GetLocalPingLocation(SteamNetworkPingLocation_t &result)=0
virtual SteamNetworkingMicroseconds GetLocalTimestamp()=0
virtual int GetPingToDataCenter(SteamNetworkingPOPID popID, SteamNetworkingPOPID *pViaRelayPoP)=0
virtual ESteamNetworkingFakeIPType GetIPv4FakeIPType(uint32 nIPv4)=0
virtual void SetDebugOutputFunction(ESteamNetworkingSocketsDebugOutputType eDetailLevel, FSteamNetworkingSocketsDebugOutput pfnFunc)=0
virtual int GetPOPCount()=0
Get number of network points of presence in the config.
virtual int EstimatePingTimeBetweenTwoLocations(const SteamNetworkPingLocation_t &location1, const SteamNetworkPingLocation_t &location2)=0
virtual ESteamNetworkingAvailability GetRelayNetworkStatus(SteamRelayNetworkStatus_t *pDetails)=0
bool SetGlobalCallback_SteamNetAuthenticationStatusChanged(FnSteamNetAuthenticationStatusChanged fnCallback)
virtual EResult GetRealIdentityForFakeIP(const SteamNetworkingIPAddr &fakeIP, SteamNetworkingIdentity *pOutRealIdentity)=0
bool SetGlobalCallback_SteamNetConnectionStatusChanged(FnSteamNetConnectionStatusChanged fnCallback)
bool SetConnectionConfigValueString(HSteamNetConnection hConn, ESteamNetworkingConfigValue eValue, const char *val)
virtual bool SteamNetworkingIdentity_ParseString(SteamNetworkingIdentity *pIdentity, const char *pszStr)=0
virtual bool ParsePingLocationString(const char *pszString, SteamNetworkPingLocation_t &result)=0
bool SetGlobalCallback_MessagesSessionFailed(FnSteamNetworkingMessagesSessionFailed fnCallback)
bool SetGlobalConfigValueInt32(ESteamNetworkingConfigValue eValue, int32 val)
virtual void SteamNetworkingIPAddr_ToString(const SteamNetworkingIPAddr &addr, char *buf, size_t cbBuf, bool bWithPort)=0
#define STEAMNETWORKINGUTILS_INTERFACE_VERSION
const char *typedef uint32(S_CALLTYPE *SteamAPI_CheckCallbackRegistered_t)(int iCallbackNum)
@ k_iSteamNetworkingUtilsCallbacks
S_API void *S_CALLTYPE SteamInternal_FindOrCreateGameServerInterface(HSteamUser hSteamUser, const char *pszVersion)
S_API void *S_CALLTYPE SteamInternal_FindOrCreateUserInterface(HSteamUser hSteamUser, const char *pszVersion)
#define STEAM_DEFINE_INTERFACE_ACCESSOR(type, name, expr, kind, version)
#define STEAMNETWORKINGSOCKETS_INTERFACE
ESteamNetworkingSocketsDebugOutputType
void(*) FnSteamNetConnectionStatusChanged(SteamNetConnectionStatusChangedCallback_t *)
void(*) FnSteamNetworkingFakeIPResult(SteamNetworkingFakeIPResult_t *)
int64 SteamNetworkingMicroseconds
ESteamNetworkingFakeIPType
@ k_ESteamNetworkingFakeIPType_NotFake
uint32 HSteamNetConnection
Handle used to identify a connection to a remote host.
void(*) FnSteamNetAuthenticationStatusChanged(SteamNetAuthenticationStatus_t *)
ESteamNetworkingConfigScope
Configuration values can be applied to different types of objects.
@ k_ESteamNetworkingConfig_Connection
Options for a specific connection.
@ k_ESteamNetworkingConfig_Global
ESteamNetworkingConfigValue
Configuration options.
@ k_ESteamNetworkingConfig_Callback_ConnectionStatusChanged
@ k_ESteamNetworkingConfig_Callback_RelayNetworkStatusChanged
@ k_ESteamNetworkingConfig_Callback_MessagesSessionFailed
@ k_ESteamNetworkingConfig_Callback_MessagesSessionRequest
@ k_ESteamNetworkingConfig_Callback_FakeIPResult
@ k_ESteamNetworkingConfig_Callback_AuthStatusChanged
void(*) FSteamNetworkingSocketsDebugOutput(ESteamNetworkingSocketsDebugOutputType nType, const char *pszMsg)
Setup callback for debug output, and the desired verbosity you want.
ESteamNetworkingAvailability
Describe the status of a particular network resource.
void(*) FnSteamNetworkingMessagesSessionRequest(SteamNetworkingMessagesSessionRequest_t *)
void(*) FnSteamNetworkingMessagesSessionFailed(SteamNetworkingMessagesSessionFailed_t *)
ESteamNetworkingGetConfigValueResult
Return value of ISteamNetworkintgUtils::GetConfigValue.
void(*) FnSteamRelayNetworkStatusChanged(SteamRelayNetworkStatus_t *)
uint32 SteamNetworkingPOPID
ESteamNetworkingConfigDataType
@ k_ESteamNetworkingConfig_String
@ k_ESteamNetworkingConfig_Int32
@ k_ESteamNetworkingConfig_Ptr
@ k_ESteamNetworkingConfig_Float
int int32
Definition steamtypes.h:57
ESteamNetworkingConfigValue m_eValue
Which option is being set.
union SteamNetworkingConfigValue_t::@226264230310136375067366131222017367032047164040 m_val
ESteamNetworkingConfigDataType m_eDataType
Which field below did you fill in?
bool ParseString(const char *pszStr)
ESteamNetworkingFakeIPType GetFakeIPType() const
void ToString(char *buf, size_t cbBuf, bool bWithPort) const
SteamNetworkingIPAddrRender(const SteamNetworkingIPAddr &x, bool bWithPort=true)
char buf[SteamNetworkingIPAddr::k_cchMaxString]
bool ParseString(const char *pszStr)
void ToString(char *buf, size_t cbBuf) const
char buf[SteamNetworkingIdentity::k_cchMaxString]
SteamNetworkingIdentityRender(const SteamNetworkingIdentity &x)
A message that has been received.
ESteamNetworkingAvailability m_eAvailNetworkConfig
ESteamNetworkingAvailability m_eAvailAnyRelay
ESteamNetworkingAvailability m_eAvail