-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuakeClient.cpp
1137 lines (1040 loc) · 26 KB
/
QuakeClient.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
// QuakeClient.cpp: implementation of the CQuakeClient class.
//
// Pandora Bot v2.0
// By Darrin W. Cullop ([email protected])
//
// Copyright (c) 1998-1999 by Darrin W. Cullop. All Rights Reserved.
//
// Permission to use, copy and distribute unedited copies of this whole
// document is hereby granted, provided that no fee is charged for the
// use or availability of this document (other than the normal connection
// costs for on-line services, if applicable). The above copyright notice
// and this permission notice must be left intact in all copies of this
// document. Short excerpts of this document may be quoted in discussion
// groups or mailing list articles, as long as a reference to the full
// document is given.
//
// Commercial distribution of this document, in whole or in part,
// requires prior agreement with the author. Commercial distribution
// includes any means by which the user has to pay either for the support
// (e.g. book, newsletter or CD-ROM) or for the document itself.
//
// Unauthorized commercial distribution is prohibited.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Pandora.h"
#include "QuakeClient.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#ifdef _DEBUG
#define PACKET_TYPE_DEBUG
#endif
#ifdef PACKET_TYPE_DEBUG
#define PACKET_TYPE_TRACE ::AfxTrace
#else
#define PACKET_TYPE_TRACE (void)0
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CQuakeClient::CQuakeClient()
{
m_tTotalConnect.SetValue( 0.0 );
m_qsSocket.SetClientMode();
m_nRefFrame = 0;
m_nFrameNumber = 0;
m_nRetries = 0;
m_nRetriesMax = 0;
}
//////////////////////////////////////////////////////////////////////
// Operations
//////////////////////////////////////////////////////////////////////
void CQuakeClient::Connect(const CString& strConnectInfo)
{
m_strRemoteInfo = strConnectInfo;
OnPreConnect();
SendChallengeRequest();
}
void CQuakeClient::DisplayText( const UINT& nResID )
{
DisplayText( CString((LPCSTR)nResID) );
}
void CQuakeClient::DisplayText( const CString& strText )
{
CTextMessage* pDisplay = new CTextMessage;
pDisplay->SetText( strText );
ProcessDisplayText( pDisplay );
}
void CQuakeClient::GetConnectTime( CString& strTime ) const
{
if ( m_csStatus == csConnected )
{
CAdvTime tTemp( m_tCurrentConnect.Elapsed() + m_tTotalConnect );
tTemp.GetString( strTime );
}
else
{
m_tTotalConnect.GetString( strTime );
}
}
void CQuakeClient::Say(const CString& strSayText)
{
CString strMessage;
strMessage.Format( CString((LPCSTR)IDS_CMD_SAY), strSayText );
SendStringCmd( strMessage );
}
void CQuakeClient::SayTeam(const CString& strSayText)
{
CString strMessage;
strMessage.Format( CString((LPCSTR)IDS_CMD_SAYTEAM), strSayText );
SendStringCmd( strMessage );
}
void CQuakeClient::SendMove( const CBotMove& rNewMove )
{
m_mlMoves.NewMove( rNewMove, GetBot()->GetPlayerInfo().GetDeltaAngles() );
SendMove();
}
void CQuakeClient::Wave( const BYTE nWaveType )
{
CString strFormat;
CString strWaveCmd;
strFormat.LoadString( IDS_FMT_CMD_WAVE );
strWaveCmd.Format( strFormat, nWaveType );
SendStringCmd( strWaveCmd );
}
//////////////////////////////////////////////////////////////////////
// Overrides
//////////////////////////////////////////////////////////////////////
void CQuakeClient::OnDisconnected()
{
CQuakeConnect::OnDisconnected();
m_tTotalConnect += m_tCurrentConnect.Elapsed();
Reset();
m_nRetries = 0;
}
void CQuakeClient::ProcessConnectionless( const CString& strMessage )
{
CString strCommand = strMessage.SpanExcluding(" ");
if ( m_csStatus != csConnected )
{
CString strTemp;
strTemp.LoadString( IDS_CMD_CHALLENGE_ACCEPT );
if ( strCommand == strTemp )
{
strCommand = strMessage.Right( strMessage.GetLength() - strCommand.GetLength() - 1 );
SendConnectRequest( strCommand );
}
else
{
strTemp.LoadString( IDS_CMD_CONNECT_RESPONSE );
if ( strCommand == strTemp )
{
SendStringCmd( IDS_CMD_NEW );
}
else
{
if ( m_csStatus != csLevelChange )
{
DisplayText( strMessage );
if (m_nRetries < m_nRetriesMax)
{
m_nRetries++;
m_qsSocket.ResendLastConnectionless();
}
else
{
Disconnect();
}
}
}
}
}
else
{
// TODO: Write code to parse the "Status" responses
}
}
void CQuakeClient::ProcessDataPacket( CQuakePacket* pData )
{
BYTE nMessageID;
PACKET_TYPE_TRACE("*** Begin Server Data Decode ***\n");
Lock();
while ( pData->DataToRead() )
{
nMessageID = pData->ReadByte();
switch( nMessageID )
{
case SVC_BAD:
ProcessErrorMessage( IDS_ERR_SVC_BAD );
OnServerReadError( pData );
break;
case SVC_MUZZLEFLASH:
PACKET_TYPE_TRACE("\tGot a SVC_MUZZLEFLASH!\n");
DecodeMuzzleFlash( pData );
break;
case SVC_MUZZLFLASH2:
PACKET_TYPE_TRACE("\tGot a SVC_MUZZLFLASH2!\n");
DecodeMuzzleFlash2( pData );
break;
case SVC_TEMP_ENTITY:
PACKET_TYPE_TRACE("\tGot a SVC_TEMP_ENTITY!\n");
DecodeTempEntity( pData );
break;
case SVC_LAYOUT:
PACKET_TYPE_TRACE("\tGot a SVC_LAYOUT!\n");
DecodeLayout( pData );
break;
case SVC_INVENTORY:
PACKET_TYPE_TRACE("\tGot a SVC_INVENTORY!\n");
DecodeInventory( pData );
break;
case SVC_NOP:
PACKET_TYPE_TRACE("\tGot a SVC_NOP!\n");
OnServerNoOp();
break;
case SVC_DISCONNECT:
PACKET_TYPE_TRACE("\tGot a SVC_DISCONNECT!\n");
OnServerDisconnect();
pData->SkipToEnd();
break;
case SVC_RECONNECT:
PACKET_TYPE_TRACE("\tGot a SVC_RECONNECT!\n");
OnServerReconnect();
pData->SkipToEnd();
break;
case SVC_SOUND:
PACKET_TYPE_TRACE("\tGot a SVC_SOUND!\n");
DecodeSound( pData );
break;
case SVC_PRINT:
PACKET_TYPE_TRACE("\tGot a SVC_PRINT!\n");
DecodePrint( pData );
break;
case SVC_STUFFTEXT:
PACKET_TYPE_TRACE("\tGot a SVC_STUFFTEXT!\n");
DecodeStuffText( pData );
break;
case SVC_SERVERDATA:
PACKET_TYPE_TRACE("\tGot a SVC_SERVERDATA!\n");
DecodeServerData( pData );
break;
case SVC_CONFIGSTRING:
PACKET_TYPE_TRACE("\tGot a SVC_CONFIGSTRING!\n");
DecodeConfigString( pData );
break;
case SVC_SPAWNBASELINE:
PACKET_TYPE_TRACE("\tGot a SVC_SPAWNBASELINE!\n");
DecodeSpawnBaseline( pData );
break;
case SVC_CENTERPRINT:
PACKET_TYPE_TRACE("\tGot a SVC_CENTERPRINT!\n");
DecodeCenterPrint( pData );
break;
case SVC_DOWNLOAD:
PACKET_TYPE_TRACE("\tGot a SVC_DOWNLOAD!\n");
DecodeDownload( pData );
break;
case SVC_PLAYERINFO:
PACKET_TYPE_TRACE("\tGot a SVC_PLAYERINFO!\n");
DecodePlayerInfo( pData );
break;
case SVC_PACKETENTITIES:
PACKET_TYPE_TRACE("\tGot a SVC_PACKETENTITIES!\n");
DecodePacketEntities( pData );
break;
case SVC_DELTAPACKETENTITIES:
PACKET_TYPE_TRACE("\tGot a SVC_DELTAPACKETENTITIES!\n");
DecodeDeltaPacketEntities( pData );
break;
case SVC_FRAME:
PACKET_TYPE_TRACE("\tGot a SVC_FRAME!\n");
DecodeFrame( pData );
break;
default:
ProcessErrorMessage( IDS_ERR_UNKNOWN_MESSAGE );
OnServerReadError( pData );
break;
}
}
PACKET_TYPE_TRACE("*** End Server Data Decode ***\n");
Unlock();
}
void CQuakeClient::SendDisconnect()
{
SendStringCmd( IDS_CMD_DISCONNECT );
}
//////////////////////////////////////////////////////////////////////
// Overridables
//////////////////////////////////////////////////////////////////////
void CQuakeClient::OnLevelChange()
{
m_csStatus = csLevelChange;
Reset();
SendStringCmd( IDS_CMD_NEW );
m_tTotalConnect += m_tCurrentConnect.Elapsed();
m_nFrameNumber = -1;
//OnServerBeginLevel();
}
void CQuakeClient::OnPreConnect()
{
if ( m_csStatus == csConnected )
{
Disconnect();
}
Reset();
m_qsSocket.Disconnect();
m_qsSocket.Init( DEFAULT_CLIENT_PORT );
m_qsSocket.SetRemoteInfo( m_strRemoteInfo, DEFAULT_SERVER_PORT );
}
void CQuakeClient::OnServerBeginLevel()
{
m_csStatus = csConnected;
DisplayText( IDS_CONNECTED );
m_mlMoves.BeginLevel();
// BeginLevel();
m_tCurrentConnect.SetCurrent();
}
void CQuakeClient::OnServerDisconnect()
{
DisplayText( IDS_DISCONNECTED );
OnDisconnected();
}
void CQuakeClient::OnServerReadError( CQuakePacket* pData )
{
ProcessErrorMessage( IDS_ERR_NETWORK_READ );
pData->SkipToEnd();
SendDisconnect();
}
void CQuakeClient::OnServerReconnect()
{
DisplayText( IDS_RECONNECT );
OnPreConnect();
SendChallengeRequest();
}
void CQuakeClient::ProcessCenterText( const CString& strCenter )
{
TRACE("Center: %s\n", strCenter);
}
void CQuakeClient::ProcessDisplayText( CTextMessage* pDisplay )
{
ASSERT( pDisplay != NULL );
TRACE("Display Message: %s\n", pDisplay->GetText());
delete pDisplay;
}
void CQuakeClient::ProcessLayout( const CString& strLayout )
{
TRACE("Layout: %s\n", strLayout);
}
void CQuakeClient::ProcessPrint( CTextMessage* pPrintMe )
{
ASSERT( pPrintMe != NULL );
TRACE("Print Message: %s\n", pPrintMe->GetText());
delete pPrintMe;
}
void CQuakeClient::ProcessSound( CSound* pSound )
{
ASSERT( pSound != NULL );
delete pSound;
}
void CQuakeClient::ProcessStuffText( const CString& strCmd )
{
CString strTemp;
strTemp.LoadString( IDS_CMD_RECONNECT );
if ( strCmd.Left(strTemp.GetLength()) == strTemp )
{
OnLevelChange();
}
else
{
strTemp.LoadString( IDS_CMD_PRECACHE );
if ( strCmd.Left(strTemp.GetLength()) == strTemp )
{
CString strTemp2;
strTemp2 = strCmd.Right( strCmd.GetLength() - strTemp.GetLength() );
strTemp.LoadString( IDS_CMD_BEGIN );
SendStringCmd( strTemp + strTemp2 );
OnServerBeginLevel();
}
else
{
strTemp.LoadString( IDS_CMD_CONSOLE );
if ( strCmd.Left(strTemp.GetLength()) == strTemp )
{
CString strTemp2;
strTemp2 = strCmd.Right( strCmd.GetLength() - strTemp.GetLength() );
//strTemp2.TrimRight();
//strTemp2.TrimLeft();
SendStringCmd( strTemp2 );
}
}
}
}
void CQuakeClient::ProcessTempEntity( CTempEntity* pTempEnt )
{
ASSERT( pTempEnt != NULL );
delete pTempEnt;
}
/////////////////////////////////////////////////////////////////////////////
// CQuakeClient private operations
// Send Functions
void CQuakeClient::SendChallengeRequest()
{
CString strConnect;
m_csStatus = csConnecting;
strConnect.LoadString( IDS_CMD_CHALLENGE_REQUEST );
m_qsSocket.SendConnectionless( strConnect );
}
void CQuakeClient::SendConnectRequest(const CString& strChallengeID)
{
CString strConnect;
strConnect.Format( "%s %d %d %s \"%s\"\n",
CString( (LPCSTR)IDS_CMD_CONNECT_REQUEST ), PROTOCOL_VERSION,
m_qsSocket.GetQPort(), strChallengeID, GetClientStats());
m_qsSocket.SendConnectionless( strConnect );
}
void CQuakeClient::SendNoOp()
{
CQuakePacket* pNoOp = new CQuakePacket;
pNoOp->WriteByte( CLC_NOP );
m_qsSocket.SendUnreliable( pNoOp );
}
void CQuakeClient::SendStringCmd(const CString& strCmd)
{
CQuakePacket* pStringCmd = new CQuakePacket;
pStringCmd->WriteByte( CLC_STRINGCMD );
pStringCmd->WriteString( strCmd );
m_qsSocket.SendReliable( pStringCmd );
}
void CQuakeClient::SendStringCmd(const UINT& nResID)
{
CString strTemp;
strTemp.LoadString( nResID );
SendStringCmd( strTemp );
}
void CQuakeClient::SendUserInfo(const CString& strInfo)
{
CQuakePacket* pUserInfo = new CQuakePacket;
pUserInfo->WriteByte( CLC_USERINFO );
pUserInfo->WriteString( strInfo );
m_qsSocket.SendReliable( pUserInfo );
}
void CQuakeClient::SendMove()
{
if (m_csStatus == csConnected)
{
CQuakePacket* pSendMove;
CMoveData* pToSend;
BYTE nCheckSum;
BYTE nRenderTime;
register int nCount;
pSendMove = new CQuakePacket;
pSendMove->WriteLong( GetFrameNumber() );
m_mlMoves.Lock();
for (nCount = 0; nCount < MOVE_FRAMES ; nCount++)
{
pToSend = m_mlMoves.GetMoveFrame( nCount );
ASSERT( pToSend != NULL );
pSendMove->WriteByte( pToSend->GetBitMask() );
if ( pToSend->IsFlagSet(BM_PITCH) )
{
pSendMove->WriteShort( pToSend->GetPitch() );
}
if ( pToSend->IsFlagSet(BM_YAW) )
{
pSendMove->WriteShort( pToSend->GetYaw() );
}
if ( pToSend->IsFlagSet(BM_ROLL) )
{
pSendMove->WriteShort( pToSend->GetRoll() );
}
if ( pToSend->IsFlagSet(BM_FORWARD) )
{
pSendMove->WriteShort( pToSend->GetForward() );
}
if ( pToSend->IsFlagSet(BM_RIGHT) )
{
pSendMove->WriteShort( pToSend->GetRight() );
}
if ( pToSend->IsFlagSet(BM_UP) )
{
pSendMove->WriteShort( pToSend->GetUp() );
}
if ( pToSend->IsFlagSet(BM_BUTTONS) )
{
pSendMove->WriteByte( pToSend->GetButtons() );
}
if ( pToSend->IsFlagSet(BM_IMPULSE) )
{
pSendMove->WriteByte( pToSend->GetImpulse() );
}
nRenderTime = pToSend->GetMilliseconds();
if ( nRenderTime == 0 )
{
TRACE( "Zero Render Time\n" );
nRenderTime = ((BYTE)((double)m_tLastMove.Elapsed() * 1000));
m_tLastMove.SetCurrent();
pToSend->SetMilliseconds( nRenderTime );
}
pSendMove->WriteByte( nRenderTime );
pSendMove->WriteByte( pToSend->GetLighting() );
}
m_mlMoves.Unlock();
UINT nSeqNum = m_qsSocket.GetNextSequenceNumber();
while ((nSeqNum % 0x798) > 0x794)
{
m_qsSocket.SkipSequenceNumber();
nSeqNum = m_qsSocket.GetNextSequenceNumber();
}
nCheckSum = ComputeChecksum( pSendMove, nSeqNum );
pSendMove->Insert( nCheckSum );
pSendMove->Insert( CLC_MOVE );
m_qsSocket.SendUnreliable( pSendMove );
OnMoveSent();
}
}
// Receive Functions
void CQuakeClient::DecodeMuzzleFlash( CQuakePacket* pData )
{
WORD nPlayer = pData->ReadShort();
BYTE nEffect = pData->ReadByte();
CEntity* pEntity = GetEntity( nPlayer );
if (pEntity == NULL)
{
ProcessErrorMessage( IDS_ERR_MUZZLEFLASH );
}
else
{
pEntity->SetMuzzleFlash( nEffect );
OnMuzzleFlash( nPlayer );
}
}
void CQuakeClient::DecodeMuzzleFlash2( CQuakePacket* pData )
{
WORD nEntity = pData->ReadShort();
BYTE nEffect = pData->ReadByte();
CEntity* pEntity = GetEntity( nEntity );
if (pEntity == NULL)
{
ProcessErrorMessage( IDS_ERR_MUZZLEFLASH2 );
}
else
{
pEntity->SetMuzzleFlash2( nEffect );
OnMuzzleFlash2( nEntity );
}
}
void CQuakeClient::DecodeTempEntity( CQuakePacket* pData )
{
CTempEntity* pNew = new CTempEntity;
pData->ReadByte( pNew->GetSetType() );
switch( pNew->GetType() )
{
// point entity
case TE_EXPLOSION1:
case TE_EXPLOSION2:
case TE_ROCKET_EXPLOSION:
case TE_GRENADE_EXPLOSION:
case TE_ROCKET_EXPLOSION_WATER:
case TE_GRENADE_EXPLOSION_WATER:
case TE_BFG_EXPLOSION:
case TE_BFG_BIGEXPLOSION:
case TE_BOSSTPORT:
pData->ReadVector( pNew->GetSetOrigin() );
break;
// impact entity
case TE_GUNSHOT:
case TE_BLOOD:
case TE_BLASTER:
case TE_SHOTGUN:
case TE_SPARKS:
case TE_SCREEN_SPARKS:
case TE_SHIELD_SPARKS:
case TE_BULLET_SPARKS:
case TE_GREENBLOOD:
pData->ReadVector( pNew->GetSetOrigin() );
pData->ReadByte( pNew->GetSetDirectionIndex() );
break;
// line entity
case TE_RAILTRAIL:
case TE_BUBBLETRAIL:
case TE_BFG_LASER:
case TE_PLASMATRAIL:
pData->ReadVector( pNew->GetSetOrigin() );
pData->ReadVector( pNew->GetSetEndPosition() );
break;
// special entity
case TE_SPLASH:
pData->ReadByte( pNew->GetSetCount() );
pData->ReadVector( pNew->GetSetOrigin() );
pData->ReadByte( pNew->GetSetDirectionIndex() );
pData->ReadByte( pNew->GetSetSounds() );
break;
case TE_LASER_SPARKS:
case TE_WELDING_SPARKS:
pData->ReadByte( pNew->GetSetCount() );
pData->ReadVector( pNew->GetSetOrigin() );
pData->ReadByte( pNew->GetSetDirectionIndex() );
pData->ReadByte( pNew->GetSetColor() );
break;
case TE_PARASITE_ATTACK:
case TE_MEDIC_CABLE_ATTACK:
pData->ReadWord( pNew->GetSetEntity() );
pData->ReadVector( pNew->GetSetOrigin() );
pData->ReadVector( pNew->GetSetEndPosition() );
break;
case TE_GRAPPLE_CABLE:
pData->ReadWord( pNew->GetSetEntity() );
pData->ReadVector( pNew->GetSetOrigin() );
pData->ReadVector( pNew->GetSetEndPosition() );
pData->ReadVector( pNew->GetSetOffset() );
break;
default:
TRACE("UNKNOWN TEMP ENTITY: %d\r\n", pNew->GetType());
ProcessErrorMessage( IDS_ERR_UNKNOWN_TEMP_ENTITY );
delete pNew;
pNew = NULL;
OnServerReadError( pData );
break;
}
if ( pNew != NULL )
{
ProcessTempEntity( pNew );
}
}
void CQuakeClient::DecodeLayout( CQuakePacket* pData )
{
CString strTemp;
pData->ReadString( strTemp );
ProcessLayout( strTemp );
}
void CQuakeClient::DecodeInventory( CQuakePacket* pData )
{
CBot* pBot = GetBot();
register int nCount;
WORD nAmount;
for (nCount = 0; nCount < MAX_ITEMS; nCount++)
{
nAmount = pData->ReadShort();
pBot->SetItemCount( nCount, nAmount );
}
OnUpdateInventory();
}
void CQuakeClient::DecodeSound( CQuakePacket* pData )
{
CSound* pNew = new CSound;
BYTE nBitMask;
pData->ReadByte( nBitMask );
pData->ReadByte( pNew->GetSetSoundIndex() );
// Read the volume level
if (nBitMask & 0x01)
{
pNew->SetVolume( ((float)pData->ReadByte() / ((float)255.0)) );
}
else
{
pNew->SetVolume( 1.0 );
}
// Read the Attenuation
if (nBitMask & 0x02)
{
pNew->SetAttenuation( pData->ReadByte() >> 6 );
}
else
{
pNew->SetAttenuation( 1 );
}
// Read the TimeOffset
if (nBitMask & 0x10)
{
pData->ReadByte( pNew->GetSetTimeOffset() );
}
if (nBitMask & 0x08)
{
pData->ReadWord( pNew->GetSetEntity_Channel() );
}
if (nBitMask & 0x04)
{
pData->ReadVector( pNew->GetSetOrigin() );
}
ProcessSound( pNew );
}
void CQuakeClient::DecodePrint( CQuakePacket* pData )
{
CTextMessage* pPrint = new CTextMessage;
pData->ReadByte( pPrint->GetSetType() );
pData->ReadString( pPrint->GetSetText() );
ProcessPrint( pPrint );
}
void CQuakeClient::DecodeStuffText( CQuakePacket* pData )
{
CString strTemp;
CString strCmd;
pData->ReadString( strTemp );
while ( strTemp.GetLength() )
{
strCmd = strTemp.SpanExcluding(";");
strTemp = strTemp.Right( strTemp.GetLength() - strCmd.GetLength() - 1 );
strCmd.TrimRight();
strCmd.TrimLeft();
ProcessStuffText( strCmd );
if ( strTemp.GetLength() )
{
strCmd = strTemp.SpanIncluding(";");
strTemp = strTemp.Right( strTemp.GetLength() - strCmd.GetLength() );
strTemp.TrimRight();
strTemp.TrimLeft();
}
}
}
void CQuakeClient::DecodeServerData( CQuakePacket* pData )
{
pData->ReadLong( m_nServerVersion );
if ( m_nServerVersion != PROTOCOL_VERSION )
{
TRACE("Incorrect server version: %d\r\n", m_nServerVersion);
ProcessErrorMessage( IDS_ERR_INCORRECT_SERVER_VERSION );
OnServerDisconnect();
}
else
{
pData->ReadLong( m_nLevelKey );
pData->ReadByte( m_nIsDemo );
pData->ReadString( m_strGameDir );
pData->ReadWord( GetSetBotNumber() );
pData->ReadString( m_strMapName );
OnUpdateServerData();
}
}
void CQuakeClient::DecodeConfigString( CQuakePacket* pData )
{
WORD nIndex = pData->ReadShort();
CString strConfig = pData->ReadString();
SetConfigString( nIndex, strConfig );
}
void CQuakeClient::DecodeSpawnBaseline( CQuakePacket* pData )
{
UINT nBitMask;
WORD nEntity;
DecodeEntityHeader( pData, nEntity, nBitMask );
DecodeEntityState( pData, (GetEntity(nEntity))->GetBaseline(), nBitMask );
}
void CQuakeClient::DecodeCenterPrint( CQuakePacket* pData )
{
CString strTemp;
pData->ReadString( strTemp );
ProcessCenterText( strTemp );
}
void CQuakeClient::DecodeDownload( CQuakePacket* pData )
{
TRACE("Received Download Message!\r\n");
ProcessErrorMessage( IDS_ERR_SVC_DOWNLOAD );
OnServerReadError( pData );
}
void CQuakeClient::DecodePlayerInfo( CQuakePacket* pData )
{
CPlayerInfo* pCurrent = GetBot()->GetPlayerInfoPtr();
UINT nBitMask = pData->ReadShort();
register int nCount;
// TODO: #define the bitmask values
if (nBitMask & 0x0001)
{
pData->ReadByte( pCurrent->GetSetMoveType() );
}
if (nBitMask & 0x0002)
{
pCurrent->SetOrigin( pData->ReadVector() );
}
if (nBitMask & 0x0004)
{
pCurrent->SetVelocity( pData->ReadVector() );
}
if (nBitMask & 0x0008)
{
pData->ReadByte( pCurrent->GetSetMoveTime() );
}
if (nBitMask & 0x0010)
{
pData->ReadByte( pCurrent->GetSetMoveFlags() );
}
if (nBitMask & 0x0020)
{
pData->ReadWord( pCurrent->GetSetGravity() );
}
if (nBitMask & 0x0040)
{
pData->ReadAngles16( pCurrent->GetSetDeltaAngles() );
}
if (nBitMask & 0x0080)
{
pCurrent->GetSetViewOffset().SetX( pData->ReadChar() / ((float)4.0) );
pCurrent->GetSetViewOffset().SetY( pData->ReadChar() / ((float)4.0) );
pCurrent->GetSetViewOffset().SetZ( pData->ReadChar() / ((float)4.0) );
}
if (nBitMask & 0x0100)
{
pData->ReadAngles16( pCurrent->GetSetViewAngles() );
}
if (nBitMask & 0x0200)
{
pCurrent->GetSetKickAngles().SetX( pData->ReadChar() / ((float)4.0) );
pCurrent->GetSetKickAngles().SetY( pData->ReadChar() / ((float)4.0) );
pCurrent->GetSetKickAngles().SetZ( pData->ReadChar() / ((float)4.0) );
}
if (nBitMask & 0x1000)
{
pCurrent->SetGunIndex( pData->ReadByte() );
}
if (nBitMask & 0x2000)
{
pData->ReadByte( pCurrent->GetSetGunFrame() );
pCurrent->GetSetGunOffset().SetX( pData->ReadChar() / ((float)4.0) );
pCurrent->GetSetGunOffset().SetY( pData->ReadChar() / ((float)4.0) );
pCurrent->GetSetGunOffset().SetZ( pData->ReadChar() / ((float)4.0) );
pCurrent->GetSetGunAngles().SetX( pData->ReadChar() / ((float)4.0) );
pCurrent->GetSetGunAngles().SetY( pData->ReadChar() / ((float)4.0) );
pCurrent->GetSetGunAngles().SetZ( pData->ReadChar() / ((float)4.0) );
}
if (nBitMask & 0x0400)
{
for (nCount = 0 ; nCount < MAX_BLENDS ; nCount++)
{
pCurrent->GetSetBlend(nCount) = ( pData->ReadByte() / ((float)255.0) );
}
}
if (nBitMask & 0x0800)
{
pData->ReadByte( pCurrent->GetSetFOV() );
}
if (nBitMask & 0x4000)
{
pData->ReadByte( pCurrent->GetSetRenderFlags() );
}
// Read in the Stat Fields
pData->ReadLong( (long&)nBitMask );
for (nCount = 0 ; nCount < MAX_STATS ; nCount++)
{
if (nBitMask & (0x00000001 << nCount))
{
pCurrent->SetStat( nCount, pData->ReadShort() );
}
}
}
void CQuakeClient::DecodePacketEntities( CQuakePacket* pData )
{
CEntityState* pCurrent;
CEntity* pEntity;
UINT nBitMask;
WORD nEntity;
DecodeEntityHeader( pData, nEntity, nBitMask);
while ( nEntity )
{
pEntity = GetEntity( nEntity );
ASSERT( pEntity != NULL );
pEntity->BeforeUpdate( m_nFrameNumber, m_nRefFrame );
pCurrent = pEntity->GetCurrent();
DecodeEntityState( pData, pCurrent, nBitMask );
if ( pCurrent->GetActive() )
{
OnUpdateEntityActive( nEntity );
}
else
{
OnUpdateEntityRemove( nEntity );
}
pEntity->AfterUpdate();
DecodeEntityHeader( pData, nEntity, nBitMask );
}
}
void CQuakeClient::DecodeDeltaPacketEntities( CQuakePacket* pData )
{
ProcessErrorMessage( IDS_ERR_SVC_DELTAPACKETENTITIES );
OnServerReadError( pData );
}
void CQuakeClient::DecodeFrame( CQuakePacket* pData )
{
BYTE nCount;
pData->ReadUInt( m_nFrameNumber );
pData->ReadUInt( m_nRefFrame );
// Skip the odd byte added in protocol version 31
pData->ReadByte();
// Read in the visibility list
// TODO : Store / use this information
pData->ReadByte( nCount );
while ( nCount-- )
{
pData->ReadByte();
}
// Process the new frame information
if (!NewFrame( m_nFrameNumber, m_nRefFrame ))
{
ProcessErrorMessage( IDS_ERR_NEW_FRAME );
OnServerReadError( pData );
}
// m_mlMoves.ComputeDeltaOrigin( 2.0f * (m_qsSocket.GetPing() / 1000.0f) );
// The above line has been changed to:
m_mlMoves.ComputeDeltaOrigin( (m_qsSocket.GetPing() / 500.0f) );
TRACE("\tNew DeltaOrigin: %s\n", GetDeltaOrigin().GetString() );
}
void CQuakeClient::DecodeEntityHeader( CQuakePacket* pData, WORD& nEntity, UINT& nBitMask )
{
nBitMask = pData->ReadByte();
if (nBitMask & 0x00000080)
{
nBitMask |= (pData->ReadByte() << 8);
}
if (nBitMask & 0x00008000)
{
nBitMask |= (pData->ReadByte() << 16);
}
if (nBitMask & 0x00800000)
{
nBitMask |= (pData->ReadByte() << 24);
}
nEntity = (nBitMask & 0x00000100) ? pData->ReadShort() : pData->ReadByte();
}
void CQuakeClient::DecodeEntityState( CQuakePacket* pData, CEntityState* pNew, const UINT& nBitMask )
{
if (nBitMask & 0x00000040)
{
pNew->SetActive( FALSE );
}
else
{
pNew->SetActive( TRUE );