steamworks
[vg.git] / vg_steam_networking.h
1 #ifndef VG_STEAM_NETWORKING_H
2 #define VG_STEAM_NETWORKING_H
3
4 #include "vg_steam.h"
5
6 #ifdef VALVE_CALLBACK_PACK_SMALL
7 ;
8 #pragma pack(push,4)
9 #else
10 #pragma pack(push,8)
11 #endif
12
13 enum ESteamNetworkingConfigScope
14 {
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
20 };
21 typedef enum ESteamNetworkingConfigScope ESteamNetworkingConfigScope;
22
23 enum ESteamNetworkingConfigDataType
24 {
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,
30
31 k_ESteamNetworkingConfigDataType__Force32Bit = 0x7fffffff
32 };
33 typedef enum ESteamNetworkingConfigDataType ESteamNetworkingConfigDataType;
34
35 enum ESteamNetworkingConfigValue
36 {
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
95 };
96 typedef enum ESteamNetworkingConfigValue ESteamNetworkingConfigValue;
97
98
99 enum ESteamNetworkingConnectionState
100 {
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
111 };
112 typedef enum ESteamNetworkingConnectionState ESteamNetworkingConnectionState;
113
114 enum ESteamNetConnectionEnd
115 {
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,
131
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,
139
140 k_ESteamNetConnectionEnd_Remote_Max = 4999,
141
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,
151
152 k_ESteamNetConnectionEnd_Misc_Max = 5999,
153 k_ESteamNetConnectionEnd__Force32Bit = 0x7fffffff
154 };
155 typedef enum ESteamNetConnectionEnd ESteamNetConnectionEnd;
156
157 enum ESteamNetworkingIdentityType
158 {
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,
166 };
167 typedef enum ESteamNetworkingIdentityType ESteamNetworkingIdentityType;
168
169 enum ESteamNetworkingAvailability
170 {
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,
181 };
182 typedef enum ESteamNetworkingAvailability ESteamNetworkingAvailability;
183
184 /* Handle used to identify a connection to a remote host. */
185 typedef u32 HSteamNetConnection;
186 HSteamNetConnection const k_HSteamNetConnection_Invalid = 0;
187
188 /*
189 * Handle used to identify a "listen socket". Unlike traditional
190 * Berkeley sockets, a listen socket and a connection are two
191 * different abstractions.
192 */
193 typedef u32 HSteamListenSocket;
194 HSteamListenSocket const k_HSteamListenSocket_Invalid = 0;
195
196 typedef u32 SteamNetworkingPOPID;
197 typedef i64 SteamNetworkingMicroseconds;
198
199 #pragma pack(push,1)
200 /* Store an IP and port. IPv6 is always used; IPv4 is represented using
201 * "IPv4-mapped" addresses: IPv4 aa.bb.cc.dd => IPv6 ::ffff:aabb:ccdd
202 * (RFC 4291 section 2.5.5.2.)
203 */
204 typedef struct SteamNetworkingIPAddr SteamNetworkingIPAddr;
205 struct SteamNetworkingIPAddr
206 {
207 union
208 {
209 u8 m_ipv6[ 16 ];
210
211 /* RFC4038, section 4.2 */
212 struct IPv4MappedAddress
213 {
214 u64 m_8zeros;
215 u16 m_0000;
216 u16 m_ffff;
217 u8 m_ip[ 4 ]; /* NOTE: As bytes, i.e. network byte order */
218 }
219 m_ipv4;
220 };
221
222 u16 m_port; // Host byte order
223 };
224
225 typedef struct SteamNetworkingIdentity SteamNetworkingIdentity;
226 struct SteamNetworkingIdentity
227 {
228 ESteamNetworkingIdentityType m_eType;
229
230 int m_cbSize;
231 union
232 {
233 u64 m_steamID64;
234 char m_szGenericString[ 32 ];
235 u8 m_genericBytes[ 32 ];
236 char m_szUnknownRawString[ 128 ];
237 SteamNetworkingIPAddr m_ip;
238 u32 m_reserved[ 32 ];
239 };
240 };
241
242 #pragma pack(pop)
243
244 /*
245 * "Fake IPs" are assigned to hosts, to make it easier to interface with
246 * older code that assumed all hosts will have an IPv4 address
247 */
248 enum ESteamNetworkingFakeIPType
249 {
250 k_ESteamNetworkingFakeIPType_Invalid,
251 k_ESteamNetworkingFakeIPType_NotFake,
252 k_ESteamNetworkingFakeIPType_GlobalIPv4,
253 k_ESteamNetworkingFakeIPType_LocalIPv4,
254 k_ESteamNetworkingFakeIPType__Force32Bit = 0x7fffffff
255 };
256 typedef enum ESteamNetworkingFakeIPType ESteamNetworkingFakeIPType;
257
258 /* Set everything to zero. E.g. [::]:0 */
259 void SteamAPI_SteamNetworkingIPAddr_Clear( SteamNetworkingIPAddr* self );
260
261 /* Returns true if the IP is ::0. (Doesn't check port.) */
262 int SteamAPI_SteamNetworkingIPAddr_IsIPv6AllZeros(
263 SteamNetworkingIPAddr* self );
264
265 /*
266 * Set IPv6 address. IP is interpreted as bytes, so there are no endian issues.
267 * (Same as inaddr_in6.) The IP can be a mapped IPv4 address
268 */
269 void SteamAPI_SteamNetworkingIPAddr_SetIPv6( SteamNetworkingIPAddr* self,
270 u8 *ipv6, u16 nPort );
271
272 /* Sets to IPv4 mapped address. IP and port are in host byte order. */
273 void SteamAPI_SteamNetworkingIPAddr_SetIPv4( SteamNetworkingIPAddr* self,
274 u32 nIP, u16 nPort );
275
276 /* Return true if IP is mapped IPv4 */
277 steamapi_bool
278 SteamAPI_SteamNetworkingIPAddr_IsIPv4( SteamNetworkingIPAddr *self );
279
280 /*
281 * Returns IP in host byte order (e.g. aa.bb.cc.dd as 0xaabbccdd).
282 * Returns 0 if IP is not mapped IPv4.
283 */
284 u32 SteamAPI_SteamNetworkingIPAddr_GetIPv4( SteamNetworkingIPAddr* self );
285
286 /* Set to the IPv6 localhost address ::1, and the specified port. */
287 void SteamAPI_SteamNetworkingIPAddr_SetIPv6LocalHost(
288 SteamNetworkingIPAddr* self, u16 nPort );
289
290 /*
291 * Return true if this identity is localhost.
292 * (Either IPv6 ::1, or IPv4 127.0.0.1)
293 */
294 steamapi_bool SteamAPI_SteamNetworkingIPAddr_IsLocalHost(
295 SteamNetworkingIPAddr* self );
296
297 /*
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
303 *
304 * See also SteamNetworkingIdentityRender
305 */
306 void SteamAPI_SteamNetworkingIPAddr_ToString( SteamNetworkingIPAddr* self,
307 char *buf, u32 cbBuf, steamapi_bool bWithPort );
308
309 /*
310 * Parse an IP address and optional port. If a port is not present, it is set
311 * to 0.
312 * (This means that you cannot tell if a zero port was explicitly specified.)
313 */
314 steamapi_bool SteamAPI_SteamNetworkingIPAddr_ParseString(
315 SteamNetworkingIPAddr* self, const char *pszStr );
316
317 /* See if two addresses are identical */
318 steamapi_bool SteamAPI_SteamNetworkingIPAddr_IsEqualTo(
319 SteamNetworkingIPAddr *self, SteamNetworkingIPAddr *x );
320
321 /*
322 * Classify address as FakeIP. This function never returns
323 * k_ESteamNetworkingFakeIPType_Invalid.
324 */
325 ESteamNetworkingFakeIPType SteamAPI_SteamNetworkingIPAddr_GetFakeIPType(
326 SteamNetworkingIPAddr* self );
327
328 /* Return true if we are a FakeIP */
329 steamapi_bool SteamAPI_SteamNetworkingIPAddr_IsFakeIP( SteamNetworkingIPAddr* self );
330
331 /*
332 * In a few places we need to set configuration options on listen sockets and
333 * connections, and have them take effect *before* the listen socket or
334 * connection really starts doing anything. Creating the object and then setting
335 * the options "immediately" after creation doesn't work completely, because
336 * network packets could be received between the time the object is created and
337 * when the options are applied. To set options at creation time in a reliable
338 * way, they must be passed to the creation function. This structure is used to
339 * pass those options.
340 *
341 * For the meaning of these fields, see ISteamNetworkingUtils::SetConfigValue.
342 * Basically when the object is created, we just iterate over the list of
343 * options and call ISteamNetworkingUtils::SetConfigValueStruct, where the scope
344 * arguments are supplied by the object being created.
345 */
346 typedef struct SteamNetworkingConfigValue_t SteamNetworkingConfigValue_t;
347 struct SteamNetworkingConfigValue_t
348 {
349 /* Which option is being set */
350 ESteamNetworkingConfigValue m_eValue;
351
352 /// Which field below did you fill in?
353 ESteamNetworkingConfigDataType m_eDataType;
354
355 /// Option value
356 union
357 {
358 i32 m_int32;
359 i64 m_int64;
360 float m_float;
361 const char *m_string; // Points to your '\0'-terminated buffer
362 void *m_ptr;
363 } m_val;
364 };
365
366 void SteamAPI_SteamNetworkingConfigValue_t_SetInt32(
367 SteamNetworkingConfigValue_t* self,
368 ESteamNetworkingConfigValue eVal, i32 data );
369
370 void SteamAPI_SteamNetworkingConfigValue_t_SetInt64(
371 SteamNetworkingConfigValue_t* self,
372 ESteamNetworkingConfigValue eVal, i64 data );
373
374 void SteamAPI_SteamNetworkingConfigValue_t_SetFloat(
375 SteamNetworkingConfigValue_t* self,
376 ESteamNetworkingConfigValue eVal, float data );
377
378 void SteamAPI_SteamNetworkingConfigValue_t_SetPtr(
379 SteamNetworkingConfigValue_t* self,
380 ESteamNetworkingConfigValue eVal, void *data );
381
382 void SteamAPI_SteamNetworkingConfigValue_t_SetString(
383 SteamNetworkingConfigValue_t* self, ESteamNetworkingConfigValue eVal,
384 const char * data );
385
386 typedef void ISteamNetworkingSockets;
387 typedef struct SteamNetworkingMessage_t SteamNetworkingMessage_t;
388 typedef struct SteamNetConnectionInfo_t SteamNetConnectionInfo_t;
389
390
391 /*
392 * Handle used to identify a poll group, used to query many
393 * connections at once efficiently.
394 */
395 typedef u32 HSteamNetPollGroup;
396 HSteamNetPollGroup const k_HSteamNetPollGroup_Invalid = 0;
397
398 ISteamNetworkingSockets
399 *SteamAPI_SteamGameServerNetworkingSockets_SteamAPI_v012(void);
400
401 ISteamNetworkingSockets
402 *SteamAPI_SteamGameServerNetworkingSockets_SteamAPI(void)
403 {
404 return SteamAPI_SteamGameServerNetworkingSockets_SteamAPI_v012();
405 }
406
407
408 ISteamNetworkingSockets *SteamAPI_SteamNetworkingSockets_SteamAPI_v012();
409 ISteamNetworkingSockets *SteamAPI_SteamNetworkingSockets_SteamAPI()
410 {
411 return SteamAPI_SteamNetworkingSockets_SteamAPI_v012();
412 }
413
414
415 /*
416 * Send the message unreliably. Can be lost. Messages *can* be larger than a
417 * single MTU (UDP packet), but there is no retransmission, so if any piece
418 * of the message is lost, the entire message will be dropped.
419
420 * The sending API does have some knowledge of the underlying connection, so
421 * if there is no NAT-traversal accomplished or there is a recognized adjustment
422 * happening on the connection, the packet will be batched until the connection
423 * is open again.
424
425 * Migration note: This is not exactly the same as k_EP2PSendUnreliable! You
426 * probably want k_ESteamNetworkingSendType_UnreliableNoNagle
427 */
428 const int k_nSteamNetworkingSend_Unreliable = 0;
429
430 /*
431 * Disable Nagle's algorithm.
432 * By default, Nagle's algorithm is applied to all outbound messages. This means
433 * that the message will NOT be sent immediately, in case further messages are
434 * sent soon after you send this, which can be grouped together. Any time there
435 * is enough buffered data to fill a packet, the packets will be pushed out
436 * immediately, but partially-full packets not be sent until the Nagle timer
437 * expires. See ISteamNetworkingSockets::FlushMessagesOnConnection,
438 * ISteamNetworkingMessages::FlushMessagesToUser
439 *
440 * NOTE: Don't just send every message without Nagle because you want packets to
441 * get there quicker. Make sure you understand the problem that Nagle is
442 * solving before disabling it. If you are sending small messages, often many at
443 * the same time, then it is very likely that it will be more efficient to leave
444 * Nagle enabled. A typical proper use of this flag is when you are sending
445 * what you know will be the last message sent for a while (e.g. the last in the
446 * server simulation tick to a particular client), and you use this flag to
447 * flush all messages.
448 */
449 const int k_nSteamNetworkingSend_NoNagle = 1;
450
451 /*
452 * Send a message unreliably, bypassing Nagle's algorithm for this message and
453 * any messages currently pending on the Nagle timer. This is equivalent to
454 * using k_ESteamNetworkingSend_Unreliable and then immediately flushing the
455 * messages using ISteamNetworkingSockets::FlushMessagesOnConnection or
456 * ISteamNetworkingMessages::FlushMessagesToUser. (But using this flag is more
457 * efficient since you only make one API call.)
458 */
459 const int k_nSteamNetworkingSend_UnreliableNoNagle =
460 k_nSteamNetworkingSend_Unreliable |
461 k_nSteamNetworkingSend_NoNagle;
462 /*
463 * If the message cannot be sent very soon (because the connection is still
464 * doing some initial handshaking, route negotiations, etc), then just drop it.
465 * This is only applicable for unreliable messages. Using this flag on reliable
466 * messages is invalid.
467 */
468 const int k_nSteamNetworkingSend_NoDelay = 4;
469
470 /*
471 * Send an unreliable message, but if it cannot be sent relatively quickly, just
472 * drop it instead of queuing it. This is useful for messages that are not
473 * useful if they are excessively delayed, such as voice data.
474 * NOTE: The Nagle algorithm is not used, and if the message is not dropped, any
475 * messages waiting on the Nagle timer are immediately flushed.
476 *
477 * A message will be dropped under the following circumstances:
478 * - the connection is not fully connected. (E.g. the "Connecting" or
479 * "FindingRoute" states)
480 * - there is a sufficiently large number of messages queued up already such
481 * that the current message will not be placed on the wire in the next
482 * ~200ms or so.
483 *
484 * If a message is dropped for these reasons, k_EResultIgnored will be returned.
485 */
486 const int k_nSteamNetworkingSend_UnreliableNoDelay =
487 k_nSteamNetworkingSend_Unreliable |
488 k_nSteamNetworkingSend_NoDelay |
489 k_nSteamNetworkingSend_NoNagle;
490
491 /*
492 * Reliable message send. Can send up to
493 * k_cbMaxSteamNetworkingSocketsMessageSizeSend bytes in a single message.
494 * Does fragmentation/re-assembly of messages under the hood, as well as a
495 * sliding window for efficient sends of large chunks of data.
496 * The Nagle algorithm is used. See notes on
497 * k_ESteamNetworkingSendType_Unreliable for more details.
498 * See k_ESteamNetworkingSendType_ReliableNoNagle,
499 * ISteamNetworkingSockets::FlushMessagesOnConnection,
500 * ISteamNetworkingMessages::FlushMessagesToUser
501 *
502 * Migration note: This is NOT the same as k_EP2PSendReliable, it's more like
503 * k_EP2PSendReliableWithBuffering
504 */
505 const int k_nSteamNetworkingSend_Reliable = 8;
506
507 /*
508 * Send a message reliably, but bypass Nagle's algorithm.
509 *
510 * Migration note: This is equivalent to k_EP2PSendReliable
511 */
512 const int k_nSteamNetworkingSend_ReliableNoNagle =
513 k_nSteamNetworkingSend_Reliable |
514 k_nSteamNetworkingSend_NoNagle;
515
516
517 HSteamListenSocket SteamAPI_ISteamNetworkingSockets_CreateListenSocketIP(
518 ISteamNetworkingSockets *self,
519 SteamNetworkingIPAddr *localAddress, int nOptions,
520 SteamNetworkingConfigValue_t *pOptions );
521
522 HSteamNetConnection SteamAPI_ISteamNetworkingSockets_ConnectByIPAddress(
523 ISteamNetworkingSockets *self,
524 SteamNetworkingIPAddr *address, int nOptions,
525 SteamNetworkingConfigValue_t *pOptions );
526
527
528 EResult SteamAPI_ISteamNetworkingSockets_AcceptConnection(
529 ISteamNetworkingSockets *self,
530 HSteamNetConnection hConn );
531
532 steamapi_bool SteamAPI_ISteamNetworkingSockets_CloseConnection(
533 ISteamNetworkingSockets *self,
534 HSteamNetConnection hPeer, int nReason, const char *pszDebug,
535 steamapi_bool bEnableLinger );
536
537 steamapi_bool SteamAPI_ISteamNetworkingSockets_GetListenSocketAddress(
538 ISteamNetworkingSockets *self, HSteamListenSocket hSocket,
539 SteamNetworkingIPAddr *address );
540
541 steamapi_bool SteamAPI_ISteamNetworkingSockets_CloseConnection(
542 ISteamNetworkingSockets *self,
543 HSteamNetConnection hPeer, int nReason, const char *pszDebug,
544 steamapi_bool bEnableLinger );
545
546 steamapi_bool SteamAPI_ISteamNetworkingSockets_CloseListenSocket(
547 ISteamNetworkingSockets *self, HSteamListenSocket hSocket );
548
549 EResult SteamAPI_ISteamNetworkingSockets_SendMessageToConnection(
550 ISteamNetworkingSockets* self,
551 HSteamNetConnection hConn, const void *pData, u32 cbData, int nSendFlags,
552 i64 * pOutMessageNumber );
553
554 void SteamAPI_ISteamNetworkingSockets_SendMessages(
555 ISteamNetworkingSockets* self,
556 int nMessages, SteamNetworkingMessage_t *const *pMessages,
557 i64 *pOutMessageNumberOrResult );
558
559 EResult SteamAPI_ISteamNetworkingSockets_FlushMessagesOnConnection(
560 ISteamNetworkingSockets* self,
561 HSteamNetConnection hConn );
562
563 int SteamAPI_ISteamNetworkingSockets_ReceiveMessagesOnConnection(
564 ISteamNetworkingSockets* self,
565 HSteamNetConnection hConn,
566 SteamNetworkingMessage_t **ppOutMessages,
567 int nMaxMessages );
568
569 /*
570 * Poll Groups
571 */
572
573 HSteamNetPollGroup SteamAPI_ISteamNetworkingSockets_CreatePollGroup(
574 ISteamNetworkingSockets *self );
575
576 steamapi_bool SteamAPI_ISteamNetworkingSockets_DestroyPollGroup(
577 ISteamNetworkingSockets *self,
578 HSteamNetPollGroup hPollGroup );
579
580 steamapi_bool SteamAPI_ISteamNetworkingSockets_SetConnectionPollGroup(
581 ISteamNetworkingSockets *self,
582 HSteamNetConnection hConn, HSteamNetPollGroup hPollGroup );
583
584 int SteamAPI_ISteamNetworkingSockets_ReceiveMessagesOnPollGroup(
585 ISteamNetworkingSockets *self,
586 HSteamNetPollGroup hPollGroup, SteamNetworkingMessage_t **ppOutMessages,
587 int nMaxMessages );
588 /*
589 * Returns basic information about the high-level state of the connection.
590 * Returns false if the connection handle is invalid.
591 */
592 steamapi_bool SteamAPI_ISteamNetworkingSockets_GetConnectionInfo(
593 ISteamNetworkingSockets* self,
594 HSteamNetConnection hConn, SteamNetConnectionInfo_t * pInfo );
595
596 int SteamAPI_ISteamNetworkingSockets_GetDetailedConnectionStatus(
597 ISteamNetworkingSockets* self,
598 HSteamNetConnection hConn, char *pszBuf, int cbBuf );
599
600 steamapi_bool SteamAPI_ISteamNetworkingSockets_SetConnectionUserData(
601 ISteamNetworkingSockets* self, HSteamNetConnection hPeer, i64 nUserData );
602
603 i64 SteamAPI_ISteamNetworkingSockets_GetConnectionUserData(
604 ISteamNetworkingSockets* self, HSteamNetConnection hPeer );
605
606 steamapi_bool SteamAPI_ISteamNetworkingSockets_GetListenSocketAddress(
607 ISteamNetworkingSockets* self,
608 HSteamListenSocket hSocket, SteamNetworkingIPAddr *address );
609
610 enum{ k_cchSteamNetworkingMaxConnectionCloseReason = 128 };
611 enum{ k_cchSteamNetworkingMaxConnectionDescription = 128 };
612 enum{ k_cchSteamNetworkingMaxConnectionAppName = 32 };
613 enum{ k_nSteamNetworkConnectionInfoFlags_Unauthenticated = 1 };
614 enum{ k_nSteamNetworkConnectionInfoFlags_Unencrypted = 2 };
615 enum{ k_nSteamNetworkConnectionInfoFlags_LoopbackBuffers = 4 };
616 enum{ k_nSteamNetworkConnectionInfoFlags_Fast = 8 };
617 enum{ k_nSteamNetworkConnectionInfoFlags_Relayed = 16 };
618 enum{ k_nSteamNetworkConnectionInfoFlags_DualWifi = 32 };
619
620 /* Describe the state of a connection. */
621 struct SteamNetConnectionInfo_t
622 {
623 /*
624 * Who is on the other end? Depending on the connection type and phase of the
625 * connection, we might not know
626 */
627 SteamNetworkingIdentity m_identityRemote;
628
629 /* Arbitrary user data set by the local application code */
630 i64 m_nUserData;
631
632 /*
633 * Handle to listen socket this was connected on, or
634 * k_HSteamListenSocket_Invalid if we initiated the connection
635 */
636 HSteamListenSocket m_hListenSocket;
637
638 /*
639 * Remote address. Might be all 0's if we don't know it, or if this is N/A.
640 * (E.g. Basically everything except direct UDP connection.)
641 */
642 SteamNetworkingIPAddr m_addrRemote;
643 u16 m__pad1;
644
645 /* What data center is the remote host in? (0 if we don't know.) */
646 SteamNetworkingPOPID m_idPOPRemote;
647
648 /*
649 * What relay are we using to communicate with the remote host?
650 * (0 if not applicable.)
651 */
652 SteamNetworkingPOPID m_idPOPRelay;
653
654 /* High level state of the connection */
655 ESteamNetworkingConnectionState m_eState;
656
657 /*
658 * Basic cause of the connection termination or problem.
659 * See ESteamNetConnectionEnd for the values used
660 */
661 int m_eEndReason;
662
663 /*
664 * Human-readable, but non-localized explanation for connection
665 * termination or problem. This is intended for debugging /
666 * diagnostic purposes only, not to display to users. It might
667 * have some details specific to the issue.
668 */
669 char m_szEndDebug[ k_cchSteamNetworkingMaxConnectionCloseReason ];
670
671 /*
672 * Debug description. This includes the internal connection ID,
673 * connection type (and peer information), and any name
674 * given to the connection by the app. This string is used in various
675 * internal logging messages.
676 *
677 * Note that the connection ID *usually* matches the HSteamNetConnection
678 * handle, but in certain cases with symmetric connections it might not.
679 */
680 char m_szConnectionDescription
681 [ k_cchSteamNetworkingMaxConnectionDescription ];
682
683 /* Misc flags. Bitmask of k_nSteamNetworkConnectionInfoFlags_Xxxx */
684 int m_nFlags;
685
686 /* Internal stuff, room to change API easily */
687 u32 reserved[63];
688 };
689
690 /*
691 * Quick connection state, pared down to something you could call
692 * more frequently without it being too big of a perf hit.
693 */
694 struct SteamNetConnectionRealTimeStatus_t
695 {
696 /* High level state of the connection */
697 ESteamNetworkingConnectionState m_eState;
698
699 /* Current ping (ms) */
700 int m_nPing;
701
702 /*
703 * Connection quality measured locally, 0...1.
704 * (Percentage of packets delivered end-to-end in order).
705 */
706 float m_flConnectionQualityLocal;
707
708 /* Packet delivery success rate as observed from remote host */
709 float m_flConnectionQualityRemote;
710
711 /* Current data rates from recent history. */
712 float m_flOutPacketsPerSec;
713 float m_flOutBytesPerSec;
714 float m_flInPacketsPerSec;
715 float m_flInBytesPerSec;
716
717 /*
718 * Estimate rate that we believe that we can send data to our peer.
719 * Note that this could be significantly higher than m_flOutBytesPerSec,
720 * meaning the capacity of the channel is higher than you are sending data.
721 * (That's OK!)
722 */
723 int m_nSendRateBytesPerSecond;
724
725 /*
726 * Number of bytes pending to be sent. This is data that you have recently
727 * requested to be sent but has not yet actually been put on the wire. The
728 * reliable number ALSO includes data that was previously placed on the wire,
729 * but has now been scheduled for re-transmission. Thus, it's possible to
730 * observe m_cbPendingReliable increasing between two checks, even if no
731 * calls were made to send reliable data between the checks. Data that is
732 * awaiting the Nagle delay will appear in these numbers.
733 */
734 int m_cbPendingUnreliable;
735 int m_cbPendingReliable;
736
737 /*
738 * Number of bytes of reliable data that has been placed the wire, but
739 * for which we have not yet received an acknowledgment, and thus we may
740 * have to re-transmit.
741 */
742 int m_cbSentUnackedReliable;
743
744 /*
745 * If you queued a message right now, approximately how long would that
746 * message wait in the queue before we actually started putting its data on
747 * the wire in a packet?
748 *
749 * In general, data that is sent by the application is limited by the
750 * bandwidth of the channel. If you send data faster than this, it must be
751 * queued and put on the wire at a metered rate. Even sending a small amount
752 * of data (e.g. a few MTU, say ~3k) will require some of the data to be
753 * delayed a bit.
754 *
755 * Ignoring multiple lanes,the estimated delay will be approximately equal to
756 *
757 * ( m_cbPendingUnreliable+m_cbPendingReliable ) /
758 * m_nSendRateBytesPerSecond
759 *
760 * plus or minus one MTU. It depends on how much time has elapsed since the
761 * last packet was put on the wire. For example, the queue might have *just*
762 * been emptied, and the last packet placed on the wire, and we are exactly
763 * up against the send rate limit. In that case we might need to wait for
764 * one packet's worth of time to elapse before we can send again. On the
765 * other extreme, the queue might have data in it waiting for Nagle. (This
766 * will always be less than one packet, because as soon as we have a complete
767 * packet we would send it.) In that case, we might be ready to send data
768 * now, and this value will be 0.
769 *
770 * This value is only valid if multiple lanes are not used. If multiple lanes
771 * are in use, then the queue time will be different for each lane, and you
772 * must use the value in SteamNetConnectionRealTimeLaneStatus_t.
773 *
774 * Nagle delay is ignored for the purposes of this calculation.
775 */
776 SteamNetworkingMicroseconds m_usecQueueTime;
777
778 // Internal stuff, room to change API easily
779 u32 reserved[16];
780 };
781
782 /*
783 * Callbacks
784 */
785
786 enum { k_iSteamNetConnectionStatusChangedCallBack =
787 k_iSteamNetworkingSocketsCallbacks + 1 };
788
789 typedef struct SteamNetConnectionStatusChangedCallback_t
790 SteamNetConnectionStatusChangedCallback_t;
791 struct SteamNetConnectionStatusChangedCallback_t
792 {
793 /// Connection handle
794 HSteamNetConnection m_hConn;
795
796 /// Full connection info
797 SteamNetConnectionInfo_t m_info;
798
799 /// Previous state. (Current state is in m_info.m_eState)
800 ESteamNetworkingConnectionState m_eOldState;
801 };
802
803 enum { k_iSteamNetAuthenticationStatus =
804 k_iSteamNetworkingSocketsCallbacks + 2 };
805
806 typedef struct SteamNetAuthenticationStatus_t SteamNetAuthenticationStatus_t;
807 struct SteamNetAuthenticationStatus_t
808 {
809 /// Status
810 ESteamNetworkingAvailability m_eAvail;
811
812 /// Non-localized English language status. For diagnostic/debugging
813 /// purposes only.
814 char m_debugMsg[ 256 ];
815 };
816
817 #pragma pack(pop)
818
819 /* This does not have packing specified in the steamnetworkingtypes.h, it seems
820 * to use default */
821 struct SteamNetworkingMessage_t
822 {
823 /*
824 * Message payload
825 */
826 void *m_pData;
827
828 /*
829 * Size of the payload.
830 */
831 int m_cbSize;
832
833 HSteamNetConnection m_conn;
834
835 /*
836 * For inbound messages: Who sent this to us?
837 * For outbound messages on connections: not used.
838 * For outbound messages on the ad-hoc ISteamNetworkingMessages interface:
839 * who should we send this to?
840 */
841 SteamNetworkingIdentity m_identityPeer;
842
843 /*
844 * For messages received on connections, this is the user data
845 * associated with the connection.
846 *
847 * This is *usually* the same as calling GetConnection() and then
848 * fetching the user data associated with that connection, but for
849 * the following subtle differences:
850 *
851 * - This user data will match the connection's user data at the time
852 * is captured at the time the message is returned by the API.
853 * If you subsequently change the userdata on the connection,
854 * this won't be updated.
855 * - This is an inline call, so it's *much* faster.
856 * - You might have closed the connection, so fetching the user data
857 * would not be possible.
858 *
859 * Not used when sending messages.
860 */
861 i64 m_nConnUserData;
862
863 /*
864 * Local timestamp when the message was received
865 * Not used for outbound messages.
866 */
867 SteamNetworkingMicroseconds m_usecTimeReceived;
868
869 /*
870 * Message number assigned by the sender. This is not used for outbound
871 * messages. Note that if multiple lanes are used, each lane has its own
872 * message numbers, which are assigned sequentially, so messages from
873 * different lanes will share the same numbers.
874 */
875 i64 m_nMessageNumber;
876
877 /*
878 * Function used to free up m_pData. This mechanism exists so that
879 * apps can create messages with buffers allocated from their own
880 * heap, and pass them into the library. This function will
881 * usually be something like:
882 *
883 * free( pMsg->m_pData );
884 */
885 void (*m_pfnFreeData)( SteamNetworkingMessage_t *pMsg );
886
887 /*
888 * Function to used to decrement the internal reference count and, if
889 * it's zero, release the message. You should not set this function pointer,
890 * or need to access this directly! Use the Release() function instead!
891 */
892 void (*m_pfnRelease)( SteamNetworkingMessage_t *pMsg );
893
894 /*
895 * When using ISteamNetworkingMessages, the channel number the message was
896 * received on (Not used for messages sent or received on "connections")
897 */
898 int m_nChannel;
899
900 /*
901 * Bitmask of k_nSteamNetworkingSend_xxx flags.
902 * For received messages, only the k_nSteamNetworkingSend_Reliable bit is
903 * valid.
904 * For outbound messages, all bits are relevant
905 */
906 int m_nFlags;
907
908 /*
909 * Arbitrary user data that you can use when sending messages using
910 * ISteamNetworkingUtils::AllocateMessage and
911 * ISteamNetworkingSockets::SendMessage.
912 * (The callback you set in m_pfnFreeData might use this field.)
913 *
914 * Not used for received messages.
915 */
916 i64 m_nUserData;
917
918 /*
919 * For outbound messages, which lane to use? See
920 * ISteamNetworkingSockets::ConfigureConnectionLanes.
921 * For inbound messages, what lane was the message received on?
922 */
923 u16 m_idxLane;
924 u16 _pad1__;
925 };
926
927 void SteamAPI_SteamNetworkingMessage_t_Release(SteamNetworkingMessage_t* self);
928
929
930
931
932 /*
933 * Utility
934 */
935
936 static const char *string_ESteamNetworkingConnectionState(
937 ESteamNetworkingConnectionState s )
938 {
939 switch(s)
940 {
941 case k_ESteamNetworkingConnectionState_None:
942 return "None";
943 break;
944 case k_ESteamNetworkingConnectionState_Connecting:
945 return "Connecting";
946 break;
947 case k_ESteamNetworkingConnectionState_FindingRoute:
948 return "Finding route";
949 break;
950 case k_ESteamNetworkingConnectionState_Connected:
951 return "Connected";
952 break;
953 case k_ESteamNetworkingConnectionState_ClosedByPeer:
954 return "Closed By Peer";
955 break;
956 case k_ESteamNetworkingConnectionState_ProblemDetectedLocally:
957 return "Problem detected locally";
958 break;
959 case k_ESteamNetworkingConnectionState_FinWait:
960 return "Finwait";
961 break;
962 case k_ESteamNetworkingConnectionState_Linger:
963 return "Linger";
964 break;
965 case k_ESteamNetworkingConnectionState_Dead:
966 return "Dead";
967 break;
968 case k_ESteamNetworkingConnectionState__Force32Bit:
969 return "Force 32 Bit";
970 break;
971 }
972
973 return "Error";
974 }
975
976 static const char *string_ESteamNetworkingAvailability(
977 ESteamNetworkingAvailability s )
978 {
979 switch(s)
980 {
981 case k_ESteamNetworkingAvailability_CannotTry:
982 return "Cannot Try";
983 break;
984 case k_ESteamNetworkingAvailability_Failed:
985 return "Failed";
986 break;
987 case k_ESteamNetworkingAvailability_Previously:
988 return "Previously";
989 break;
990 case k_ESteamNetworkingAvailability_Retrying:
991 return "Retrying";
992 break;
993 case k_ESteamNetworkingAvailability_NeverTried:
994 return "Never tried";
995 break;
996 case k_ESteamNetworkingAvailability_Waiting:
997 return "Waiting";
998 break;
999 case k_ESteamNetworkingAvailability_Attempting:
1000 return "Attempting";
1001 break;
1002 case k_ESteamNetworkingAvailability_Current:
1003 return "Current";
1004 break;
1005 case k_ESteamNetworkingAvailability_Unknown:
1006 return "Unknown";
1007 break;
1008 default:
1009 return "Error";
1010 break;
1011 }
1012 }
1013
1014 #endif /* VG_STEAM_NETWORKING_H */