/
cl_main.cpp
3140 lines (2659 loc) · 85.3 KB
/
cl_main.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:
//
// $Workfile: $
// $Date: $
// $NoKeywords: $
//===========================================================================//
#include "client_pch.h"
#include "sound.h"
#include <inetchannel.h>
#include "checksum_engine.h"
#include "con_nprint.h"
#include "r_local.h"
#include "gl_lightmap.h"
#include "console.h"
#include "traceinit.h"
#include "cl_demo.h"
#include "cdll_engine_int.h"
#include "debugoverlay.h"
#include "filesystem_engine.h"
#include "icliententity.h"
#include "dt_recv_eng.h"
#include "vgui_baseui_interface.h"
#include "testscriptmgr.h"
#include <tier0/vprof.h>
#include <proto_oob.h>
#include "materialsystem/imaterialsystemhardwareconfig.h"
#include "gl_matsysiface.h"
#include "staticpropmgr.h"
#include "ispatialpartitioninternal.h"
#include "cbenchmark.h"
#include "vox.h"
#include "LocalNetworkBackdoor.h"
#include <tier0/icommandline.h>
#include "GameEventManager.h"
#include "host_saverestore.h"
#include "ivideomode.h"
#include "host_phonehome.h"
#include "decal.h"
#include "sv_rcon.h"
#include "cl_rcon.h"
#include "vgui_baseui_interface.h"
#include "snd_audio_source.h"
#include "iregistry.h"
#include "sys.h"
#include <vstdlib/random.h>
#include "tier0/etwprof.h"
#include "tier0/vcrmode.h"
#include "sys_dll.h"
#include "video/ivideoservices.h"
#include "cl_steamauth.h"
#include "filesystem/IQueuedLoader.h"
#include "tier2/tier2.h"
#include "host_state.h"
#include "enginethreads.h"
#include "vgui/ISystem.h"
#include "pure_server.h"
#include "SoundEmitterSystem/isoundemittersystembase.h"
#include "LoadScreenUpdate.h"
#include "tier0/systeminformation.h"
#include "steam/steam_api.h"
#include "SourceAppInfo.h"
#include "cl_steamauth.h"
#include "sv_steamauth.h"
#include "engine/ivmodelinfo.h"
#ifdef _X360
#include "xbox/xbox_launch.h"
#endif
#if defined( REPLAY_ENABLED )
#include "replay_internal.h"
#endif
#include "igame.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
extern IVEngineClient *engineClient;
void R_UnloadSkys( void );
void CL_ResetEntityBits( void );
void EngineTool_UpdateScreenshot();
void WriteConfig_f( ConVar *var, const char *pOldString );
// If we get more than 250 messages in the incoming buffer queue, dump any above this #
#define MAX_INCOMING_MESSAGES 250
// Size of command send buffer
#define MAX_CMD_BUFFER 4000
CGlobalVarsBase g_ClientGlobalVariables( true );
IVideoRecorder *g_pVideoRecorder = NULL;
extern ConVar rcon_password;
extern ConVar host_framerate;
extern ConVar cl_clanid;
ConVar sv_unlockedchapters( "sv_unlockedchapters", "1", FCVAR_ARCHIVE | FCVAR_ARCHIVE_XBOX, "Highest unlocked game chapter." );
static ConVar tv_nochat ( "tv_nochat", "0", FCVAR_ARCHIVE | FCVAR_USERINFO, "Don't receive chat messages from other SourceTV spectators" );
static ConVar cl_LocalNetworkBackdoor( "cl_localnetworkbackdoor", "1", 0, "Enable network optimizations for single player games." );
static ConVar cl_ignorepackets( "cl_ignorepackets", "0", FCVAR_CHEAT, "Force client to ignore packets (for debugging)." );
static ConVar cl_playback_screenshots( "cl_playback_screenshots", "0", 0, "Allows the client to playback screenshot and jpeg commands in demos." );
#if defined( STAGING_ONLY ) || defined( _DEBUG )
static ConVar cl_block_usercommand( "cl_block_usercommand", "0", FCVAR_CHEAT, "Force client to not send usercommand (for debugging)." );
#endif // STAGING_ONLY || _DEBUG
ConVar dev_loadtime_map_start( "dev_loadtime_map_start", "0.0", FCVAR_HIDDEN);
ConVar dev_loadtime_map_elapsed( "dev_loadtime_map_elapsed", "0.0", FCVAR_HIDDEN );
MovieInfo_t cl_movieinfo;
// FIXME: put these on hunk?
dlight_t cl_dlights[MAX_DLIGHTS];
dlight_t cl_elights[MAX_ELIGHTS];
CFastPointLeafNum g_DLightLeafAccessors[MAX_DLIGHTS];
CFastPointLeafNum g_ELightLeafAccessors[MAX_ELIGHTS];
bool cl_takesnapshot = false;
static bool cl_takejpeg = false;
static bool cl_takesnapshot_internal = false;
static int cl_jpegquality = DEFAULT_JPEG_QUALITY;
static ConVar jpeg_quality( "jpeg_quality", "90", 0, "jpeg screenshot quality." );
static int cl_snapshotnum = 0;
static char cl_snapshotname[MAX_OSPATH];
static char cl_snapshot_subdirname[MAX_OSPATH];
// Must match game .dll definition
// HACK HACK FOR E3 -- Remove this after E3
#define HIDEHUD_ALL ( 1<<2 )
void PhonemeMP3Shutdown( void );
struct ResourceLocker
{
ResourceLocker()
{
g_pFileSystem->AsyncFinishAll();
g_pFileSystem->AsyncSuspend();
// Need to temporarily disable queued material system, then lock it
m_QMS = Host_AllowQueuedMaterialSystem( false );
m_MatLock = g_pMaterialSystem->Lock();
}
~ResourceLocker()
{
// Restore QMS
materials->Unlock( m_MatLock );
Host_AllowQueuedMaterialSystem( m_QMS );
g_pFileSystem->AsyncResume();
// ??? What? Why?
//// Need to purge cached materials due to a sv_pure change.
//g_pMaterialSystem->UncacheAllMaterials();
}
bool m_QMS;
MaterialLock_t m_MatLock;
};
// Reloads a list of files if they are still loaded
void CL_ReloadFilesInList( IFileList *pFilesToReload )
{
if ( !pFilesToReload )
{
return;
}
ResourceLocker crashPreventer;
// Handle materials..
materials->ReloadFilesInList( pFilesToReload );
// Handle models.. NOTE: this MUST come after materials->ReloadFilesInList because the
// models need to know which materials got flushed.
modelloader->ReloadFilesInList( pFilesToReload );
S_ReloadFilesInList( pFilesToReload );
// Let the client at it (for particles)
if ( g_ClientDLL )
{
g_ClientDLL->ReloadFilesInList( pFilesToReload );
}
}
void CL_HandlePureServerWhitelist( CPureServerWhitelist *pWhitelist, /* out */ IFileList *&pFilesToReload )
{
// Free the old whitelist and get the new one.
if ( cl.m_pPureServerWhitelist )
cl.m_pPureServerWhitelist->Release();
cl.m_pPureServerWhitelist = pWhitelist;
if ( cl.m_pPureServerWhitelist )
cl.m_pPureServerWhitelist->AddRef();
g_pFileSystem->RegisterFileWhitelist( pWhitelist, &pFilesToReload );
// Now that we've flushed any files that shouldn't have been on disk, we should have a CRC
// set that we can check with the server.
cl.m_bCheckCRCsWithServer = true;
}
void PrintSvPureWhitelistClassification( const CPureServerWhitelist *pWhiteList )
{
if ( pWhiteList == NULL )
{
Msg( "The server is using sv_pure -1 (no file checking).\n" );
return;
}
// Load up the default whitelist
CPureServerWhitelist *pStandardList = CPureServerWhitelist::Create( g_pFullFileSystem );
pStandardList->Load( 0 );
if ( *pStandardList == *pWhiteList )
{
Msg( "The server is using sv_pure 0. (Enforcing consistency for select files only)\n" );
}
else
{
pStandardList->Load( 2 );
if ( *pStandardList == *pWhiteList )
{
Msg( "The server is using sv_pure 2. (Fully pure)\n" );
}
else
{
Msg( "The server is using sv_pure 1. (Custom pure server rules.)\n" );
}
}
pStandardList->Release();
}
void CL_PrintWhitelistInfo()
{
PrintSvPureWhitelistClassification( cl.m_pPureServerWhitelist );
if ( cl.m_pPureServerWhitelist )
{
cl.m_pPureServerWhitelist->PrintWhitelistContents();
}
}
// Console command to force a whitelist on the system.
#ifdef _DEBUG
void whitelist_f( const CCommand &args )
{
int pureLevel = 2;
if ( args.ArgC() == 2 )
{
pureLevel = atoi( args[1] );
}
else
{
Warning( "Whitelist 0, 1, or 2\n" );
}
if ( pureLevel == 0 )
{
Warning( "whitelist 0: CL_HandlePureServerWhitelist( NULL )\n" );
IFileList *pFilesToReload = NULL;
CL_HandlePureServerWhitelist( NULL, pFilesToReload );
CL_ReloadFilesInList( pFilesToReload );
}
else
{
CPureServerWhitelist *pWhitelist = CPureServerWhitelist::Create( g_pFileSystem );
pWhitelist->Load( pureLevel == 1 );
IFileList *pFilesToReload = NULL;
CL_HandlePureServerWhitelist( pWhitelist, pFilesToReload );
CL_ReloadFilesInList( pFilesToReload );
pWhitelist->Release();
}
}
ConCommand whitelist( "whitelist", whitelist_f );
#endif
const CPrecacheUserData* CL_GetPrecacheUserData( INetworkStringTable *table, int index )
{
int testLength;
const CPrecacheUserData *data = ( CPrecacheUserData * )table->GetStringUserData( index, &testLength );
if ( data )
{
ErrorIfNot(
testLength == sizeof( *data ),
("CL_GetPrecacheUserData(%d,%d) - length (%d) invalid.", table->GetTableId(), index, testLength)
);
}
return data;
}
//-----------------------------------------------------------------------------
// Purpose: setup the demo flag, split from CL_IsHL2Demo so CL_IsHL2Demo can be inline
//-----------------------------------------------------------------------------
static bool s_bIsHL2Demo = false;
void CL_InitHL2DemoFlag()
{
#if defined(_X360)
s_bIsHL2Demo = false;
#else
static bool initialized = false;
if ( !initialized )
{
if ( Steam3Client().SteamApps() && !Q_stricmp( COM_GetModDirectory(), "hl2" ) )
{
initialized = true;
// if user didn't buy HL2 yet, this must be the free demo
if ( VCRGetMode() != VCR_Playback )
{
s_bIsHL2Demo = !Steam3Client().SteamApps()->BIsSubscribedApp( GetAppSteamAppId( k_App_HL2 ) );
}
#if !defined( NO_VCR )
VCRGenericValue( "e", &s_bIsHL2Demo, sizeof( s_bIsHL2Demo ) );
#endif
}
if ( !Q_stricmp( COM_GetModDirectory(), "hl2" ) && CommandLine()->CheckParm( "-demo" ) )
{
s_bIsHL2Demo = true;
}
}
#endif
}
//-----------------------------------------------------------------------------
// Purpose: Returns true if the user is playing the HL2 Demo (rather than the full game)
//-----------------------------------------------------------------------------
bool CL_IsHL2Demo()
{
CL_InitHL2DemoFlag();
return s_bIsHL2Demo;
}
static bool s_bIsPortalDemo = false;
void CL_InitPortalDemoFlag()
{
#if defined(_X360)
s_bIsPortalDemo = false;
#else
static bool initialized = false;
if ( !initialized )
{
if ( Steam3Client().SteamApps() && !Q_stricmp( COM_GetModDirectory(), "portal" ) )
{
initialized = true;
// if user didn't buy Portal yet, this must be the free demo
if ( VCRGetMode() != VCR_Playback )
{
s_bIsPortalDemo = !Steam3Client().SteamApps()->BIsSubscribedApp( GetAppSteamAppId( k_App_PORTAL ) );
}
#if !defined( NO_VCR )
VCRGenericValue( "e", &s_bIsPortalDemo, sizeof( s_bIsPortalDemo ) );
#endif
}
if ( !Q_stricmp( COM_GetModDirectory(), "portal" ) && CommandLine()->CheckParm( "-demo" ) )
{
s_bIsPortalDemo = true;
}
}
#endif
}
//-----------------------------------------------------------------------------
// Purpose: Returns true if the user is playing the Portal Demo (rather than the full game)
//-----------------------------------------------------------------------------
bool CL_IsPortalDemo()
{
CL_InitPortalDemoFlag();
return s_bIsPortalDemo;
}
#ifdef _XBOX
extern void Host_WriteConfiguration( const char *dirname, const char *filename );
//-----------------------------------------------------------------------------
// Convar callback to write the user configuration
//-----------------------------------------------------------------------------
void WriteConfig_f( ConVar *var, const char *pOldString )
{
Host_WriteConfiguration( "xboxuser.cfg" );
}
#endif
//-----------------------------------------------------------------------------
// Purpose: If the client is in the process of connecting and the cl.signon hits
// is complete, make sure the client thinks its totally connected.
//-----------------------------------------------------------------------------
void CL_CheckClientState( void )
{
// Setup the local network backdoor (we do this each frame so it can be toggled on and off).
bool useBackdoor = cl_LocalNetworkBackdoor.GetInt() &&
(cl.m_NetChannel ? cl.m_NetChannel->IsLoopback() : false) &&
sv.IsActive() &&
!demorecorder->IsRecording() &&
!demoplayer->IsPlayingBack() &&
Host_IsSinglePlayerGame();
CL_SetupLocalNetworkBackDoor( useBackdoor );
}
//-----------------------------------------------------------------------------
// bool CL_CheckCRCs( const char *pszMap )
//-----------------------------------------------------------------------------
bool CL_CheckCRCs( const char *pszMap )
{
CRC32_t mapCRC; // If this is the worldmap, CRC against server's map
MD5Value_t mapMD5;
V_memset( mapMD5.bits, 0, MD5_DIGEST_LENGTH );
// Don't verify CRC if we are running a local server (i.e., we are playing single player, or we are the server in multiplay
if ( sv.IsActive() ) // Single player
return true;
if ( IsX360() )
{
return true;
}
bool couldHash = false;
if ( g_ClientGlobalVariables.network_protocol > PROTOCOL_VERSION_17 )
{
couldHash = MD5_MapFile( &mapMD5, pszMap );
}
else
{
CRC32_Init(&mapCRC);
couldHash = CRC_MapFile( &mapCRC, pszMap );
}
if (!couldHash )
{
// Does the file exist?
FileHandle_t fp = 0;
int nSize = -1;
nSize = COM_OpenFile( pszMap, &fp );
if ( fp )
g_pFileSystem->Close( fp );
if ( nSize != -1 )
{
COM_ExplainDisconnection( true, "Couldn't CRC map %s, disconnecting\n", pszMap);
Host_Error( "Bad map" );
}
else
{
COM_ExplainDisconnection( true, "Missing map %s, disconnecting\n", pszMap);
Host_Error( "Map is missing" );
}
return false;
}
bool hashValid = false;
if ( g_ClientGlobalVariables.network_protocol > PROTOCOL_VERSION_17 )
{
hashValid = MD5_Compare( cl.serverMD5, mapMD5 );
}
// Hacked map
if ( !hashValid && !demoplayer->IsPlayingBack())
{
if ( IsX360() )
{
Warning( "Disconnect: BSP CRC failed!\n" );
}
COM_ExplainDisconnection( true, "Your map [%s] differs from the server's.\n", pszMap );
Host_Error( "Client's map differs from the server's" );
return false;
}
return true;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : nMaxClients -
//-----------------------------------------------------------------------------
void CL_ReallocateDynamicData( int maxclients )
{
Assert( entitylist );
if ( entitylist )
{
entitylist->SetMaxEntities( MAX_EDICTS );
}
}
/*
=================
CL_ReadPackets
Updates the local time and reads/handles messages on client net connection.
=================
*/
void CL_ReadPackets ( bool bFinalTick )
{
VPROF_BUDGET( "CL_ReadPackets", VPROF_BUDGETGROUP_OTHER_NETWORKING );
tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ );
if ( !Host_ShouldRun() )
return;
// update client times/tick
cl.oldtickcount = cl.GetServerTickCount();
if ( !cl.IsPaused() )
{
cl.SetClientTickCount( cl.GetClientTickCount() + 1 );
// While clock correction is off, we have the old behavior of matching the client and server clocks.
if ( !CClockDriftMgr::IsClockCorrectionEnabled() )
cl.SetServerTickCount( cl.GetClientTickCount() );
g_ClientGlobalVariables.tickcount = cl.GetClientTickCount();
g_ClientGlobalVariables.curtime = cl.GetTime();
}
// 0 or tick_rate if simulating
g_ClientGlobalVariables.frametime = cl.GetFrameTime();
// read packets, if any in queue
if ( demoplayer->IsPlayingBack() && cl.m_NetChannel )
{
tmZoneFiltered( TELEMETRY_LEVEL0, 50, TMZF_NONE, "ReadPacket" );
// process data from demo file
cl.m_NetChannel->ProcessPlayback();
}
else
{
if ( !cl_ignorepackets.GetInt() )
{
tmZoneFiltered( TELEMETRY_LEVEL0, 50, TMZF_NONE, "ProcessSocket" );
// process data from net socket
NET_ProcessSocket( NS_CLIENT, &cl );
}
}
// check timeout, but not if running _DEBUG engine
#if !defined( _DEBUG )
// Only check on final frame because that's when the server might send us a packet in single player. This avoids
// a bug where if you sit in the game code in the debugger then you get a timeout here on resuming the engine
// because the timestep is > 1 tick because of the debugging delay but the server hasn't sent the next packet yet. ywb 9/5/03
if ( (cl.m_NetChannel?cl.m_NetChannel->IsTimedOut():false) &&
bFinalTick &&
!demoplayer->IsPlayingBack() &&
cl.IsConnected() )
{
ConMsg ("\nServer connection timed out.\n");
// Show the vgui dialog on timeout
COM_ExplainDisconnection( false, "Lost connection to server.");
if ( IsPC() )
{
EngineVGui()->ShowErrorMessage();
}
Host_Disconnect( true, "Lost connection" );
return;
}
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CL_ClearState ( void )
{
// clear out the current whitelist
IFileList *pFilesToReload = NULL;
CL_HandlePureServerWhitelist( NULL, pFilesToReload );
CL_ReloadFilesInList( pFilesToReload );
CL_ResetEntityBits();
R_UnloadSkys();
// clear decal index directories
Decal_Init();
StaticPropMgr()->LevelShutdownClient();
// shutdown this level in the client DLL
if ( g_ClientDLL )
{
if ( host_state.worldmodel )
{
char mapname[256];
CL_SetupMapName( modelloader->GetName( host_state.worldmodel ), mapname, sizeof( mapname ) );
phonehome->Message( IPhoneHome::PHONE_MSG_MAPEND, mapname );
}
audiosourcecache->LevelShutdown();
g_ClientDLL->LevelShutdown();
}
R_LevelShutdown();
if ( IsX360() )
{
// Reset material system temporary memory (frees up memory for map loading)
bool bOnLevelShutdown = true;
materials->ResetTempHWMemory( bOnLevelShutdown );
}
if ( g_pLocalNetworkBackdoor )
g_pLocalNetworkBackdoor->ClearState();
// clear other arrays
memset (cl_dlights, 0, sizeof(cl_dlights));
memset (cl_elights, 0, sizeof(cl_elights));
// Wipe the hunk ( unless the server is active )
Host_FreeStateAndWorld( false );
Host_FreeToLowMark( false );
PhonemeMP3Shutdown();
// Wipe the remainder of the structure.
cl.Clear();
}
//-----------------------------------------------------------------------------
// Purpose: Used for sorting sounds
// Input : &sound1 -
// &sound2 -
// Output : static bool
//-----------------------------------------------------------------------------
static bool CL_SoundMessageLessFunc( SoundInfo_t const &sound1, SoundInfo_t const &sound2 )
{
return sound1.nSequenceNumber < sound2.nSequenceNumber;
}
static CUtlRBTree< SoundInfo_t, int > g_SoundMessages( 0, 0, CL_SoundMessageLessFunc );
extern ConVar snd_show;
//-----------------------------------------------------------------------------
// Purpose: Add sound to queue
// Input : sound -
//-----------------------------------------------------------------------------
void CL_AddSound( const SoundInfo_t &sound )
{
g_SoundMessages.Insert( sound );
}
//-----------------------------------------------------------------------------
// Purpose: Play sound packet
// Input : sound -
//-----------------------------------------------------------------------------
void CL_DispatchSound( const SoundInfo_t &sound )
{
int nSoundNum = sound.nSoundNum;
CSfxTable *pSfx;
char name[ MAX_QPATH ];
name[ 0 ] = 0;
if ( sound.bIsSentence )
{
// make dummy sfx for sentences
const char *pSentenceName = VOX_SentenceNameFromIndex( sound.nSoundNum );
if ( !pSentenceName )
{
pSentenceName = "";
}
V_snprintf( name, sizeof( name ), "%c%s", CHAR_SENTENCE, pSentenceName );
pSfx = S_DummySfx( name );
}
else
{
V_strncpy( name, cl.GetSoundName( sound.nSoundNum ), sizeof( name ) );
const char *pchTranslatedName = g_ClientDLL->TranslateEffectForVisionFilter( "sounds", name );
if ( V_strcmp( pchTranslatedName, name ) != 0 )
{
V_strncpy( name, pchTranslatedName, sizeof( name ) );
nSoundNum = cl.LookupSoundIndex( name );
}
pSfx = cl.GetSound( nSoundNum );
}
if ( snd_show.GetInt() >= 2 )
{
DevMsg( "%i (seq %i) %s : src %d : ch %d : %d dB : vol %.2f : time %.3f (%.4f delay) @%.1f %.1f %.1f\n",
host_framecount,
sound.nSequenceNumber,
name,
sound.nEntityIndex,
sound.nChannel,
sound.Soundlevel,
sound.fVolume,
cl.GetTime(),
sound.fDelay,
sound.vOrigin.x,
sound.vOrigin.y,
sound.vOrigin.z );
}
StartSoundParams_t params;
params.staticsound = (sound.nChannel == CHAN_STATIC) ? true : false;
params.soundsource = sound.nEntityIndex;
params.entchannel = params.staticsound ? CHAN_STATIC : sound.nChannel;
params.pSfx = pSfx;
params.origin = sound.vOrigin;
params.fvol = sound.fVolume;
params.soundlevel = sound.Soundlevel;
params.flags = sound.nFlags;
params.pitch = sound.nPitch;
params.specialdsp = sound.nSpecialDSP;
params.fromserver = true;
params.delay = sound.fDelay;
// we always want to do this when this flag is set - even if the delay is zero we need to precisely
// schedule this sound
if ( sound.nFlags & SND_DELAY )
{
// anything adjusted less than 100ms forward was probably scheduled this frame
if ( sound.fDelay > -0.100f )
{
float soundtime = cl.m_flLastServerTickTime + sound.fDelay;
// this adjusts for host_thread_mode or any other cases where we're running more than one
// tick at a time, but we get network updates on the first tick
soundtime -= ((g_ClientGlobalVariables.simTicksThisFrame-1) * host_state.interval_per_tick);
// this sound was networked over from the server, use server clock
params.delay = S_ComputeDelayForSoundtime( soundtime, CLOCK_SYNC_SERVER );
#if 0
static float lastSoundTime = 0;
Msg("[%.3f] Play %s at %.3f %.1fsms delay\n", soundtime - lastSoundTime, name, soundtime, params.delay * 1000.0f );
lastSoundTime = soundtime;
#endif
if ( params.delay <= 0 )
{
// leave a little delay to flag the channel in the low-level sound system
params.delay = 1e-6f;
}
}
else
{
params.delay = sound.fDelay;
}
}
params.speakerentity = sound.nSpeakerEntity;
// Give the client DLL a chance to run arbitrary code to affect the sound parameters before we
// play.
g_ClientDLL->ClientAdjustStartSoundParams( params );
if ( params.staticsound )
{
S_StartSound( params );
}
else
{
// Don't actually play non-static sounds if playing a demo and skipping ahead
// but always stop sounds
if ( demoplayer->IsSkipping() && !(sound.nFlags&SND_STOP) )
{
return;
}
S_StartSound( params );
}
}
//-----------------------------------------------------------------------------
// Purpose: Called after reading network messages to play sounds encoded in the network packet
//-----------------------------------------------------------------------------
void CL_DispatchSounds( void )
{
int i;
// Walk list in sequence order
i = g_SoundMessages.FirstInorder();
while ( i != g_SoundMessages.InvalidIndex() )
{
SoundInfo_t const *msg = &g_SoundMessages[ i ];
Assert( msg );
if ( msg )
{
// Play the sound
CL_DispatchSound( *msg );
}
i = g_SoundMessages.NextInorder( i );
}
// Reset the queue each time we empty it!!!
g_SoundMessages.RemoveAll();
}
//-----------------------------------------------------------------------------
// Retry last connection (e.g., after we enter a password)
//-----------------------------------------------------------------------------
void CL_Retry()
{
if ( !cl.m_szRetryAddress[ 0 ] )
{
ConMsg( "Can't retry, no previous connection\n" );
return;
}
// Check that we can add the two execution markers
bool bCanAddExecutionMarkers = Cbuf_HasRoomForExecutionMarkers( 2 );
ConMsg( "Commencing connection retry to %s\n", cl.m_szRetryAddress );
// We need to temporarily disable this execution marker so the connect command succeeds if it was executed by the server.
// We would still need this even if we called CL_Connect directly because the connect process may execute commands which we want to succeed.
const char *pszCommand = va( "connect %s %s\n", cl.m_szRetryAddress, cl.m_sRetrySourceTag.String() );
if ( cl.m_bRestrictServerCommands && bCanAddExecutionMarkers )
Cbuf_AddTextWithMarkers( eCmdExecutionMarker_Disable_FCVAR_SERVER_CAN_EXECUTE, pszCommand, eCmdExecutionMarker_Enable_FCVAR_SERVER_CAN_EXECUTE );
else
Cbuf_AddText( pszCommand );
}
CON_COMMAND_F( retry, "Retry connection to last server.", FCVAR_DONTRECORD | FCVAR_SERVER_CAN_EXECUTE | FCVAR_CLIENTCMD_CAN_EXECUTE )
{
CL_Retry();
}
/*
=====================
CL_Connect_f
User command to connect to server
=====================
*/
void CL_Connect( const char *address, const char *pszSourceTag )
{
// If it's not a single player connection to "localhost", initialize networking & stop listenserver
if ( Q_strncmp( address, "localhost", 9 ) )
{
Host_Disconnect(false);
// allow remote
NET_SetMutiplayer( true );
// start progress bar immediately for remote connection
EngineVGui()->EnabledProgressBarForNextLoad();
SCR_BeginLoadingPlaque();
EngineVGui()->UpdateProgressBar(PROGRESS_BEGINCONNECT);
}
else
{
// we are connecting/reconnecting to local game
// so don't stop listenserver
cl.Disconnect( "Connecting to local host", false );
}
// This happens as part of the load process anyway, but on slower systems it causes the server to timeout the
// connection. Use the opportunity to flush anything before starting a new connection.
UpdateMaterialSystemConfig();
cl.Connect( address, pszSourceTag );
// Reset error conditions
gfExtendedError = false;
}
CON_COMMAND_F( connect, "Connect to specified server.", FCVAR_DONTRECORD )
{
// Default command processing considers ':' a command separator,
// and we donly want spaces to count. So we'll need to re-split the arg string
CUtlVector<char*> vecArgs;
V_SplitString( args.ArgS(), " ", vecArgs );
// How many arguments?
if ( vecArgs.Count() == 1 )
{
CL_Connect( vecArgs[0], "" );
}
else if ( vecArgs.Count() == 2 )
{
CL_Connect( vecArgs[0], vecArgs[1] );
}
else
{
ConMsg( "Usage: connect <server>\n" );
}
vecArgs.PurgeAndDeleteElements();
}
CON_COMMAND_F( redirect, "Redirect client to specified server.", FCVAR_DONTRECORD | FCVAR_SERVER_CAN_EXECUTE )
{
if ( !CBaseClientState::ConnectMethodAllowsRedirects() )
{
ConMsg( "redirect: Current connection method does not allow silent redirects.\n");
return;
}
// Default command processing considers ':' a command separator,
// and we donly want spaces to count. So we'll need to re-split the arg string
CUtlVector<char*> vecArgs;
V_SplitString( args.ArgS(), " ", vecArgs );
if ( vecArgs.Count() == 1 )
{
CL_Connect( vecArgs[0], "redirect" );
}
else
{
ConMsg( "Usage: redirect <server>\n" );
}
vecArgs.PurgeAndDeleteElements();
}
//-----------------------------------------------------------------------------
// Takes the map name, strips path and extension
//-----------------------------------------------------------------------------
void CL_SetupMapName( const char* pName, char* pFixedName, int maxlen )
{
const char* pSlash = strrchr( pName, '\\' );
const char* pSlash2 = strrchr( pName, '/' );
if (pSlash2 > pSlash)
pSlash = pSlash2;
if (pSlash)
++pSlash;
else
pSlash = pName;
Q_strncpy( pFixedName, pSlash, maxlen );
char* pExt = strchr( pFixedName, '.' );
if (pExt)
*pExt = 0;
}
CPureServerWhitelist* CL_LoadWhitelist( INetworkStringTable *pTable, const char *pName )
{
// If there is no entry for the pure server whitelist, then sv_pure is off and the client can do whatever it wants.
int iString = pTable->FindStringIndex( pName );
if ( iString == INVALID_STRING_INDEX )
return NULL;
int dataLen;
const void *pData = pTable->GetStringUserData( iString, &dataLen );
if ( pData )
{
CUtlBuffer buf( pData, dataLen, CUtlBuffer::READ_ONLY );
CPureServerWhitelist *pWhitelist = CPureServerWhitelist::Create( g_pFullFileSystem );
pWhitelist->Decode( buf );
return pWhitelist;
}
else
{
return NULL;
}
}
void CL_CheckForPureServerWhitelist( /* out */ IFileList *&pFilesToReload )
{
#ifdef DISABLE_PURE_SERVER_STUFF
return;
#endif
// Don't do sv_pure stuff in SP games or HLTV/replay
if ( cl.m_nMaxClients <= 1 || cl.ishltv || demoplayer->IsPlayingBack()
#ifdef REPLAY_ENABLED
|| cl.isreplay
#endif // ifdef REPLAY_ENABLED
)
return;
CPureServerWhitelist *pWhitelist = NULL;
if ( cl.m_pServerStartupTable )
pWhitelist = CL_LoadWhitelist( cl.m_pServerStartupTable, "PureServerWhitelist" );
PrintSvPureWhitelistClassification( pWhitelist );
CL_HandlePureServerWhitelist( pWhitelist, pFilesToReload );
if ( pWhitelist )
{
pWhitelist->Release();
}
}
int CL_GetServerQueryPort()
{
// Yes, this is ugly getting this data out of a string table. Would be better to have it in our network protocol,
// but we don't have a way to change the protocol without breaking things for people.
if ( !cl.m_pServerStartupTable )
return 0;
int iString = cl.m_pServerStartupTable->FindStringIndex( "QueryPort" );
if ( iString == INVALID_STRING_INDEX )