forked from SwagSoftware/Kisak-Strike
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmm_framework.cpp
960 lines (807 loc) · 25.4 KB
/
mm_framework.cpp
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
//===== Copyright © 1996-2009, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#include "mm_framework.h"
#include "mm_netmsgcontroller.h"
#include "matchsystem.h"
#include "mm_title_main.h"
#include "x360_lobbyapi.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
// Stress testing events listeners every frame
ConVar mm_events_listeners_validation( "mm_events_listeners_validation", "0", FCVAR_DEVELOPMENTONLY );
//
// Implementation of Steam invite listener
//
uint64 g_uiLastInviteFlags = 0ull;
#if !defined( _X360 ) && !defined( NO_STEAM ) && !defined( SWDS )
class CMatchSteamInviteListener
{
public:
void RunFrame();
void Register();
STEAM_CALLBACK_MANUAL( CMatchSteamInviteListener, Steam_OnGameLobbyJoinRequested, GameLobbyJoinRequested_t, m_CallbackOnGameLobbyJoinRequested );
#ifdef _PS3
STEAM_CALLBACK_MANUAL( CMatchSteamInviteListener, Steam_OnPSNGameBootInviteResult, PSNGameBootInviteResult_t, m_CallbackOnPSNGameBootInviteResult );
#endif
protected:
GameLobbyJoinRequested_t m_msgPending;
}
g_MatchSteamInviteListener;
void CMatchSteamInviteListener::Register()
{
m_CallbackOnGameLobbyJoinRequested.Register( this, &CMatchSteamInviteListener::Steam_OnGameLobbyJoinRequested );
#ifdef _PS3
m_CallbackOnPSNGameBootInviteResult.Register( this, &CMatchSteamInviteListener::Steam_OnPSNGameBootInviteResult );
#endif
}
#else
class CMatchSteamInviteListener
{
public:
void RunFrame() {}
void Register() {}
}
g_MatchSteamInviteListener;
#endif
//
// Implementation
//
CMatchFramework::CMatchFramework() :
m_pMatchSession( NULL ),
m_bJoinTeamSession( false ),
m_pTeamSessionSettings( NULL )
{
}
CMatchFramework::~CMatchFramework()
{
;
}
InitReturnVal_t CMatchFramework::Init()
{
InitReturnVal_t ret = INIT_OK;
ret = MM_Title_Init();
if ( ret != INIT_OK )
return ret;
g_MatchSteamInviteListener.Register();
return INIT_OK;
}
void CMatchFramework::Shutdown()
{
// Shutdown event system
g_pMatchEventsSubscription->Shutdown();
// Shutdown the title
MM_Title_Shutdown();
// Cancel any pending server updates before shutdown
g_pServerManager->EnableServersUpdate( false );
// Cancel any pending datacenter queries
g_pDatacenter->EnableUpdate( false );
}
void CMatchFramework::RunFrame()
{
// Run frame listeners validation if requested
if ( mm_events_listeners_validation.GetBool() )
{
g_pMatchEventsSubscription->BroadcastEvent( new KeyValues( "mm_events_listeners_validation" ) );
}
#ifdef _X360
if ( IXOnline *pIXOnline = g_pMatchExtensions->GetIXOnline() )
pIXOnline->RunFrame();
MMX360_UpdateDormantOperations();
SysSession360_UpdatePending();
#endif
RunFrame_Invite();
g_MatchSteamInviteListener.RunFrame();
#ifdef _X360
// Pump rate adjustments
MatchSession_RateAdjustmentUpdate();
#endif
// Let the network mgr run
g_pConnectionlessLanMgr->Update();
// Let the matchsystem run
g_pMatchSystem->Update();
// Let the match session run
if ( m_pMatchSession )
m_pMatchSession->Update();
// Let the match title run frame
g_pIMatchTitle->RunFrame();
if ( m_bJoinTeamSession )
{
m_bJoinTeamSession = false;
MatchSession( m_pTeamSessionSettings );
m_pTeamSessionSettings->deleteThis();
m_pTeamSessionSettings = NULL;
}
}
IMatchExtensions * CMatchFramework::GetMatchExtensions()
{
return g_pMatchExtensions;
}
IMatchEventsSubscription * CMatchFramework::GetEventsSubscription()
{
return g_pMatchEventsSubscription;
}
IMatchTitle * CMatchFramework::GetMatchTitle()
{
return g_pIMatchTitle;
}
IMatchTitleGameSettingsMgr * CMatchFramework::GetMatchTitleGameSettingsMgr()
{
return g_pIMatchTitleGameSettingsMgr;
}
IMatchNetworkMsgController * CMatchFramework::GetMatchNetworkMsgController()
{
return g_pMatchNetMsgControllerBase;
}
IMatchSystem * CMatchFramework::GetMatchSystem()
{
return g_pMatchSystem;
}
void CMatchFramework::ApplySettings( KeyValues* keyValues )
{
g_pMatchExtensions->GetIServerGameDLL()->ApplyGameSettings( keyValues );
}
#ifdef _X360
static XINVITE_INFO s_InviteInfo;
#else
static uint64 s_InviteInfo;
#endif
static bool s_bInviteSessionDelayedJoin;
static int s_nInviteConfirmed;
template < int datasize >
static bool IsZeroData( void const *pvData )
{
static char s_zerodata[ datasize ];
return !memcmp( s_zerodata, pvData, datasize );
}
static bool ValidateInviteController( int iController )
{
#ifdef _X360
XUSER_SIGNIN_STATE eSignInState = XUserGetSigninState( iController );
XUSER_SIGNIN_INFO xsi = {0};
if ( ( eSignInState != eXUserSigninState_SignedInToLive ) ||
( ERROR_SUCCESS != XUserGetSigninInfo( iController, XUSER_GET_SIGNIN_INFO_ONLINE_XUID_ONLY, &xsi ) ) ||
! ( xsi.dwInfoFlags & XUSER_INFO_FLAG_LIVE_ENABLED ) )
{
DevWarning( "ValidateInviteController: ctrl%d check1 failed (state=%d, flags=0x%X, xuid=%llx)!\n",
eSignInState, xsi.dwInfoFlags, xsi.xuid );
if ( KeyValues *notify = new KeyValues(
"OnInvite", "action", "error", "error", "NotOnline" ) )
{
notify->SetInt( "user", iController );
g_pMatchEventsSubscription->BroadcastEvent( notify );
}
return false;
}
BOOL bMultiplayer = FALSE;
if ( ( ERROR_SUCCESS != XUserCheckPrivilege( iController, XPRIVILEGE_MULTIPLAYER_SESSIONS, &bMultiplayer ) ) ||
( !bMultiplayer ) )
{
DevWarning( "ValidateInviteController: ctrl%d check2 failed (state=%d, flags=0x%X, xuid=%llx) - on multiplayer priv!\n",
eSignInState, xsi.dwInfoFlags, xsi.xuid );
if ( KeyValues *notify = new KeyValues(
"OnInvite", "action", "error", "error", "NoMultiplayer" ) )
{
notify->SetInt( "user", iController );
g_pMatchEventsSubscription->BroadcastEvent( notify );
}
return false;
}
#endif
return true;
}
static bool ValidateInviteControllers()
{
for ( DWORD k = 0; k < XBX_GetNumGameUsers(); ++ k )
{
if ( !ValidateInviteController( XBX_GetUserId( k ) ) )
return false;
}
return true;
}
static bool VerifyInviteEligibility()
{
#ifdef _X360
// Make sure that the inviter is not signed in
for ( int k = 0; k < XUSER_MAX_COUNT; ++ k )
{
XUID xuid;
if ( ERROR_SUCCESS == XUserGetXUID( k, &xuid ) &&
xuid == s_InviteInfo.xuidInviter )
{
g_pMatchEventsSubscription->BroadcastEvent( new KeyValues(
"OnInvite", "action", "error", "error", "SameConsole" ) );
return false;
}
}
// Check if the user is currently inactive
bool bExistingUser = false;
for ( DWORD k = 0; k < XBX_GetNumGameUsers(); ++ k )
{
if ( XBX_GetInvitedUserId() == (DWORD) XBX_GetUserId( k ) &&
!XBX_GetUserIsGuest( k ) )
{
bExistingUser = true;
break;
}
}
// Check if this is the existing user that the invite is for a different session
// than the session they are currently in (e.g. they are in a lobby and do
// "Join Party and Game" with another user who is in the same lobby)
char chInviteSessionInfo[ XSESSION_INFO_STRING_LENGTH ] = {0};
MMX360_SessionInfoToString( s_InviteInfo.hostInfo, chInviteSessionInfo );
if ( IMatchSession *pIMatchSession = g_pMatchFramework->GetMatchSession() )
{
bool bJoinable = ( ( IMatchSessionInternal * ) pIMatchSession )->IsAnotherSessionJoinable( chInviteSessionInfo );
if ( !bJoinable && bExistingUser )
{
Warning( "VerifyInviteEligibility: declined invite due to local session!\n" );
return false;
}
}
// New user is eligible since otherwise he shouldn't be able to accept an invite
if ( !bExistingUser || ( XBX_GetNumGameUsers() < 2 ) ||
( g_pMMF->GetMatchTitle()->GetTitleSettingsFlags() & MATCHTITLE_INVITE_ONLY_SINGLE_USER ) )
{
if ( !ValidateInviteController( XBX_GetInvitedUserId() ) )
return false;
else
return true;
}
#endif
// Check that every user is valid
return ValidateInviteControllers();
}
static void JoinInviteSession()
{
s_bInviteSessionDelayedJoin = false;
#ifdef _X360
if ( 0ull == ( uint64 const & ) s_InviteInfo.hostInfo.sessionID )
#else
if ( !s_InviteInfo )
#endif
return;
if ( g_pMatchExtensions->GetIVEngineClient()->IsDrawingLoadingImage() )
{
s_bInviteSessionDelayedJoin = true;
return;
}
// Invites cannot be accepted from inside an event broadcast
// internally used events must be top-level events since they
// operate on signed in / active users, trigger playermanager,
// account access and other events
// Wait until next frame in such case
if ( g_pMatchEventsSubscription && g_pMatchEventsSubscription->IsBroacasting() )
{
s_bInviteSessionDelayedJoin = true;
return;
}
#if !defined( NO_STEAM ) && !defined( _GAMECONSOLE ) && !defined( SWDS )
extern bool g_bSteamStatsReceived;
if ( !g_bSteamStatsReceived && ( g_uiLastInviteFlags & MM_INVITE_FLAG_PCBOOT ) )
{
s_bInviteSessionDelayedJoin = true;
return;
}
#endif
#ifdef _X360
DevMsg( "JoinInviteSession: sessionid = %llx, xuid = %llx\n", ( uint64 const & ) s_InviteInfo.hostInfo.sessionID, s_InviteInfo.xuidInvitee );
#else
DevMsg( "JoinInviteSession: sessionid = %llx\n", s_InviteInfo );
#endif
//
// Validate the user accepting the invite
//
#ifdef _GAMECONSOLE
if ( XBX_GetInvitedUserId() == INVALID_USER_ID )
{
DevWarning( "JoinInviteSession: no invited user!\n" );
return;
}
#endif
#ifdef _X360
XUSER_SIGNIN_STATE eSignInState = XUserGetSigninState( XBX_GetInvitedUserId() );
XUSER_SIGNIN_INFO xsi = {0};
if ( ( eSignInState != eXUserSigninState_SignedInToLive ) ||
( ERROR_SUCCESS != XUserGetSigninInfo( XBX_GetInvitedUserId(), XUSER_GET_SIGNIN_INFO_ONLINE_XUID_ONLY, &xsi ) ) ||
! ( xsi.dwInfoFlags & XUSER_INFO_FLAG_LIVE_ENABLED ) ||
( xsi.dwInfoFlags & XUSER_INFO_FLAG_GUEST ) ||
!IsEqualXUID( xsi.xuid, s_InviteInfo.xuidInvitee ) )
{
DevWarning( "JoinInviteSession: invited user signin information validation failed (state=%d, flags=0x%X, xuid=%llx)!\n",
eSignInState, xsi.dwInfoFlags, xsi.xuid );
return;
}
BOOL bMultiplayer = FALSE;
if ( ( ERROR_SUCCESS != XUserCheckPrivilege( XBX_GetInvitedUserId(), XPRIVILEGE_MULTIPLAYER_SESSIONS, &bMultiplayer ) ) ||
( !bMultiplayer ) )
{
DevWarning( "JoinInviteSession: no multiplayer priv!\n" );
return;
}
#endif
//
// Check if the currently-involved user is accepting the invite
//
#ifdef _GAMECONSOLE
bool bExistingUser = false;
for ( DWORD k = 0; k < XBX_GetNumGameUsers(); ++ k )
{
if ( XBX_GetInvitedUserId() == (DWORD) XBX_GetUserId( k ) &&
!XBX_GetUserIsGuest( k ) )
{
bExistingUser = true;
break;
}
}
if ( !bExistingUser ||
( ( XBX_GetNumGameUsers() > 1 ) && ( g_pMMF->GetMatchTitle()->GetTitleSettingsFlags() & MATCHTITLE_INVITE_ONLY_SINGLE_USER ) ) )
{
// Another controller is accepting the invite or guest status
// has changed.
// then we need to reset all our XBX core state:
DevMsg( "JoinInviteSession: activating inactive controller%d\n", XBX_GetInvitedUserId() );
g_pMatchEventsSubscription->BroadcastEvent( new KeyValues( "OnProfilesWriteOpportunity", "reason", "deactivation" ) );
XBX_ClearUserIdSlots();
XBX_SetPrimaryUserId( XBX_GetInvitedUserId() );
XBX_SetPrimaryUserIsGuest( 0 );
XBX_SetUserId( 0, XBX_GetInvitedUserId() );
XBX_SetUserIsGuest( 0, 0 );
XBX_SetNumGameUsers( 1 );
g_pMatchEventsSubscription->BroadcastEvent( new KeyValues( "OnProfilesChanged", "numProfiles", int(1) ) );
IPlayerLocal *pPlayer = g_pPlayerManager->GetLocalPlayer( XBX_GetPrimaryUserId() );
if ( !pPlayer )
{
g_pMatchEventsSubscription->BroadcastEvent( new KeyValues(
"OnInvite", "action", "error", "error", "" ) );
return;
}
( ( PlayerLocal * ) pPlayer )->SetFlag_AwaitingTitleData();
// Since we have activated a new profile, we need to wait until title data gets loaded
DevMsg( "JoinInviteSession: activated inactive controller%d, waiting for title data...\n", XBX_GetInvitedUserId() );
return;
}
#endif
// Validate storage device
s_nInviteConfirmed = -1;
if ( KeyValues *notify = new KeyValues( "OnInvite" ) )
{
#ifdef _X360
char chSessionInfo[ XSESSION_INFO_STRING_LENGTH ] = {0};
MMX360_SessionInfoToString( s_InviteInfo.hostInfo, chSessionInfo );
notify->SetInt( "user", XBX_GetInvitedUserId() );
notify->SetString( "sessioninfo", chSessionInfo );
#else
notify->SetUint64( "sessionid", s_InviteInfo );
#endif
notify->SetString( "action", "storage" );
notify->SetPtr( "confirmed", &s_nInviteConfirmed );
g_pMatchEventsSubscription->BroadcastEvent( notify );
// If handlers decided they need to confirm storage devices, etc.
if ( s_nInviteConfirmed != -1 )
{
DevMsg( "JoinInviteSession: waiting for storage device selection...\n" );
return;
}
}
// Verify eligibility
DevMsg( "JoinInviteSession: verifying eligibility...\n" );
if ( !VerifyInviteEligibility() )
return;
DevMsg( "JoinInviteSession: connecting...\n" );
//
// Argument validation
//
#ifdef _GAMECONSOLE
Assert( XBX_GetInvitedUserId() >= 0 );
Assert( XBX_GetInvitedUserId() < XUSER_MAX_COUNT );
Assert( XBX_GetSlotByUserId( XBX_GetInvitedUserId() ) < ( int ) XBX_GetNumGameUsers() );
Assert( XBX_GetNumGameUsers() < MAX_SPLITSCREEN_CLIENTS );
#endif
// Requesting to join the stored off session
KeyValues *pSettings = KeyValues::FromString(
"settings",
" system { "
" network LIVE "
" } "
" options { "
" action joinsession "
" } "
);
#ifdef _X360
pSettings->SetUint64( "options/sessionid", ( const uint64 & ) s_InviteInfo.hostInfo.sessionID );
if ( !IsZeroData< sizeof( s_InviteInfo.hostInfo.keyExchangeKey ) >( &s_InviteInfo.hostInfo.keyExchangeKey ) )
{
// Missing sessioninfo will cause the session info to be discovered during session
// creation time
char chSessionInfoBuffer[ XSESSION_INFO_STRING_LENGTH ] = {0};
MMX360_SessionInfoToString( s_InviteInfo.hostInfo, chSessionInfoBuffer );
pSettings->SetString( "options/sessioninfo", chSessionInfoBuffer );
}
#else
pSettings->SetUint64( "options/sessionid", s_InviteInfo );
#endif
KeyValues::AutoDelete autodelete( pSettings );
Q_memset( &s_InviteInfo, 0, sizeof( s_InviteInfo ) );
g_pMatchFramework->MatchSession( pSettings );
}
static void OnInviteAccepted()
{
// Verify eligibility
DevMsg( "OnInviteAccepted: verifying eligibility...\n" );
if ( !VerifyInviteEligibility() )
return;
DevMsg( "OnInviteAccepted: confirming...\n" );
// Make sure the user confirms the invite
s_nInviteConfirmed = -1;
if ( KeyValues *notify = new KeyValues( "OnInvite" ) )
{
#ifdef _X360
char chSessionInfo[ XSESSION_INFO_STRING_LENGTH ] = {0};
MMX360_SessionInfoToString( s_InviteInfo.hostInfo, chSessionInfo );
notify->SetInt( "user", XBX_GetInvitedUserId() );
notify->SetString( "sessioninfo", chSessionInfo );
#else
notify->SetUint64( "sessionid", s_InviteInfo );
#endif
notify->SetString( "action", "accepted" );
notify->SetPtr( "confirmed", &s_nInviteConfirmed );
g_pMatchEventsSubscription->BroadcastEvent( notify );
// If handlers decided they need to confirm destructive actions or
// select storage devices, etc.
if ( s_nInviteConfirmed != -1 )
{
DevMsg( "OnInviteAccepted: waiting for confirmation...\n" );
return;
}
}
DevMsg( "OnInviteAccepted: accepting...\n" );
// Otherwise, launch depending on our current MOD
// if ( !Q_stricmp( GetCurrentMod(), "left4dead2" ) ) <-- for multi-game package
{
// Kick off our join
JoinInviteSession();
}
// else <-- for multi-game package supporting cross-game invites
// {
// // Save off our session ID for later retrieval
// // NOTE: We may need to actually save off the inviter's XID and search for them later on if we took too long or the
// // session they were a part of went away
//
// XBX_SetInviteSessionId( inviteInfo.hostInfo.sessionID );
//
// // Quit via the menu path "QuitNoConfirm"
// EngineVGui()->SystemNotification( SYSTEMNOTIFY_INVITE_SHUTDOWN, NULL );
// }
}
void CMatchFramework::RunFrame_Invite()
{
if ( s_bInviteSessionDelayedJoin )
JoinInviteSession();
}
void CMatchFramework::AcceptInvite( int iController )
{
#ifdef _X360
s_bInviteSessionDelayedJoin = false;
// Grab our invite info
DWORD dwError = g_pMatchExtensions->GetIXOnline()->XInviteGetAcceptedInfo( iController, &s_InviteInfo );
if ( dwError != ERROR_SUCCESS )
{
ZeroMemory( &s_InviteInfo, sizeof( s_InviteInfo ) );
return;
}
// We only care if we're asked to join this title's session
if ( s_InviteInfo.dwTitleID != GetMatchTitle()->GetTitleID() )
{
ZeroMemory( &s_InviteInfo, sizeof( s_InviteInfo ) );
return;
}
// We just mark the invited user and let the matchmaking handle profile changes
XBX_SetInvitedUserId( iController );
// Invite accepted logic after globals have been setup
OnInviteAccepted();
#endif
}
#if !defined( _X360 ) && !defined( NO_STEAM ) && !defined( SWDS )
void CMatchSteamInviteListener::Steam_OnGameLobbyJoinRequested( GameLobbyJoinRequested_t *pJoinInvite )
{
#ifdef _PS3
if ( pJoinInvite->m_steamIDFriend.ConvertToUint64() != ~0ull )
{
g_uiLastInviteFlags = ( pJoinInvite->m_steamIDFriend.BConsoleUserAccount() ? MM_INVITE_FLAG_CONSOLE : 0 );
}
#endif
#if !defined( _GAMECONSOLE )
g_uiLastInviteFlags = ( pJoinInvite->m_steamIDFriend.ConvertToUint64() == ~0ull ) ? MM_INVITE_FLAG_PCBOOT : 0;
#endif
m_msgPending = GameLobbyJoinRequested_t();
s_bInviteSessionDelayedJoin = false;
s_InviteInfo = pJoinInvite->m_steamIDLobby.ConvertToUint64();
if ( !s_InviteInfo )
return;
#ifdef _GAMECONSOLE
// We just mark the invited user and let the matchmaking handle profile changes
XBX_SetInvitedUserId( XBX_GetPrimaryUserId() );
#endif
// Whether we have to make invite go pending
char chBuffer[2] = {};
if ( g_pMatchExtensions->GetIVEngineClient()->IsDrawingLoadingImage() ||
( g_pMatchEventsSubscription && g_pMatchEventsSubscription->IsBroacasting() ) ||
( g_pMatchExtensions->GetIBaseClientDLL()->GetStatus( chBuffer, 2 ), ( chBuffer[0] != '+' ) ) )
{
m_msgPending = *pJoinInvite;
return;
}
// Invite accepted logic after globals have been setup
OnInviteAccepted();
}
#ifdef _PS3
void CMatchSteamInviteListener::Steam_OnPSNGameBootInviteResult( PSNGameBootInviteResult_t *pParam )
{
if ( pParam->m_bGameBootInviteExists && pParam->m_steamIDLobby.IsValid() )
{
g_uiLastInviteFlags = MM_INVITE_FLAG_CONSOLE;
}
}
#endif
void CMatchSteamInviteListener::RunFrame()
{
if ( m_msgPending.m_steamIDLobby.IsValid() )
{
GameLobbyJoinRequested_t msgRequest = m_msgPending;
Steam_OnGameLobbyJoinRequested( &msgRequest );
}
}
#endif
IMatchSession *CMatchFramework::GetMatchSession()
{
return m_pMatchSession;
}
void CMatchFramework::CreateSession( KeyValues *pSettings )
{
DevMsg( "CreateSession: \n");
KeyValuesDumpAsDevMsg( pSettings );
#ifndef SWDS
if ( !pSettings )
return;
IMatchSessionInternal *pMatchSessionNew = NULL;
//
// Analyze the type of session requested to create
//
char const *szNetwork = pSettings->GetString( "system/network", "offline" );
#ifdef _X360
if ( !Q_stricmp( "LIVE", szNetwork ) && !ValidateInviteControllers() )
return;
#endif
// Recompute XUIDs for the session type that we are creating
g_pPlayerManager->RecomputePlayerXUIDs( szNetwork );
//
// Process create session request
//
if ( !Q_stricmp( "offline", szNetwork ) )
{
CMatchSessionOfflineCustom *pSession = new CMatchSessionOfflineCustom( pSettings );
pMatchSessionNew = pSession;
}
else
{
CMatchSessionOnlineHost *pSession = new CMatchSessionOnlineHost( pSettings );
pMatchSessionNew = pSession;
}
if ( pMatchSessionNew )
{
CloseSession();
m_pMatchSession = pMatchSessionNew;
}
#endif
}
void CMatchFramework::MatchSession( KeyValues *pSettings )
{
#ifndef SWDS
if ( !pSettings )
return;
DevMsg( "MatchSession: \n");
KeyValuesDumpAsDevMsg( pSettings );
IMatchSessionInternal *pMatchSessionNew = NULL;
//
// Analyze what kind of client-side matchmaking
// needs to happen.
//
char const *szNetwork = pSettings->GetString( "system/network", "LIVE" );
char const *szAction = pSettings->GetString( "options/action", "" );
// Recompute XUIDs for the session type that we are creating
g_pPlayerManager->RecomputePlayerXUIDs( szNetwork );
//
// Process match session request
//
if ( !Q_stricmp( "joinsession", szAction ) )
{
#ifdef _X360
// For LIVE sessions we need to be eligible
if ( !Q_stricmp( "LIVE", szNetwork ) && !ValidateInviteControllers() )
return;
#endif
// We have an explicit session to join
CMatchSessionOnlineClient *pSession = new CMatchSessionOnlineClient( pSettings );
pMatchSessionNew = pSession;
}
else if ( !Q_stricmp( "joininvitesession", szAction ) )
{
#ifdef _X360
ZeroMemory( &s_InviteInfo, sizeof( s_InviteInfo ) );
XUSER_SIGNIN_INFO xsi;
if ( ERROR_SUCCESS == XUserGetSigninInfo( XBX_GetInvitedUserId(), XUSER_GET_SIGNIN_INFO_ONLINE_XUID_ONLY, &xsi ) )
s_InviteInfo.xuidInvitee = xsi.xuid;
uint64 uiSessionID = pSettings->GetUint64( "options/sessionid", 0ull );
s_InviteInfo.hostInfo.sessionID = ( XNKID & ) uiSessionID;
OnInviteAccepted();
#endif
}
else // "quickmatch" or "custommatch"
{
#ifdef _X360
// For LIVE sessions we need to be eligible
if ( !Q_stricmp( "LIVE", szNetwork ) && !ValidateInviteControllers() )
return;
#endif
CMatchSessionOnlineSearch *pSession = new CMatchSessionOnlineSearch( pSettings );
pMatchSessionNew = pSession;
}
if ( pMatchSessionNew )
{
CloseSession();
m_pMatchSession = pMatchSessionNew;
}
#endif
}
void CMatchFramework::CloseSession()
{
// Destroy the session
if ( m_pMatchSession )
{
IMatchSessionInternal *pMatchSession = m_pMatchSession;
m_pMatchSession = NULL;
pMatchSession->Destroy();
g_pMatchEventsSubscription->BroadcastEvent( new KeyValues( "OnMatchSessionUpdate", "state", "closed" ) );
}
}
bool CMatchFramework::IsOnlineGame( void )
{
IMatchSession *pMatchSession = GetMatchSession();
if ( pMatchSession )
{
KeyValues* kv = pMatchSession->GetSessionSettings();
if ( kv )
{
char const *szMode = kv->GetString( "system/network", NULL );
if ( szMode && !V_stricmp( "LIVE", szMode ) )
{
return true;
}
}
}
return false;
}
void CMatchFramework::UpdateTeamProperties( KeyValues *pTeamProperties )
{
IMatchSession *pMatchSession = GetMatchSession();
IMatchTitleGameSettingsMgr *pMatchTitleGameSettingsMgr = GetMatchTitleGameSettingsMgr();
if ( pMatchSession && pMatchTitleGameSettingsMgr )
{
pMatchSession->UpdateTeamProperties( pTeamProperties );
KeyValues *pCurrentSettings = pMatchSession->GetSessionSettings();
pMatchTitleGameSettingsMgr->UpdateTeamProperties( pCurrentSettings, pTeamProperties );
}
}
void CMatchFramework::OnEvent( KeyValues *pEvent )
{
char const *szEvent = pEvent->GetName();
if ( !Q_stricmp( "mmF->CloseSession", szEvent ) )
{
CloseSession();
return;
}
else if ( !Q_stricmp( "OnInvite", szEvent ) )
{
if ( !Q_stricmp( "join", pEvent->GetString( "action" ) ) )
{
s_bInviteSessionDelayedJoin = true;
}
else if ( !Q_stricmp( "deny", pEvent->GetString( "action" ) ) )
{
Q_memset( &s_InviteInfo, 0, sizeof( s_InviteInfo ) );
s_bInviteSessionDelayedJoin = false;
}
return;
}
else if ( !Q_stricmp( "OnSteamOverlayCall::LobbyJoin", szEvent ) )
{
#if !defined( _X360 ) && !defined( NO_STEAM ) && !defined( SWDS )
GameLobbyJoinRequested_t msg;
msg.m_steamIDLobby.SetFromUint64( pEvent->GetUint64( "sessionid" ) );
msg.m_steamIDFriend.SetFromUint64( ~0ull );
g_MatchSteamInviteListener.Steam_OnGameLobbyJoinRequested( &msg );
#endif
return;
}
else if ( !Q_stricmp( "OnMatchSessionUpdate", szEvent ) )
{
KeyValues *pUpdate = pEvent->FindKey( "update" );
if ( pUpdate )
{
const char *pAction = pUpdate->GetString( "options/action", "" );
if ( !Q_stricmp( "joinsession", pAction ) )
{
KeyValues *pTeamMembers = pUpdate->FindKey( "teamMembers" );
if ( pTeamMembers )
{
// Received console team match settings from host
// Find what team we are on
int numPlayers = pTeamMembers->GetInt( "numPlayers" );
int playerTeam = -1;
int activeUer = XBX_GetPrimaryUserId();
IPlayerLocal *player = g_pPlayerManager->GetLocalPlayer( activeUer );
uint64 localPlayerId = player->GetXUID();
for ( int i = 0; i < numPlayers; i++ )
{
KeyValues *pTeamPlayer = pTeamMembers->FindKey( CFmtStr( "player%d", i ) );
uint64 playerId = pTeamPlayer->GetUint64( "xuid" );
if ( playerId == localPlayerId )
{
int team = pTeamPlayer->GetInt( "team" );
DevMsg( "Adding player %llu to team %d\n", playerId, team );
playerTeam = team;
break;
}
}
m_pTeamSessionSettings = pUpdate->MakeCopy();
m_pTeamSessionSettings->SetName( "settings ");
// Delete the "teamMembers" key
m_pTeamSessionSettings->RemoveSubKey( m_pTeamSessionSettings->FindKey( "teamMembers" ) );
// Add "conteam" value
m_pTeamSessionSettings->SetInt( "conteam", playerTeam );
// Add the "sessionHostDataUnpacked" key
KeyValues *pSessionHostDataSrc = pUpdate->FindKey( "sessionHostDataUnpacked" );
if ( pSessionHostDataSrc )
{
KeyValues *pSessionHostDataDst = m_pTeamSessionSettings->CreateNewKey();
pSessionHostDataDst->SetName( "sessionHostDataUnpacked" );
pSessionHostDataSrc->CopySubkeys( pSessionHostDataDst );
}
m_bJoinTeamSession = true;
}
}
}
}
//
// Delegate to the managers
//
if ( g_pPlayerManager )
g_pPlayerManager->OnEvent( pEvent );
if ( g_pServerManager )
g_pServerManager->OnEvent( pEvent );
if ( g_pDatacenter )
g_pDatacenter->OnEvent( pEvent );
if ( g_pDlcManager )
g_pDlcManager->OnEvent( pEvent );
//
// Delegate to the title
//
if ( g_pIMatchTitleEventsSink )
g_pIMatchTitleEventsSink->OnEvent( pEvent );
//
// Delegate to the session
//
if ( m_pMatchSession )
m_pMatchSession->OnEvent( pEvent );
}
void CMatchFramework::SetCurrentMatchSession( IMatchSessionInternal *pNewMatchSession )
{
m_pMatchSession = pNewMatchSession;
}
uint64 CMatchFramework::GetLastInviteFlags()
{
return g_uiLastInviteFlags;
}