forked from nillerusr/source-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseGamesPage.cpp
2205 lines (1866 loc) · 67.8 KB
/
BaseGamesPage.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
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 "pch_serverbrowser.h"
#if defined( _X360 )
#include "xbox/xbox_win32stubs.h"
#endif
using namespace vgui;
#define FILTER_ALLSERVERS 0
#define FILTER_SECURESERVERSONLY 1
#define FILTER_INSECURESERVERSONLY 2
#define UNIVERSE_OFFICIAL 0
#define UNIVERSE_CUSTOMGAMES 1
#define QUICKLIST_FILTER_MIN_PING 0
#define MAX_MAP_NAME 128
const char *COM_GetModDirectory();
#undef wcscat
ConVar sb_mod_suggested_maxplayers( "sb_mod_suggested_maxplayers", "0", FCVAR_HIDDEN );
ConVar sb_filter_incompatible_versions( "sb_filter_incompatible_versions",
#ifdef STAGING_ONLY
"0",
#else
"1",
#endif
0, "Hides servers running incompatible versions from the server browser. (Internet tab only.)" );
bool GameSupportsReplay()
{
extern IEngineReplay *g_pEngineReplay;
return g_pEngineReplay && g_pEngineReplay->IsSupportedModAndPlatform();
}
#ifdef STAGING_ONLY
ConVar sb_fake_app_id( "sb_fake_app_id", "0", 0, "If nonzero, then server browser requests will use this App ID instead" );
#endif
//--------------------------------------------------------------------------------------------------------
bool IsReplayServer( newgameserver_t &server )
{
bool bReplay = false;
if ( GameSupportsReplay() )
{
if ( server.m_szGameTags[0] )
{
CUtlVector<char*> TagList;
V_SplitString( server.m_szGameTags, ",", TagList );
for ( int i = 0; i < TagList.Count(); i++ )
{
if ( Q_stricmp( TagList[i], "replays" ) == 0 )
{
bReplay = true;
}
}
}
}
return bReplay;
}
//--------------------------------------------------------------------------------------------------------
inline char *CloneString( const char *str )
{
char *cloneStr = new char [ strlen(str)+1 ];
strcpy( cloneStr, str );
return cloneStr;
}
const char *COM_GetModDirectory()
{
static char modDir[MAX_PATH];
if ( Q_strlen( modDir ) == 0 )
{
const char *gamedir = CommandLine()->ParmValue("-game", CommandLine()->ParmValue( "-defaultgamedir", "hl2" ) );
Q_strncpy( modDir, gamedir, sizeof(modDir) );
if ( strchr( modDir, '/' ) || strchr( modDir, '\\' ) )
{
Q_StripLastDir( modDir, sizeof(modDir) );
int dirlen = Q_strlen( modDir );
Q_strncpy( modDir, gamedir + dirlen, sizeof(modDir) - dirlen );
}
}
return modDir;
}
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CGameListPanel::CGameListPanel( CBaseGamesPage *pOuter, const char *pName ) :
BaseClass( pOuter, pName )
{
m_pOuter = pOuter;
}
//-----------------------------------------------------------------------------
// Purpose: Forward KEY_ENTER to the CBaseGamesPage.
//-----------------------------------------------------------------------------
void CGameListPanel::OnKeyCodePressed(vgui::KeyCode code)
{
// Let the outer class handle it.
if ( code == KEY_ENTER && m_pOuter->OnGameListEnterPressed() )
return;
BaseClass::OnKeyCodePressed( code );
}
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CBaseGamesPage::CBaseGamesPage( vgui::Panel *parent, const char *name, EPageType eType, const char *pCustomResFilename)
: PropertyPage(parent, name),
m_CallbackFavoritesMsg( this, &CBaseGamesPage::OnFavoritesMsg ),
m_hRequest( NULL ),
m_pCustomResFilename( pCustomResFilename )
{
SetSize( 624, 278 );
m_szGameFilter[0] = 0;
m_szMapFilter[0] = 0;
m_iMaxPlayerFilter = 0;
m_iPingFilter = 0;
m_iServerRefreshCount = 0;
m_bFilterNoFullServers = false;
m_bFilterNoEmptyServers = false;
m_bFilterNoPasswordedServers = false;
m_iSecureFilter = FILTER_ALLSERVERS;
m_hFont = NULL;
m_eMatchMakingType = eType;
m_bFilterReplayServers = false;
SetDefLessFunc( m_mapServers );
SetDefLessFunc( m_mapServerIP );
SetDefLessFunc( m_mapGamesFilterItem );
// Not always loaded
m_pWorkshopFilter = NULL;
bool bRunningTF2 = GameSupportsReplay();
// get the 'all' text
wchar_t *all = g_pVGuiLocalize->Find("ServerBrowser_All");
Q_UnicodeToUTF8(all, m_szComboAllText, sizeof(m_szComboAllText));
// Init UI
m_pConnect = new Button(this, "ConnectButton", "#ServerBrowser_Connect");
m_pConnect->SetEnabled(false);
m_pRefreshAll = new Button(this, "RefreshButton", "#ServerBrowser_Refresh");
m_pAddServer = new Button(this, "AddServerButton", "#ServerBrowser_AddServer");
m_pAddCurrentServer = new Button(this, "AddCurrentServerButton", "#ServerBrowser_AddCurrentServer");
m_pGameList = new CGameListPanel(this, "gamelist");
m_pGameList->SetAllowUserModificationOfColumns(true);
m_pRefreshQuick = new Button(this, "RefreshQuickButton", "#ServerBrowser_RefreshQuick");
m_pQuickList = new PanelListPanel(this, "quicklist");
m_pQuickList->SetFirstColumnWidth( 0 );
m_pAddToFavoritesButton = new vgui::Button( this, "AddToFavoritesButton", "" );
m_pAddToFavoritesButton->SetEnabled( false );
m_pAddToFavoritesButton->SetVisible( false );
// Increment this number if columns are added / removed or some other change is done that requires
// tossing out old saved user configs.
m_pGameList->m_nUserConfigFileVersion = 2;
// Add the column headers
m_pGameList->AddColumnHeader( k_nColumn_Password, "Password", "#ServerBrowser_Password", 16, ListPanel::COLUMN_FIXEDSIZE | ListPanel::COLUMN_IMAGE);
m_pGameList->AddColumnHeader( k_nColumn_Secure, "Secure", "#ServerBrowser_Secure", 16, ListPanel::COLUMN_FIXEDSIZE | ListPanel::COLUMN_IMAGE);
int nReplayWidth = 16;
if ( !bRunningTF2 )
{
nReplayWidth = 0;
}
m_pGameList->AddColumnHeader( k_nColumn_Replay, "Replay", "#ServerBrowser_Replay", nReplayWidth, ListPanel::COLUMN_FIXEDSIZE | ListPanel::COLUMN_IMAGE);
m_pGameList->AddColumnHeader( k_nColumn_Name, "Name", "#ServerBrowser_Servers", 50, ListPanel::COLUMN_RESIZEWITHWINDOW | ListPanel::COLUMN_UNHIDABLE);
m_pGameList->AddColumnHeader( k_nColumn_IPAddr, "IPAddr", "#ServerBrowser_IPAddress", 64, ListPanel::COLUMN_HIDDEN);
m_pGameList->AddColumnHeader( k_nColumn_GameDesc, "GameDesc", "#ServerBrowser_Game", 112,
112, // minwidth
300, // maxwidth
0 // flags
);
m_pGameList->AddColumnHeader( k_nColumn_Players, "Players", "#ServerBrowser_Players", 80, ListPanel::COLUMN_FIXEDSIZE);
m_pGameList->AddColumnHeader( k_nColumn_Bots, "Bots", "#ServerBrowser_Bots", 60, ListPanel::COLUMN_FIXEDSIZE);
m_pGameList->AddColumnHeader( k_nColumn_Map, "Map", "#ServerBrowser_Map", 90,
90, // minwidth
300, // maxwidth
0 // flags
);
m_pGameList->AddColumnHeader( k_nColumn_Ping, "Ping", "#ServerBrowser_Latency", 55, ListPanel::COLUMN_RESIZEWITHWINDOW);
m_pGameList->SetColumnHeaderTooltip( k_nColumn_Password, "#ServerBrowser_PasswordColumn_Tooltip");
m_pGameList->SetColumnHeaderTooltip( k_nColumn_Bots, "#ServerBrowser_BotColumn_Tooltip");
m_pGameList->SetColumnHeaderTooltip( k_nColumn_Secure, "#ServerBrowser_SecureColumn_Tooltip");
if ( bRunningTF2 )
{
m_pGameList->SetColumnHeaderTooltip( k_nColumn_Replay, "#ServerBrowser_ReplayColumn_Tooltip");
}
// setup fast sort functions
m_pGameList->SetSortFunc( k_nColumn_Password, PasswordCompare);
m_pGameList->SetSortFunc( k_nColumn_Bots, BotsCompare);
m_pGameList->SetSortFunc( k_nColumn_Secure, SecureCompare);
if ( bRunningTF2 )
{
m_pGameList->SetSortFunc( k_nColumn_Replay, ReplayCompare);
}
m_pGameList->SetSortFunc( k_nColumn_Name, ServerNameCompare);
m_pGameList->SetSortFunc( k_nColumn_IPAddr, IPAddressCompare);
m_pGameList->SetSortFunc( k_nColumn_GameDesc, GameCompare);
m_pGameList->SetSortFunc( k_nColumn_Players, PlayersCompare);
m_pGameList->SetSortFunc( k_nColumn_Map, MapCompare);
m_pGameList->SetSortFunc( k_nColumn_Ping, PingCompare);
// Sort by ping time by default
m_pGameList->SetSortColumn( k_nColumn_Ping );
CreateFilters();
LoadFilterSettings();
m_bAutoSelectFirstItemInGameList = false;
// In TF2, fill out the max player count so that we sort all >24 player servers below the rest.
if ( bRunningTF2 )
{
sb_mod_suggested_maxplayers.SetValue( 24 );
}
}
//-----------------------------------------------------------------------------
// Purpose: Destructor
//-----------------------------------------------------------------------------
CBaseGamesPage::~CBaseGamesPage()
{
if ( m_hRequest )
{
steamapicontext->SteamMatchmakingServers()->ReleaseRequest( m_hRequest );
m_hRequest = NULL;
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CBaseGamesPage::GetInvalidServerListID()
{
return m_pGameList->InvalidItemID();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseGamesPage::PerformLayout()
{
BaseClass::PerformLayout();
if ( GetSelectedServerID() == -1 )
{
m_pConnect->SetEnabled(false);
}
else
{
m_pConnect->SetEnabled(true);
}
if (SupportsItem(IGameList::GETNEWLIST))
{
m_pRefreshAll->SetText("#ServerBrowser_RefreshAll");
}
else
{
m_pRefreshAll->SetText("#ServerBrowser_Refresh");
}
if ( SupportsItem(IGameList::ADDSERVER) )
{
// m_pFilterString->SetWide( 90 ); // shrink the filter label to fix the add current server button
m_pAddServer->SetVisible(true);
}
else
{
m_pAddServer->SetVisible(false);
}
if ( SupportsItem(IGameList::ADDCURRENTSERVER) )
{
m_pAddCurrentServer->SetVisible(true);
}
else
{
m_pAddCurrentServer->SetVisible(false);
}
if ( IsRefreshing() )
{
m_pRefreshAll->SetText( "#ServerBrowser_StopRefreshingList" );
}
m_pRefreshQuick->SetVisible( false );
m_pFilter->SetVisible(false);
Repaint();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseGamesPage::ApplySchemeSettings(IScheme *pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);
// load the password icon
ImageList *imageList = new ImageList(false);
m_nImageIndexPassword = imageList->AddImage(scheme()->GetImage("servers/icon_password", false));
//imageList->AddImage(scheme()->GetImage("servers/icon_bots", false));
m_nImageIndexSecure = imageList->AddImage(scheme()->GetImage("servers/icon_robotron", false));
m_nImageIndexSecureVacBanned = imageList->AddImage(scheme()->GetImage("servers/icon_secure_deny", false));
m_nImageIndexReplay = imageList->AddImage(scheme()->GetImage("servers/icon_replay", false));
int passwordColumnImage = imageList->AddImage(scheme()->GetImage("servers/icon_password_column", false));
//int botColumnImage = imageList->AddImage(scheme()->GetImage("servers/icon_bots_column", false));
int secureColumnImage = imageList->AddImage(scheme()->GetImage("servers/icon_robotron_column", false));
int replayColumnImage = imageList->AddImage(scheme()->GetImage("servers/icon_replay_column", false));
m_pGameList->SetImageList(imageList, true);
m_hFont = pScheme->GetFont( "ListSmall", IsProportional() );
if ( !m_hFont )
m_hFont = pScheme->GetFont( "DefaultSmall", IsProportional() );
m_pGameList->SetFont( m_hFont );
m_pGameList->SetColumnHeaderImage( k_nColumn_Password, passwordColumnImage);
//m_pGameList->SetColumnHeaderImage( k_nColumn_Bots, botColumnImage);
m_pGameList->SetColumnHeaderImage( k_nColumn_Secure, secureColumnImage);
m_pGameList->SetColumnHeaderImage( k_nColumn_Replay, replayColumnImage);
}
struct serverqualitysort_t
{
int iIndex;
int iPing;
int iPlayerCount;
int iMaxPlayerCount;
};
int ServerQualitySort( const serverqualitysort_t *pSQ1, const serverqualitysort_t *pSQ2 )
{
return pSQ1->iPing - pSQ2->iPing;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseGamesPage::SelectQuickListServers( void )
{
}
int ServerPingSortFunc( const serverping_t *p1, const serverping_t *p2 )
{
return p1->m_nPing - p2->m_nPing;
}
//-----------------------------------------------------------------------------
// Purpose: prepares all the QuickListPanel map panels...
//-----------------------------------------------------------------------------
void CBaseGamesPage::PrepareQuickListMap( newgameserver_t *server, int iListID )
{
char szMapName[ 512 ];
Q_snprintf( szMapName, sizeof( szMapName ), "%s", server->m_szMap );
Q_strlower( szMapName );
char path[ 512 ];
Q_snprintf( path, sizeof( path ), "maps/%s.bsp", szMapName );
char szFriendlyName[MAX_MAP_NAME];
const char *pszFriendlyGameTypeName = ServerBrowser().GetMapFriendlyNameAndGameType( szMapName, szFriendlyName, sizeof(szFriendlyName) );
//Add the map to our list of panels.
if ( m_pQuickList )
{
serverping_t serverping;
const char *pFriendlyName = CloneString( szFriendlyName );
const char *pOriginalName = CloneString( szMapName );
char path[ 512 ];
Q_snprintf( path, sizeof( path ), "maps/%s.bsp", szMapName );
CQuickListPanel *pQuickListPanel = new CQuickListPanel( m_pQuickList, "QuickListPanel");
if ( pQuickListPanel )
{
pQuickListPanel->InvalidateLayout();
pQuickListPanel->SetName( pOriginalName );
pQuickListPanel->SetMapName( pFriendlyName );
pQuickListPanel->SetImage( pOriginalName );
pQuickListPanel->SetGameType( pszFriendlyGameTypeName );
pQuickListPanel->SetVisible( true );
pQuickListPanel->SetRefreshing();
pQuickListPanel->SetServerInfo( m_pGameList->GetItem( iListID ), iListID, 1 );
serverping.iPanelIndex = m_pQuickList->AddItem( NULL, pQuickListPanel );
serverping.m_nPing = server->m_nPing;
m_vecServersFound.AddToTail( serverping );
m_vecServersFound.Sort( ServerPingSortFunc );
}
}
//Now make sure that list is sorted.
CUtlVector<int> *pPanelSort = m_pQuickList->GetSortedVector();
if ( pPanelSort )
{
pPanelSort->RemoveAll();
for ( int i = 0; i < m_vecServersFound.Count(); i++ )
{
pPanelSort->AddToTail( m_vecServersFound[i].iPanelIndex );
}
}
}
//-----------------------------------------------------------------------------
// Purpose: gets information about specified server
//-----------------------------------------------------------------------------
newgameserver_t *CBaseGamesPage::GetServer( unsigned int serverID )
{
if( serverID >= m_serversInfo.Count() ) return NULL;
return &m_serversInfo[serverID];
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CBaseGamesPage::TagsExclude( void )
{
if ( m_pTagsIncludeFilter == NULL )
return false;
return m_pTagsIncludeFilter->GetActiveItem();
}
//-----------------------------------------------------------------------------
// Purpose: What mode the workshop selection is in for pages that use it
//-----------------------------------------------------------------------------
CBaseGamesPage::eWorkshopMode CBaseGamesPage::WorkshopMode()
{
if ( !m_pWorkshopFilter || !ServerBrowser().IsWorkshopEnabled() )
{
return eWorkshop_None;
}
return (eWorkshopMode)m_pWorkshopFilter->GetActiveItem();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseGamesPage::HideReplayFilter( void )
{
if ( m_pReplayFilterCheck && m_pReplayFilterCheck->IsVisible() )
{
m_pReplayFilterCheck->SetVisible( false );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseGamesPage::CreateFilters()
{
m_pFilter = new ToggleButton(this, "Filter", "#ServerBrowser_Filters");
m_pFilterString = new Label(this, "FilterString", "");
if ( Q_stricmp( COM_GetModDirectory(), "cstrike" ) == 0 )
{
m_pFilter->SetSelected( false );
m_bFiltersVisible = false;
}
else
{
m_pFilter->SetSelected( true );
m_bFiltersVisible = true;
}
// filter controls
m_pGameFilter = new ComboBox(this, "GameFilter", 6, false);
m_pLocationFilter = new ComboBox(this, "LocationFilter", 6, false);
m_pLocationFilter->AddItem("", NULL);
m_pMapFilter = new TextEntry(this, "MapFilter");
m_pMaxPlayerFilter = new TextEntry(this, "MaxPlayerFilter");
m_pPingFilter = new ComboBox(this, "PingFilter", 6, false);
m_pPingFilter->AddItem("#ServerBrowser_All", NULL);
m_pPingFilter->AddItem("#ServerBrowser_LessThan50", NULL);
m_pPingFilter->AddItem("#ServerBrowser_LessThan100", NULL);
m_pPingFilter->AddItem("#ServerBrowser_LessThan150", NULL);
m_pPingFilter->AddItem("#ServerBrowser_LessThan250", NULL);
m_pPingFilter->AddItem("#ServerBrowser_LessThan350", NULL);
m_pPingFilter->AddItem("#ServerBrowser_LessThan600", NULL);
m_pSecureFilter = new ComboBox(this, "SecureFilter", 3, false);
m_pSecureFilter->AddItem("#ServerBrowser_All", NULL);
m_pSecureFilter->AddItem("#ServerBrowser_SecureOnly", NULL);
m_pSecureFilter->AddItem("#ServerBrowser_InsecureOnly", NULL);
m_pTagsIncludeFilter = new ComboBox(this, "TagsInclude", 2, false);
m_pTagsIncludeFilter->AddItem("#ServerBrowser_TagsInclude", NULL);
m_pTagsIncludeFilter->AddItem("#ServerBrowser_TagsDoNotInclude", NULL);
m_pTagsIncludeFilter->SetVisible( false );
if ( ServerBrowser().IsWorkshopEnabled() )
{
m_pWorkshopFilter = new ComboBox(this, "WorkshopFilter", 3, false);
m_pWorkshopFilter->AddItem("#ServerBrowser_All", NULL);
m_pWorkshopFilter->AddItem("#ServerBrowser_WorkshopFilterWorkshopOnly", NULL);
m_pWorkshopFilter->AddItem("#ServerBrowser_WorkshopFilterSubscribed", NULL);
m_pWorkshopFilter->SetVisible( false );
}
m_pNoEmptyServersFilterCheck = new CheckButton(this, "ServerEmptyFilterCheck", "");
m_pNoFullServersFilterCheck = new CheckButton(this, "ServerFullFilterCheck", "");
m_pNoPasswordFilterCheck = new CheckButton(this, "NoPasswordFilterCheck", "");
m_pQuickListCheckButton = new CCheckBoxWithStatus(this, "QuickListCheck", "");
m_pReplayFilterCheck = new CheckButton(this, "ReplayFilterCheck", "");
KeyValues *pkv = new KeyValues("mod", "gamedir", "", "appid", NULL );
m_pGameFilter->AddItem("#ServerBrowser_All", pkv);
for (int i = 0; i < ModList().ModCount(); i++)
{
pkv->SetString("gamedir", ModList().GetModDir(i));
pkv->SetUint64("appid", ModList().GetAppID(i).ToUint64() );
int iItemID = m_pGameFilter->AddItem(ModList().GetModName(i), pkv);
m_mapGamesFilterItem.Insert( ModList().GetAppID(i).ToUint64(), iItemID );
}
pkv->deleteThis();
}
//-----------------------------------------------------------------------------
// Purpose: loads filter settings from the keyvalues
//-----------------------------------------------------------------------------
void CBaseGamesPage::LoadFilterSettings()
{
KeyValues *filter = ServerBrowserDialog().GetFilterSaveData(GetName());
if (ServerBrowserDialog().GetActiveModName())
{
Q_strncpy(m_szGameFilter, ServerBrowserDialog().GetActiveModName(), sizeof(m_szGameFilter));
m_iLimitToAppID = ServerBrowserDialog().GetActiveAppID();
}
else
{
Q_strncpy(m_szGameFilter, filter->GetString("game"), sizeof(m_szGameFilter));
m_iLimitToAppID = CGameID( filter->GetUint64( "appid", 0 ) );
}
Q_strncpy(m_szMapFilter, filter->GetString("map"), sizeof(m_szMapFilter));
m_iMaxPlayerFilter = filter->GetInt("MaxPlayerCount");
m_iPingFilter = filter->GetInt("ping");
m_bFilterNoFullServers = filter->GetInt("NoFull");
m_bFilterNoEmptyServers = filter->GetInt("NoEmpty");
m_bFilterNoPasswordedServers = filter->GetInt("NoPassword");
m_bFilterReplayServers = filter->GetInt("Replay");
m_pQuickListCheckButton->SetSelected( filter->GetInt( "QuickList", IsAndroid() ) );
int secureFilter = filter->GetInt("Secure");
m_pSecureFilter->ActivateItem(secureFilter);
int tagsinclude = filter->GetInt("tagsinclude");
m_pTagsIncludeFilter->ActivateItem( tagsinclude );
if ( m_pWorkshopFilter )
{
int workshopFilter = filter->GetInt("workshopfilter");
m_pWorkshopFilter->ActivateItem( workshopFilter );
}
// apply to the controls
UpdateGameFilter();
m_pMapFilter->SetText(m_szMapFilter);
m_pLocationFilter->ActivateItem(filter->GetInt("location"));
if (m_iMaxPlayerFilter)
{
char buf[32];
Q_snprintf(buf, sizeof(buf), "%d", m_iMaxPlayerFilter);
m_pMaxPlayerFilter->SetText(buf);
}
if (m_iPingFilter)
{
char buf[32];
Q_snprintf(buf, sizeof(buf), "< %d", m_iPingFilter);
m_pPingFilter->SetText(buf);
}
m_pNoFullServersFilterCheck->SetSelected(m_bFilterNoFullServers);
m_pNoEmptyServersFilterCheck->SetSelected(m_bFilterNoEmptyServers);
m_pNoPasswordFilterCheck->SetSelected(m_bFilterNoPasswordedServers);
m_pReplayFilterCheck->SetSelected(m_bFilterReplayServers);
OnLoadFilter( filter );
UpdateFilterSettings();
UpdateFilterAndQuickListVisibility();
}
//-----------------------------------------------------------------------------
// Purpose: Sets the game filter combo box to be the saved setting
//-----------------------------------------------------------------------------
void CBaseGamesPage::UpdateGameFilter()
{
bool bFound = false;
for (int i = 0; i < m_pGameFilter->GetItemCount(); i++)
{
KeyValues *kv = m_pGameFilter->GetItemUserData(i);
CGameID gameID( kv->GetUint64( "appID", 0 ) );
const char *pchGameDir = kv->GetString( "gamedir" );
if ( ( gameID == m_iLimitToAppID || m_iLimitToAppID.AppID() == 0 ) && ( !m_szGameFilter[0] ||
( pchGameDir && pchGameDir[0] && !Q_strncmp( pchGameDir, m_szGameFilter, Q_strlen( pchGameDir ) ) ) ) )
{
if ( i != m_pGameFilter->GetActiveItem() )
{
m_pGameFilter->ActivateItem(i);
}
bFound = true;
break;
}
}
if (!bFound)
{
// default to empty
if ( 0 != m_pGameFilter->GetActiveItem() )
{
m_pGameFilter->ActivateItem(0);
}
}
// only one mod is allowed in the game
if ( ServerBrowserDialog().GetActiveModName() )
{
m_pGameFilter->SetEnabled( false );
m_pGameFilter->SetText( ServerBrowserDialog().GetActiveGameName() );
}
}
//-----------------------------------------------------------------------------
// Purpose: Handles incoming server refresh data
// updates the server browser with the refreshed information from the server itself
//-----------------------------------------------------------------------------
/*void CBaseGamesPage::ServerResponded( gameserveritem_t &server )
{
int nIndex = -1; // start at -1 and work backwards to find the next free slot for this adhoc query
while ( m_mapServers.Find( nIndex ) != m_mapServers.InvalidIndex() )
nIndex--;
ServerResponded( nIndex, &server );
}*/
//-----------------------------------------------------------------------------
// Purpose: Callback for ISteamMatchmakingServerListResponse
//-----------------------------------------------------------------------------
/*void CBaseGamesPage::ServerResponded( HServerListRequest hReq, int iServer )
{
gameserveritem_t *pServerItem = steamapicontext->SteamMatchmakingServers()->GetServerDetails( hReq, iServer );
if ( !pServerItem )
{
Assert( !"Missing server response" );
return;
}
// FIXME(johns): This is a workaround for a steam bug, where it inproperly reads signed bytes out of the
// message. Once the upstream fix makes it into our SteamSDK, this block can be removed.
pServerItem->m_nPlayers = (uint8)(int8)pServerItem->m_nPlayers;
pServerItem->m_nBotPlayers = (uint8)(int8)pServerItem->m_nBotPlayers;
pServerItem->m_nMaxPlayers = (uint8)(int8)pServerItem->m_nMaxPlayers;
ServerResponded( iServer, pServerItem );
}*/
//-----------------------------------------------------------------------------
// Purpose: Handles incoming server refresh data
// updates the server browser with the refreshed information from the server itself
//-----------------------------------------------------------------------------
void CBaseGamesPage::ServerResponded( int iServer, gameserveritem_t *pServerItem )
{
#if 0
int iServerMap = m_mapServers.Find( iServer );
if ( iServerMap == m_mapServers.InvalidIndex() )
{
netadr_t netAdr( pServerItem->m_NetAdr.GetIP(), pServerItem->m_NetAdr.GetConnectionPort() );
int iServerIP = m_mapServerIP.Find( netAdr );
if ( iServerIP != m_mapServerIP.InvalidIndex() )
{
// if we already had this entry under another index remove the old entry
int iServerMap = m_mapServers.Find( m_mapServerIP[ iServerIP ] );
if ( iServerMap != m_mapServers.InvalidIndex() )
{
serverdisplay_t &server = m_mapServers[ iServerMap ];
if ( m_pGameList->IsValidItemID( server.m_iListID ) )
m_pGameList->RemoveItem( server.m_iListID );
m_mapServers.RemoveAt( iServerMap );
}
m_mapServerIP.RemoveAt( iServerIP );
}
serverdisplay_t serverFind;
serverFind.m_iListID = -1;
serverFind.m_bDoNotRefresh = false;
iServerMap = m_mapServers.Insert( iServer, serverFind );
m_mapServerIP.Insert( netAdr, iServer );
}
serverdisplay_t *pServer = &m_mapServers[ iServerMap ];
pServer->m_iServerID = iServer;
Assert( pServerItem->m_NetAdr.GetIP() != 0 );
// check filters
bool removeItem = false;
if ( !CheckPrimaryFilters( *pServerItem ) )
{
// server has been filtered at a primary level
// remove from lists
pServer->m_bDoNotRefresh = true;
// remove from UI list
removeItem = true;
if ( m_pGameList->IsValidItemID( pServer->m_iListID ) )
{
m_pGameList->RemoveItem( pServer->m_iListID );
pServer->m_iListID = GetInvalidServerListID();
}
return;
}
else if (!CheckSecondaryFilters( *pServerItem ))
{
// we still ping this server in the future; however it is removed from UI list
removeItem = true;
}
// update UI
KeyValues *kv;
if ( m_pGameList->IsValidItemID( pServer->m_iListID ) )
{
// we're updating an existing entry
kv = m_pGameList->GetItem( pServer->m_iListID );
m_pGameList->SetUserData( pServer->m_iListID, pServer->m_iServerID );
}
else
{
// new entry
kv = new KeyValues("Server");
}
kv->SetString("name", pServerItem->GetName());
kv->SetString("map", pServerItem->m_szMap);
kv->SetString("GameDir", pServerItem->m_szGameDir);
kv->SetString("GameDesc", pServerItem->m_szGameDescription);
kv->SetInt("password", pServerItem->m_bPassword ? m_nImageIndexPassword : 0);
if ( pServerItem->m_nBotPlayers > 0 )
kv->SetInt("bots", pServerItem->m_nBotPlayers);
else
kv->SetString("bots", "");
if ( pServerItem->m_bSecure )
{
// show the denied icon if banned from secure servers, the secure icon otherwise
kv->SetInt("secure", ServerBrowser().IsVACBannedFromGame( pServerItem->m_nAppID ) ? m_nImageIndexSecureVacBanned : m_nImageIndexSecure );
}
else
{
kv->SetInt("secure", 0);
}
kv->SetString( "IPAddr", pServerItem->m_NetAdr.GetConnectionAddressString() );
int nAdjustedForBotsPlayers = max( 0, pServerItem->m_nPlayers - pServerItem->m_nBotPlayers );
char buf[32];
Q_snprintf(buf, sizeof(buf), "%d / %d", nAdjustedForBotsPlayers, pServerItem->m_nMaxPlayers );
kv->SetString("Players", buf);
kv->SetInt("PlayerCount", nAdjustedForBotsPlayers );
kv->SetInt("MaxPlayerCount", pServerItem->m_nMaxPlayers );
kv->SetInt("Ping", pServerItem->m_nPing);
kv->SetString("Tags", pServerItem->m_szGameTags );
kv->SetInt("Replay", IsReplayServer( *pServerItem ) ? m_nImageIndexReplay : 0);
if ( pServerItem->m_ulTimeLastPlayed )
{
// construct a time string for last played time
struct tm *now;
now = localtime( (time_t*)&pServerItem->m_ulTimeLastPlayed );
if ( now )
{
char buf[64];
strftime(buf, sizeof(buf), "%a %d %b %I:%M%p", now);
Q_strlower(buf + strlen(buf) - 4);
kv->SetString("LastPlayed", buf);
}
}
if ( pServer->m_bDoNotRefresh )
{
// clear out the vars
kv->SetString("Ping", "");
kv->SetWString("GameDesc", g_pVGuiLocalize->Find("#ServerBrowser_NotResponding"));
kv->SetString("Players", "");
kv->SetString("map", "");
}
if ( !m_pGameList->IsValidItemID( pServer->m_iListID ) )
{
// new server, add to list
pServer->m_iListID = m_pGameList->AddItem(kv, pServer->m_iServerID, false, false);
if ( m_bAutoSelectFirstItemInGameList && m_pGameList->GetItemCount() == 1 )
{
m_pGameList->AddSelectedItem( pServer->m_iListID );
}
m_pGameList->SetItemVisible( pServer->m_iListID, !removeItem );
kv->deleteThis();
}
else
{
// tell the list that we've changed the data
m_pGameList->ApplyItemChanges( pServer->m_iListID );
m_pGameList->SetItemVisible( pServer->m_iListID, !removeItem );
}
PrepareQuickListMap( pServerItem->m_szMap, pServer->m_iListID );
UpdateStatus();
m_iServerRefreshCount++;
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseGamesPage::UpdateFilterAndQuickListVisibility()
{
bool showQuickList = m_pQuickListCheckButton->IsSelected();
bool showFilter = m_pFilter->IsSelected();
m_bFiltersVisible = !showQuickList && !m_pCustomResFilename && showFilter;
int wide, tall;
GetSize( wide, tall );
int w = 640; int h = 384;
w = IsProportional() ? vgui::scheme()->GetProportionalScaledValue(w) : w;
h = IsProportional() ? vgui::scheme()->GetProportionalScaledValue(h) : h;
SetSize( w, h );
UpdateDerivedLayouts();
UpdateGameFilter();
if ( m_hFont )
{
SETUP_PANEL( m_pGameList );
m_pGameList->SetFont( m_hFont );
}
SetSize( wide, tall );
m_pQuickList->SetVisible( showQuickList );
m_pGameList->SetVisible( !showQuickList );
m_pFilter->SetVisible( !showQuickList );
m_pFilterString->SetVisible ( !showQuickList );
InvalidateLayout();
UpdateFilterSettings();
ApplyGameFilters();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseGamesPage::SetQuickListEnabled( bool bEnabled )
{
m_pQuickListCheckButton->SetSelected( bEnabled );
m_pQuickList->SetVisible( m_pQuickListCheckButton->IsSelected() );
m_pGameList->SetVisible( !m_pQuickListCheckButton->IsSelected() );
m_pFilter->SetVisible( !m_pQuickListCheckButton->IsSelected() );
m_pFilterString->SetVisible( !m_pQuickListCheckButton->IsSelected() );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseGamesPage::SetFiltersVisible( bool bVisible )
{
if ( bVisible == m_pFilter->IsSelected() )
return;
m_pFilter->SetSelected( bVisible );
OnButtonToggled( m_pFilter, bVisible );
}
//-----------------------------------------------------------------------------
// Purpose: Handles filter dropdown being toggled
//-----------------------------------------------------------------------------
void CBaseGamesPage::OnButtonToggled( Panel *panel, int state )
{
UpdateFilterAndQuickListVisibility();
if (panel == m_pNoFullServersFilterCheck || panel == m_pNoEmptyServersFilterCheck || panel == m_pNoPasswordFilterCheck || panel == m_pReplayFilterCheck)
{
// treat changing these buttons like any other filter has changed
OnTextChanged(panel, "");
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseGamesPage::UpdateDerivedLayouts( void )
{
char rgchControlSettings[MAX_PATH];
if ( m_pCustomResFilename )
{
Q_snprintf( rgchControlSettings, sizeof( rgchControlSettings ), "%s", m_pCustomResFilename );
}
else
{
if ( m_pFilter->IsSelected() && !m_pQuickListCheckButton->IsSelected() )
{
// drop down
V_strncpy( rgchControlSettings, "servers/InternetGamesPage_Filters.res", sizeof( rgchControlSettings ) );
}
else
{
// hide filter area
V_strncpy( rgchControlSettings, "servers/InternetGamesPage.res", sizeof( rgchControlSettings ) );
}
}
const char *pPathID = "PLATFORM";
if ( g_pFullFileSystem->FileExists( rgchControlSettings, "MOD" ) )
{
pPathID = "MOD";
}
LoadControlSettings( rgchControlSettings, pPathID );
if ( !GameSupportsReplay() )
{
HideReplayFilter();
}
}
//-----------------------------------------------------------------------------
// Purpose: Called when the game dir combo box is changed
//-----------------------------------------------------------------------------
void CBaseGamesPage::OnTextChanged(Panel *panel, const char *text)
{
if (!Q_stricmp(text, m_szComboAllText))
{
ComboBox *box = dynamic_cast<ComboBox *>(panel);
if (box)
{
box->SetText("");