1 #ifndef VG_STEAM_NETWORKING_H
2 #define VG_STEAM_NETWORKING_H
6 #ifdef VALVE_CALLBACK_PACK_SMALL
12 typedef enum ESteamNetworkingConfigScope ESteamNetworkingConfigScope
;
13 enum ESteamNetworkingConfigScope
15 k_ESteamNetworkingConfig_Global
= 1,
16 k_ESteamNetworkingConfig_SocketsInterface
= 2,
17 k_ESteamNetworkingConfig_ListenSocket
= 3,
18 k_ESteamNetworkingConfig_Connection
= 4,
19 k_ESteamNetworkingConfigScope__Force32Bit
= 0x7fffffff
22 typedef enum ESteamNetworkingConfigDataType ESteamNetworkingConfigDataType
;
23 enum ESteamNetworkingConfigDataType
25 k_ESteamNetworkingConfig_Int32
= 1,
26 k_ESteamNetworkingConfig_Int64
= 2,
27 k_ESteamNetworkingConfig_Float
= 3,
28 k_ESteamNetworkingConfig_String
= 4,
29 k_ESteamNetworkingConfig_Ptr
= 5,
31 k_ESteamNetworkingConfigDataType__Force32Bit
= 0x7fffffff
34 typedef enum ESteamNetworkingConfigValue ESteamNetworkingConfigValue
;
35 enum ESteamNetworkingConfigValue
37 k_ESteamNetworkingConfig_Invalid
= 0,
38 k_ESteamNetworkingConfig_TimeoutInitial
= 24,
39 k_ESteamNetworkingConfig_TimeoutConnected
= 25,
40 k_ESteamNetworkingConfig_SendBufferSize
= 9,
41 k_ESteamNetworkingConfig_ConnectionUserData
= 40,
42 k_ESteamNetworkingConfig_SendRateMin
= 10,
43 k_ESteamNetworkingConfig_SendRateMax
= 11,
44 k_ESteamNetworkingConfig_NagleTime
= 12,
45 k_ESteamNetworkingConfig_IP_AllowWithoutAuth
= 23,
46 k_ESteamNetworkingConfig_MTU_PacketSize
= 32,
47 k_ESteamNetworkingConfig_MTU_DataSize
= 33,
48 k_ESteamNetworkingConfig_Unencrypted
= 34,
49 k_ESteamNetworkingConfig_SymmetricConnect
= 37,
50 k_ESteamNetworkingConfig_LocalVirtualPort
= 38,
51 k_ESteamNetworkingConfig_DualWifi_Enable
= 39,
52 k_ESteamNetworkingConfig_EnableDiagnosticsUI
= 46,
53 k_ESteamNetworkingConfig_FakePacketLoss_Send
= 2,
54 k_ESteamNetworkingConfig_FakePacketLoss_Recv
= 3,
55 k_ESteamNetworkingConfig_FakePacketLag_Send
= 4,
56 k_ESteamNetworkingConfig_FakePacketLag_Recv
= 5,
57 k_ESteamNetworkingConfig_FakePacketReorder_Send
= 6,
58 k_ESteamNetworkingConfig_FakePacketReorder_Recv
= 7,
59 k_ESteamNetworkingConfig_FakePacketReorder_Time
= 8,
60 k_ESteamNetworkingConfig_FakePacketDup_Send
= 26,
61 k_ESteamNetworkingConfig_FakePacketDup_Recv
= 27,
62 k_ESteamNetworkingConfig_FakePacketDup_TimeMax
= 28,
63 k_ESteamNetworkingConfig_PacketTraceMaxBytes
= 41,
64 k_ESteamNetworkingConfig_FakeRateLimit_Send_Rate
= 42,
65 k_ESteamNetworkingConfig_FakeRateLimit_Send_Burst
= 43,
66 k_ESteamNetworkingConfig_FakeRateLimit_Recv_Rate
= 44,
67 k_ESteamNetworkingConfig_FakeRateLimit_Recv_Burst
= 45,
68 k_ESteamNetworkingConfig_Callback_ConnectionStatusChanged
= 201,
69 k_ESteamNetworkingConfig_Callback_AuthStatusChanged
= 202,
70 k_ESteamNetworkingConfig_Callback_RelayNetworkStatusChanged
= 203,
71 k_ESteamNetworkingConfig_Callback_MessagesSessionRequest
= 204,
72 k_ESteamNetworkingConfig_Callback_MessagesSessionFailed
= 205,
73 k_ESteamNetworkingConfig_Callback_CreateConnectionSignaling
= 206,
74 k_ESteamNetworkingConfig_Callback_FakeIPResult
= 207,
75 k_ESteamNetworkingConfig_P2P_STUN_ServerList
= 103,
76 k_ESteamNetworkingConfig_P2P_Transport_ICE_Enable
= 104,
77 k_ESteamNetworkingConfig_P2P_Transport_ICE_Penalty
= 105,
78 k_ESteamNetworkingConfig_P2P_Transport_SDR_Penalty
= 106,
79 k_ESteamNetworkingConfig_SDRClient_ConsecutitivePingTimeoutsFailInitial
= 19,
80 k_ESteamNetworkingConfig_SDRClient_ConsecutitivePingTimeoutsFail
= 20,
81 k_ESteamNetworkingConfig_SDRClient_MinPingsBeforePingAccurate
= 21,
82 k_ESteamNetworkingConfig_SDRClient_SingleSocket
= 22,
83 k_ESteamNetworkingConfig_SDRClient_ForceRelayCluster
= 29,
84 k_ESteamNetworkingConfig_SDRClient_DebugTicketAddress
= 30,
85 k_ESteamNetworkingConfig_SDRClient_ForceProxyAddr
= 31,
86 k_ESteamNetworkingConfig_SDRClient_FakeClusterPing
= 36,
87 k_ESteamNetworkingConfig_LogLevel_AckRTT
= 13,
88 k_ESteamNetworkingConfig_LogLevel_PacketDecode
= 14,
89 k_ESteamNetworkingConfig_LogLevel_Message
= 15,
90 k_ESteamNetworkingConfig_LogLevel_PacketGaps
= 16,
91 k_ESteamNetworkingConfig_LogLevel_P2PRendezvous
= 17,
92 k_ESteamNetworkingConfig_LogLevel_SDRRelayPings
= 18,
93 k_ESteamNetworkingConfig_DELETED_EnumerateDevVars
= 35,
94 k_ESteamNetworkingConfigValue__Force32Bit
= 0x7fffffff
98 typedef enum ESteamNetworkingConnectionState ESteamNetworkingConnectionState
;
99 enum ESteamNetworkingConnectionState
101 k_ESteamNetworkingConnectionState_None
= 0,
102 k_ESteamNetworkingConnectionState_Connecting
= 1,
103 k_ESteamNetworkingConnectionState_FindingRoute
= 2,
104 k_ESteamNetworkingConnectionState_Connected
= 3,
105 k_ESteamNetworkingConnectionState_ClosedByPeer
= 4,
106 k_ESteamNetworkingConnectionState_ProblemDetectedLocally
= 5,
107 k_ESteamNetworkingConnectionState_FinWait
= -1,
108 k_ESteamNetworkingConnectionState_Linger
= -2,
109 k_ESteamNetworkingConnectionState_Dead
= -3,
110 k_ESteamNetworkingConnectionState__Force32Bit
= 0x7fffffff
113 typedef enum ESteamNetConnectionEnd ESteamNetConnectionEnd
;
114 enum ESteamNetConnectionEnd
116 k_ESteamNetConnectionEnd_Invalid
= 0,
117 k_ESteamNetConnectionEnd_App_Min
= 1000,
118 k_ESteamNetConnectionEnd_App_Generic
= k_ESteamNetConnectionEnd_App_Min
,
119 k_ESteamNetConnectionEnd_App_Max
= 1999,
120 k_ESteamNetConnectionEnd_AppException_Min
= 2000,
121 k_ESteamNetConnectionEnd_AppException_Generic
=
122 k_ESteamNetConnectionEnd_AppException_Min
,
123 k_ESteamNetConnectionEnd_AppException_Max
= 2999,
124 k_ESteamNetConnectionEnd_Local_Min
= 3000,
125 k_ESteamNetConnectionEnd_Local_OfflineMode
= 3001,
126 k_ESteamNetConnectionEnd_Local_ManyRelayConnectivity
= 3002,
127 k_ESteamNetConnectionEnd_Local_HostedServerPrimaryRelay
= 3003,
128 k_ESteamNetConnectionEnd_Local_NetworkConfig
= 3004,
129 k_ESteamNetConnectionEnd_Local_Rights
= 3005,
130 k_ESteamNetConnectionEnd_Local_P2P_ICE_NoPublicAddresses
= 3006,
132 k_ESteamNetConnectionEnd_Local_Max
= 3999,
133 k_ESteamNetConnectionEnd_Remote_Min
= 4000,
134 k_ESteamNetConnectionEnd_Remote_Timeout
= 4001,
135 k_ESteamNetConnectionEnd_Remote_BadCrypt
= 4002,
136 k_ESteamNetConnectionEnd_Remote_BadCert
= 4003,
137 k_ESteamNetConnectionEnd_Remote_BadProtocolVersion
= 4006,
138 k_ESteamNetConnectionEnd_Remote_P2P_ICE_NoPublicAddresses
= 4007,
140 k_ESteamNetConnectionEnd_Remote_Max
= 4999,
142 k_ESteamNetConnectionEnd_Misc_Min
= 5000,
143 k_ESteamNetConnectionEnd_Misc_Generic
= 5001,
144 k_ESteamNetConnectionEnd_Misc_InternalError
= 5002,
145 k_ESteamNetConnectionEnd_Misc_Timeout
= 5003,
146 k_ESteamNetConnectionEnd_Misc_SteamConnectivity
= 5005,
147 k_ESteamNetConnectionEnd_Misc_NoRelaySessionsToClient
= 5006,
148 k_ESteamNetConnectionEnd_Misc_P2P_Rendezvous
= 5008,
149 k_ESteamNetConnectionEnd_Misc_P2P_NAT_Firewall
= 5009,
150 k_ESteamNetConnectionEnd_Misc_PeerSentNoConnection
= 5010,
152 k_ESteamNetConnectionEnd_Misc_Max
= 5999,
153 k_ESteamNetConnectionEnd__Force32Bit
= 0x7fffffff
156 typedef enum ESteamNetworkingIdentityType ESteamNetworkingIdentityType
;
157 enum ESteamNetworkingIdentityType
159 k_ESteamNetworkingIdentityType_Invalid
= 0,
160 k_ESteamNetworkingIdentityType_SteamID
= 16,
161 k_ESteamNetworkingIdentityType_IPAddress
= 1,
162 k_ESteamNetworkingIdentityType_GenericString
= 2,
163 k_ESteamNetworkingIdentityType_GenericBytes
= 3,
164 k_ESteamNetworkingIdentityType_UnknownType
= 4,
165 k_ESteamNetworkingIdentityType__Force32bit
= 0x7fffffff,
168 typedef enum ESteamNetworkingAvailability ESteamNetworkingAvailability
;
169 enum ESteamNetworkingAvailability
171 k_ESteamNetworkingAvailability_CannotTry
= -102,
172 k_ESteamNetworkingAvailability_Failed
= -101,
173 k_ESteamNetworkingAvailability_Previously
= -100,
174 k_ESteamNetworkingAvailability_Retrying
= -10,
175 k_ESteamNetworkingAvailability_NeverTried
= 1,
176 k_ESteamNetworkingAvailability_Waiting
= 2,
177 k_ESteamNetworkingAvailability_Attempting
= 3,
178 k_ESteamNetworkingAvailability_Current
= 100,
179 k_ESteamNetworkingAvailability_Unknown
= 0,
180 k_ESteamNetworkingAvailability__Force32bit
= 0x7fffffff,
183 /* Handle used to identify a connection to a remote host. */
184 typedef u32 HSteamNetConnection
;
185 HSteamNetConnection
const k_HSteamNetConnection_Invalid
= 0;
188 * Handle used to identify a "listen socket". Unlike traditional
189 * Berkeley sockets, a listen socket and a connection are two
190 * different abstractions.
192 typedef u32 HSteamListenSocket
;
193 HSteamListenSocket
const k_HSteamListenSocket_Invalid
= 0;
195 typedef u32 SteamNetworkingPOPID
;
197 #define k_cchSteamNetworkingMaxConnectionCloseReason 128
198 #define k_cchSteamNetworkingMaxConnectionDescription 128
199 #define k_cchSteamNetworkingMaxConnectionAppName 32
202 /* Store an IP and port. IPv6 is always used; IPv4 is represented using
203 * "IPv4-mapped" addresses: IPv4 aa.bb.cc.dd => IPv6 ::ffff:aabb:ccdd
204 * (RFC 4291 section 2.5.5.2.)
206 typedef struct SteamNetworkingIPAddr SteamNetworkingIPAddr
;
207 struct SteamNetworkingIPAddr
213 /* RFC4038, section 4.2 */
214 struct IPv4MappedAddress
219 u8 m_ip
[ 4 ]; /* NOTE: As bytes, i.e. network byte order */
224 u16 m_port
; // Host byte order
227 typedef struct SteamNetworkingIdentity SteamNetworkingIdentity
;
228 struct SteamNetworkingIdentity
230 ESteamNetworkingIdentityType m_eType
;
236 char m_szGenericString
[ 32 ];
237 u8 m_genericBytes
[ 32 ];
238 char m_szUnknownRawString
[ 128 ];
239 SteamNetworkingIPAddr m_ip
;
240 u32 m_reserved
[ 32 ];
247 * "Fake IPs" are assigned to hosts, to make it easier to interface with
248 * older code that assumed all hosts will have an IPv4 address
250 typedef enum ESteamNetworkingFakeIPType ESteamNetworkingFakeIPType
;
251 enum ESteamNetworkingFakeIPType
253 k_ESteamNetworkingFakeIPType_Invalid
,
254 k_ESteamNetworkingFakeIPType_NotFake
,
255 k_ESteamNetworkingFakeIPType_GlobalIPv4
,
256 k_ESteamNetworkingFakeIPType_LocalIPv4
,
257 k_ESteamNetworkingFakeIPType__Force32Bit
= 0x7fffffff
260 /* Set everything to zero. E.g. [::]:0 */
261 void SteamAPI_SteamNetworkingIPAddr_Clear( SteamNetworkingIPAddr
* self
);
263 /* Returns true if the IP is ::0. (Doesn't check port.) */
264 int SteamAPI_SteamNetworkingIPAddr_IsIPv6AllZeros(
265 SteamNetworkingIPAddr
* self
);
268 * Set IPv6 address. IP is interpreted as bytes, so there are no endian issues.
269 * (Same as inaddr_in6.) The IP can be a mapped IPv4 address
271 void SteamAPI_SteamNetworkingIPAddr_SetIPv6( SteamNetworkingIPAddr
* self
,
272 u8
*ipv6
, u16 nPort
);
274 /* Sets to IPv4 mapped address. IP and port are in host byte order. */
275 void SteamAPI_SteamNetworkingIPAddr_SetIPv4( SteamNetworkingIPAddr
* self
,
276 u32 nIP
, u16 nPort
);
278 /* Return true if IP is mapped IPv4 */
279 int SteamAPI_SteamNetworkingIPAddr_IsIPv4( SteamNetworkingIPAddr
* self
);
282 * Returns IP in host byte order (e.g. aa.bb.cc.dd as 0xaabbccdd).
283 * Returns 0 if IP is not mapped IPv4.
285 u32
SteamAPI_SteamNetworkingIPAddr_GetIPv4( SteamNetworkingIPAddr
* self
);
287 /* Set to the IPv6 localhost address ::1, and the specified port. */
288 void SteamAPI_SteamNetworkingIPAddr_SetIPv6LocalHost(
289 SteamNetworkingIPAddr
* self
, u16 nPort
);
292 * Return true if this identity is localhost.
293 * (Either IPv6 ::1, or IPv4 127.0.0.1)
295 int SteamAPI_SteamNetworkingIPAddr_IsLocalHost( SteamNetworkingIPAddr
* self
);
298 * Print to a string, with or without the port. Mapped IPv4 addresses are
299 * printed as dotted decimal (12.34.56.78), otherwise this will print the
300 * canonical form according to RFC5952. If you include the port, IPv6 will be
301 * surrounded by brackets, e.g. [::1:2]:80. Your buffer should be at least
302 * k_cchMaxString bytes to avoid truncation
304 * See also SteamNetworkingIdentityRender
306 void SteamAPI_SteamNetworkingIPAddr_ToString( SteamNetworkingIPAddr
* self
,
307 char *buf
, u32 cbBuf
, int bWithPort
);
310 * Parse an IP address and optional port. If a port is not present, it is set
312 * (This means that you cannot tell if a zero port was explicitly specified.)
314 int SteamAPI_SteamNetworkingIPAddr_ParseString( SteamNetworkingIPAddr
* self
,
315 const char *pszStr
);
317 /* See if two addresses are identical */
318 int SteamAPI_SteamNetworkingIPAddr_IsEqualTo( SteamNetworkingIPAddr
* self
,
319 SteamNetworkingIPAddr
*x
);
322 * Classify address as FakeIP. This function never returns
323 * k_ESteamNetworkingFakeIPType_Invalid.
325 ESteamNetworkingFakeIPType
SteamAPI_SteamNetworkingIPAddr_GetFakeIPType(
326 SteamNetworkingIPAddr
* self
);
328 /* Return true if we are a FakeIP */
329 int SteamAPI_SteamNetworkingIPAddr_IsFakeIP( SteamNetworkingIPAddr
* self
);
332 /* Describe the state of a connection. */
333 typedef struct SteamNetConnectionInfo_t SteamNetConnectionInfo_t
;
334 struct SteamNetConnectionInfo_t
336 SteamNetworkingIdentity m_identityRemote
;
338 /* Arbitrary user data set by the local application code */
341 /* Handle to listen socket this was connected on, or
342 * k_HSteamListenSocket_Invalid if we initiated the connection */
343 HSteamListenSocket m_hListenSocket
;
345 /* Remote address. Might be all 0's if we don't know it, or if this is N/A.
346 * (E.g. Basically everything except direct UDP connection.) */
347 SteamNetworkingIPAddr m_addrRemote
;
350 /* What data center is the remote host in? (0 if we don't know.) */
351 SteamNetworkingPOPID m_idPOPRemote
;
353 /* What relay are we using to communicate with the remote host?
354 * (0 if not applicable.) */
355 SteamNetworkingPOPID m_idPOPRelay
;
357 /* High level state of the connection */
358 ESteamNetworkingConnectionState m_eState
;
360 /* Basic cause of the connection termination or problem.
361 * See ESteamNetConnectionEnd for the values used */
365 * Human-readable, but non-localized explanation for connection
366 * termination or problem. This is intended for debugging /
367 * diagnostic purposes only, not to display to users. It might
368 * have some details specific to the issue.
370 char m_szEndDebug
[ 128 ];
373 * Debug description. This includes the internal connection ID,
374 * connection type (and peer information), and any name
375 * given to the connection by the app. This string is used in various
376 * internal logging messages.
378 * Note that the connection ID *usually* matches the HSteamNetConnection
379 * handle, but in certain cases with symmetric connections it might not.
381 char m_szConnectionDescription
[ 128 ];
384 * Misc flags. Bitmask of k_nSteamNetworkConnectionInfoFlags_Xxxx
389 * Internal stuff, room to change API easily
395 * In a few places we need to set configuration options on listen sockets and
396 * connections, and have them take effect *before* the listen socket or
397 * connection really starts doing anything. Creating the object and then setting
398 * the options "immediately" after creation doesn't work completely, because
399 * network packets could be received between the time the object is created and
400 * when the options are applied. To set options at creation time in a reliable
401 * way, they must be passed to the creation function. This structure is used to
402 * pass those options.
404 * For the meaning of these fields, see ISteamNetworkingUtils::SetConfigValue.
405 * Basically when the object is created, we just iterate over the list of
406 * options and call ISteamNetworkingUtils::SetConfigValueStruct, where the scope
407 * arguments are supplied by the object being created.
409 typedef struct SteamNetworkingConfigValue_t SteamNetworkingConfigValue_t
;
410 struct SteamNetworkingConfigValue_t
412 /* Which option is being set */
413 ESteamNetworkingConfigValue m_eValue
;
415 /// Which field below did you fill in?
416 ESteamNetworkingConfigDataType m_eDataType
;
424 const char *m_string
; // Points to your '\0'-terminated buffer
429 void SteamAPI_SteamNetworkingConfigValue_t_SetInt32(
430 SteamNetworkingConfigValue_t
* self
,
431 ESteamNetworkingConfigValue eVal
, i32 data
);
433 void SteamAPI_SteamNetworkingConfigValue_t_SetInt64(
434 SteamNetworkingConfigValue_t
* self
,
435 ESteamNetworkingConfigValue eVal
, i64 data
);
437 void SteamAPI_SteamNetworkingConfigValue_t_SetFloat(
438 SteamNetworkingConfigValue_t
* self
,
439 ESteamNetworkingConfigValue eVal
, float data
);
441 void SteamAPI_SteamNetworkingConfigValue_t_SetPtr(
442 SteamNetworkingConfigValue_t
* self
,
443 ESteamNetworkingConfigValue eVal
, void *data
);
445 void SteamAPI_SteamNetworkingConfigValue_t_SetString(
446 SteamNetworkingConfigValue_t
* self
, ESteamNetworkingConfigValue eVal
,
450 * Handle used to identify a poll group, used to query many
451 * connections at once efficiently.
453 typedef u32 HSteamNetPollGroup
;
454 HSteamNetPollGroup
const k_HSteamNetPollGroup_Invalid
= 0;
456 void *SteamAPI_SteamGameServerNetworkingSockets_SteamAPI_v012(void);
457 void *SteamAPI_SteamGameServerNetworkingSockets_SteamAPI(void)
459 return SteamAPI_SteamGameServerNetworkingSockets_SteamAPI_v012();
463 void *SteamAPI_SteamNetworkingSockets_SteamAPI_v012();
464 void *SteamAPI_SteamNetworkingSockets_SteamAPI()
466 return SteamAPI_SteamNetworkingSockets_SteamAPI_v012();
469 HSteamListenSocket
SteamAPI_ISteamNetworkingSockets_CreateListenSocketIP(
470 void *self
, SteamNetworkingIPAddr
*localAddress
, int nOptions
,
471 SteamNetworkingConfigValue_t
*pOptions
);
473 HSteamNetConnection
SteamAPI_ISteamNetworkingSockets_ConnectByIPAddress(
475 SteamNetworkingIPAddr
*address
, int nOptions
,
476 SteamNetworkingConfigValue_t
*pOptions
);
479 int SteamAPI_ISteamNetworkingSockets_GetListenSocketAddress(
480 void *self
, HSteamListenSocket hSocket
,
481 SteamNetworkingIPAddr
*address
);
483 int SteamAPI_ISteamNetworkingSockets_CloseConnection(
484 void *self
, HSteamNetConnection hPeer
, int nReason
, const char *pszDebug
,
487 int SteamAPI_ISteamNetworkingSockets_CloseListenSocket(
488 void *self
, HSteamListenSocket hSocket
);
494 enum { k_iSteamNetConnectionStatusChangedCallBack
=
495 k_iSteamNetworkingSocketsCallbacks
+ 1 };
497 typedef struct SteamNetConnectionStatusChangedCallback_t
498 SteamNetConnectionStatusChangedCallback_t
;
499 struct SteamNetConnectionStatusChangedCallback_t
501 /// Connection handle
502 HSteamNetConnection m_hConn
;
504 /// Full connection info
505 SteamNetConnectionInfo_t m_info
;
507 /// Previous state. (Current state is in m_info.m_eState)
508 ESteamNetworkingConnectionState m_eOldState
;
511 enum { k_iSteamNetAuthenticationStatus
=
512 k_iSteamNetworkingSocketsCallbacks
+ 2 };
514 typedef struct SteamNetAuthenticationStatus_t SteamNetAuthenticationStatus_t
;
515 struct SteamNetAuthenticationStatus_t
518 ESteamNetworkingAvailability m_eAvail
;
520 /// Non-localized English language status. For diagnostic/debugging
522 char m_debugMsg
[ 256 ];
526 #endif /* VG_STEAM_NETWORKING_H */