-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathtf_quickplay_ui.cpp
More file actions
2998 lines (2579 loc) · 100 KB
/
tf_quickplay_ui.cpp
File metadata and controls
2998 lines (2579 loc) · 100 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 Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#include "cbase.h"
// for messaging with the GC
#include "tf_gcmessages.h"
#include "tf_item_inventory.h"
#include "econ_game_account_server.h"
#include "gc_clientsystem.h"
#include "tf_gc_client.h"
#include "tf_partyclient.h"
#include "tf_quickplay.h"
// ui related
#include "filesystem.h"
#include "tf_controls.h"
#include "clientmode_tf.h"
#include "confirm_dialog.h"
#include "econ_controls.h"
#include "game/client/iviewport.h"
#include "ienginevgui.h"
#include "tf_hud_mainmenuoverride.h"
#include "tf_hud_statpanel.h"
#include "tf_mouseforwardingpanel.h"
#include "vgui/ILocalize.h"
#include "vgui/ISurface.h"
#include "vgui_controls/PanelListPanel.h"
#include "vgui_controls/ProgressBar.h"
#include "vgui_controls/RadioButton.h"
#include "ServerBrowser/blacklisted_server_manager.h"
#include "rtime.h"
#include "c_tf_gamestats.h"
#include "tf_gamerules.h"
#include "ServerBrowser/IServerBrowser.h"
// other
#include "tier1/netadr.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
const char *COM_GetModDirectory();
extern int g_iQuickplaySessionIndex;
#include "tf_matchmaking_scoring.h"
ConVar tf_matchmaking_debug( "tf_matchmaking_spew_level",
#ifdef _DEBUG
"3",
#else
"1",
#endif
FCVAR_NONE, "Set to 1 for basic console spew of quickplay-related decisions. 4 for maximum verbosity." );
ConVar tf_quickplay_pref_community_servers( "tf_quickplay_pref_community_servers", "0", FCVAR_ARCHIVE, "0=Valve only, 1=Community only, 2=Either" );
#define TF_MATCHMAKING_SPEW( lvl, pStrFmt, ...) \
if ( tf_matchmaking_debug.GetInt() >= lvl ) \
{ \
Msg( pStrFmt, ##__VA_ARGS__ ); \
}
// Hack to force it to search for other app ID's for testing
static inline int GetTfMatchmakingAppID()
{
// !TEST!
// return 440;
return engine->GetAppID();
}
// A server that we recently were matched to and attempted to join
struct RecentlyMatchedServer
{
uint32 m_ip;
uint16 m_port;
RTime32 m_timeMatched;
};
// Just store them in a simple list. This will be small, and it won't hurt
// to scan the whole thing, so it won't do any good to do anything fancy
static CUtlVector<RecentlyMatchedServer> s_vecRecentlyMatchedServers;
// Search for a recently matched server. Also process cooldown expiry
static int FindRecentlyMatchedServer( uint32 ip, uint16 port )
{
RTime32 timeOfOldestEntryToKeep = CRTime::RTime32TimeCur() - tf_matchmaking_retry_cooldown_seconds.GetInt();
int i = 0;
int result = -1;
while ( i < s_vecRecentlyMatchedServers.Count() )
{
// Expire?
if ( s_vecRecentlyMatchedServers[i].m_timeMatched < timeOfOldestEntryToKeep )
{
DevLog(" Expiring quickplay recently joined server entry %08X:%d\n", s_vecRecentlyMatchedServers[i].m_ip, (int)s_vecRecentlyMatchedServers[i].m_port );
s_vecRecentlyMatchedServers.Remove( i );
}
else
{
// Address match?
if ( s_vecRecentlyMatchedServers[i].m_ip == ip && s_vecRecentlyMatchedServers[i].m_port == port )
{
Assert( result < 0 ); // dups in the list?
result = i;
}
// Record is still active. Keep it
++i;
}
}
// Return index of the entry we found, if any
return result;
}
ConVar tf_quickplay_pref_increased_maxplayers( "tf_quickplay_pref_increased_maxplayers", "0", FCVAR_ARCHIVE, "0=Default only, 1=Yes, 2=Don't care" );
ConVar tf_quickplay_pref_disable_random_crits( "tf_quickplay_pref_disable_random_crits", "0", FCVAR_ARCHIVE, "0=Random crits enabled, 1=Random crits disabled, 2=Don't care" );
ConVar tf_quickplay_pref_enable_damage_spread( "tf_quickplay_pref_enable_damage_spread", "0", FCVAR_ARCHIVE, "0=Damage spread disabled, 1=Damage spread enabled, 2=Don't care" );
ConVar tf_quickplay_pref_respawn_times( "tf_quickplay_pref_respawn_times", "0", FCVAR_ARCHIVE, "0=Default respawn times only, 1=Instant respawn times ('norespawn' tag), 2=Don't care" );
ConVar tf_quickplay_pref_advanced_view( "tf_quickplay_pref_advanced_view", "0", FCVAR_NONE, "0=Default to simplified view, 1=Default to more detailed options view" );
ConVar tf_quickplay_pref_beta_content( "tf_quickplay_pref_beta_content", "0", FCVAR_ARCHIVE, "0=No beta content, 1=Only beta content" );
static bool BHasTag( const CUtlStringList &TagList, const char *tag )
{
for ( int i = 0; i < TagList.Count(); i++ )
{
if ( !Q_stricmp( TagList[i], tag) )
{
return true;
}
}
return false;
}
static void GetQuickplayTags( const QuickplaySearchOptions &opt, CUtlStringList &requiredTags, CUtlStringList &illegalTags )
{
// Always required
// requiredTags.CopyAndAddToTail( "_registered" );
// Always illegal
illegalTags.CopyAndAddToTail( "friendlyfire" );
illegalTags.CopyAndAddToTail( "highlander" );
illegalTags.CopyAndAddToTail( "noquickplay" );
illegalTags.CopyAndAddToTail( "trade" );
switch ( opt.m_eRespawnTimes )
{
case QuickplaySearchOptions::eRespawnTimesDefault:
illegalTags.CopyAndAddToTail( "respawntimes" );
illegalTags.CopyAndAddToTail( "norespawntime" );
break;
case QuickplaySearchOptions::eRespawnTimesInstant:
requiredTags.CopyAndAddToTail( "norespawntime" );
break;
default:
Assert( false );
case QuickplaySearchOptions::eRespawnTimesDontCare:
break;
}
switch ( opt.m_eRandomCrits )
{
case QuickplaySearchOptions::eRandomCritsYes:
illegalTags.CopyAndAddToTail( "nocrits" );
break;
case QuickplaySearchOptions::eRandomCritsNo:
requiredTags.CopyAndAddToTail( "nocrits" );
break;
default:
Assert( false );
case QuickplaySearchOptions::eRandomCritsDontCare:
break;
}
switch ( opt.m_eDamageSpread )
{
case QuickplaySearchOptions::eDamageSpreadYes:
requiredTags.CopyAndAddToTail( "dmgspread" );
break;
case QuickplaySearchOptions::eDamageSpreadNo:
illegalTags.CopyAndAddToTail( "dmgspread" );
break;
default:
Assert( false );
case QuickplaySearchOptions::eDamageSpreadDontCare:
break;
}
switch ( opt.m_eMaxPlayers )
{
case QuickplaySearchOptions::eMaxPlayers24:
illegalTags.CopyAndAddToTail( "increased_maxplayers" );
break;
case QuickplaySearchOptions::eMaxPlayers30Plus:
requiredTags.CopyAndAddToTail( "increased_maxplayers" );
break;
default:
Assert( false );
case QuickplaySearchOptions::eMaxPlayersDontCare:
break;
}
switch ( opt.m_eBetaContent )
{
case QuickplaySearchOptions::eBetaYes:
requiredTags.CopyAndAddToTail( "beta" );
break;
case QuickplaySearchOptions::eBetaNo:
illegalTags.CopyAndAddToTail( "beta" );
break;
default:
Assert( false );
break;
}
}
//-----------------------------------------------------------------------------
static void OpenQuickplayDialogCallback( bool bConfirmed, void *pContext )
{
engine->ClientCmd_Unrestricted( "OpenQuickplayDialog" );
}
// Why does it take so many lines of code to do stuff like this?
static CDllDemandLoader g_ServerBrowser( "ServerBrowser" );
static IServerBrowser *GetServerBrowser()
{
static IServerBrowser *pServerBrowser = NULL;
if ( pServerBrowser == NULL )
{
int iReturnCode;
pServerBrowser = (IServerBrowser *)g_ServerBrowser.GetFactory()( SERVERBROWSER_INTERFACE_VERSION, &iReturnCode );
Assert( pServerBrowser );
}
return pServerBrowser;
}
//=============================================================================
enum eGameServerFilter
{
kGameServerListFilter_Internet,
kGameServerListFilter_Favorites,
};
struct sortable_gameserveritem_t
{
sortable_gameserveritem_t()
{
m_bRegistered = false;
m_bValve = false;
m_bNewUserFriendly = false;
m_bMapIsQuickPlayOK = false;
userScore = -999.9f;
serverScore = -999.9f;
m_fRecentMatchPenalty = -999.9f;
m_fTotalScoreFromGC = -9999.9f;
m_eStatus = TF_Gamestats_QuickPlay_t::k_Server_Invalid;
m_nOptionsScoreFromGC = INT_MAX;
}
gameserveritem_t server;
bool m_bRegistered;
bool m_bValve;
bool m_bNewUserFriendly;
bool m_bMapIsQuickPlayOK;
float userScore;
float serverScore;
float m_fRecentMatchPenalty;
float m_fTotalScoreFromGC;
TF_Gamestats_QuickPlay_t::eServerStatus m_eStatus;
int m_nOptionsScoreFromGC;
inline float TotalScore() const { return userScore + serverScore; }
};
// Store a server that has been scored by the GC and
// is ready to receive the final confirmation ping
struct gameserver_ping_queue_entry_t
{
float m_fTotalScore;
netadr_t m_adr;
};
//-----------------------------------------------------------------------------
// Purpose: Score a game server based on number of players and ping
//-----------------------------------------------------------------------------
class CGameServerItemSort
{
public:
bool Less( const sortable_gameserveritem_t *src1, const sortable_gameserveritem_t *src2, void *pCtx )
{
// we want higher scores sorted to the front
return src1->TotalScore() > src2->TotalScore();
}
bool Less( const gameserver_ping_queue_entry_t &src1, const gameserver_ping_queue_entry_t &src2, void *pCtx )
{
// we want higher scores sorted to the front
return src1.m_fTotalScore > src2.m_fTotalScore;
}
};
// !KLUDGE! This is duplicated from serverbrowserQuickListPanel.h
class CQuickListPanel : public vgui::EditablePanel
{
DECLARE_CLASS_SIMPLE( CQuickListPanel, vgui::EditablePanel );
public:
CQuickListPanel( vgui::Panel *parent, const char *panelName );
virtual void ApplySchemeSettings(vgui::IScheme *pScheme);
void SetMapName( const char *pMapName );
void SetImage( const char *pMapName );
void SetGameType( const char *pGameType );
const char *GetMapName( void ) { return m_szMapName; }
void SetRefreshing( void );
virtual void OnMousePressed( vgui::MouseCode code );
virtual void OnMouseDoublePressed( vgui::MouseCode code );
void SetServerInfo ( KeyValues *pKV, int iListID, int iTotalServers );
int GetListID( void ) { return m_iListID; }
virtual void PerformLayout( void )
{
BaseClass::PerformLayout();
}
MESSAGE_FUNC_INT( OnPanelSelected, "PanelSelected", state )
{
if ( state )
{
vgui::IScheme *pScheme = vgui::scheme()->GetIScheme( GetScheme() );
if ( pScheme && m_pBGroundPanel )
{
m_pBGroundPanel->SetBgColor( pScheme->GetColor("QuickListBGSelected", Color(255, 255, 255, 0 ) ) );
}
}
else
{
vgui::IScheme *pScheme = vgui::scheme()->GetIScheme( GetScheme() );
if ( pScheme && m_pBGroundPanel )
{
m_pBGroundPanel->SetBgColor( pScheme->GetColor("QuickListBGDeselected", Color(255, 255, 255, 0 ) ) );
}
}
PostMessage( GetParent()->GetVParent(), new KeyValues("PanelSelected") );
}
private:
char m_szMapName[64];
vgui::ImagePanel *m_pLatencyImage;
vgui::Label *m_pLatencyLabel;
vgui::Label *m_pPlayerCountLabel;
vgui::Label *m_pOtherServersLabel;
vgui::Label *m_pServerNameLabel;
vgui::Panel *m_pBGroundPanel;
vgui::ImagePanel *m_pMapImage;
vgui::Panel *m_pListPanelParent;
vgui::Label *m_pGameTypeLabel;
vgui::Label *m_pMapNameLabel;
vgui::ImagePanel *m_pReplayImage;
int m_iListID;
};
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CQuickListPanel::CQuickListPanel( vgui::Panel* pParent, const char *pElementName ) : BaseClass( pParent, pElementName )
{
SetParent( pParent );
m_pListPanelParent = pParent;
SetScheme( "SourceScheme" );
SetProportional( false );
CMouseMessageForwardingPanel *panel = new CMouseMessageForwardingPanel(this, NULL);
panel->SetZPos(3);
m_pLatencyImage = new ImagePanel( this, "latencyimage" );
m_pPlayerCountLabel = new Label( this, "playercount", "" );
m_pOtherServersLabel = new Label( this, "otherservercount", "" );
m_pServerNameLabel = new Label( this, "servername", "" );
m_pBGroundPanel = new Panel( this, "background" );
m_pMapImage = new ImagePanel( this, "mapimage" );
m_pGameTypeLabel = new Label( this, "gametype", "" );
m_pMapNameLabel = new Label( this, "mapname", "" );
m_pLatencyLabel = new Label( this, "latencytext", "" );
m_pReplayImage = new ImagePanel( this, "replayimage" );
const char *pPathID = "PLATFORM";
if ( g_pFullFileSystem->FileExists( "Servers/QuickListPanel.res", "MOD" ) )
{
pPathID = "MOD";
}
LoadControlSettings( "Servers/QuickListPanel.res", pPathID );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CQuickListPanel::ApplySchemeSettings(IScheme *pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);
if ( pScheme && m_pBGroundPanel )
{
m_pBGroundPanel->SetBgColor( pScheme->GetColor("QuickListBGDeselected", Color(255, 255, 255, 0 ) ) );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CQuickListPanel::SetRefreshing( void )
{
if ( m_pServerNameLabel )
{
m_pServerNameLabel->SetText( g_pVGuiLocalize->Find("#ServerBrowser_QuickListRefreshing") );
}
if ( m_pPlayerCountLabel )
{
m_pPlayerCountLabel->SetVisible( false );
}
if ( m_pOtherServersLabel )
{
m_pOtherServersLabel->SetVisible( false );
}
if ( m_pLatencyImage )
{
m_pLatencyImage->SetVisible( false );
}
if ( m_pReplayImage )
{
m_pReplayImage->SetVisible( false );
}
if ( m_pLatencyLabel )
{
m_pLatencyLabel->SetVisible( false );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CQuickListPanel::SetMapName( const char *pMapName )
{
Q_strncpy( m_szMapName, pMapName, sizeof( m_szMapName ) );
if ( m_pMapNameLabel )
{
m_pMapNameLabel->SetText( pMapName );
m_pMapNameLabel->SizeToContents();
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CQuickListPanel::SetGameType( const char *pGameType )
{
if ( strlen ( pGameType ) == 0 )
{
m_pGameTypeLabel->SetVisible( false );
return;
}
char gametype[ 512 ];
Q_snprintf( gametype, sizeof( gametype ), "(%s)", pGameType );
m_pGameTypeLabel->SetText( gametype );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CQuickListPanel::SetServerInfo ( KeyValues *pKV, int iListID, int iTotalServers )
{
if ( pKV == NULL )
return;
m_iListID = iListID;
m_pServerNameLabel->SetText( pKV->GetString( "name", " " ) );
int iPing = pKV->GetInt( "ping", 0 );
if ( iPing <= 100 )
{
m_pLatencyImage->SetImage( "../vgui/icon_con_high.vmt" );
}
else if ( iPing <= 150 )
{
m_pLatencyImage->SetImage( "../vgui/icon_con_medium.vmt" );
}
else
{
m_pLatencyImage->SetImage( "../vgui/icon_con_low.vmt" );
}
m_pLatencyImage->SetVisible( false );
//if ( GameSupportsReplay() )
{
m_pReplayImage->SetVisible( pKV->GetInt( "Replay", 0 ) > 0 );
}
char ping[ 512 ];
Q_snprintf( ping, sizeof( ping ), "%d ms", iPing );
m_pLatencyLabel->SetText( ping );
m_pLatencyLabel->SetVisible( true );
wchar_t players[ 512 ];
wchar_t playercount[16];
wchar_t *pwszPlayers = g_pVGuiLocalize->Find("#ServerBrowser_Players");
g_pVGuiLocalize->ConvertANSIToUnicode( pKV->GetString( "players", " " ), playercount, sizeof( playercount ) );
_snwprintf( players, ARRAYSIZE( players ), L"%ls %ls", playercount, pwszPlayers );
m_pPlayerCountLabel->SetText( players );
m_pPlayerCountLabel->SetVisible( true );
// Now setup the other server count
if ( iTotalServers == 2 )
{
m_pOtherServersLabel->SetText( g_pVGuiLocalize->Find("#ServerBrowser_QuickListOtherServer") );
m_pOtherServersLabel->SetVisible( true );
}
else if ( iTotalServers > 2 )
{
wchar_t *pwszServers = g_pVGuiLocalize->Find("#ServerBrowser_QuickListOtherServers");
_snwprintf( playercount, Q_ARRAYSIZE(playercount), L"%d", (iTotalServers-1) );
g_pVGuiLocalize->ConstructString_safe( players, pwszServers, 1, playercount );
m_pOtherServersLabel->SetText( players );
m_pOtherServersLabel->SetVisible( true );
}
else
{
m_pOtherServersLabel->SetVisible( false );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CQuickListPanel::SetImage( const char *pMapName )
{
char path[ 512 ];
Q_snprintf( path, sizeof( path ), "materials/vgui/maps/menu_thumb_%s.vmt", pMapName );
char map[ 512 ];
Q_snprintf( map, sizeof( map ), "maps/%s.bsp", pMapName );
if ( g_pFullFileSystem->FileExists( map, "MOD" ) == false )
{
pMapName = "default_download";
}
else
{
if ( g_pFullFileSystem->FileExists( path, "MOD" ) == false )
{
pMapName = "default";
}
}
if ( m_pMapImage )
{
char imagename[ 512 ];
Q_snprintf( imagename, sizeof( imagename ), "..\\vgui\\maps\\menu_thumb_%s", pMapName );
m_pMapImage->SetImage ( imagename );
m_pMapImage->SetMouseInputEnabled( false );
}
}
void CQuickListPanel::OnMousePressed( vgui::MouseCode code )
{
if ( m_pListPanelParent )
{
vgui::PanelListPanel *pParent = dynamic_cast < vgui::PanelListPanel *> ( m_pListPanelParent );
if ( pParent )
{
pParent->SetSelectedPanel( this );
m_pListPanelParent->CallParentFunction( new KeyValues("ItemSelected", "itemID", -1 ) );
}
if ( code == MOUSE_RIGHT )
{
m_pListPanelParent->CallParentFunction( new KeyValues("OpenContextMenu", "itemID", -1 ) );
}
}
}
void CQuickListPanel::OnMouseDoublePressed( vgui::MouseCode code )
{
if ( code == MOUSE_RIGHT )
return;
// call the panel
OnMousePressed( code );
m_pListPanelParent->CallParentFunction( new KeyValues("ConnectToServer", "code", code) );
}
CUtlString GetCommaDelimited( const CUtlStringList &list )
{
CUtlString sResult;
FOR_EACH_VEC( list, idx )
{
if ( idx != 0 )
sResult.Append( "," );
sResult.Append( list[idx] );
}
return sResult;
}
class CQuickplayWaitDialog;
static CQuickplayWaitDialog *s_pQuickPlayWaitingDialog;
// Busy indicator and also server list if the didn't use "I'm feeling lucky"
class CQuickplayWaitDialog : public CGenericWaitingDialog, public ISteamMatchmakingServerListResponse, public ISteamMatchmakingPingResponse
{
DECLARE_CLASS_SIMPLE( CQuickplayWaitDialog, CGenericWaitingDialog );
public:
CQuickplayWaitDialog( bool bFeelingLucky, const QuickplaySearchOptions &opt )
: CGenericWaitingDialog( NULL )
, m_options( opt )
, m_fHoursPlayed( 0 )
, m_nAppID( GetTfMatchmakingAppID() )
, m_hServerListRequest( NULL )
, m_hServerQueryRequest( HSERVERQUERY_INVALID )
, m_fPingA( tf_matchmaking_ping_a.GetFloat() )
, m_fPingAScore( tf_matchmaking_ping_a_score.GetFloat() )
, m_fPingB( tf_matchmaking_ping_b.GetFloat() )
, m_fPingBScore( tf_matchmaking_ping_b_score.GetFloat() )
, m_fPingC( tf_matchmaking_ping_c.GetFloat() )
, m_fPingCScore( tf_matchmaking_ping_c_score.GetFloat() )
, m_bFeelingLucky( bFeelingLucky )
, m_eCurrentStep( k_EStep_GMSQuery )
, m_timeGCScoreTimeout( 0.0 )
, m_timeGMSSearchStarted( 0.0 )
, m_timePingServerTimeout( 0.0 )
, m_pBusyContainer( NULL )
, m_pResultsContainer( NULL )
, m_pServerListPanel( NULL )
, m_pProgressBar( NULL )
, m_ScoringNumbers( steamapicontext ? steamapicontext->SteamUser()->GetSteamID() : CSteamID() )
{
// Check the panel name since we are changing the resource
SetName("QuickPlayBusyDialog");
Assert( s_pQuickPlayWaitingDialog == NULL );
s_pQuickPlayWaitingDialog = this;
m_blackList.LoadServersFromFile( BLACKLIST_DEFAULT_SAVE_FILE, false );
m_fHoursPlayed = CTFStatPanel::GetTotalHoursPlayed();
m_Stats.m_fUserHoursPlayed = m_fHoursPlayed;
m_Stats.m_iExperimentGroup = m_ScoringNumbers.m_eExperimentGroup;
// Determine bonus we'll give to valve servers, using linear
// interpolation with clamped endpoints
float m_fValveBonusHrsA = tf_matchmaking_numbers_valve_bonus_hrs_a.GetFloat();
float m_fValveBonusPtsA = tf_matchmaking_numbers_valve_bonus_pts_a.GetFloat();
float m_fValveBonusHrsB = tf_matchmaking_numbers_valve_bonus_hrs_b.GetFloat();
float m_fValveBonusPtsB = tf_matchmaking_numbers_valve_bonus_pts_b.GetFloat();
Assert( m_fValveBonusHrsA < m_fValveBonusHrsB );
if ( m_fHoursPlayed < m_fValveBonusHrsA )
{
m_fValveBonus = m_fValveBonusPtsA;
}
else if ( m_fHoursPlayed < m_fValveBonusHrsB )
{
m_fValveBonus = lerp( m_fValveBonusHrsA, m_fValveBonusPtsA, m_fValveBonusHrsB, m_fValveBonusPtsB, m_fHoursPlayed );
}
else
{
m_fValveBonus = m_fValveBonusPtsB;
}
// Calc bonus given if the map is noob friendly
float fNoobTime = tf_matchmaking_noob_hours_played.GetFloat();
m_fNoobMapBonus = 0.0f;
if ( m_fHoursPlayed < fNoobTime )
{
float fNoobPct = 1.0f - ( fNoobTime / fNoobTime );
m_fNoobMapBonus = fNoobPct * tf_matchmaking_noob_map_score_boost.GetFloat();
}
switch ( m_options.m_eSelectedGameType )
{
case kGameCategory_Quickplay: m_Stats.m_sUserGameMode = "(any)"; break;
case kGameCategory_Escort: m_Stats.m_sUserGameMode = "escort"; break;
case kGameCategory_CTF: m_Stats.m_sUserGameMode = "ctf"; break;
case kGameCategory_AttackDefense: m_Stats.m_sUserGameMode = "attackdefense"; break;
case kGameCategory_Koth: m_Stats.m_sUserGameMode = "koth"; break;
case kGameCategory_CP: m_Stats.m_sUserGameMode = "cp"; break;
case kGameCategory_EscortRace: m_Stats.m_sUserGameMode = "escortrace"; break;
case kGameCategory_EventMix: m_Stats.m_sUserGameMode = "eventmix"; break;
case kGameCategory_Event247: m_Stats.m_sUserGameMode = "event247"; break;
case kGameCategory_SD: m_Stats.m_sUserGameMode = "sd"; break;
case kGameCategory_RobotDestruction: m_Stats.m_sUserGameMode = "rd"; break;
case kGameCategory_Powerup: m_Stats.m_sUserGameMode = "powerup"; break;
case kGameCategory_Featured: m_Stats.m_sUserGameMode = "featured"; break;
case kGameCategory_Passtime: m_Stats.m_sUserGameMode = "passtime"; break;
case kGameCategory_Community_Update: m_Stats.m_sUserGameMode = "community_update"; break;
case kGameCategory_Misc: m_Stats.m_sUserGameMode = "misc"; break;
//case kQuickplayGameType_Arena: stats.m_sUserGameMode = "arena"; break;
//case kQuickplayGameType_Specialty: stats.m_sUserGameMode = "specialty"; break;
default:
Assert( false );
m_Stats.m_sUserGameMode.Format( "%d", m_options.m_eSelectedGameType );
break;
}
SetDefLessFunc( m_mapServers );
// Sanity
Assert( 0.0 < m_fPingA ); Assert( m_fPingA < m_fPingB ); Assert( m_fPingB < m_fPingC );
Assert( 1.0 > m_fPingAScore ); Assert( m_fPingAScore > m_fPingBScore ); Assert( m_fPingBScore > m_fPingCScore );
// Setup search filters
CUtlVector<MatchMakingKeyValuePair_t> vecServerFilters;
AddFilter( vecServerFilters, "gamedir", COM_GetModDirectory() );
if ( GetUniverse() == k_EUniversePublic )
{
AddFilter( vecServerFilters, "secure", "1" );
AddFilter( vecServerFilters, "dedicated", "1" );
}
AddFilter( vecServerFilters, "full", "1" ); // actually means "not full"
GetQuickplayTags( m_options, m_vecStrRequiredTags, m_vecStrRejectTags );
// Specified map filter if one is specified
if ( !m_options.m_strMapName.IsEmpty() )
{
AddFilter( vecServerFilters, "map", m_options.m_strMapName );
}
else
{
// Add filter for the game mode tag
switch ( m_options.m_eSelectedGameType )
{
case kGameCategory_Escort:
case kGameCategory_EscortRace:
m_vecStrRequiredTags.CopyAndAddToTail( "payload" );
AddMapsFilter( vecServerFilters, m_options.m_eSelectedGameType );
break;
case kGameCategory_Koth:
case kGameCategory_AttackDefense:
case kGameCategory_CP:
m_vecStrRequiredTags.CopyAndAddToTail( "cp" );
AddMapsFilter( vecServerFilters, m_options.m_eSelectedGameType );
break;
case kGameCategory_CTF:
m_vecStrRequiredTags.CopyAndAddToTail( "ctf" );
AddMapsFilter( vecServerFilters, m_options.m_eSelectedGameType );
break;
case kGameCategory_EventMix:
m_vecStrRequiredTags.CopyAndAddToTail( "eventmix" );
m_vecStrRejectTags.CopyAndAddToTail( "event247" );
AddMapsFilter( vecServerFilters, m_options.m_eSelectedGameType );
break;
case kGameCategory_Event247:
m_vecStrRequiredTags.CopyAndAddToTail( "event247" );
m_vecStrRejectTags.CopyAndAddToTail( "eventmix" );
AddMapsFilter( vecServerFilters, m_options.m_eSelectedGameType );
break;
case kGameCategory_SD:
m_vecStrRequiredTags.CopyAndAddToTail( "sd" );
AddMapsFilter( vecServerFilters, m_options.m_eSelectedGameType );
break;
case kGameCategory_RobotDestruction:
m_vecStrRequiredTags.CopyAndAddToTail( "rd" );
AddMapsFilter( vecServerFilters, m_options.m_eSelectedGameType );
break;
case kGameCategory_Powerup:
m_vecStrRequiredTags.CopyAndAddToTail( "powerup" );
AddMapsFilter( vecServerFilters, m_options.m_eSelectedGameType );
break;
case kGameCategory_Featured:
m_vecStrRequiredTags.CopyAndAddToTail( "featured" );
AddMapsFilter( vecServerFilters, m_options.m_eSelectedGameType );
break;
case kGameCategory_Passtime:
m_vecStrRequiredTags.CopyAndAddToTail( "passtime" );
AddMapsFilter( vecServerFilters, m_options.m_eSelectedGameType );
break;
case kGameCategory_Community_Update:
m_vecStrRequiredTags.CopyAndAddToTail( "community_update" );
AddMapsFilter( vecServerFilters, m_options.m_eSelectedGameType );
break;
case kGameCategory_Misc:
m_vecStrRequiredTags.CopyAndAddToTail( "misc" );
AddMapsFilter( vecServerFilters, m_options.m_eSelectedGameType );
break;
case kGameCategory_Quickplay:
// Grrrrr. Anything we can do here?
// The list of all the maps won't fit. We do not yet have an "or" syntax.
// So we're stuck filtering them client side
break;
default:
Assert( false );
break;
}
}
AddFilter( vecServerFilters, "ngametype", GetCommaDelimited( m_vecStrRejectTags ) );
AddFilter( vecServerFilters, "gametype", GetCommaDelimited( m_vecStrRequiredTags ) );
AddFilter( vecServerFilters, "steamblocking", "1" );
if ( m_options.m_eServers == QuickplaySearchOptions::eServersOfficial )
{
AddFilter( vecServerFilters, "white", "1" );
}
else if ( m_options.m_eServers == QuickplaySearchOptions::eServersCommunity )
{
// community servers *ONLY*
AddFilter( vecServerFilters, "nor", "1" );
AddFilter( vecServerFilters, "white", "1" );
}
// Remember when we started
m_timeGMSSearchStarted = Plat_FloatTime();
// Print for debugging
if ( tf_matchmaking_debug.GetInt() >= 2 )
{
CUtlString sFilter;
FOR_EACH_VEC( vecServerFilters, idx )
{
sFilter.Append( vecServerFilters[idx].m_szKey );
sFilter.Append( " - " );
sFilter.Append( vecServerFilters[idx].m_szValue );
sFilter.Append( "\n" );
}
Msg( "Using GMS filter: %s\n", sFilter.String() );
}
// Initiate the search
MatchMakingKeyValuePair_t *pFilters = vecServerFilters.Base(); // <<<< Note, this is weird, but correct.
m_hServerListRequest = steamapicontext->SteamMatchmakingServers()->RequestInternetServerList( GetTfMatchmakingAppID(), &pFilters, vecServerFilters.Count(), this );
}
virtual ~CQuickplayWaitDialog()
{
Assert( s_pQuickPlayWaitingDialog == this );
s_pQuickPlayWaitingDialog = NULL;
DestroyServerQueryRequest();
DestroyServerListRequest();
}
virtual const char* GetResFile() const { return "Resource/UI/QuickPlayBusyDialog.res"; }
void OnReceivedGCScores( CMsgTFQuickplay_ScoreServersResponse &msg )
{
// Make sure we're expecting them
if ( m_eCurrentStep != k_EStep_GCScore )
{
Warning(" Received CGCTFQuickplay_ScoreServers_Response, but not expecting them (current step = %d)?\n", m_eCurrentStep );
return;
}
m_vecServerJoinQueue.RemoveAll();
// Do we have any GC scores?
if ( msg.servers_size() > 0 )
{
TF_MATCHMAKING_SPEW( 1, "Received %d server scores from GC\n", msg.servers_size());
// Put them in a queue. We will try them in score order
TF_MATCHMAKING_SPEW( 2, "SteamID, IP, score\n" );
for ( int i = 0; i < msg.servers_size(); ++i )
{
const CMsgTFQuickplay_ScoreServersResponse_ServerInfo &info = msg.servers( i );
netadr_t adr( info.server_address(), info.server_port() );
CSteamID steamID( info.steam_id() );
TF_MATCHMAKING_SPEW( 2, "\"%s\", \"%s\", %.2f\n",
steamID.Render(), adr.ToString(), info.total_score() );
gameserver_ping_queue_entry_t item;
item.m_adr.SetIPAndPort( info.server_address(), info.server_port() );
item.m_fTotalScore = info.total_score();
int nOptionsScore = RemapValClamped( info.options_score(), 0.f, 30000.f, tf_mm_options_bonus.GetFloat(), tf_mm_options_penalty.GetFloat() );
item.m_fTotalScore += nOptionsScore;
m_vecServerJoinQueue.InsertNoSort( item );
// Locate the original entry. Try by IP first,
// and if that fails, try steam ID. (Can happen due
// to mismatch of public/private IP)
int idx = m_mapServers.Find( adr );
if ( m_mapServers.IsValidIndex( idx ) )
{
// Might actually fail in race condition, but should
// be extremely rare. If it's happening frequently,
// we probably have a bug or have misunderstood something
Assert( m_mapServers[idx].server.m_steamID == steamID );
}
else
{
bool bFound = false;
FOR_EACH_MAP_FAST( m_mapServers, j )
{
if ( m_mapServers[j].server.m_steamID == steamID )
{
Assert( !m_mapServers.IsValidIndex( idx ) ); // duplicate?
idx = j;
bFound = true;
break;
}
}
if ( bFound )
{
// Remove it and re-insert, updating the address
// we got from the GC, which is probably the public IP.
// this IP is more useful for scoring purposes
sortable_gameserveritem_t temp = m_mapServers[idx];
temp.server.m_NetAdr.SetIP( info.server_address() );
m_mapServers.RemoveAt( idx );
idx = m_mapServers.InsertOrReplace( adr, temp );
}
}
if ( m_mapServers.IsValidIndex( idx ) )
{
m_mapServers[ idx ].m_eStatus = TF_Gamestats_QuickPlay_t::k_Server_Scored;
m_mapServers[ idx ].m_fTotalScoreFromGC = info.total_score();
m_mapServers[ idx ].m_nOptionsScoreFromGC = info.options_score();
}
else
{
Warning( "Received score from GC for %s @ %s, but I didn't ask for that server!\n", steamID.Render(), adr.ToString() );
Assert( m_mapServers.IsValidIndex( idx ) );
}
}
} else {
TF_MATCHMAKING_SPEW(1, "Using client-only scoring (no reputation data)\n" );
// Just add all of the servers that we thought were good enough to send to the GC
// to even request a score into the list of possible ones to join
FOR_EACH_MAP( m_mapServers, i )
{
sortable_gameserveritem_t &s = m_mapServers[i];
if ( s.m_eStatus >= TF_Gamestats_QuickPlay_t::k_Server_RequestedScore )
{
gameserver_ping_queue_entry_t item;
item.m_adr.SetIPAndPort( s.server.m_NetAdr.GetIP(), s.server.m_NetAdr.GetConnectionPort() );
item.m_fTotalScore = s.TotalScore(); // client-side score only, no reputation data
m_vecServerJoinQueue.InsertNoSort( item );
}
}
}
m_vecServerJoinQueue.RedoSort();
if ( msg.servers_size() > 0 )
{
TF_MATCHMAKING_SPEW(1, "Best GC score was %.2f\n", m_vecServerJoinQueue[0].m_fTotalScore );
}
// Show some UI