-
Notifications
You must be signed in to change notification settings - Fork 238
Expand file tree
/
Copy pathsteam_networking_sockets.cpp
More file actions
2143 lines (1922 loc) · 102 KB
/
steam_networking_sockets.cpp
File metadata and controls
2143 lines (1922 loc) · 102 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (C) 2019 Mr Goldberg
This file is part of the Goldberg Emulator
The Goldberg Emulator is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
The Goldberg Emulator is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the Goldberg Emulator; if not, see
<http://www.gnu.org/licenses/>. */
#include "dll/steam_networking_sockets.h"
void Steam_Networking_Sockets::steam_callback(void *object, Common_Message *msg)
{
// PRINT_DEBUG_ENTRY();
Steam_Networking_Sockets *steam_networkingsockets = (Steam_Networking_Sockets *)object;
steam_networkingsockets->Callback(msg);
}
void Steam_Networking_Sockets::steam_run_every_runcb(void *object)
{
// PRINT_DEBUG_ENTRY();
Steam_Networking_Sockets *steam_networkingsockets = (Steam_Networking_Sockets *)object;
steam_networkingsockets->RunCallbacks();
}
SteamNetworkingMessage_t* Steam_Networking_Sockets::get_steam_message_connection(HSteamNetConnection hConn)
{
auto connect_socket = sbcs->connect_sockets.find(hConn);
if (connect_socket == sbcs->connect_sockets.end()) return NULL;
if (connect_socket->second.data.empty()) return NULL;
SteamNetworkingMessage_t *pMsg = new SteamNetworkingMessage_t();
unsigned long size = static_cast<unsigned long>(connect_socket->second.data.top().data().size());
pMsg->m_pData = malloc(size);
pMsg->m_cbSize = size;
memcpy(pMsg->m_pData, connect_socket->second.data.top().data().data(), size);
pMsg->m_conn = hConn;
pMsg->m_identityPeer = connect_socket->second.remote_identity;
pMsg->m_nConnUserData = connect_socket->second.user_data;
pMsg->m_usecTimeReceived = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - created).count();
//TODO: check where messagenumber starts
pMsg->m_nMessageNumber = connect_socket->second.data.top().message_number();
pMsg->m_pfnFreeData = &free_steam_message_data;
pMsg->m_pfnRelease = &delete_steam_message;
pMsg->m_nChannel = 0;
connect_socket->second.data.pop();
PRINT_DEBUG("get_steam_message_connection %u %lu, %llu", hConn, size, pMsg->m_nMessageNumber);
return pMsg;
}
void Steam_Networking_Sockets::free_steam_message_data(SteamNetworkingMessage_t *pMsg)
{
free(pMsg->m_pData);
pMsg->m_pData = NULL;
}
void Steam_Networking_Sockets::delete_steam_message(SteamNetworkingMessage_t *pMsg)
{
if (pMsg->m_pfnFreeData) pMsg->m_pfnFreeData(pMsg);
delete pMsg;
}
unsigned long Steam_Networking_Sockets::get_socket_id()
{
static unsigned long socket_id;
socket_id++;
return socket_id;
}
HSteamNetConnection Steam_Networking_Sockets::new_connect_socket(SteamNetworkingIdentity remote_identity, int virtual_port, int real_port, enum connect_socket_status status, HSteamListenSocket listen_socket_id, HSteamNetConnection remote_id)
{
Connect_Socket socket = {};
socket.remote_identity = remote_identity;
socket.virtual_port = virtual_port;
socket.real_port = real_port;
socket.listen_socket_id = listen_socket_id;
socket.remote_id = remote_id;
socket.status = status;
socket.user_data = -1;
socket.poll_group = k_HSteamNetPollGroup_Invalid;
socket.created_by = settings->get_local_steam_id();
socket.connect_request_last_sent = std::chrono::steady_clock::now();
socket.connect_requests_sent = 0;
socket.packet_send_counter = 1;
HSteamNetConnection socket_id = get_socket_id();
if (socket_id == k_HSteamNetConnection_Invalid) ++socket_id;
if (sbcs->connect_sockets.insert(std::make_pair(socket_id, socket)).second == false) {
return k_HSteamNetConnection_Invalid;
}
return socket_id;
}
struct Listen_Socket* Steam_Networking_Sockets::get_connection_socket(HSteamListenSocket id)
{
auto conn = std::find_if(sbcs->listen_sockets.begin(), sbcs->listen_sockets.end(), [&id](struct Listen_Socket const& conn) { return conn.socket_id == id;});
if (conn == sbcs->listen_sockets.end()) return NULL;
return &(*conn);
}
bool Steam_Networking_Sockets::send_packet_new_connection(HSteamNetConnection m_hConn)
{
auto connect_socket = sbcs->connect_sockets.find(m_hConn);
if (connect_socket == sbcs->connect_sockets.end()) return false;
//TODO: right now this only supports connecting with steam id, might need to make ip/port connections work in the future when I find a game that uses them.
Common_Message msg;
msg.set_source_id(connect_socket->second.created_by.ConvertToUint64());
msg.set_allocated_networking_sockets(new Networking_Sockets);
if (connect_socket->second.status == CONNECT_SOCKET_CONNECTING) {
msg.mutable_networking_sockets()->set_type(Networking_Sockets::CONNECTION_REQUEST);
} else if (connect_socket->second.status == CONNECT_SOCKET_CONNECTED) {
msg.mutable_networking_sockets()->set_type(Networking_Sockets::CONNECTION_ACCEPTED);
}
msg.mutable_networking_sockets()->set_virtual_port(connect_socket->second.virtual_port);
msg.mutable_networking_sockets()->set_real_port(connect_socket->second.real_port);
msg.mutable_networking_sockets()->set_connection_id_from(connect_socket->first);
msg.mutable_networking_sockets()->set_connection_id(connect_socket->second.remote_id);
uint64_t steam_id = connect_socket->second.remote_identity.GetSteamID64();
if (steam_id) {
msg.set_dest_id(steam_id);
return network->sendTo(&msg, true);
}
const SteamNetworkingIPAddr *ip_addr = connect_socket->second.remote_identity.GetIPAddr();
if (ip_addr) {
return network->sendToIPPort(&msg, ip_addr->GetIPv4(), ip_addr->m_port, true);
}
return false;
}
shared_between_client_server* Steam_Networking_Sockets::get_shared_between_client_server()
{
return sbcs;
}
HSteamListenSocket Steam_Networking_Sockets::new_listen_socket(int nSteamConnectVirtualPort, int real_port)
{
HSteamListenSocket socket_id = get_socket_id();
if (socket_id == k_HSteamListenSocket_Invalid) ++socket_id;
CSteamID steam_id = settings->get_local_steam_id();
auto conn = std::find_if(sbcs->listen_sockets.begin(), sbcs->listen_sockets.end(), [&nSteamConnectVirtualPort,&steam_id](struct Listen_Socket const& conn) { return conn.virtual_port == nSteamConnectVirtualPort && conn.created_by == steam_id;});
if (conn != sbcs->listen_sockets.end()) return k_HSteamListenSocket_Invalid;
struct Listen_Socket listen_socket;
listen_socket.socket_id = socket_id;
listen_socket.virtual_port = nSteamConnectVirtualPort;
listen_socket.real_port = real_port;
listen_socket.created_by = steam_id;
sbcs->listen_sockets.push_back(listen_socket);
return socket_id;
}
ESteamNetworkingConnectionState Steam_Networking_Sockets::convert_status(enum connect_socket_status old_status)
{
if (old_status == CONNECT_SOCKET_NO_CONNECTION) return k_ESteamNetworkingConnectionState_None;
if (old_status == CONNECT_SOCKET_CONNECTING) return k_ESteamNetworkingConnectionState_Connecting;
if (old_status == CONNECT_SOCKET_NOT_ACCEPTED) return k_ESteamNetworkingConnectionState_Connecting;
if (old_status == CONNECT_SOCKET_CONNECTED) return k_ESteamNetworkingConnectionState_Connected;
if (old_status == CONNECT_SOCKET_CLOSED) return k_ESteamNetworkingConnectionState_ClosedByPeer;
if (old_status == CONNECT_SOCKET_TIMEDOUT) return k_ESteamNetworkingConnectionState_ProblemDetectedLocally;
return k_ESteamNetworkingConnectionState_None;
}
void Steam_Networking_Sockets::set_steamnetconnectioninfo(std::map<HSteamNetConnection, Connect_Socket>::iterator connect_socket, SteamNetConnectionInfo_t *pInfo)
{
pInfo->m_identityRemote = connect_socket->second.remote_identity;
pInfo->m_nUserData = connect_socket->second.user_data;
pInfo->m_hListenSocket = connect_socket->second.listen_socket_id;
pInfo->m_addrRemote.Clear(); //TODO
if (connect_socket->second.real_port != SNS_DISABLED_PORT) {
pInfo->m_addrRemote.SetIPv4(network->getIP(connect_socket->second.remote_identity.GetSteamID()), connect_socket->second.real_port);
}
pInfo->m_idPOPRemote = 0;
pInfo->m_idPOPRelay = 0;
pInfo->m_eState = convert_status(connect_socket->second.status);
pInfo->m_eEndReason = 0; //TODO
pInfo->m_szEndDebug[0] = 0;
snprintf(pInfo->m_szConnectionDescription, sizeof(pInfo->m_szConnectionDescription), "%u", connect_socket->first);
//Note some games might not allocate a struct the whole size of SteamNetConnectionInfo_t when calling GetConnectionInfo
//keep this in mind in future interface updates
}
void Steam_Networking_Sockets::set_steamnetconnectioninfo_001(std::map<HSteamNetConnection, Connect_Socket>::iterator connect_socket, SteamNetConnectionInfo001_t* pInfo)
{
pInfo->m_steamIDRemote = connect_socket->second.remote_identity.GetSteamID();
pInfo->m_nUserData = connect_socket->second.user_data;
pInfo->m_hListenSocket = connect_socket->second.listen_socket_id;
if (connect_socket->second.real_port != SNS_DISABLED_PORT) {
pInfo->m_unIPRemote = network->getIP(connect_socket->second.remote_identity.GetSteamID());
pInfo->m_unPortRemote = connect_socket->second.real_port;
}
pInfo->m_idPOPRemote = 0;
pInfo->m_idPOPRelay = 0;
pInfo->m_eState = convert_status(connect_socket->second.status);
pInfo->m_eEndReason = 0; //TODO
pInfo->m_szEndDebug[0] = 0;
//Note some games might not allocate a struct the whole size of SteamNetConnectionInfo_t when calling GetConnectionInfo
//keep this in mind in future interface updates
}
void Steam_Networking_Sockets::launch_callback(HSteamNetConnection m_hConn, enum connect_socket_status old_status)
{
auto connect_socket = sbcs->connect_sockets.find(m_hConn);
if (connect_socket == sbcs->connect_sockets.end()) return;
struct SteamNetConnectionStatusChangedCallback_t data = {};
data.m_hConn = connect_socket->first;
data.m_eOldState = convert_status(old_status);
set_steamnetconnectioninfo(connect_socket, &data.m_info);
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
}
Steam_Networking_Sockets::Steam_Networking_Sockets(class Settings *settings, class Networking *network, class SteamCallResults *callback_results, class SteamCallBacks *callbacks, class RunEveryRunCB *run_every_runcb, shared_between_client_server *sbcs)
{
this->settings = settings;
this->network = network;
this->run_every_runcb = run_every_runcb;
this->callback_results = callback_results;
this->callbacks = callbacks;
this->created = std::chrono::steady_clock::now();
if (!sbcs) { // client
this->sbcs = new shared_between_client_server();
this->sbcs->used = 0;
} else { // game server
this->sbcs = sbcs;
++this->sbcs->used;
}
this->network->setCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_Networking_Sockets::steam_callback, this);
this->network->setCallback(CALLBACK_ID_NETWORKING_SOCKETS, settings->get_local_steam_id(), &Steam_Networking_Sockets::steam_callback, this);
this->run_every_runcb->add(&Steam_Networking_Sockets::steam_run_every_runcb, this);
}
Steam_Networking_Sockets::~Steam_Networking_Sockets()
{
this->network->rmCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_Networking_Sockets::steam_callback, this);
this->network->rmCallback(CALLBACK_ID_NETWORKING_SOCKETS, settings->get_local_steam_id(), &Steam_Networking_Sockets::steam_callback, this);
this->run_every_runcb->remove(&Steam_Networking_Sockets::steam_run_every_runcb, this);
if (this->sbcs) {
if (this->sbcs->used) {
--this->sbcs->used;
} else {
delete this->sbcs;
this->sbcs = nullptr;
}
}
}
/// Creates a "server" socket that listens for clients to connect to, either by calling
/// ConnectSocketBySteamID or ConnectSocketByIPv4Address.
///
/// nSteamConnectVirtualPort specifies how clients can connect to this socket using
/// ConnectBySteamID. A negative value indicates that this functionality is
/// disabled and clients must connect by IP address. It's very common for applications
/// to only have one listening socket; in that case, use zero. If you need to open
/// multiple listen sockets and have clients be able to connect to one or the other, then
/// nSteamConnectVirtualPort should be a small integer constant unique to each listen socket
/// you create.
///
/// In the open-source version of this API, you must pass -1 for nSteamConnectVirtualPort
///
/// If you want clients to connect to you by your IPv4 addresses using
/// ConnectByIPv4Address, then you must set nPort to be nonzero. Steam will
/// bind a UDP socket to the specified local port, and clients will send packets using
/// ordinary IP routing. It's up to you to take care of NAT, protecting your server
/// from DoS, etc. If you don't need clients to connect to you by IP, then set nPort=0.
/// Use nIP if you wish to bind to a particular local interface. Typically you will use 0,
/// which means to listen on all interfaces, and accept the default outbound IP address.
/// If nPort is zero, then nIP must also be zero.
///
/// A SocketStatusCallback_t callback when another client attempts a connection.
HSteamListenSocket Steam_Networking_Sockets::CreateListenSocket( int nSteamConnectVirtualPort, uint32 nIP, uint16 nPort )
{
PRINT_DEBUG("%i %u %u", nSteamConnectVirtualPort, nIP, nPort);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return new_listen_socket(nSteamConnectVirtualPort, nPort);
}
/// Creates a "server" socket that listens for clients to connect to by
/// calling ConnectByIPAddress, over ordinary UDP (IPv4 or IPv6)
///
/// You must select a specific local port to listen on and set it
/// the port field of the local address.
///
/// Usually you wil set the IP portion of the address to zero, (SteamNetworkingIPAddr::Clear()).
/// This means that you will not bind to any particular local interface. In addition,
/// if possible the socket will be bound in "dual stack" mode, which means that it can
/// accept both IPv4 and IPv6 clients. If you wish to bind a particular interface, then
/// set the local address to the appropriate IPv4 or IPv6 IP.
///
/// When a client attempts to connect, a SteamNetConnectionStatusChangedCallback_t
/// will be posted. The connection will be in the connecting state.
HSteamListenSocket Steam_Networking_Sockets::CreateListenSocketIP( const SteamNetworkingIPAddr &localAddress )
{
PRINT_DEBUG("old");
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return new_listen_socket(SNS_DISABLED_PORT, localAddress.m_port);
}
HSteamListenSocket Steam_Networking_Sockets::CreateListenSocketIP( const SteamNetworkingIPAddr *localAddress )
{
PRINT_DEBUG("old1");
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return new_listen_socket(SNS_DISABLED_PORT, localAddress->m_port);
}
HSteamListenSocket Steam_Networking_Sockets::CreateListenSocketIP( const SteamNetworkingIPAddr &localAddress, int nOptions, const SteamNetworkingConfigValue_t *pOptions )
{
PRINT_DEBUG_ENTRY();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return new_listen_socket(SNS_DISABLED_PORT, localAddress.m_port);
}
/// Creates a connection and begins talking to a "server" over UDP at the
/// given IPv4 or IPv6 address. The remote host must be listening with a
/// matching call to CreateListenSocketIP on the specified port.
///
/// A SteamNetConnectionStatusChangedCallback_t callback will be triggered when we start
/// connecting, and then another one on either timeout or successful connection.
///
/// If the server does not have any identity configured, then their network address
/// will be the only identity in use. Or, the network host may provide a platform-specific
/// identity with or without a valid certificate to authenticate that identity. (These
/// details will be contained in the SteamNetConnectionStatusChangedCallback_t.) It's
/// up to your application to decide whether to allow the connection.
///
/// By default, all connections will get basic encryption sufficient to prevent
/// casual eavesdropping. But note that without certificates (or a shared secret
/// distributed through some other out-of-band mechanism), you don't have any
/// way of knowing who is actually on the other end, and thus are vulnerable to
/// man-in-the-middle attacks.
HSteamNetConnection Steam_Networking_Sockets::ConnectByIPAddress( const SteamNetworkingIPAddr &address )
{
PRINT_DEBUG("old");
std::lock_guard<std::recursive_mutex> lock(global_mutex);
SteamNetworkingIdentity ip_id;
ip_id.SetIPAddr(address);
HSteamNetConnection socket = new_connect_socket(ip_id, SNS_DISABLED_PORT, address.m_port);
send_packet_new_connection(socket);
return socket;
}
HSteamNetConnection Steam_Networking_Sockets::ConnectByIPAddress( const SteamNetworkingIPAddr *address )
{
PRINT_DEBUG("old1");
std::lock_guard<std::recursive_mutex> lock(global_mutex);
SteamNetworkingIdentity ip_id;
ip_id.SetIPAddr(*address);
HSteamNetConnection socket = new_connect_socket(ip_id, SNS_DISABLED_PORT, address->m_port);
send_packet_new_connection(socket);
return socket;
}
HSteamNetConnection Steam_Networking_Sockets::ConnectByIPAddress( const SteamNetworkingIPAddr &address, int nOptions, const SteamNetworkingConfigValue_t *pOptions )
{
PRINT_DEBUG("%X", address.GetIPv4());
std::lock_guard<std::recursive_mutex> lock(global_mutex);
SteamNetworkingIdentity ip_id;
ip_id.SetIPAddr(address);
HSteamNetConnection socket = new_connect_socket(ip_id, SNS_DISABLED_PORT, address.m_port);
send_packet_new_connection(socket);
return socket;
}
/// Like CreateListenSocketIP, but clients will connect using ConnectP2P
///
/// nVirtualPort specifies how clients can connect to this socket using
/// ConnectP2P. It's very common for applications to only have one listening socket;
/// in that case, use zero. If you need to open multiple listen sockets and have clients
/// be able to connect to one or the other, then nVirtualPort should be a small integer (<1000)
/// unique to each listen socket you create.
///
/// If you use this, you probably want to call ISteamNetworkingUtils::InitializeRelayNetworkAccess()
/// when your app initializes
HSteamListenSocket Steam_Networking_Sockets::CreateListenSocketP2P( int nVirtualPort )
{
PRINT_DEBUG("old %i", nVirtualPort);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return new_listen_socket(nVirtualPort, SNS_DISABLED_PORT);
}
HSteamListenSocket Steam_Networking_Sockets::CreateListenSocketP2P( int nVirtualPort, int nOptions, const SteamNetworkingConfigValue_t *pOptions )
{
PRINT_DEBUG("%i", nVirtualPort);
//TODO config options
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return new_listen_socket(nVirtualPort, SNS_DISABLED_PORT);
}
/// Begin connecting to a server that is identified using a platform-specific identifier.
/// This requires some sort of third party rendezvous service, and will depend on the
/// platform and what other libraries and services you are integrating with.
///
/// At the time of this writing, there is only one supported rendezvous service: Steam.
/// Set the SteamID (whether "user" or "gameserver") and Steam will determine if the
/// client is online and facilitate a relay connection. Note that all P2P connections on
/// Steam are currently relayed.
///
/// If you use this, you probably want to call ISteamNetworkingUtils::InitializeRelayNetworkAccess()
/// when your app initializes
HSteamNetConnection Steam_Networking_Sockets::ConnectP2P( const SteamNetworkingIdentity &identityRemote, int nVirtualPort )
{
PRINT_DEBUG("old %i", nVirtualPort);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
const SteamNetworkingIPAddr *ip = identityRemote.GetIPAddr();
if (identityRemote.m_eType == k_ESteamNetworkingIdentityType_SteamID) {
PRINT_DEBUG("%llu", identityRemote.GetSteamID64());
//steam id identity
} else if (ip) {
PRINT_DEBUG("%u:%u ipv4? %u", ip->GetIPv4(), ip->m_port, ip->IsIPv4());
//ip addr
} else {
return k_HSteamNetConnection_Invalid;
}
HSteamNetConnection socket = new_connect_socket(identityRemote, nVirtualPort, SNS_DISABLED_PORT);
send_packet_new_connection(socket);
return socket;
}
HSteamNetConnection Steam_Networking_Sockets::ConnectP2P( const SteamNetworkingIdentity *identityRemote, int nVirtualPort )
{
PRINT_DEBUG("old1");
return ConnectP2P(*identityRemote, nVirtualPort);
}
HSteamNetConnection Steam_Networking_Sockets::ConnectP2P( const SteamNetworkingIdentity &identityRemote, int nVirtualPort, int nOptions, const SteamNetworkingConfigValue_t *pOptions )
{
PRINT_DEBUG("%i", nVirtualPort);
//TODO config options
return ConnectP2P(identityRemote, nVirtualPort);
}
/// Creates a connection and begins talking to a remote destination. The remote host
/// must be listening with a matching call to CreateListenSocket.
///
/// Use ConnectBySteamID to connect using the SteamID (client or game server) as the network address.
/// Use ConnectByIPv4Address to connect by IP address.
///
/// A SteamNetConnectionStatusChangedCallback_t callback will be triggered when we start connecting,
/// and then another one on timeout or successful connection
//#ifndef STEAMNETWORKINGSOCKETS_OPENSOURCE
HSteamNetConnection Steam_Networking_Sockets::ConnectBySteamID( CSteamID steamIDTarget, int nVirtualPort )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return k_HSteamNetConnection_Invalid;
}
//#endif
HSteamNetConnection Steam_Networking_Sockets::ConnectByIPv4Address( uint32 nIP, uint16 nPort )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return k_HSteamNetConnection_Invalid;
}
/// Accept an incoming connection that has been received on a listen socket.
///
/// When a connection attempt is received (perhaps after a few basic handshake
/// packets have been exchanged to prevent trivial spoofing), a connection interface
/// object is created in the k_ESteamNetworkingConnectionState_Connecting state
/// and a SteamNetConnectionStatusChangedCallback_t is posted. At this point, your
/// application MUST either accept or close the connection. (It may not ignore it.)
/// Accepting the connection will transition it either into the connected state,
/// of the finding route state, depending on the connection type.
///
/// You should take action within a second or two, because accepting the connection is
/// what actually sends the reply notifying the client that they are connected. If you
/// delay taking action, from the client's perspective it is the same as the network
/// being unresponsive, and the client may timeout the connection attempt. In other
/// words, the client cannot distinguish between a delay caused by network problems
/// and a delay caused by the application.
///
/// This means that if your application goes for more than a few seconds without
/// processing callbacks (for example, while loading a map), then there is a chance
/// that a client may attempt to connect in that interval and fail due to timeout.
///
/// If the application does not respond to the connection attempt in a timely manner,
/// and we stop receiving communication from the client, the connection attempt will
/// be timed out locally, transitioning the connection to the
/// k_ESteamNetworkingConnectionState_ProblemDetectedLocally state. The client may also
/// close the connection before it is accepted, and a transition to the
/// k_ESteamNetworkingConnectionState_ClosedByPeer is also possible depending the exact
/// sequence of events.
///
/// Returns k_EResultInvalidParam if the handle is invalid.
/// Returns k_EResultInvalidState if the connection is not in the appropriate state.
/// (Remember that the connection state could change in between the time that the
/// notification being posted to the queue and when it is received by the application.)
EResult Steam_Networking_Sockets::AcceptConnection( HSteamNetConnection hConn )
{
PRINT_DEBUG("%u", hConn);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
auto connect_socket = sbcs->connect_sockets.find(hConn);
if (connect_socket == sbcs->connect_sockets.end()) return k_EResultInvalidParam;
if (connect_socket->second.status != CONNECT_SOCKET_NOT_ACCEPTED) return k_EResultInvalidState;
connect_socket->second.status = CONNECT_SOCKET_CONNECTED;
send_packet_new_connection(connect_socket->first);
launch_callback(connect_socket->first, CONNECT_SOCKET_NOT_ACCEPTED);
return k_EResultOK;
}
/// Disconnects from the remote host and invalidates the connection handle.
/// Any unread data on the connection is discarded.
///
/// nReason is an application defined code that will be received on the other
/// end and recorded (when possible) in backend analytics. The value should
/// come from a restricted range. (See ESteamNetConnectionEnd.) If you don't need
/// to communicate any information to the remote host, and do not want analytics to
/// be able to distinguish "normal" connection terminations from "exceptional" ones,
/// You may pass zero, in which case the generic value of
/// k_ESteamNetConnectionEnd_App_Generic will be used.
///
/// pszDebug is an optional human-readable diagnostic string that will be received
/// by the remote host and recorded (when possible) in backend analytics.
///
/// If you wish to put the socket into a "linger" state, where an attempt is made to
/// flush any remaining sent data, use bEnableLinger=true. Otherwise reliable data
/// is not flushed.
///
/// If the connection has already ended and you are just freeing up the
/// connection interface, the reason code, debug string, and linger flag are
/// ignored.
bool Steam_Networking_Sockets::CloseConnection( HSteamNetConnection hPeer, int nReason, const char *pszDebug, bool bEnableLinger )
{
PRINT_DEBUG("%u", hPeer);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
auto connect_socket = sbcs->connect_sockets.find(hPeer);
if (connect_socket == sbcs->connect_sockets.end()) return false;
if (connect_socket->second.status != CONNECT_SOCKET_CLOSED && connect_socket->second.status != CONNECT_SOCKET_TIMEDOUT) {
//TODO send/nReason and pszDebug
Common_Message msg;
msg.set_source_id(connect_socket->second.created_by.ConvertToUint64());
msg.set_dest_id(connect_socket->second.remote_identity.GetSteamID64());
msg.set_allocated_networking_sockets(new Networking_Sockets);
msg.mutable_networking_sockets()->set_type(Networking_Sockets::CONNECTION_END);
msg.mutable_networking_sockets()->set_virtual_port(connect_socket->second.virtual_port);
msg.mutable_networking_sockets()->set_real_port(connect_socket->second.real_port);
msg.mutable_networking_sockets()->set_connection_id_from(connect_socket->first);
msg.mutable_networking_sockets()->set_connection_id(connect_socket->second.remote_id);
network->sendTo(&msg, true);
}
sbcs->connect_sockets.erase(connect_socket);
return true;
}
/// Destroy a listen socket, and all the client sockets generated by accepting connections
/// on the listen socket.
///
/// pszNotifyRemoteReason determines what cleanup actions are performed on the client
/// sockets being destroyed. (See DestroySocket for more details.)
///
/// Note that if cleanup is requested and you have requested the listen socket bound to a
/// particular local port to facilitate direct UDP/IPv4 connections, then the underlying UDP
/// socket must remain open until all clients have been cleaned up.
bool Steam_Networking_Sockets::CloseListenSocket( HSteamListenSocket hSocket, const char *pszNotifyRemoteReason )
{
PRINT_DEBUG("old");
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return CloseListenSocket(hSocket);
}
/// Destroy a listen socket. All the connections that were accepting on the listen
/// socket are closed ungracefully.
bool Steam_Networking_Sockets::CloseListenSocket( HSteamListenSocket hSocket )
{
PRINT_DEBUG_ENTRY();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
auto conn = std::find_if(sbcs->listen_sockets.begin(), sbcs->listen_sockets.end(), [&hSocket](struct Listen_Socket const& conn) { return conn.socket_id == hSocket;});
if (conn == sbcs->listen_sockets.end()) return false;
std::queue<HSteamNetConnection> to_close;
auto socket_conn = std::begin(sbcs->connect_sockets);
while (socket_conn != std::end(sbcs->connect_sockets)) {
if (socket_conn->second.listen_socket_id == hSocket) {
to_close.push(socket_conn->first);
}
++socket_conn;
}
while (to_close.size()) {
CloseConnection(to_close.front(), 0, "", false);
to_close.pop();
}
sbcs->listen_sockets.erase(conn);
return true;
}
/// Set connection user data. Returns false if the handle is invalid.
bool Steam_Networking_Sockets::SetConnectionUserData( HSteamNetConnection hPeer, int64 nUserData )
{
PRINT_DEBUG_ENTRY();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
auto connect_socket = sbcs->connect_sockets.find(hPeer);
if (connect_socket == sbcs->connect_sockets.end()) return false;
connect_socket->second.user_data = nUserData;
return true;
}
/// Fetch connection user data. Returns -1 if handle is invalid
/// or if you haven't set any userdata on the connection.
int64 Steam_Networking_Sockets::GetConnectionUserData( HSteamNetConnection hPeer )
{
PRINT_DEBUG_ENTRY();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
auto connect_socket = sbcs->connect_sockets.find(hPeer);
if (connect_socket == sbcs->connect_sockets.end()) return -1;
return connect_socket->second.user_data;
}
/// Set a name for the connection, used mostly for debugging
void Steam_Networking_Sockets::SetConnectionName( HSteamNetConnection hPeer, const char *pszName )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
}
/// Fetch connection name. Returns false if handle is invalid
bool Steam_Networking_Sockets::GetConnectionName( HSteamNetConnection hPeer, char *pszName, int nMaxLen )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return false;
}
/// Send a message to the remote host on the connected socket.
///
/// eSendType determines the delivery guarantees that will be provided,
/// when data should be buffered, etc.
///
/// Note that the semantics we use for messages are not precisely
/// the same as the semantics of a standard "stream" socket.
/// (SOCK_STREAM) For an ordinary stream socket, the boundaries
/// between chunks are not considered relevant, and the sizes of
/// the chunks of data written will not necessarily match up to
/// the sizes of the chunks that are returned by the reads on
/// the other end. The remote host might read a partial chunk,
/// or chunks might be coalesced. For the message semantics
/// used here, however, the sizes WILL match. Each send call
/// will match a successful read call on the remote host
/// one-for-one. If you are porting existing stream-oriented
/// code to the semantics of reliable messages, your code should
/// work the same, since reliable message semantics are more
/// strict than stream semantics. The only caveat is related to
/// performance: there is per-message overhead to retain the
/// messages sizes, and so if your code sends many small chunks
/// of data, performance will suffer. Any code based on stream
/// sockets that does not write excessively small chunks will
/// work without any changes.
EResult Steam_Networking_Sockets::SendMessageToConnection( HSteamNetConnection hConn, const void *pData, uint32 cbData, ESteamNetworkingSendType eSendType )
{
PRINT_DEBUG("old");
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return k_EResultFail;
}
/// Send a message to the remote host on the specified connection.
///
/// nSendFlags determines the delivery guarantees that will be provided,
/// when data should be buffered, etc. E.g. k_nSteamNetworkingSend_Unreliable
///
/// Note that the semantics we use for messages are not precisely
/// the same as the semantics of a standard "stream" socket.
/// (SOCK_STREAM) For an ordinary stream socket, the boundaries
/// between chunks are not considered relevant, and the sizes of
/// the chunks of data written will not necessarily match up to
/// the sizes of the chunks that are returned by the reads on
/// the other end. The remote host might read a partial chunk,
/// or chunks might be coalesced. For the message semantics
/// used here, however, the sizes WILL match. Each send call
/// will match a successful read call on the remote host
/// one-for-one. If you are porting existing stream-oriented
/// code to the semantics of reliable messages, your code should
/// work the same, since reliable message semantics are more
/// strict than stream semantics. The only caveat is related to
/// performance: there is per-message overhead to retain the
/// message sizes, and so if your code sends many small chunks
/// of data, performance will suffer. Any code based on stream
/// sockets that does not write excessively small chunks will
/// work without any changes.
///
/// The pOutMessageNumber is an optional pointer to receive the
/// message number assigned to the message, if sending was successful.
///
/// Returns:
/// - k_EResultInvalidParam: invalid connection handle, or the individual message is too big.
/// (See k_cbMaxSteamNetworkingSocketsMessageSizeSend)
/// - k_EResultInvalidState: connection is in an invalid state
/// - k_EResultNoConnection: connection has ended
/// - k_EResultIgnored: You used k_nSteamNetworkingSend_NoDelay, and the message was dropped because
/// we were not ready to send it.
/// - k_EResultLimitExceeded: there was already too much data queued to be sent.
/// (See k_ESteamNetworkingConfig_SendBufferSize)
EResult Steam_Networking_Sockets::SendMessageToConnection( HSteamNetConnection hConn, const void *pData, uint32 cbData, int nSendFlags, int64 *pOutMessageNumber )
{
PRINT_DEBUG("%u, len %u, flags %i", hConn, cbData, nSendFlags);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
auto connect_socket = sbcs->connect_sockets.find(hConn);
if (connect_socket == sbcs->connect_sockets.end()) return k_EResultInvalidParam;
if (connect_socket->second.status == CONNECT_SOCKET_CLOSED) return k_EResultNoConnection;
if (connect_socket->second.status == CONNECT_SOCKET_TIMEDOUT) return k_EResultNoConnection;
if (connect_socket->second.status != CONNECT_SOCKET_CONNECTED && connect_socket->second.status != CONNECT_SOCKET_CONNECTING) return k_EResultInvalidState;
Common_Message msg;
msg.set_source_id(connect_socket->second.created_by.ConvertToUint64());
msg.set_dest_id(connect_socket->second.remote_identity.GetSteamID64());
msg.set_allocated_networking_sockets(new Networking_Sockets);
msg.mutable_networking_sockets()->set_type(Networking_Sockets::DATA);
msg.mutable_networking_sockets()->set_virtual_port(connect_socket->second.virtual_port);
msg.mutable_networking_sockets()->set_real_port(connect_socket->second.real_port);
msg.mutable_networking_sockets()->set_connection_id_from(connect_socket->first);
msg.mutable_networking_sockets()->set_connection_id(connect_socket->second.remote_id);
msg.mutable_networking_sockets()->set_data(pData, cbData);
uint64 message_number = connect_socket->second.packet_send_counter;
msg.mutable_networking_sockets()->set_message_number(message_number);
connect_socket->second.packet_send_counter += 1;
bool reliable = false;
if (nSendFlags & k_nSteamNetworkingSend_Reliable) reliable = true;
if (network->sendTo(&msg, reliable)) {
if (pOutMessageNumber) *pOutMessageNumber = message_number;
return k_EResultOK;
}
return k_EResultFail;
}
EResult Steam_Networking_Sockets::SendMessageToConnection( HSteamNetConnection hConn, const void *pData, uint32 cbData, int nSendFlags )
{
PRINT_DEBUG("old %u, len %u, flags %i", hConn, cbData, nSendFlags);
return SendMessageToConnection(hConn, pData, cbData, nSendFlags, NULL);
}
/// Send one or more messages without copying the message payload.
/// This is the most efficient way to send messages. To use this
/// function, you must first allocate a message object using
/// ISteamNetworkingUtils::AllocateMessage. (Do not declare one
/// on the stack or allocate your own.)
///
/// You should fill in the message payload. You can either let
/// it allocate the buffer for you and then fill in the payload,
/// or if you already have a buffer allocated, you can just point
/// m_pData at your buffer and set the callback to the appropriate function
/// to free it. Note that if you use your own buffer, it MUST remain valid
/// until the callback is executed. And also note that your callback can be
/// invoked at ant time from any thread (perhaps even before SendMessages
/// returns!), so it MUST be fast and threadsafe.
///
/// You MUST also fill in:
/// - m_conn - the handle of the connection to send the message to
/// - m_nFlags - bitmask of k_nSteamNetworkingSend_xxx flags.
///
/// All other fields are currently reserved and should not be modified.
///
/// The library will take ownership of the message structures. They may
/// be modified or become invalid at any time, so you must not read them
/// after passing them to this function.
///
/// pOutMessageNumberOrResult is an optional array that will receive,
/// for each message, the message number that was assigned to the message
/// if sending was successful. If sending failed, then a negative EResult
/// valid is placed into the array. For example, the array will hold
/// -k_EResultInvalidState if the connection was in an invalid state.
/// See ISteamNetworkingSockets::SendMessageToConnection for possible
/// failure codes.
void Steam_Networking_Sockets::SendMessages( int nMessages, SteamNetworkingMessage_t *const *pMessages, int64 *pOutMessageNumberOrResult )
{
PRINT_DEBUG_ENTRY();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
for (int i = 0; i < nMessages; ++i) {
int64 out_number = 0;
int result = SendMessageToConnection(pMessages[i]->m_conn, pMessages[i]->m_pData, pMessages[i]->m_cbSize, pMessages[i]->m_nFlags, &out_number);
if (pOutMessageNumberOrResult) {
if (result == k_EResultOK) {
pOutMessageNumberOrResult[i] = out_number;
} else {
pOutMessageNumberOrResult[i] = -result;
}
}
pMessages[i]->m_pfnFreeData(pMessages[i]);
pMessages[i]->Release();
}
}
/// If Nagle is enabled (its on by default) then when calling
/// SendMessageToConnection the message will be queued up the Nagle time
/// before being sent to merge small messages into the same packet.
///
/// Call this function to flush any queued messages and send them immediately
/// on the next transmission time (often that means right now).
EResult Steam_Networking_Sockets::FlushMessagesOnConnection( HSteamNetConnection hConn )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return k_EResultOK;
}
/// Fetch the next available message(s) from the connection, if any.
/// Returns the number of messages returned into your array, up to nMaxMessages.
/// If the connection handle is invalid, -1 is returned.
///
/// The order of the messages returned in the array is relevant.
/// Reliable messages will be received in the order they were sent (and with the
/// same sizes --- see SendMessageToConnection for on this subtle difference from a stream socket).
///
/// Unreliable messages may be dropped, or delivered out of order withrespect to
/// each other or with respect to reliable messages. The same unreliable message
/// may be received multiple times.
///
/// If any messages are returned, you MUST call SteamNetworkingMessage_t::Release() on each
/// of them free up resources after you are done. It is safe to keep the object alive for
/// a little while (put it into some queue, etc), and you may call Release() from any thread.
int Steam_Networking_Sockets::ReceiveMessagesOnConnection( HSteamNetConnection hConn, SteamNetworkingMessage_t **ppOutMessages, int nMaxMessages )
{
PRINT_DEBUG("%u %i", hConn, nMaxMessages);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (!ppOutMessages || !nMaxMessages) return 0;
SteamNetworkingMessage_t *msg = NULL;
int messages = 0;
while (messages < nMaxMessages && (msg = get_steam_message_connection(hConn))) {
ppOutMessages[messages] = msg;
++messages;
}
PRINT_DEBUG("messages %u", messages);
return messages;
}
/// Same as ReceiveMessagesOnConnection, but will return the next message available
/// on any connection that was accepted through the specified listen socket. Examine
/// SteamNetworkingMessage_t::m_conn to know which client connection.
///
/// Delivery order of messages among different clients is not defined. They may
/// be returned in an order different from what they were actually received. (Delivery
/// order of messages from the same client is well defined, and thus the order of the
/// messages is relevant!)
int Steam_Networking_Sockets::ReceiveMessagesOnListenSocket( HSteamListenSocket hSocket, SteamNetworkingMessage_t **ppOutMessages, int nMaxMessages )
{
PRINT_DEBUG("%u %i", hSocket, nMaxMessages);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (!ppOutMessages || !nMaxMessages) return 0;
SteamNetworkingMessage_t *msg = NULL;
int messages = 0;
auto socket_conn = std::begin(sbcs->connect_sockets);
while (socket_conn != std::end(sbcs->connect_sockets) && messages < nMaxMessages) {
if (socket_conn->second.listen_socket_id == hSocket) {
while (messages < nMaxMessages && (msg = get_steam_message_connection(socket_conn->first))) {
ppOutMessages[messages] = msg;
++messages;
}
}
++socket_conn;
}
return messages;
}
/// Returns basic information about the high-level state of the connection.
bool Steam_Networking_Sockets::GetConnectionInfo( HSteamNetConnection hConn, SteamNetConnectionInfo_t *pInfo )
{
PRINT_DEBUG("%u %i", hConn, pInfo == NULL);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (!pInfo) return false;
auto connect_socket = sbcs->connect_sockets.find(hConn);
if (connect_socket == sbcs->connect_sockets.end()) return false;
set_steamnetconnectioninfo(connect_socket, pInfo);
//Note some games might not allocate a struct the whole size of SteamNetConnectionInfo_t
//keep this in mind in future interface updates
return true;
}
/// Returns a small set of information about the real-time state of the connection
/// and the queue status of each lane.
///
/// - pStatus may be NULL if the information is not desired. (E.g. you are only interested
/// in the lane information.)
/// - On entry, nLanes specifies the length of the pLanes array. This may be 0
/// if you do not wish to receive any lane data. It's OK for this to be smaller than
/// the total number of configured lanes.
/// - pLanes points to an array that will receive lane-specific info. It can be NULL
/// if this is not needed.
///
/// Return value:
/// - k_EResultNoConnection - connection handle is invalid or connection has been closed.
/// - k_EResultInvalidParam - nLanes is bad
EResult Steam_Networking_Sockets::GetConnectionRealTimeStatus( HSteamNetConnection hConn, SteamNetConnectionRealTimeStatus_t *pStatus, int nLanes, SteamNetConnectionRealTimeLaneStatus_t *pLanes )
{
PRINT_DEBUG("%u %p %i %p", hConn, pStatus, nLanes, pLanes);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
auto connect_socket = sbcs->connect_sockets.find(hConn);
if (connect_socket == sbcs->connect_sockets.end()) return k_EResultNoConnection;
if (pStatus) {
pStatus->m_eState = convert_status(connect_socket->second.status);
pStatus->m_nPing = 10; //TODO: calculate real numbers?
pStatus->m_flConnectionQualityLocal = 1.0;
pStatus->m_flConnectionQualityRemote = 1.0;
//TODO: rest
pStatus->m_flOutPacketsPerSec = 0.0;
pStatus->m_flOutBytesPerSec = 0.0;
pStatus->m_flInPacketsPerSec = 0.0;
pStatus->m_flInBytesPerSec = 0.0;
pStatus->m_cbSentUnackedReliable = 0;
pStatus->m_usecQueueTime = 0;
//Note some games (volcanoids) might not allocate a struct the whole size of SteamNetworkingQuickConnectionStatus
//keep this in mind in future interface updates
//NOTE: need to implement GetQuickConnectionStatus seperately if this changes.
}
//TODO: lanes
return k_EResultOK;
}
/// Fetch the next available message(s) from the socket, if any.
/// Returns the number of messages returned into your array, up to nMaxMessages.
/// If the connection handle is invalid, -1 is returned.
///
/// The order of the messages returned in the array is relevant.
/// Reliable messages will be received in the order they were sent (and with the
/// same sizes --- see SendMessageToConnection for on this subtle difference from a stream socket).
///
/// FIXME - We're still debating the exact set of guarantees for unreliable, so this might change.
/// Unreliable messages may not be received. The order of delivery of unreliable messages
/// is NOT specified. They may be received out of order with respect to each other or
/// reliable messages. They may be received multiple times!
///
/// If any messages are returned, you MUST call Release() to each of them free up resources
/// after you are done. It is safe to keep the object alive for a little while (put it
/// into some queue, etc), and you may call Release() from any thread.
int Steam_Networking_Sockets::ReceiveMessagesOnConnection( HSteamNetConnection hConn, SteamNetworkingMessage001_t **ppOutMessages, int nMaxMessages )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return -1;
}
/// Same as ReceiveMessagesOnConnection, but will return the next message available
/// on any client socket that was accepted through the specified listen socket. Examine
/// SteamNetworkingMessage_t::m_conn to know which client connection.
///
/// Delivery order of messages among different clients is not defined. They may