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 
11 #include "steamnetworkingtypes.h"
12 #include "steam_api_common.h"
13 
14 struct SteamDatagramRelayAuthTicket;
15 struct SteamRelayNetworkStatus_t;
16 
17 //-----------------------------------------------------------------------------
18 /// Misc networking utilities for checking the local networking environment
19 /// and estimating pings.
20 class ISteamNetworkingUtils
21 {
22 public:
23 	//
24 	// Efficient message sending
25 	//
26 
27 	/// Allocate and initialize a message object.  Usually the reason
28 	/// you call this is to pass it to ISteamNetworkingSockets::SendMessages.
29 	/// The returned object will have all of the relevant fields cleared to zero.
30 	///
31 	/// Optionally you can also request that this system allocate space to
32 	/// hold the payload itself.  If cbAllocateBuffer is nonzero, the system
33 	/// will allocate memory to hold a payload of at least cbAllocateBuffer bytes.
34 	/// m_pData will point to the allocated buffer, m_cbSize will be set to the
35 	/// size, and m_pfnFreeData will be set to the proper function to free up
36 	/// the buffer.
37 	///
38 	/// If cbAllocateBuffer=0, then no buffer is allocated.  m_pData will be NULL,
39 	/// m_cbSize will be zero, and m_pfnFreeData will be NULL.  You will need to
40 	/// set each of these.
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 
51 	/// If you know that you are going to be using the relay network (for example,
52 	/// because you anticipate making P2P connections), call this to initialize the
53 	/// relay network.  If you do not call this, the initialization will
54 	/// be delayed until the first time you use a feature that requires access
55 	/// to the relay network, which will delay that first access.
56 	///
57 	/// You can also call this to force a retry if the previous attempt has failed.
58 	/// Performing any action that requires access to the relay network will also
59 	/// trigger a retry, and so calling this function is never strictly necessary,
60 	/// but it can be useful to call it a program launch time, if access to the
61 	/// relay network is anticipated.
62 	///
63 	/// Use GetRelayNetworkStatus or listen for SteamRelayNetworkStatus_t
64 	/// callbacks to know when initialization has completed.
65 	/// Typically initialization completes in a few seconds.
66 	///
67 	/// Note: dedicated servers hosted in known data centers do *not* need
68 	/// to call this, since they do not make routing decisions.  However, if
69 	/// the dedicated server will be using P2P functionality, it will act as
70 	/// a "client" and this should be called.
71 	inline void InitRelayNetworkAccess();
72 
73 	/// Fetch current status of the relay network.
74 	///
75 	/// SteamRelayNetworkStatus_t is also a callback.  It will be triggered on
76 	/// both the user and gameserver interfaces any time the status changes, or
77 	/// ping measurement starts or stops.
78 	///
79 	/// SteamRelayNetworkStatus_t::m_eAvail is returned.  If you want
80 	/// more details, you can pass a non-NULL value.
81 	virtual ESteamNetworkingAvailability GetRelayNetworkStatus( SteamRelayNetworkStatus_t *pDetails ) = 0;
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 
101 	/// Return location info for the current host.  Returns the approximate
102 	/// age of the data, in seconds, or -1 if no data is available.
103 	///
104 	/// It takes a few seconds to initialize access to the relay network.  If
105 	/// you call this very soon after calling InitRelayNetworkAccess,
106 	/// the data may not be available yet.
107 	///
108 	/// This always return the most up-to-date information we have available
109 	/// right now, even if we are in the middle of re-calculating ping times.
110 	virtual float GetLocalPingLocation( SteamNetworkPingLocation_t &result ) = 0;
111 
112 	/// Estimate the round-trip latency between two arbitrary locations, in
113 	/// milliseconds.  This is a conservative estimate, based on routing through
114 	/// the relay network.  For most basic relayed connections, this ping time
115 	/// will be pretty accurate, since it will be based on the route likely to
116 	/// be actually used.
117 	///
118 	/// If a direct IP route is used (perhaps via NAT traversal), then the route
119 	/// will be different, and the ping time might be better.  Or it might actually
120 	/// be a bit worse!  Standard IP routing is frequently suboptimal!
121 	///
122 	/// But even in this case, the estimate obtained using this method is a
123 	/// reasonable upper bound on the ping time.  (Also it has the advantage
124 	/// of returning immediately and not sending any packets.)
125 	///
126 	/// In a few cases we might not able to estimate the route.  In this case
127 	/// a negative value is returned.  k_nSteamNetworkingPing_Failed means
128 	/// the reason was because of some networking difficulty.  (Failure to
129 	/// ping, etc)  k_nSteamNetworkingPing_Unknown is returned if we cannot
130 	/// currently answer the question for some other reason.
131 	///
132 	/// Do you need to be able to do this from a backend/matchmaking server?
133 	/// You are looking for the "ticketgen" library.
134 	virtual int EstimatePingTimeBetweenTwoLocations( const SteamNetworkPingLocation_t &location1, const SteamNetworkPingLocation_t &location2 ) = 0;
135 
136 	/// Same as EstimatePingTime, but assumes that one location is the local host.
137 	/// This is a bit faster, especially if you need to calculate a bunch of
138 	/// these in a loop to find the fastest one.
139 	///
140 	/// In rare cases this might return a slightly different estimate than combining
141 	/// GetLocalPingLocation with EstimatePingTimeBetweenTwoLocations.  That's because
142 	/// this function uses a slightly more complete set of information about what
143 	/// route would be taken.
144 	virtual int EstimatePingTimeFromLocalHost( const SteamNetworkPingLocation_t &remoteLocation ) = 0;
145 
146 	/// Convert a ping location into a text format suitable for sending over the wire.
147 	/// The format is a compact and human readable.  However, it is subject to change
148 	/// so please do not parse it yourself.  Your buffer must be at least
149 	/// k_cchMaxSteamNetworkingPingLocationString bytes.
150 	virtual void ConvertPingLocationToString( const SteamNetworkPingLocation_t &location, char *pszBuf, int cchBufSize ) = 0;
151 
152 	/// Parse back SteamNetworkPingLocation_t string.  Returns false if we couldn't understand
153 	/// the string.
154 	virtual bool ParsePingLocationString( const char *pszString, SteamNetworkPingLocation_t &result ) = 0;
155 
156 	/// Check if the ping data of sufficient recency is available, and if
157 	/// it's too old, start refreshing it.
158 	///
159 	/// Please only call this function when you *really* do need to force an
160 	/// immediate refresh of the data.  (For example, in response to a specific
161 	/// user input to refresh this information.)  Don't call it "just in case",
162 	/// before every connection, etc.  That will cause extra traffic to be sent
163 	/// for no benefit. The library will automatically refresh the information
164 	/// as needed.
165 	///
166 	/// Returns true if sufficiently recent data is already available.
167 	///
168 	/// Returns false if sufficiently recent data is not available.  In this
169 	/// case, ping measurement is initiated, if it is not already active.
170 	/// (You cannot restart a measurement already in progress.)
171 	///
172 	/// You can use GetRelayNetworkStatus or listen for SteamRelayNetworkStatus_t
173 	/// to know when ping measurement completes.
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 
182 	/// Fetch ping time of best available relayed route from this host to
183 	/// the specified data center.
184 	virtual int GetPingToDataCenter( SteamNetworkingPOPID popID, SteamNetworkingPOPID *pViaRelayPoP ) = 0;
185 
186 	/// Get *direct* ping time to the relays at the data center.
187 	virtual int GetDirectPingToPOP( SteamNetworkingPOPID popID ) = 0;
188 
189 	/// Get number of network points of presence in the config
190 	virtual int GetPOPCount() = 0;
191 
192 	/// Get list of all POP IDs.  Returns the number of entries that were filled into
193 	/// your list.
194 	virtual int GetPOPList( SteamNetworkingPOPID *list, int nListSz ) = 0;
195 
196 	//
197 	// Misc
198 	//
199 
200 	/// Fetch current timestamp.  This timer has the following properties:
201 	///
202 	/// - Monotonicity is guaranteed.
203 	/// - The initial value will be at least 24*3600*30*1e6, i.e. about
204 	///   30 days worth of microseconds.  In this way, the timestamp value of
205 	///   0 will always be at least "30 days ago".  Also, negative numbers
206 	///   will never be returned.
207 	/// - Wraparound / overflow is not a practical concern.
208 	///
209 	/// If you are running under the debugger and stop the process, the clock
210 	/// might not advance the full wall clock time that has elapsed between
211 	/// calls.  If the process is not blocked from normal operation, the
212 	/// timestamp values will track wall clock time, even if you don't call
213 	/// the function frequently.
214 	///
215 	/// The value is only meaningful for this run of the process.  Don't compare
216 	/// it to values obtained on another computer, or other runs of the same process.
217 	virtual SteamNetworkingMicroseconds GetLocalTimestamp() = 0;
218 
219 	/// Set a function to receive network-related information that is useful for debugging.
220 	/// This can be very useful during development, but it can also be useful for troubleshooting
221 	/// problems with tech savvy end users.  If you have a console or other log that customers
222 	/// can examine, these log messages can often be helpful to troubleshoot network issues.
223 	/// (Especially any warning/error messages.)
224 	///
225 	/// The detail level indicates what message to invoke your callback on.  Lower numeric
226 	/// value means more important, and the value you pass is the lowest priority (highest
227 	/// numeric value) you wish to receive callbacks for.
228 	///
229 	/// The value here controls the detail level for most messages.  You can control the
230 	/// detail level for various subsystems (perhaps only for certain connections) by
231 	/// adjusting the configuration values k_ESteamNetworkingConfig_LogLevel_Xxxxx.
232 	///
233 	/// Except when debugging, you should only use k_ESteamNetworkingSocketsDebugOutputType_Msg
234 	/// or k_ESteamNetworkingSocketsDebugOutputType_Warning.  For best performance, do NOT
235 	/// request a high detail level and then filter out messages in your callback.  This incurs
236 	/// all of the expense of formatting the messages, which are then discarded.  Setting a high
237 	/// priority value (low numeric value) here allows the library to avoid doing this work.
238 	///
239 	/// IMPORTANT: This may be called from a service thread, while we own a mutex, etc.
240 	/// Your output function must be threadsafe and fast!  Do not make any other
241 	/// Steamworks calls from within the handler.
242 	virtual void SetDebugOutputFunction( ESteamNetworkingSocketsDebugOutputType eDetailLevel, FSteamNetworkingSocketsDebugOutput pfnFunc ) = 0;
243 
244 	//
245 	// Set and get configuration values, see ESteamNetworkingConfigValue for individual descriptions.
246 	//
247 
248 	// Shortcuts for common cases.  (Implemented as inline functions below)
249 	bool SetGlobalConfigValueInt32( ESteamNetworkingConfigValue eValue, int32 val );
250 	bool SetGlobalConfigValueFloat( ESteamNetworkingConfigValue eValue, float val );
251 	bool SetGlobalConfigValueString( ESteamNetworkingConfigValue eValue, const char *val );
252 	bool SetGlobalConfigValuePtr( ESteamNetworkingConfigValue eValue, void *val );
253 	bool SetConnectionConfigValueInt32( HSteamNetConnection hConn, ESteamNetworkingConfigValue eValue, int32 val );
254 	bool SetConnectionConfigValueFloat( HSteamNetConnection hConn, ESteamNetworkingConfigValue eValue, float val );
255 	bool SetConnectionConfigValueString( HSteamNetConnection hConn, ESteamNetworkingConfigValue eValue, const char *val );
256 
257 	//
258 	// Set global callbacks.  If you do not want to use Steam's callback dispatch mechanism and you
259 	// want to use the same callback on all (or most) listen sockets and connections, then
260 	// simply install these callbacks first thing, and you are good to go.
261 	// See ISteamNetworkingSockets::RunCallbacks
262 	//
263 	bool SetGlobalCallback_SteamNetConnectionStatusChanged( FnSteamNetConnectionStatusChanged fnCallback );
264 	bool SetGlobalCallback_SteamNetAuthenticationStatusChanged( FnSteamNetAuthenticationStatusChanged fnCallback );
265 	bool SetGlobalCallback_SteamRelayNetworkStatusChanged( FnSteamRelayNetworkStatusChanged fnCallback );
266 	bool SetGlobalCallback_MessagesSessionRequest( FnSteamNetworkingMessagesSessionRequest fnCallback );
267 	bool SetGlobalCallback_MessagesSessionFailed( FnSteamNetworkingMessagesSessionFailed fnCallback );
268 
269 	/// Set a configuration value.
270 	/// - eValue: which value is being set
271 	/// - eScope: Onto what type of object are you applying the setting?
272 	/// - scopeArg: Which object you want to change?  (Ignored for global scope).  E.g. connection handle, listen socket handle, interface pointer, etc.
273 	/// - eDataType: What type of data is in the buffer at pValue?  This must match the type of the variable exactly!
274 	/// - pArg: Value to set it to.  You can pass NULL to remove a non-global setting at this scope,
275 	///   causing the value for that object to use global defaults.  Or at global scope, passing NULL
276 	///   will reset any custom value and restore it to the system default.
277 	///   NOTE: When setting pointers (e.g. callback functions), do not pass the function pointer directly.
278 	///   Your argument should be a pointer to a function pointer.
279 	virtual bool SetConfigValue( ESteamNetworkingConfigValue eValue, ESteamNetworkingConfigScope eScopeType, intptr_t scopeObj,
280 		ESteamNetworkingConfigDataType eDataType, const void *pArg ) = 0;
281 
282 	/// Set a configuration value, using a struct to pass the value.
283 	/// (This is just a convenience shortcut; see below for the implementation and
284 	/// a little insight into how SteamNetworkingConfigValue_t is used when
285 	/// setting config options during listen socket and connection creation.)
286 	bool SetConfigValueStruct( const SteamNetworkingConfigValue_t &opt, ESteamNetworkingConfigScope eScopeType, intptr_t scopeObj );
287 
288 	/// Get a configuration value.
289 	/// - eValue: which value to fetch
290 	/// - eScopeType: query setting on what type of object
291 	/// - eScopeArg: the object to query the setting for
292 	/// - pOutDataType: If non-NULL, the data type of the value is returned.
293 	/// - pResult: Where to put the result.  Pass NULL to query the required buffer size.  (k_ESteamNetworkingGetConfigValue_BufferTooSmall will be returned.)
294 	/// - cbResult: IN: the size of your buffer.  OUT: the number of bytes filled in or required.
295 	virtual ESteamNetworkingGetConfigValueResult GetConfigValue( ESteamNetworkingConfigValue eValue, ESteamNetworkingConfigScope eScopeType, intptr_t scopeObj,
296 		ESteamNetworkingConfigDataType *pOutDataType, void *pResult, size_t *cbResult ) = 0;
297 
298 	/// Returns info about a configuration value.  Returns false if the value does not exist.
299 	/// pOutNextValue can be used to iterate through all of the known configuration values.
300 	/// (Use GetFirstConfigValue() to begin the iteration, will be k_ESteamNetworkingConfig_Invalid on the last value)
301 	/// Any of the output parameters can be NULL if you do not need that information.
302 	///
303 	/// See k_ESteamNetworkingConfig_EnumerateDevVars for some more info about "dev" variables,
304 	/// which are usually excluded from the set of variables enumerated using this function.
305 	virtual bool GetConfigValueInfo( ESteamNetworkingConfigValue eValue, const char **pOutName, ESteamNetworkingConfigDataType *pOutDataType, ESteamNetworkingConfigScope *pOutScope, ESteamNetworkingConfigValue *pOutNextValue ) = 0;
306 
307 	/// Return the lowest numbered configuration value available in the current environment.
308 	virtual ESteamNetworkingConfigValue GetFirstConfigValue() = 0;
309 
310 	// String conversions.  You'll usually access these using the respective
311 	// inline methods.
312 	virtual void SteamNetworkingIPAddr_ToString( const SteamNetworkingIPAddr &addr, char *buf, size_t cbBuf, bool bWithPort ) = 0;
313 	virtual bool SteamNetworkingIPAddr_ParseString( SteamNetworkingIPAddr *pAddr, const char *pszStr ) = 0;
314 	virtual void SteamNetworkingIdentity_ToString( const SteamNetworkingIdentity &identity, char *buf, size_t cbBuf ) = 0;
315 	virtual bool SteamNetworkingIdentity_ParseString( SteamNetworkingIdentity *pIdentity, const char *pszStr ) = 0;
316 
317 protected:
318 	~ISteamNetworkingUtils(); // Silence some warnings
319 };
320 #define STEAMNETWORKINGUTILS_INTERFACE_VERSION "SteamNetworkingUtils003"
321 
322 // Global accessors
323 // Using standalone lib
324 #ifdef STEAMNETWORKINGSOCKETS_STANDALONELIB
325 
326 	// Standalone lib
327 	static_assert( STEAMNETWORKINGUTILS_INTERFACE_VERSION[22] == '3', "Version mismatch" );
328 	STEAMNETWORKINGSOCKETS_INTERFACE ISteamNetworkingUtils *SteamNetworkingUtils_LibV3();
SteamNetworkingUtils_Lib()329 	inline ISteamNetworkingUtils *SteamNetworkingUtils_Lib() { return SteamNetworkingUtils_LibV3(); }
330 
331 	#ifndef STEAMNETWORKINGSOCKETS_STEAMAPI
SteamNetworkingUtils()332 		inline ISteamNetworkingUtils *SteamNetworkingUtils() { return SteamNetworkingUtils_LibV3(); }
333 	#endif
334 #endif
335 
336 // Using Steamworks SDK
337 #ifdef STEAMNETWORKINGSOCKETS_STEAMAPI
338 	STEAM_DEFINE_INTERFACE_ACCESSOR( ISteamNetworkingUtils *, SteamNetworkingUtils_SteamAPI,
339 		/* Prefer user version of the interface.  But if it isn't found, then use
340 		gameserver one.  Yes, this is a completely terrible hack */
341 		SteamInternal_FindOrCreateUserInterface( 0, STEAMNETWORKINGUTILS_INTERFACE_VERSION ) ?
342 		SteamInternal_FindOrCreateUserInterface( 0, STEAMNETWORKINGUTILS_INTERFACE_VERSION ) :
343 		SteamInternal_FindOrCreateGameServerInterface( 0, STEAMNETWORKINGUTILS_INTERFACE_VERSION ),
344 		"global",
345 		STEAMNETWORKINGUTILS_INTERFACE_VERSION
346 	)
347 
348 	#ifndef STEAMNETWORKINGSOCKETS_STANDALONELIB
SteamNetworkingUtils()349 		inline ISteamNetworkingUtils *SteamNetworkingUtils() { return SteamNetworkingUtils_SteamAPI(); }
350 	#endif
351 #endif
352 
353 /// A struct used to describe our readiness to use the relay network.
354 /// To do this we first need to fetch the network configuration,
355 /// which describes what POPs are available.
356 struct SteamRelayNetworkStatus_t
357 {
358 	enum { k_iCallback = k_iSteamNetworkingUtilsCallbacks + 1 };
359 
360 	/// Summary status.  When this is "current", initialization has
361 	/// completed.  Anything else means you are not ready yet, or
362 	/// there is a significant problem.
363 	ESteamNetworkingAvailability m_eAvail;
364 
365 	/// Nonzero if latency measurement is in progress (or pending,
366 	/// awaiting a prerequisite).
367 	int m_bPingMeasurementInProgress;
368 
369 	/// Status obtaining the network config.  This is a prerequisite
370 	/// for relay network access.
371 	///
372 	/// Failure to obtain the network config almost always indicates
373 	/// a problem with the local internet connection.
374 	ESteamNetworkingAvailability m_eAvailNetworkConfig;
375 
376 	/// Current ability to communicate with ANY relay.  Note that
377 	/// the complete failure to communicate with any relays almost
378 	/// always indicates a problem with the local Internet connection.
379 	/// (However, just because you can reach a single relay doesn't
380 	/// mean that the local connection is in perfect health.)
381 	ESteamNetworkingAvailability m_eAvailAnyRelay;
382 
383 	/// Non-localized English language status.  For diagnostic/debugging
384 	/// purposes only.
385 	char m_debugMsg[ 256 ];
386 };
387 
388 /// Utility class for printing a SteamNetworkingIdentity.
389 /// E.g. printf( "Identity is '%s'\n", SteamNetworkingIdentityRender( identity ).c_str() );
390 struct SteamNetworkingIdentityRender
391 {
SteamNetworkingIdentityRenderSteamNetworkingIdentityRender392 	SteamNetworkingIdentityRender( const SteamNetworkingIdentity &x ) { x.ToString( buf, sizeof(buf) ); }
c_strSteamNetworkingIdentityRender393 	inline const char *c_str() const { return buf; }
394 private:
395 	char buf[ SteamNetworkingIdentity::k_cchMaxString ];
396 };
397 
398 /// Utility class for printing a SteamNetworkingIPAddrRender.
399 struct SteamNetworkingIPAddrRender
400 {
401 	SteamNetworkingIPAddrRender( const SteamNetworkingIPAddr &x, bool bWithPort = true ) { x.ToString( buf, sizeof(buf), bWithPort ); }
c_strSteamNetworkingIPAddrRender402 	inline const char *c_str() const { return buf; }
403 private:
404 	char buf[ SteamNetworkingIPAddr::k_cchMaxString ];
405 };
406 
407 ///////////////////////////////////////////////////////////////////////////////
408 //
409 // Internal stuff
410 
InitRelayNetworkAccess()411 inline void ISteamNetworkingUtils::InitRelayNetworkAccess() { CheckPingDataUpToDate( 1e10f ); }
SetGlobalConfigValueInt32(ESteamNetworkingConfigValue eValue,int32 val)412 inline bool ISteamNetworkingUtils::SetGlobalConfigValueInt32( ESteamNetworkingConfigValue eValue, int32 val ) { return SetConfigValue( eValue, k_ESteamNetworkingConfig_Global, 0, k_ESteamNetworkingConfig_Int32, &val ); }
SetGlobalConfigValueFloat(ESteamNetworkingConfigValue eValue,float val)413 inline bool ISteamNetworkingUtils::SetGlobalConfigValueFloat( ESteamNetworkingConfigValue eValue, float val ) { return SetConfigValue( eValue, k_ESteamNetworkingConfig_Global, 0, k_ESteamNetworkingConfig_Float, &val ); }
SetGlobalConfigValueString(ESteamNetworkingConfigValue eValue,const char * val)414 inline bool ISteamNetworkingUtils::SetGlobalConfigValueString( ESteamNetworkingConfigValue eValue, const char *val ) { return SetConfigValue( eValue, k_ESteamNetworkingConfig_Global, 0, k_ESteamNetworkingConfig_String, val ); }
SetGlobalConfigValuePtr(ESteamNetworkingConfigValue eValue,void * val)415 inline bool ISteamNetworkingUtils::SetGlobalConfigValuePtr( ESteamNetworkingConfigValue eValue, void *val ) { return SetConfigValue( eValue, k_ESteamNetworkingConfig_Global, 0, k_ESteamNetworkingConfig_Ptr, &val ); } // Note: passing pointer to pointer.
SetConnectionConfigValueInt32(HSteamNetConnection hConn,ESteamNetworkingConfigValue eValue,int32 val)416 inline bool ISteamNetworkingUtils::SetConnectionConfigValueInt32( HSteamNetConnection hConn, ESteamNetworkingConfigValue eValue, int32 val ) { return SetConfigValue( eValue, k_ESteamNetworkingConfig_Connection, hConn, k_ESteamNetworkingConfig_Int32, &val ); }
SetConnectionConfigValueFloat(HSteamNetConnection hConn,ESteamNetworkingConfigValue eValue,float val)417 inline bool ISteamNetworkingUtils::SetConnectionConfigValueFloat( HSteamNetConnection hConn, ESteamNetworkingConfigValue eValue, float val ) { return SetConfigValue( eValue, k_ESteamNetworkingConfig_Connection, hConn, k_ESteamNetworkingConfig_Float, &val ); }
SetConnectionConfigValueString(HSteamNetConnection hConn,ESteamNetworkingConfigValue eValue,const char * val)418 inline bool ISteamNetworkingUtils::SetConnectionConfigValueString( HSteamNetConnection hConn, ESteamNetworkingConfigValue eValue, const char *val ) { return SetConfigValue( eValue, k_ESteamNetworkingConfig_Connection, hConn, k_ESteamNetworkingConfig_String, val ); }
SetGlobalCallback_SteamNetConnectionStatusChanged(FnSteamNetConnectionStatusChanged fnCallback)419 inline bool ISteamNetworkingUtils::SetGlobalCallback_SteamNetConnectionStatusChanged( FnSteamNetConnectionStatusChanged fnCallback ) { return SetGlobalConfigValuePtr( k_ESteamNetworkingConfig_Callback_ConnectionStatusChanged, (void*)fnCallback ); }
SetGlobalCallback_SteamNetAuthenticationStatusChanged(FnSteamNetAuthenticationStatusChanged fnCallback)420 inline bool ISteamNetworkingUtils::SetGlobalCallback_SteamNetAuthenticationStatusChanged( FnSteamNetAuthenticationStatusChanged fnCallback ) { return SetGlobalConfigValuePtr( k_ESteamNetworkingConfig_Callback_AuthStatusChanged, (void*)fnCallback ); }
SetGlobalCallback_SteamRelayNetworkStatusChanged(FnSteamRelayNetworkStatusChanged fnCallback)421 inline bool ISteamNetworkingUtils::SetGlobalCallback_SteamRelayNetworkStatusChanged( FnSteamRelayNetworkStatusChanged fnCallback ) { return SetGlobalConfigValuePtr( k_ESteamNetworkingConfig_Callback_RelayNetworkStatusChanged, (void*)fnCallback ); }
SetGlobalCallback_MessagesSessionRequest(FnSteamNetworkingMessagesSessionRequest fnCallback)422 inline bool ISteamNetworkingUtils::SetGlobalCallback_MessagesSessionRequest( FnSteamNetworkingMessagesSessionRequest fnCallback ) { return SetGlobalConfigValuePtr( k_ESteamNetworkingConfig_Callback_MessagesSessionRequest, (void*)fnCallback ); }
SetGlobalCallback_MessagesSessionFailed(FnSteamNetworkingMessagesSessionFailed fnCallback)423 inline bool ISteamNetworkingUtils::SetGlobalCallback_MessagesSessionFailed( FnSteamNetworkingMessagesSessionFailed fnCallback ) { return SetGlobalConfigValuePtr( k_ESteamNetworkingConfig_Callback_MessagesSessionFailed, (void*)fnCallback ); }
424 
SetConfigValueStruct(const SteamNetworkingConfigValue_t & opt,ESteamNetworkingConfigScope eScopeType,intptr_t scopeObj)425 inline bool ISteamNetworkingUtils::SetConfigValueStruct( const SteamNetworkingConfigValue_t &opt, ESteamNetworkingConfigScope eScopeType, intptr_t scopeObj )
426 {
427 	// Locate the argument.  Strings are a special case, since the
428 	// "value" (the whole string buffer) doesn't fit in the struct
429 	// NOTE: for pointer values, we pass a pointer to the pointer,
430 	// we do not pass the pointer directly.
431 	const void *pVal = ( opt.m_eDataType == k_ESteamNetworkingConfig_String ) ? (const void *)opt.m_val.m_string : (const void *)&opt.m_val;
432 	return SetConfigValue( opt.m_eValue, eScopeType, scopeObj, opt.m_eDataType, pVal );
433 }
434 
435 // How to get helper functions.
436 #if defined( STEAMNETWORKINGSOCKETS_STATIC_LINK ) || defined( STEAMNETWORKINGSOCKETS_STANDALONELIB )
437 
438 	// Call direct to static functions
439 	STEAMNETWORKINGSOCKETS_INTERFACE void SteamNetworkingIPAddr_ToString( const SteamNetworkingIPAddr *pAddr, char *buf, size_t cbBuf, bool bWithPort );
440 	STEAMNETWORKINGSOCKETS_INTERFACE bool SteamNetworkingIPAddr_ParseString( SteamNetworkingIPAddr *pAddr, const char *pszStr );
441 	STEAMNETWORKINGSOCKETS_INTERFACE void SteamNetworkingIdentity_ToString( const SteamNetworkingIdentity *pIdentity, char *buf, size_t cbBuf );
442 	STEAMNETWORKINGSOCKETS_INTERFACE bool SteamNetworkingIdentity_ParseString( SteamNetworkingIdentity *pIdentity, size_t sizeofIdentity, const char *pszStr );
ToString(char * buf,size_t cbBuf,bool bWithPort)443 	inline void SteamNetworkingIPAddr::ToString( char *buf, size_t cbBuf, bool bWithPort ) const { SteamNetworkingIPAddr_ToString( this, buf, cbBuf, bWithPort ); }
ParseString(const char * pszStr)444 	inline bool SteamNetworkingIPAddr::ParseString( const char *pszStr ) { return SteamNetworkingIPAddr_ParseString( this, pszStr ); }
ToString(char * buf,size_t cbBuf)445 	inline void SteamNetworkingIdentity::ToString( char *buf, size_t cbBuf ) const { SteamNetworkingIdentity_ToString( this, buf, cbBuf ); }
ParseString(const char * pszStr)446 	inline bool SteamNetworkingIdentity::ParseString( const char *pszStr ) { return SteamNetworkingIdentity_ParseString( this, sizeof(*this), pszStr ); }
447 
448 #elif defined( STEAMNETWORKINGSOCKETS_STEAMAPI )
449 	// Using steamworks SDK - go through SteamNetworkingUtils()
ToString(char * buf,size_t cbBuf,bool bWithPort)450 	inline void SteamNetworkingIPAddr::ToString( char *buf, size_t cbBuf, bool bWithPort ) const { SteamNetworkingUtils()->SteamNetworkingIPAddr_ToString( *this, buf, cbBuf, bWithPort ); }
ParseString(const char * pszStr)451 	inline bool SteamNetworkingIPAddr::ParseString( const char *pszStr ) { return SteamNetworkingUtils()->SteamNetworkingIPAddr_ParseString( this, pszStr ); }
ToString(char * buf,size_t cbBuf)452 	inline void SteamNetworkingIdentity::ToString( char *buf, size_t cbBuf ) const { SteamNetworkingUtils()->SteamNetworkingIdentity_ToString( *this, buf, cbBuf ); }
ParseString(const char * pszStr)453 	inline bool SteamNetworkingIdentity::ParseString( const char *pszStr ) { return SteamNetworkingUtils()->SteamNetworkingIdentity_ParseString( this, pszStr ); }
454 #else
455 	#error "Invalid config"
456 #endif
457 
458 #endif // ISTEAMNETWORKINGUTILS
459