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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#ifndef SWDS
#include "screen.h"
#include "cl_main.h"
#include "iprediction.h"
#include "proto_oob.h"
#include "demo.h"
#include "tier0/icommandline.h"
#include "ispatialpartitioninternal.h"
#include "GameEventManager.h"
#include "cdll_engine_int.h"
#include "voice.h"
#include "host_cmd.h"
#include "server.h"
#include "convar.h"
#include "dt_recv_eng.h"
#include "dt_common_eng.h"
#include "LocalNetworkBackdoor.h"
#include "vox.h"
#include "sound.h"
#include "r_efx.h"
#include "r_local.h"
#include "decal_private.h"
#include "vgui_baseui_interface.h"
#include "host_state.h"
#include "cl_ents_parse.h"
#include "eiface.h"
#include "server.h"
#include "cl_demoactionmanager.h"
#include "decal.h"
#include "r_decal.h"
#include "materialsystem/imaterial.h"
#include "EngineSoundInternal.h"
#include "ivideomode.h"
#include "download.h"
#include "GameUI/IGameUI.h"
#include "cl_demo.h"
#include "cdll_engine_int.h"
#if defined( REPLAY_ENABLED )
#include "replay/ienginereplay.h"
#include "replay_internal.h"
#endif
#include "audio_pch.h"
#if defined ( _X360 )
#include "matchmaking.h"
#endif
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
extern IVEngineClient *engineClient;
extern CNetworkStringTableContainer *networkStringTableContainerClient;
extern CNetworkStringTableContainer *networkStringTableContainerServer;
static ConVar cl_allowupload ( "cl_allowupload", "1", FCVAR_ARCHIVE, "Client uploads customization files" );
static ConVar cl_voice_filter( "cl_voice_filter", "", 0, "Filter voice by name substring" ); // filter incoming voice data
static ConVar *replay_voice_during_playback = NULL;
extern ConCommand quit;
void CClientState::ConnectionClosing( const char * reason )
{
// if connected, shut down host
if ( m_nSignonState > SIGNONSTATE_NONE )
{
ConMsg( "Disconnect: %s.\n", reason );
if ( !Q_stricmp( reason, INVALID_STEAM_TICKET )
|| !Q_stricmp( reason, INVALID_STEAM_LOGON_TICKET_CANCELED ) )
{
g_eSteamLoginFailure = STEAMLOGINFAILURE_BADTICKET;
}
else if ( !Q_stricmp( reason, INVALID_STEAM_LOGON_NOT_CONNECTED ) )
{
g_eSteamLoginFailure = STEAMLOGINFAILURE_NOSTEAMLOGIN;
}
else if ( !Q_stricmp( reason, INVALID_STEAM_LOGGED_IN_ELSEWHERE ) )
{
g_eSteamLoginFailure = STEAMLOGINFAILURE_LOGGED_IN_ELSEWHERE;
}
else if ( !Q_stricmp( reason, INVALID_STEAM_VACBANSTATE ) )
{
g_eSteamLoginFailure = STEAMLOGINFAILURE_VACBANNED;
}
else
{
g_eSteamLoginFailure = STEAMLOGINFAILURE_NONE;
}
if ( reason && reason[0] == '#' )
{
COM_ExplainDisconnection( true, reason );
}
else
{
COM_ExplainDisconnection( true, "Disconnect: %s.\n", reason );
}
SCR_EndLoadingPlaque();
Host_Disconnect( true, reason );
}
}
void CClientState::ConnectionCrashed( const char * reason )
{
// if connected, shut down host
if ( m_nSignonState > SIGNONSTATE_NONE )
{
DebuggerBreakIfDebugging_StagingOnly();
COM_ExplainDisconnection( true, "Disconnect: %s.\n", reason );
SCR_EndLoadingPlaque();
Host_EndGame ( true, "%s", reason );
}
}
void CClientState::FileRequested(const char *fileName, unsigned int transferID)
{
ConMsg( "File '%s' requested from server %s.\n", fileName, m_NetChannel->GetAddress() );
if ( !cl_allowupload.GetBool() )
{
ConMsg( "File uploading disabled.\n" );
m_NetChannel->DenyFile( fileName, transferID );
return;
}
// TODO check if file valid for uploading
m_NetChannel->SendFile( fileName, transferID );
}
void CClientState::FileReceived( const char * fileName, unsigned int transferID )
{
#ifndef _XBOX
// check if the client donwload manager requested this file
CL_FileReceived( fileName, transferID );
// notify client dll
if ( g_ClientDLL )
{
g_ClientDLL->FileReceived( fileName, transferID );
}
#endif
}
void CClientState::FileDenied(const char *fileName, unsigned int transferID )
{
#ifndef _XBOX
// check if the file download manager requested that file
CL_FileDenied( fileName, transferID );
#endif
}
void CClientState::FileSent( const char *fileName, unsigned int transferID )
{
}
void CClientState::PacketStart( int incoming_sequence, int outgoing_acknowledged )
{
// Ack'd incoming messages.
m_nCurrentSequence = incoming_sequence;
command_ack = outgoing_acknowledged;
}
void CClientState::PacketEnd()
{
//
// we don't know if it is ok to save a demo message until
// after we have parsed the frame
//
// Play any sounds we received this packet
CL_DispatchSounds();
// Did we get any messages this tick (i.e., did we call PreEntityPacketReceived)?
if ( GetServerTickCount() != m_nDeltaTick )
return;
// How many commands total did we run this frame
int commands_acknowledged = command_ack - last_command_ack;
// COM_Log( "cl.log", "Server ack'd %i commands this frame\n", commands_acknowledged );
//Msg( "%i/%i CL_PostReadMessages: last ack %i most recent %i acked %i commands\n",
// host_framecount, cl.tickcount,
// cl.last_command_ack,
// cl.netchan->outgoing_sequence - 1,
// commands_acknowledged );
// Highest command parsed from messages
last_command_ack = command_ack;
// Let prediction copy off pristine data and report any errors, etc.
g_pClientSidePrediction->PostNetworkDataReceived( commands_acknowledged );
#ifndef _XBOX
demoaction->DispatchEvents();
#endif
}
#undef CreateEvent
void CClientState::Disconnect( const char *pszReason, bool bShowMainMenu )
{
#if defined( REPLAY_ENABLED )
if ( g_pClientReplayContext && IsConnected() )
{
g_pClientReplayContext->OnClientSideDisconnect();
}
#endif
CBaseClientState::Disconnect( pszReason, bShowMainMenu );
#ifndef _X360
IGameEvent *event = g_GameEventManager.CreateEvent( "client_disconnect" );
if ( event )
{
if ( !pszReason )
pszReason = "";
event->SetString( "message", pszReason );
g_GameEventManager.FireEventClientSide( event );
}
#endif
// stop any demo activities
#ifndef _XBOX
demoplayer->StopPlayback();
demorecorder->StopRecording();
#endif
S_StopAllSounds( true );
R_DecalTermAll();
if ( m_nMaxClients > 1 )
{
if ( EngineVGui()->IsConsoleVisible() == false )
{
// start progress bar immediately for multiplayer level transitions
EngineVGui()->EnabledProgressBarForNextLoad();
}
}
CL_ClearState();
#ifndef _XBOX
// End any in-progress downloads
CL_HTTPStop_f();
#endif
// stop loading progress bar
if (bShowMainMenu)
{
SCR_EndLoadingPlaque();
}
// notify game ui dll of out-of-in-game status
EngineVGui()->NotifyOfServerDisconnect();
if (bShowMainMenu && !engineClient->IsDrawingLoadingImage() && (cl.demonum == -1))
{
// we're not in the middle of loading something, so show the UI
if ( EngineVGui() )
{
EngineVGui()->ActivateGameUI();
}
}
HostState_OnClientDisconnected();
// if we played a demo from the startdemos list, play next one
if (cl.demonum != -1)
{
CL_NextDemo();
}
}
bool CClientState::ProcessTick( NET_Tick *msg )
{
int tick = msg->m_nTick;
m_NetChannel->SetRemoteFramerate( msg->m_flHostFrameTime, msg->m_flHostFrameTimeStdDeviation );
m_ClockDriftMgr.SetServerTick( tick );
// Remember this for GetLastTimeStamp().
m_flLastServerTickTime = tick * host_state.interval_per_tick;
// Use the server tick while reading network data (used for interpolation samples, etc).
g_ClientGlobalVariables.tickcount = tick;
g_ClientGlobalVariables.curtime = tick * host_state.interval_per_tick;
g_ClientGlobalVariables.frametime = (tick - oldtickcount) * host_state.interval_per_tick; // We used to call GetFrameTime() here, but 'insimulation' is always
// true so we have this code right in here to keep it simple.
return true;
}
bool CClientState::ProcessStringCmd( NET_StringCmd *msg )
{
return CBaseClientState::ProcessStringCmd( msg );
}
bool CClientState::ProcessServerInfo( SVC_ServerInfo *msg )
{
// Reset client state
CL_ClearState();
if ( !CBaseClientState::ProcessServerInfo( msg ) )
{
Disconnect( "CBaseClientState::ProcessServerInfo failed", true );
return false;
}
#ifndef _XBOX
if ( demoplayer->IsPlayingBack() )
{
// Because a server doesn't run during
// demoplayback, but the decal system relies on this...
m_nServerCount = gHostSpawnCount;
}
else
{
// tell demo recorder that new map is loaded and we are receiving
// it's signon data (will be written into extra demo header file)
demorecorder->SetSignonState( SIGNONSTATE_NEW );
}
#endif
// is server a HLTV proxy ?
ishltv = msg->m_bIsHLTV;
#if defined( REPLAY_ENABLED )
// is server a replay proxy ?
isreplay = msg->m_bIsReplay;
#endif
// The MD5 of the server map must match the MD5 of the client map. or else
// the client is probably cheating.
V_memcpy( serverMD5.bits, msg->m_nMapMD5.bits, MD5_DIGEST_LENGTH );
// Multiplayer game?
if ( m_nMaxClients > 1 )
{
if ( mp_decals.GetInt() < r_decals.GetInt() )
{
r_decals.SetValue( mp_decals.GetInt() );
}
}
g_ClientGlobalVariables.maxClients = m_nMaxClients;
g_ClientGlobalVariables.network_protocol = msg->m_nProtocol;
#ifdef SHARED_NET_STRING_TABLES
// use same instance of StringTableContainer as the server does
m_StringTableContainer = networkStringTableContainerServer;
CL_HookClientStringTables();
#else
// use own instance of StringTableContainer
m_StringTableContainer = networkStringTableContainerClient;
#endif
CL_ReallocateDynamicData( m_nMaxClients );
if ( sv.IsPaused() )
{
if ( msg->m_fTickInterval != host_state.interval_per_tick )
{
Host_Error( "Expecting interval_per_tick %f, got %f\n",
host_state.interval_per_tick, msg->m_fTickInterval );
return false;
}
}
else
{
host_state.interval_per_tick = msg->m_fTickInterval;
}
// Re-init hud video, especially if we changed game directories
ClientDLL_HudVidInit();
// Don't verify the map and player .mdl crc's until after any missing resources have
// been downloaded. This will still occur before requesting the rest of the signon.
gHostSpawnCount = m_nServerCount;
videomode->MarkClientViewRectDirty(); // leave intermission full screen
return true;
}
bool CClientState::ProcessClassInfo( SVC_ClassInfo *msg )
{
if ( msg->m_bCreateOnClient )
{
#ifndef _XBOX
if ( !demoplayer->IsPlayingBack() )
#endif
{
// Create all of the send tables locally
DataTable_CreateClientTablesFromServerTables();
// Now create all of the server classes locally, too
DataTable_CreateClientClassInfosFromServerClasses( this );
// store the current data tables in demo file to make sure
// they are the same during playback
#ifndef _XBOX
demorecorder->RecordServerClasses( serverGameDLL->GetAllServerClasses() );
#endif
}
LinkClasses(); // link server and client classes
}
else
{
CBaseClientState::ProcessClassInfo( msg );
}
#ifdef DEDICATED
bool bAllowMismatches = false;
#else
bool bAllowMismatches = ( demoplayer && demoplayer->IsPlayingBack() );
#endif // DEDICATED
if ( !RecvTable_CreateDecoders( serverGameDLL->GetStandardSendProxies(), bAllowMismatches ) ) // create receive table decoders
{
Host_EndGame( true, "CL_ParseClassInfo_EndClasses: CreateDecoders failed.\n" );
return false;
}
#ifndef _XBOX
if ( !demoplayer->IsPlayingBack() )
#endif
{
CLocalNetworkBackdoor::InitFastCopy();
}
return true;
}
bool CClientState::ProcessSetPause( SVC_SetPause *msg )
{
CBaseClientState::ProcessSetPause( msg );
return true;
}
bool CClientState::ProcessSetPauseTimed( SVC_SetPauseTimed *msg )
{
CBaseClientState::ProcessSetPauseTimed( msg );
return true;
}
bool CClientState::ProcessVoiceInit( SVC_VoiceInit *msg )
{
#if !defined( NO_VOICE )//#ifndef _XBOX
if ( msg->m_szVoiceCodec[0] == 0 )
{
Voice_Deinit();
}
else
{
Voice_Init( msg->m_szVoiceCodec, msg->m_nSampleRate );
}
#endif
return true;
}
ConVar voice_debugfeedback( "voice_debugfeedback", "0" );
bool CClientState::ProcessVoiceData( SVC_VoiceData *msg )
{
char chReceived[4096];
int bitsRead = msg->m_DataIn.ReadBitsClamped( chReceived, msg->m_nLength );
#if defined ( _X360 )
DWORD dwLength = msg->m_nLength;
XUID xuid = msg->m_xuid;
Audio_GetXVoice()->PlayIncomingVoiceData( xuid, (byte*)chReceived, dwLength );
if ( voice_debugfeedback.GetBool() )
{
Msg( "Received voice from: %d\n", msg->m_nFromClient + 1 );
}
return true;
#endif
#if !defined( NO_VOICE )//#ifndef _XBOX
int iEntity = msg->m_nFromClient + 1;
if ( iEntity == (m_nPlayerSlot + 1) )
{
Voice_LocalPlayerTalkingAck();
}
player_info_t playerinfo;
engineClient->GetPlayerInfo( iEntity, &playerinfo );
if ( Q_strlen( cl_voice_filter.GetString() ) > 0 && Q_strstr( playerinfo.name, cl_voice_filter.GetString() ) == NULL )
return true;
#if defined( REPLAY_ENABLED )
extern IEngineClientReplay *g_pEngineClientReplay;
bool bInReplay = engineClient->IsPlayingDemo() && g_pEngineClientReplay && g_pEngineClientReplay->IsPlayingReplayDemo();
if ( replay_voice_during_playback == NULL )
{
replay_voice_during_playback = g_pCVar->FindVar( "replay_voice_during_playback" );
Assert( replay_voice_during_playback != NULL );
}
// Don't play back voice data during replay unless the client specified it to.
if ( bInReplay && replay_voice_during_playback && !replay_voice_during_playback->GetBool() )
return true;
#endif
// Data length can be zero when the server is just acking a client's voice data.
if ( bitsRead == 0 )
return true;
if ( !Voice_Enabled() )
{
return true;
}
// Have we already initialized the channels for this guy?
int nChannel = Voice_GetChannel( iEntity );
if ( nChannel == VOICE_CHANNEL_ERROR )
{
// Create a channel in the voice engine and a channel in the sound engine for this guy.
nChannel = Voice_AssignChannel( iEntity, msg->m_bProximity );
if ( nChannel == VOICE_CHANNEL_ERROR )
{
// If they used -nosound, then it's not a problem.
if ( S_IsInitted() )
ConDMsg("ProcessVoiceData: Voice_AssignChannel failed for client %d!\n", iEntity-1);
return true;
}
}
// Give the voice engine the data (it in turn gives it to the mixer for the sound engine).
Voice_AddIncomingData( nChannel, chReceived, Bits2Bytes( bitsRead ), m_nCurrentSequence );
#endif
return true;
};
bool CClientState::ProcessPrefetch( SVC_Prefetch *msg )
{
char const *soundname = cl.GetSoundName( msg->m_nSoundIndex );
if ( soundname && soundname [ 0 ] )
{
EngineSoundClient()->PrefetchSound( soundname );
}
return true;
}
void CClientState::ProcessSoundsWithProtoVersion( SVC_Sounds *msg, CUtlVector< SoundInfo_t > &sounds, int nProtoVersion )
{
SoundInfo_t defaultSound; defaultSound.SetDefault();
SoundInfo_t *pDeltaSound = &defaultSound;
// Max is 32 in multiplayer and 255 in singleplayer
// Reserve this memory up front so it doesn't realloc under pDeltaSound pointing at it
sounds.EnsureCapacity( 256 );
for ( int i = 0; i < msg->m_nNumSounds; i++ )
{
int nSound = sounds.AddToTail();
SoundInfo_t *pSound = &(sounds[ nSound ]);
pSound->ReadDelta( pDeltaSound, msg->m_DataIn, nProtoVersion );
pDeltaSound = pSound; // copy delta values
if ( msg->m_bReliableSound )
{
// client is incrementing the reliable sequence numbers itself
m_nSoundSequence = ( m_nSoundSequence + 1 ) & SOUND_SEQNUMBER_MASK;
Assert ( pSound->nSequenceNumber == 0 );
pSound->nSequenceNumber = m_nSoundSequence;
}
}
}
bool CClientState::ProcessSounds( SVC_Sounds *msg )
{
if ( msg->m_DataIn.IsOverflowed() )
{
// Overflowed before we even started! There's nothing we can do with this buffer.
return false;
}
CUtlVector< SoundInfo_t > sounds;
int startbit = msg->m_DataIn.GetNumBitsRead();
// Process with the reported proto version
ProcessSoundsWithProtoVersion( msg, sounds, g_ClientGlobalVariables.network_protocol );
int nRelativeBitsRead = msg->m_DataIn.GetNumBitsRead() - startbit;
if ( msg->m_nLength != nRelativeBitsRead || msg->m_DataIn.IsOverflowed() )
{
// The number of bits read is not what we expect!
sounds.RemoveAll();
int nFallbackProtocol = 0;
// If the demo file thinks it's version 18 or 19, it might actually be the other.
// This is a work around for when we broke compatibility Halloween 2011.
// -Jeep
if ( g_ClientGlobalVariables.network_protocol == PROTOCOL_VERSION_18 )
{
nFallbackProtocol = PROTOCOL_VERSION_19;
}
else if ( g_ClientGlobalVariables.network_protocol == PROTOCOL_VERSION_19 )
{
nFallbackProtocol = PROTOCOL_VERSION_18;
}
if ( nFallbackProtocol != 0 )
{
// Roll back our buffer to before we read those bits and wipe the overflow flag
msg->m_DataIn.Reset();
msg->m_DataIn.Seek( startbit );
// Try again with the fallback version
ProcessSoundsWithProtoVersion( msg, sounds, nFallbackProtocol );
nRelativeBitsRead = msg->m_DataIn.GetNumBitsRead() - startbit;
}
}
if ( msg->m_nLength == nRelativeBitsRead )
{
// Now that we know the bits were read correctly, add all the sounds
for ( int i = 0; i < sounds.Count(); ++i )
{
// Add all received sounds to sorted queue (sounds may arrive in multiple messages),
// will be processed after all packets have been completely parsed
CL_AddSound( sounds[ i ] );
}
// read the correct number of bits
return true;
}
// Wipe the overflow flag and set the buffer to how much we expected to read
msg->m_DataIn.Reset();
msg->m_DataIn.Seek( startbit + msg->m_nLength );
// didn't read the correct number of bits with either proto version attempt
return false;
}
bool CClientState::ProcessFixAngle( SVC_FixAngle *msg )
{
for (int i=0 ; i<3 ; i++)
{
// Clamp between -180 and 180
if (msg->m_Angle[i]>180)
{
msg->m_Angle[i] -= 360;
}
}
if ( msg->m_bRelative )
{
// Update running counter
addangletotal += msg->m_Angle[YAW];
AddAngle a;
a.total = addangletotal;
a.starttime = m_flLastServerTickTime;
addangle.AddToTail( a );
}
else
{
viewangles = msg->m_Angle;
}
return true;
}
bool CClientState::ProcessCrosshairAngle( SVC_CrosshairAngle *msg )
{
g_ClientDLL->SetCrosshairAngle( msg->m_Angle );
return true;
}
bool CClientState::ProcessBSPDecal( SVC_BSPDecal *msg )
{
model_t * model;
if ( msg->m_nEntityIndex )
{
model = GetModel( msg->m_nModelIndex );
}
else
{
model = host_state.worldmodel;
if ( !model )
{
Warning( "ProcessBSPDecal: Trying to project on world before host_state.worldmodel is set!!!\n" );
}
}
if ( model == NULL )
{
IMaterial *mat = Draw_DecalMaterial( msg->m_nDecalTextureIndex );
char const *matname = "???";
if ( mat )
{
matname = mat->GetName();
}
Warning( "Warning! Static BSP decal (%s), on NULL model index %i for entity index %i.\n",
matname,
msg->m_nModelIndex,
msg->m_nEntityIndex );
return true;
}
if (r_decals.GetInt())
{
g_pEfx->DecalShoot(
msg->m_nDecalTextureIndex,
msg->m_nEntityIndex,
model,
vec3_origin,
vec3_angle,
msg->m_Pos,
NULL,
msg->m_bLowPriority ? 0 : FDECAL_PERMANENT );
}
return true;
}
bool CClientState::ProcessGameEvent(SVC_GameEvent *msg)
{
tmZoneFiltered( TELEMETRY_LEVEL0, 50, TMZF_NONE, "%s", __FUNCTION__ );
int startbit = msg->m_DataIn.GetNumBitsRead();
IGameEvent *event = g_GameEventManager.UnserializeEvent( &msg->m_DataIn );
int length = msg->m_DataIn.GetNumBitsRead() - startbit;
if ( length != msg->m_nLength )
{
DevMsg("CClientState::ProcessGameEvent: KeyValue length mismatch.\n" );
return true;
}
if ( !event )
{
DevMsg("CClientState::ProcessGameEvent: UnserializeKeyValue failed.\n" );
return true;
}
g_GameEventManager.FireEventClientSide( event );
return true;
}
bool CClientState::ProcessUserMessage(SVC_UserMessage *msg)
{
// buffer for incoming user message
ALIGN4 byte userdata[ MAX_USER_MSG_DATA ] ALIGN4_POST = { 0 };
bf_read userMsg( "UserMessage(read)", userdata, sizeof( userdata ) );
int bitsRead = msg->m_DataIn.ReadBitsClamped( userdata, msg->m_nLength );
userMsg.StartReading( userdata, Bits2Bytes( bitsRead ) );
// dispatch message to client.dll
if ( !g_ClientDLL->DispatchUserMessage( msg->m_nMsgType, userMsg ) )
{
ConMsg( "Couldn't dispatch user message (%i)\n", msg->m_nMsgType );
return false;
}
return true;
}
bool CClientState::ProcessEntityMessage(SVC_EntityMessage *msg)
{
// Look up entity
IClientNetworkable *entity = entitylist->GetClientNetworkable( msg->m_nEntityIndex );
if ( !entity )
{
// message was send to use, even we don't have this entity TODO change that on server side
return true;
}
// route to entity
MDLCACHE_CRITICAL_SECTION_( g_pMDLCache );
// buffer for incoming user message
ALIGN4 byte entityData[ MAX_ENTITY_MSG_DATA ] ALIGN4_POST = { 0 };
bf_read entMsg( "EntityMessage(read)", entityData, sizeof( entityData ) );
int bitsRead = msg->m_DataIn.ReadBitsClamped( entityData, msg->m_nLength );
entMsg.StartReading( entityData, Bits2Bytes( bitsRead ) );
entity->ReceiveMessage( msg->m_nClassID, entMsg );
return true;
}
bool CClientState::ProcessPacketEntities( SVC_PacketEntities *msg )
{
if ( !msg->m_bIsDelta )
{
// Delta too old or is initial message
#ifndef _XBOX
// we can start recording now that we've received an uncompressed packet
demorecorder->SetSignonState( SIGNONSTATE_FULL );
#endif
// Tell prediction that we're recreating entities due to an uncompressed packet arriving
if ( g_pClientSidePrediction )
{
g_pClientSidePrediction->OnReceivedUncompressedPacket();
}
}
else
{
if ( m_nDeltaTick == -1 )
{
// we requested a full update but still got a delta compressed packet. ignore it.
return true;
}
// Preprocessing primarily does client prediction. So if we're processing deltas--do it
// otherwise, we're about to be told exactly what the state of everything is--so skip it.
CL_PreprocessEntities(); // setup client prediction
}
TRACE_PACKET(( "CL Receive (%d <-%d)\n", m_nCurrentSequence, msg->m_nDeltaFrom ));
TRACE_PACKET(( "CL Num Ents (%d)\n", msg->m_nUpdatedEntries ));
if ( g_pLocalNetworkBackdoor )
{
if ( m_nSignonState == SIGNONSTATE_SPAWN )
{
// We are done with signon sequence.
SetSignonState( SIGNONSTATE_FULL, m_nServerCount );
}
// ignore message, all entities are transmitted using fast local memcopy routines
m_nDeltaTick = GetServerTickCount();
return true;
}
if ( !CL_ProcessPacketEntities ( msg ) )
return false;
return CBaseClientState::ProcessPacketEntities( msg );
}
bool CClientState::ProcessTempEntities( SVC_TempEntities *msg )
{
bool bReliable = false;
float fire_time = cl.GetTime();
#ifndef _XBOX
// delay firing temp ents by cl_interp in multiplayer or demoplayback
if ( cl.m_nMaxClients > 1 || demoplayer->IsPlayingBack() )
{
float flInterpAmount = GetClientInterpAmount();
fire_time += flInterpAmount;
}
#endif
if ( msg->m_nNumEntries == 0 )
{
bReliable = true;
msg->m_nNumEntries = 1;
}
int flags = bReliable ? FEV_RELIABLE : 0;
// Don't actually queue unreliable events if playing a demo and skipping ahead
#ifndef _XBOX
if ( !bReliable && demoplayer->IsSkipping() )
{
return true;
}
#endif
bf_read &buffer = msg->m_DataIn; // shortcut
int classID = -1;
void *from = NULL;
C_ServerClassInfo *pServerClass = NULL;
ClientClass *pClientClass = NULL;
ALIGN4 unsigned char data[CEventInfo::MAX_EVENT_DATA] ALIGN4_POST;
bf_write toBuf( data, sizeof(data) );
CEventInfo *ei = NULL;
for (int i = 0; i < msg->m_nNumEntries; i++ )
{
float delay = 0.0f;
if ( buffer.ReadOneBit() )
{
delay = (float)buffer.ReadSBitLong( 8 ) / 100.0f;
}
toBuf.Reset();
if ( buffer.ReadOneBit() )
{
from = NULL; // full update
classID = buffer.ReadUBitLong( m_nServerClassBits ); // classID
// Look up the client class, etc.
// Match the server classes to the client classes.
pServerClass = m_pServerClasses ? &m_pServerClasses[ classID - 1 ] : NULL;
if ( !pServerClass )
{
DevMsg("CL_QueueEvent: missing server class info for %i.\n", classID - 1 );
return false;
}
// See if the client .dll has a handler for this class
pClientClass = FindClientClass( pServerClass->m_ClassName );
if ( !pClientClass || !pClientClass->m_pRecvTable )
{
DevMsg("CL_QueueEvent: missing client receive table for %s.\n", pServerClass->m_ClassName );
return false;
}
RecvTable_MergeDeltas( pClientClass->m_pRecvTable, NULL, &buffer, &toBuf );
}
else
{
Assert( ei );
unsigned int buffer_size = PAD_NUMBER( Bits2Bytes( ei->bits ), 4 );
bf_read fromBuf( ei->pData, buffer_size );
RecvTable_MergeDeltas( pClientClass->m_pRecvTable, &fromBuf, &buffer, &toBuf );
}
// Add a slot
ei = &cl.events[ cl.events.AddToTail() ];
Assert( ei );
int size = Bits2Bytes(toBuf.GetNumBitsWritten() );
ei->classID = classID;
ei->fire_delay = fire_time + delay;
ei->flags = flags;
ei->pClientClass = pClientClass;
ei->bits = toBuf.GetNumBitsWritten();
// deltaBitsReader.ReadNextPropIndex reads uint32s, so make sure we alloc in 4-byte chunks.
ei->pData = new byte[ ALIGN_VALUE( size, 4 ) ]; // copy raw data
Q_memcpy( ei->pData, data, size );
}
return true;
}
#endif // swds
|