1 #include "Lobby2Client_Steam.h"
2 #include "Lobby2Message_Steam.h"
3 #include <stdlib.h>
4 #include "NativeTypes.h"
5 #include "MTUSize.h"
6 #include <windows.h>
7
8 using namespace RakNet;
9
10
11 DEFINE_MULTILIST_PTR_TO_MEMBER_COMPARISONS(Lobby2Message,uint64_t,requestId);
12
SystemAddressAndRoomMemberComp(const SystemAddress & key,const Lobby2Client_Steam::RoomMember & data)13 int Lobby2Client_Steam::SystemAddressAndRoomMemberComp( const SystemAddress &key, const Lobby2Client_Steam::RoomMember &data )
14 {
15 if (key<data.systemAddress)
16 return -1;
17 if (key==data.systemAddress)
18 return 0;
19 return 1;
20 }
21
Lobby2Client_Steam()22 Lobby2Client_Steam::Lobby2Client_Steam() :
23 m_CallbackLobbyDataUpdated( this, &Lobby2Client_Steam::OnLobbyDataUpdatedCallback ),
24 m_CallbackPersonaStateChange( this, &Lobby2Client_Steam::OnPersonaStateChange ),
25 m_CallbackLobbyDataUpdate( this, &Lobby2Client_Steam::OnLobbyDataUpdate ),
26 m_CallbackChatDataUpdate( this, &Lobby2Client_Steam::OnLobbyChatUpdate ),
27 m_CallbackChatMessageUpdate( this, &Lobby2Client_Steam::OnLobbyChatMessage ),
28 m_CallbackP2PSessionRequest( this, &Lobby2Client_Steam::OnP2PSessionRequest ),
29 m_CallbackP2PSessionConnectFail( this, &Lobby2Client_Steam::OnP2PSessionConnectFail )
30 {
31 // Must recompile RakNet with MAXIMUM_MTU_SIZE set to 1200 in the preprocessor settings
32 RakAssert(MAXIMUM_MTU_SIZE<=1200);
33 }
34
Lobby2Client_Steam(const char * gameVersion)35 Lobby2Client_Steam::Lobby2Client_Steam(const char *gameVersion) :
36 m_CallbackLobbyDataUpdated( this, &Lobby2Client_Steam::OnLobbyDataUpdatedCallback ),
37 m_CallbackPersonaStateChange( this, &Lobby2Client_Steam::OnPersonaStateChange ),
38 m_CallbackLobbyDataUpdate( this, &Lobby2Client_Steam::OnLobbyDataUpdate ),
39 m_CallbackChatDataUpdate( this, &Lobby2Client_Steam::OnLobbyChatUpdate ),
40 m_CallbackChatMessageUpdate( this, &Lobby2Client_Steam::OnLobbyChatMessage ),
41 m_CallbackP2PSessionRequest( this, &Lobby2Client_Steam::OnP2PSessionRequest ),
42 m_CallbackP2PSessionConnectFail( this, &Lobby2Client_Steam::OnP2PSessionConnectFail )
43 {
44 roomId=0;
45 versionString=gameVersion;
46
47 }
~Lobby2Client_Steam()48 Lobby2Client_Steam::~Lobby2Client_Steam()
49 {
50
51 }
SendMsg(Lobby2Message * msg)52 void Lobby2Client_Steam::SendMsg(Lobby2Message *msg)
53 {
54 if (msg->ClientImpl((Lobby2Client*) this))
55 {
56 for (unsigned long i=0; i < callbacks.Size(); i++)
57 {
58 if (msg->callbackId==(unsigned char)-1 || msg->callbackId==callbacks[i]->callbackId)
59 msg->CallCallback(callbacks[i]);
60 }
61 }
62 else
63 {
64 // Won't be deleted by the user's call to Deref.
65 msg->resultCode=L2RC_PROCESSING;
66 msg->AddRef();
67 PushDeferredCallback(msg);
68 }
69 }
Update(void)70 void Lobby2Client_Steam::Update(void)
71 {
72 SteamAPI_RunCallbacks();
73
74 /*
75 // sending data
76 // must be a handle to a connected socket
77 // data is all sent via UDP, and thus send sizes are limited to 1200 bytes; after this, many routers will start dropping packets
78 // use the reliable flag with caution; although the resend rate is pretty aggressive,
79 // it can still cause stalls in receiving data (like TCP)
80 virtual bool SendDataOnSocket( SNetSocket_t hSocket, void *pubData, uint32 cubData, bool bReliable ) = 0;
81
82 // receiving data
83 // returns false if there is no data remaining
84 // fills out *pcubMsgSize with the size of the next message, in bytes
85 virtual bool IsDataAvailableOnSocket( SNetSocket_t hSocket, uint32 *pcubMsgSize ) = 0;
86
87 // fills in pubDest with the contents of the message
88 // messages are always complete, of the same size as was sent (i.e. packetized, not streaming)
89 // if *pcubMsgSize < cubDest, only partial data is written
90 // returns false if no data is available
91 virtual bool RetrieveDataFromSocket( SNetSocket_t hSocket, void *pubDest, uint32 cubDest, uint32 *pcubMsgSize ) = 0;
92 */
93 }
94
PushDeferredCallback(Lobby2Message * msg)95 void Lobby2Client_Steam::PushDeferredCallback(Lobby2Message *msg)
96 {
97 deferredCallbacks.Push(msg, msg->requestId, __FILE__, __LINE__ );
98 }
CallCBWithResultCode(Lobby2Message * msg,Lobby2ResultCode rc)99 void Lobby2Client_Steam::CallCBWithResultCode(Lobby2Message *msg, Lobby2ResultCode rc)
100 {
101 if (msg)
102 {
103 msg->resultCode=rc;
104 for (unsigned long i=0; i < callbacks.Size(); i++)
105 {
106 if (msg->callbackId==(unsigned char)-1 || msg->callbackId==callbacks[i]->callbackId)
107 msg->CallCallback(callbacks[i]);
108 }
109 }
110 }
OnLobbyMatchListCallback(LobbyMatchList_t * pCallback,bool bIOFailure)111 void Lobby2Client_Steam::OnLobbyMatchListCallback( LobbyMatchList_t *pCallback, bool bIOFailure )
112 {
113 (void) bIOFailure;
114
115 uint32_t i;
116 for (i=0; i < deferredCallbacks.GetSize(); i++)
117 {
118 // Get any instance of Console_SearchRooms
119 if (deferredCallbacks[i]->GetID()==L2MID_Console_SearchRooms)
120 {
121 Console_SearchRooms_Steam *callbackResult = (Console_SearchRooms_Steam *) deferredCallbacks[i];
122 // iterate the returned lobbies with GetLobbyByIndex(), from values 0 to m_nLobbiesMatching-1
123 // lobbies are returned in order of closeness to the user, so add them to the list in that order
124 for ( uint32 iLobby = 0; iLobby < pCallback->m_nLobbiesMatching; iLobby++ )
125 {
126 CSteamID steamId = SteamMatchmaking()->GetLobbyByIndex( iLobby );
127 callbackResult->roomIds.Push(steamId, __FILE__, __LINE__ );
128 RakNet::RakString s = SteamMatchmaking()->GetLobbyData( steamId, "name" );
129 callbackResult->roomNames.Push(s, __FILE__, __LINE__ );
130 }
131
132 CallCBWithResultCode(callbackResult, L2RC_SUCCESS);
133 msgFactory->Dealloc(callbackResult);
134 deferredCallbacks.RemoveAtIndex(i);
135 break;
136 }
137 }
138 }
OnLobbyDataUpdatedCallback(LobbyDataUpdate_t * pCallback)139 void Lobby2Client_Steam::OnLobbyDataUpdatedCallback( LobbyDataUpdate_t *pCallback )
140 {
141 uint32_t i;
142 for (i=0; i < deferredCallbacks.GetSize(); i++)
143 {
144 if (deferredCallbacks[i]->GetID()==L2MID_Console_GetRoomDetails)
145 {
146 Console_GetRoomDetails_Steam *callbackResult = (Console_GetRoomDetails_Steam *) deferredCallbacks[i];
147 if (callbackResult->roomId==pCallback->m_ulSteamIDLobby)
148 {
149 const char *pchLobbyName = SteamMatchmaking()->GetLobbyData( pCallback->m_ulSteamIDLobby, "name" );
150 if ( pchLobbyName[0] )
151 {
152 callbackResult->roomName=pchLobbyName;
153 }
154 CallCBWithResultCode(callbackResult, L2RC_SUCCESS);
155 msgFactory->Dealloc(callbackResult);
156 deferredCallbacks.RemoveAtIndex(i);
157 break;
158 }
159 }
160 }
161
162 Console_GetRoomDetails_Steam notification;
163 const char *pchLobbyName = SteamMatchmaking()->GetLobbyData( pCallback->m_ulSteamIDLobby, "name" );
164 if ( pchLobbyName[0] )
165 {
166 notification.roomName=pchLobbyName;
167 }
168 notification.roomId=pCallback->m_ulSteamIDLobby;
169 CallCBWithResultCode(¬ification, L2RC_SUCCESS);
170 }
OnLobbyCreated(LobbyCreated_t * pCallback,bool bIOFailure)171 void Lobby2Client_Steam::OnLobbyCreated( LobbyCreated_t *pCallback, bool bIOFailure )
172 {
173 (void) bIOFailure;
174
175 uint32_t i;
176 for (i=0; i < deferredCallbacks.GetSize(); i++)
177 {
178 if (deferredCallbacks[i]->GetID()==L2MID_Console_CreateRoom)
179 {
180 Console_CreateRoom_Steam *callbackResult = (Console_CreateRoom_Steam *) deferredCallbacks[i];
181 callbackResult->roomId=pCallback->m_ulSteamIDLobby;
182 SteamMatchmaking()->SetLobbyData( callbackResult->roomId, "name", callbackResult->roomName.C_String() );
183 roomId=pCallback->m_ulSteamIDLobby;
184
185 printf("\nNumber of Steam Lobby Members:%i in Lobby Name:%s\n", SteamMatchmaking()->GetNumLobbyMembers(roomId), callbackResult->roomName.C_String());
186 RoomMember roomMember;
187 roomMember.steamIDRemote=SteamMatchmaking()->GetLobbyOwner(roomId).ConvertToUint64();
188 roomMember.systemAddress.binaryAddress=nextFreeSystemAddress++;
189 roomMember.systemAddress.port=STEAM_UNUSED_PORT;
190 roomMembers.Insert(roomMember.systemAddress,roomMember,true,__FILE__,__LINE__); // GetLobbyMemberByIndex( roomId, 0 ).ConvertToUint64());
191
192 CallCBWithResultCode(callbackResult, L2RC_SUCCESS);
193 msgFactory->Dealloc(callbackResult);
194 deferredCallbacks.RemoveAtIndex(i);
195
196 // Commented out: Do not send the notification for yourself
197 // CallRoomCallbacks();
198 break;
199 }
200 }
201 }
OnLobbyJoined(LobbyEnter_t * pCallback,bool bIOFailure)202 void Lobby2Client_Steam::OnLobbyJoined( LobbyEnter_t *pCallback, bool bIOFailure )
203 {
204 (void) bIOFailure;
205
206 uint32_t i;
207 for (i=0; i < deferredCallbacks.GetSize(); i++)
208 {
209 if (deferredCallbacks[i]->GetID()==L2MID_Console_JoinRoom)
210 {
211 Console_JoinRoom_Steam *callbackResult = (Console_JoinRoom_Steam *) deferredCallbacks[i];
212
213 if (pCallback->m_EChatRoomEnterResponse==k_EChatRoomEnterResponseSuccess)
214 {
215 roomId=pCallback->m_ulSteamIDLobby;
216
217 CallCBWithResultCode(callbackResult, L2RC_SUCCESS);
218
219 // First push to prevent being notified of ourselves
220 RoomMember roomMember;
221 roomMember.steamIDRemote=SteamMatchmaking()->GetLobbyOwner(roomId).ConvertToUint64();
222 roomMember.systemAddress.binaryAddress=nextFreeSystemAddress++;
223 roomMember.systemAddress.port=STEAM_UNUSED_PORT;
224 roomMembers.Insert(roomMember.systemAddress,roomMember,true,__FILE__,__LINE__);
225
226 CallRoomCallbacks();
227
228 // In case the asynch lobby update didn't get it fast enough
229 DataStructures::DefaultIndexType rmi;
230 uint64_t myId64=SteamUser()->GetSteamID().ConvertToUint64();
231 for (rmi=0; rmi < roomMembers.Size(); rmi++)
232 {
233 if (myId64==roomMembers[rmi].steamIDRemote)
234 break;
235 }
236
237 if (rmi==roomMembers.Size())
238 {
239 roomMember.steamIDRemote=SteamMatchmaking()->GetLobbyOwner(roomId).ConvertToUint64();
240 roomMember.systemAddress.binaryAddress=nextFreeSystemAddress++;
241 roomMember.systemAddress.port=STEAM_UNUSED_PORT;
242 roomMembers.Insert(roomMember.systemAddress,roomMember,true,__FILE__,__LINE__);
243 }
244
245 DataStructures::DefaultIndexType j;
246 for (j=0; j < roomMembers.Size(); j++)
247 {
248 if (roomMembers[j].steamIDRemote==SteamUser()->GetSteamID().ConvertToUint64())
249 continue;
250 }
251 }
252 else
253 {
254 CallCBWithResultCode(callbackResult, L2RC_Console_JoinRoom_NO_SUCH_ROOM);
255 }
256
257 msgFactory->Dealloc(callbackResult);
258 deferredCallbacks.RemoveAtIndex(i);
259 break;
260 }
261 }
262 }
IsCommandRunning(Lobby2MessageID msgId)263 bool Lobby2Client_Steam::IsCommandRunning( Lobby2MessageID msgId )
264 {
265 uint32_t i;
266 for (i=0; i < deferredCallbacks.GetSize(); i++)
267 {
268 if (deferredCallbacks[i]->GetID()==msgId)
269 {
270 return true;
271 }
272 }
273 return false;
274 }
275
OnPersonaStateChange(PersonaStateChange_t * pCallback)276 void Lobby2Client_Steam::OnPersonaStateChange( PersonaStateChange_t *pCallback )
277 {
278 // callbacks are broadcast to all listeners, so we'll get this for every friend who changes state
279 // so make sure the user is in the lobby before acting
280 if ( !SteamFriends()->IsUserInSource( pCallback->m_ulSteamID, roomId ) )
281 return;
282
283 if ((pCallback->m_nChangeFlags & k_EPersonaChangeNameFirstSet) ||
284 (pCallback->m_nChangeFlags & k_EPersonaChangeName))
285 {
286 Notification_Friends_StatusChange_Steam notification;
287 notification.friendId=pCallback->m_ulSteamID;
288 const char *pchName = SteamFriends()->GetFriendPersonaName( notification.friendId );
289 notification.friendNewName=pchName;
290 CallCBWithResultCode(¬ification, L2RC_SUCCESS);
291 }
292 }
OnLobbyDataUpdate(LobbyDataUpdate_t * pCallback)293 void Lobby2Client_Steam::OnLobbyDataUpdate( LobbyDataUpdate_t *pCallback )
294 {
295 // callbacks are broadcast to all listeners, so we'll get this for every lobby we're requesting
296 if ( roomId != pCallback->m_ulSteamIDLobby )
297 return;
298
299 Notification_Console_UpdateRoomParameters_Steam notification;
300 notification.roomId=roomId;
301 notification.roomNewName=SteamMatchmaking()->GetLobbyData( roomId, "name" );
302 CallCBWithResultCode(¬ification, L2RC_SUCCESS);
303 }
OnLobbyChatUpdate(LobbyChatUpdate_t * pCallback)304 void Lobby2Client_Steam::OnLobbyChatUpdate( LobbyChatUpdate_t *pCallback )
305 {
306 // callbacks are broadcast to all listeners, so we'll get this for every lobby we're requesting
307 if ( roomId != pCallback->m_ulSteamIDLobby )
308 return;
309
310 // Purpose: Handles users in the lobby joining or leaving ??????
311 CallRoomCallbacks();
312 }
OnLobbyChatMessage(LobbyChatMsg_t * pCallback)313 void Lobby2Client_Steam::OnLobbyChatMessage( LobbyChatMsg_t *pCallback )
314 {
315 CSteamID speaker;
316 EChatEntryType entryType;
317 char data[2048];
318 int cubData=sizeof(data);
319 SteamMatchmaking()->GetLobbyChatEntry( roomId, pCallback->m_iChatID, &speaker, data, cubData, &entryType);
320 if (entryType==k_EChatEntryTypeChatMsg)
321 {
322 Notification_Console_RoomChatMessage_Steam notification;
323 notification.message=data;
324 CallCBWithResultCode(¬ification, L2RC_SUCCESS);
325 }
326
327 }
GetRoomMembers(DataStructures::OrderedList<uint64_t,uint64_t> & _roomMembers)328 void Lobby2Client_Steam::GetRoomMembers(DataStructures::OrderedList<uint64_t, uint64_t> &_roomMembers)
329 {
330 _roomMembers.Clear(true,__FILE__,__LINE__);
331 int cLobbyMembers = SteamMatchmaking()->GetNumLobbyMembers( roomId );
332 for ( int i = 0; i < cLobbyMembers; i++ )
333 {
334 CSteamID steamIDLobbyMember = SteamMatchmaking()->GetLobbyMemberByIndex( roomId, i ) ;
335 uint64_t memberid=steamIDLobbyMember.ConvertToUint64();
336 _roomMembers.Insert(memberid,memberid,true,__FILE__,__LINE__);
337 }
338 }
339
GetRoomMemberName(uint64_t memberId)340 const char * Lobby2Client_Steam::GetRoomMemberName(uint64_t memberId)
341 {
342 return SteamFriends()->GetFriendPersonaName( memberId );
343 }
344
IsRoomOwner(CSteamID roomid)345 bool Lobby2Client_Steam::IsRoomOwner(CSteamID roomid)
346 {
347 if(SteamUser()->GetSteamID() == SteamMatchmaking()->GetLobbyOwner(roomid))
348 return true;
349
350 return false;
351 }
352
IsInRoom(void) const353 bool Lobby2Client_Steam::IsInRoom(void) const
354 {
355 return roomMembers.Size() > 0;
356 }
357
CallRoomCallbacks()358 void Lobby2Client_Steam::CallRoomCallbacks()
359 {
360 DataStructures::OrderedList<uint64_t,uint64_t> currentMembers;
361 GetRoomMembers(currentMembers);
362 DataStructures::OrderedList<SystemAddress, RoomMember, SystemAddressAndRoomMemberComp> updatedRoomMembers;
363
364 DataStructures::DefaultIndexType currentMemberIndex=0, oldMemberIndex=0;
365 while (currentMemberIndex < currentMembers.Size() && oldMemberIndex < roomMembers.Size())
366 {
367 if (currentMembers[currentMemberIndex]<roomMembers[oldMemberIndex].steamIDRemote)
368 {
369 RoomMember roomMember;
370 roomMember.steamIDRemote=currentMembers[currentMemberIndex];
371 roomMember.systemAddress.binaryAddress=nextFreeSystemAddress++;
372 roomMember.systemAddress.port=STEAM_UNUSED_PORT;
373 updatedRoomMembers.Insert(roomMember.systemAddress,roomMember,true,__FILE__,__LINE__);
374
375 // new member
376 NotifyNewMember(currentMembers[currentMemberIndex]);
377 currentMemberIndex++;
378 }
379 else if (currentMembers[currentMemberIndex]>roomMembers[oldMemberIndex].steamIDRemote)
380 {
381 // dropped member
382 NotifyDroppedMember(roomMembers[oldMemberIndex].steamIDRemote);
383 oldMemberIndex++;
384 }
385 else
386 {
387 updatedRoomMembers.Insert(roomMembers[oldMemberIndex].systemAddress,roomMembers[oldMemberIndex],true,__FILE__,__LINE__);
388
389 currentMemberIndex++;
390 oldMemberIndex++;
391 }
392 }
393
394 while (oldMemberIndex < roomMembers.Size())
395 {
396 // dropped member
397 NotifyDroppedMember(roomMembers[oldMemberIndex].steamIDRemote);
398
399 oldMemberIndex++;
400 }
401 while (currentMemberIndex < currentMembers.Size())
402 {
403 RoomMember roomMember;
404 roomMember.steamIDRemote=currentMembers[currentMemberIndex];
405 roomMember.systemAddress.binaryAddress=nextFreeSystemAddress++;
406 roomMember.systemAddress.port=STEAM_UNUSED_PORT;
407 updatedRoomMembers.Insert(roomMember.systemAddress,roomMember,true,__FILE__,__LINE__);
408
409 // new member
410 NotifyNewMember(currentMembers[currentMemberIndex]);
411
412 currentMemberIndex++;
413 }
414
415 roomMembers=updatedRoomMembers;
416 }
NotifyNewMember(uint64_t memberId)417 void Lobby2Client_Steam::NotifyNewMember(uint64_t memberId)
418 {
419 // const char *pchName = SteamFriends()->GetFriendPersonaName( memberId );
420
421 Notification_Console_MemberJoinedRoom_Steam notification;
422 notification.roomId=roomId;
423 notification.srcMemberId=memberId;
424 notification.memberName=SteamFriends()->GetFriendPersonaName( memberId );
425
426 CallCBWithResultCode(¬ification, L2RC_SUCCESS);
427 }
NotifyDroppedMember(uint64_t memberId)428 void Lobby2Client_Steam::NotifyDroppedMember(uint64_t memberId)
429 {
430 /// const char *pchName = SteamFriends()->GetFriendPersonaName( memberId );
431
432 Notification_Console_MemberLeftRoom_Steam notification;
433 notification.roomId=roomId;
434 notification.srcMemberId=memberId;
435 notification.memberName=SteamFriends()->GetFriendPersonaName( memberId );
436 CallCBWithResultCode(¬ification, L2RC_SUCCESS);
437 }
ClearRoom(void)438 void Lobby2Client_Steam::ClearRoom(void)
439 {
440 roomId=0;
441 if (SteamNetworking())
442 {
443 for (DataStructures::DefaultIndexType i=0; i < roomMembers.Size(); i++)
444 {
445 SteamNetworking()->CloseP2PSessionWithUser( roomMembers[i].steamIDRemote );
446 }
447 }
448 roomMembers.Clear(true,__FILE__,__LINE__);
449 }
OnP2PSessionRequest(P2PSessionRequest_t * pCallback)450 void Lobby2Client_Steam::OnP2PSessionRequest( P2PSessionRequest_t *pCallback )
451 {
452 // we'll accept a connection from anyone
453 SteamNetworking()->AcceptP2PSessionWithUser( pCallback->m_steamIDRemote );
454 }
OnP2PSessionConnectFail(P2PSessionConnectFail_t * pCallback)455 void Lobby2Client_Steam::OnP2PSessionConnectFail( P2PSessionConnectFail_t *pCallback )
456 {
457 (void) pCallback;
458
459 // we've sent a packet to the user, but it never got through
460 // we can just use the normal timeout
461 }
NotifyLeaveRoom(void)462 void Lobby2Client_Steam::NotifyLeaveRoom(void)
463 {
464 ClearRoom();
465 }
466
RakNetSendTo(SOCKET s,const char * data,int length,SystemAddress systemAddress)467 int Lobby2Client_Steam::RakNetSendTo( SOCKET s, const char *data, int length, SystemAddress systemAddress )
468 {
469 bool objectExists;
470 DataStructures::DefaultIndexType i = roomMembers.GetIndexFromKey(systemAddress, &objectExists);
471 if (objectExists)
472 {
473 if (SteamNetworking()->SendP2PPacket(roomMembers[i].steamIDRemote, data, length, k_EP2PSendUnreliable))
474 return length;
475 else
476 return 0;
477 }
478 else if (systemAddress.port!=STEAM_UNUSED_PORT)
479 {
480 return SocketLayer::SendTo_PC(s,data,length,systemAddress.binaryAddress,systemAddress.port,__FILE__,__LINE__);
481 }
482 return 0;
483 }
484
RakNetRecvFrom(const SOCKET sIn,RakPeer * rakPeerIn,char dataOut[MAXIMUM_MTU_SIZE],SystemAddress * senderOut,bool calledFromMainThread)485 int Lobby2Client_Steam::RakNetRecvFrom( const SOCKET sIn, RakPeer *rakPeerIn, char dataOut[ MAXIMUM_MTU_SIZE ], SystemAddress *senderOut, bool calledFromMainThread)
486 {
487 (void) calledFromMainThread;
488 (void) rakPeerIn;
489 (void) sIn;
490
491 uint32 pcubMsgSize;
492 if (SteamNetworking()->IsP2PPacketAvailable(&pcubMsgSize))
493 {
494 CSteamID psteamIDRemote;
495 if (SteamNetworking()->ReadP2PPacket(dataOut, MAXIMUM_MTU_SIZE, &pcubMsgSize, &psteamIDRemote))
496 {
497 uint64_t steamIDRemote64=psteamIDRemote.ConvertToUint64();
498 DataStructures::DefaultIndexType i;
499 for (i=0; i < roomMembers.Size(); i++)
500 {
501 if (roomMembers[i].steamIDRemote==steamIDRemote64)
502 {
503 *senderOut=roomMembers[i].systemAddress;
504 break;
505 }
506 }
507 return pcubMsgSize;
508 }
509 }
510 return 0;
511 }
512
OnRakPeerShutdown(void)513 void Lobby2Client_Steam::OnRakPeerShutdown(void)
514 {
515 ClearRoom();
516 }
OnClosedConnection(SystemAddress systemAddress,RakNetGUID rakNetGUID,PI2_LostConnectionReason lostConnectionReason)517 void Lobby2Client_Steam::OnClosedConnection(SystemAddress systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason )
518 {
519 (void) lostConnectionReason;
520 (void) rakNetGUID;
521
522 bool objectExists;
523 DataStructures::DefaultIndexType i = roomMembers.GetIndexFromKey(systemAddress, &objectExists);
524 if (objectExists)
525 {
526 SteamNetworking()->CloseP2PSessionWithUser( roomMembers[i].steamIDRemote );
527 roomMembers.RemoveAtIndex(i);
528 }
529 }
OnFailedConnectionAttempt(Packet * packet,PI2_FailedConnectionAttemptReason failedConnectionAttemptReason)530 void Lobby2Client_Steam::OnFailedConnectionAttempt(Packet *packet, PI2_FailedConnectionAttemptReason failedConnectionAttemptReason)
531 {
532 (void) failedConnectionAttemptReason;
533
534 bool objectExists;
535 DataStructures::DefaultIndexType i = roomMembers.GetIndexFromKey(packet->systemAddress, &objectExists);
536 if (objectExists)
537 {
538 SteamNetworking()->CloseP2PSessionWithUser( roomMembers[i].steamIDRemote );
539 roomMembers.RemoveAtIndex(i);
540 }
541 }
542