-
Notifications
You must be signed in to change notification settings - Fork 637
/
Copy pathclient.cpp
1925 lines (1587 loc) · 51.6 KB
/
client.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 (c) 1996-2001, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
// Robin, 4-22-98: Moved set_suicide_frame() here from player.cpp to allow us to
// have one without a hardcoded player.mdl in tf_client.cpp
/*
===== client.cpp ========================================================
client/server game specific stuff
*/
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "saverestore.h"
#include "player.h"
#include "spectator.h"
#include "client.h"
#include "soundent.h"
#include "gamerules.h"
#include "game.h"
#include "customentity.h"
#include "weapons.h"
#include "weaponinfo.h"
#include "usercmd.h"
#include "netadr.h"
#include "pm_shared.h"
#if !defined ( _WIN32 )
#include <ctype.h>
#endif
extern DLL_GLOBAL ULONG g_ulModelIndexPlayer;
extern DLL_GLOBAL BOOL g_fGameOver;
extern DLL_GLOBAL int g_iSkillLevel;
extern DLL_GLOBAL ULONG g_ulFrameCount;
extern void CopyToBodyQue(entvars_t* pev);
extern int giPrecacheGrunt;
extern int gmsgSayText;
extern cvar_t allow_spectators;
extern int g_teamplay;
void LinkUserMessages( void );
/*
* used by kill command and disconnect command
* ROBIN: Moved here from player.cpp, to allow multiple player models
*/
void set_suicide_frame(entvars_t* pev)
{
if (!FStrEq(STRING(pev->model), "models/player.mdl"))
return; // allready gibbed
// pev->frame = $deatha11;
pev->solid = SOLID_NOT;
pev->movetype = MOVETYPE_TOSS;
pev->deadflag = DEAD_DEAD;
pev->nextthink = -1;
}
/*
===========
ClientConnect
called when a player connects to a server
============
*/
BOOL ClientConnect( edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ] )
{
return g_pGameRules->ClientConnected( pEntity, pszName, pszAddress, szRejectReason );
// a client connecting during an intermission can cause problems
// if (intermission_running)
// ExitIntermission ();
}
/*
===========
ClientDisconnect
called when a player disconnects from a server
GLOBALS ASSUMED SET: g_fGameOver
============
*/
void ClientDisconnect( edict_t *pEntity )
{
if (g_fGameOver)
return;
char text[256] = "" ;
if ( pEntity->v.netname )
_snprintf( text, sizeof(text), "- %s has left the game\n", STRING(pEntity->v.netname) );
text[ sizeof(text) - 1 ] = 0;
MESSAGE_BEGIN( MSG_ALL, gmsgSayText, NULL );
WRITE_BYTE( ENTINDEX(pEntity) );
WRITE_STRING( text );
MESSAGE_END();
CSound *pSound;
pSound = CSoundEnt::SoundPointerForIndex( CSoundEnt::ClientSoundIndex( pEntity ) );
{
// since this client isn't around to think anymore, reset their sound.
if ( pSound )
{
pSound->Reset();
}
}
// since the edict doesn't get deleted, fix it so it doesn't interfere.
pEntity->v.takedamage = DAMAGE_NO;// don't attract autoaim
pEntity->v.solid = SOLID_NOT;// nonsolid
UTIL_SetOrigin ( &pEntity->v, pEntity->v.origin );
g_pGameRules->ClientDisconnected( pEntity );
}
// called by ClientKill and DeadThink
void respawn(entvars_t* pev, BOOL fCopyCorpse)
{
if (gpGlobals->coop || gpGlobals->deathmatch)
{
if ( fCopyCorpse )
{
// make a copy of the dead body for appearances sake
CopyToBodyQue(pev);
}
// respawn player
GetClassPtr( (CBasePlayer *)pev)->Spawn( );
}
else
{ // restart the entire server
SERVER_COMMAND("reload\n");
}
}
/*
============
ClientKill
Player entered the suicide command
GLOBALS ASSUMED SET: g_ulModelIndexPlayer
============
*/
void ClientKill( edict_t *pEntity )
{
entvars_t *pev = &pEntity->v;
CBasePlayer *pl = (CBasePlayer*) CBasePlayer::Instance( pev );
if ( pl->m_fNextSuicideTime > gpGlobals->time )
return; // prevent suiciding too ofter
pl->m_fNextSuicideTime = gpGlobals->time + 1; // don't let them suicide for 5 seconds after suiciding
// have the player kill themself
pev->health = 0;
pl->Killed( pev, GIB_NEVER );
// pev->modelindex = g_ulModelIndexPlayer;
// pev->frags -= 2; // extra penalty
// respawn( pev );
}
/*
===========
ClientPutInServer
called each time a player is spawned
============
*/
void ClientPutInServer( edict_t *pEntity )
{
CBasePlayer *pPlayer;
entvars_t *pev = &pEntity->v;
pPlayer = GetClassPtr((CBasePlayer *)pev);
pPlayer->SetCustomDecalFrames(-1); // Assume none;
// Allocate a CBasePlayer for pev, and call spawn
pPlayer->Spawn() ;
// Reset interpolation during first frame
pPlayer->pev->effects |= EF_NOINTERP;
pPlayer->pev->iuser1 = 0; // disable any spec modes
pPlayer->pev->iuser2 = 0;
}
#include "voice_gamemgr.h"
extern CVoiceGameMgr g_VoiceGameMgr;
#if defined( _MSC_VER ) || defined( WIN32 )
typedef wchar_t uchar16;
typedef unsigned int uchar32;
#else
typedef unsigned short uchar16;
typedef wchar_t uchar32;
#endif
//-----------------------------------------------------------------------------
// Purpose: determine if a uchar32 represents a valid Unicode code point
//-----------------------------------------------------------------------------
bool Q_IsValidUChar32( uchar32 uVal )
{
// Values > 0x10FFFF are explicitly invalid; ditto for UTF-16 surrogate halves,
// values ending in FFFE or FFFF, or values in the 0x00FDD0-0x00FDEF reserved range
return ( uVal < 0x110000u ) && ( (uVal - 0x00D800u) > 0x7FFu ) && ( (uVal & 0xFFFFu) < 0xFFFEu ) && ( ( uVal - 0x00FDD0u ) > 0x1Fu );
}
// Decode one character from a UTF-8 encoded string. Treats 6-byte CESU-8 sequences
// as a single character, as if they were a correctly-encoded 4-byte UTF-8 sequence.
int Q_UTF8ToUChar32( const char *pUTF8_, uchar32 &uValueOut, bool &bErrorOut )
{
const uint8 *pUTF8 = (const uint8 *)pUTF8_;
int nBytes = 1;
uint32 uValue = pUTF8[0];
uint32 uMinValue = 0;
// 0....... single byte
if ( uValue < 0x80 )
goto decodeFinishedNoCheck;
// Expecting at least a two-byte sequence with 0xC0 <= first <= 0xF7 (110...... and 11110...)
if ( (uValue - 0xC0u) > 0x37u || ( pUTF8[1] & 0xC0 ) != 0x80 )
goto decodeError;
uValue = (uValue << 6) - (0xC0 << 6) + pUTF8[1] - 0x80;
nBytes = 2;
uMinValue = 0x80;
// 110..... two-byte lead byte
if ( !( uValue & (0x20 << 6) ) )
goto decodeFinished;
// Expecting at least a three-byte sequence
if ( ( pUTF8[2] & 0xC0 ) != 0x80 )
goto decodeError;
uValue = (uValue << 6) - (0x20 << 12) + pUTF8[2] - 0x80;
nBytes = 3;
uMinValue = 0x800;
// 1110.... three-byte lead byte
if ( !( uValue & (0x10 << 12) ) )
goto decodeFinishedMaybeCESU8;
// Expecting a four-byte sequence, longest permissible in UTF-8
if ( ( pUTF8[3] & 0xC0 ) != 0x80 )
goto decodeError;
uValue = (uValue << 6) - (0x10 << 18) + pUTF8[3] - 0x80;
nBytes = 4;
uMinValue = 0x10000;
// 11110... four-byte lead byte. fall through to finished.
decodeFinished:
if ( uValue >= uMinValue && Q_IsValidUChar32( uValue ) )
{
decodeFinishedNoCheck:
uValueOut = uValue;
bErrorOut = false;
return nBytes;
}
decodeError:
uValueOut = '?';
bErrorOut = true;
return nBytes;
decodeFinishedMaybeCESU8:
// Do we have a full UTF-16 surrogate pair that's been UTF-8 encoded afterwards?
// That is, do we have 0xD800-0xDBFF followed by 0xDC00-0xDFFF? If so, decode it all.
if ( ( uValue - 0xD800u ) < 0x400u && pUTF8[3] == 0xED && (uint8)( pUTF8[4] - 0xB0 ) < 0x10 && ( pUTF8[5] & 0xC0 ) == 0x80 )
{
uValue = 0x10000 + ( ( uValue - 0xD800u ) << 10 ) + ( (uint8)( pUTF8[4] - 0xB0 ) << 6 ) + pUTF8[5] - 0x80;
nBytes = 6;
uMinValue = 0x10000;
}
goto decodeFinished;
}
//-----------------------------------------------------------------------------
// Purpose: Returns true if UTF-8 string contains invalid sequences.
//-----------------------------------------------------------------------------
bool Q_UnicodeValidate( const char *pUTF8 )
{
bool bError = false;
while ( *pUTF8 )
{
uchar32 uVal;
// Our UTF-8 decoder silently fixes up 6-byte CESU-8 (improperly re-encoded UTF-16) sequences.
// However, these are technically not valid UTF-8. So if we eat 6 bytes at once, it's an error.
int nCharSize = Q_UTF8ToUChar32( pUTF8, uVal, bError );
if ( bError || nCharSize == 6 )
return false;
pUTF8 += nCharSize;
}
return true;
}
//// HOST_SAY
// String comes in as
// say blah blah blah
// or as
// blah blah blah
//
void Host_Say( edict_t *pEntity, int teamonly )
{
CBasePlayer *client;
int j;
char *p;
char text[128];
char szTemp[256];
const char *cpSay = "say";
const char *cpSayTeam = "say_team";
const char *pcmd = CMD_ARGV(0);
// We can get a raw string now, without the "say " prepended
if ( CMD_ARGC() == 0 )
return;
entvars_t *pev = &pEntity->v;
CBasePlayer* player = GetClassPtr((CBasePlayer *)pev);
//Not yet.
if ( player->m_flNextChatTime > gpGlobals->time )
return;
if ( !stricmp( pcmd, cpSay) || !stricmp( pcmd, cpSayTeam ) )
{
if ( CMD_ARGC() >= 2 )
{
p = (char *)CMD_ARGS();
}
else
{
// say with a blank message, nothing to do
return;
}
}
else // Raw text, need to prepend argv[0]
{
if ( CMD_ARGC() >= 2 )
{
sprintf( szTemp, "%s %s", ( char * )pcmd, (char *)CMD_ARGS() );
}
else
{
// Just a one word command, use the first word...sigh
sprintf( szTemp, "%s", ( char * )pcmd );
}
p = szTemp;
}
// remove quotes if present
if (*p == '"')
{
p++;
p[strlen(p)-1] = 0;
}
// make sure the text has content
if ( !p || !p[0] || !Q_UnicodeValidate ( p ) )
return; // no character found, so say nothing
// turn on color set 2 (color on, no sound)
// turn on color set 2 (color on, no sound)
if ( player->IsObserver() && ( teamonly ) )
sprintf( text, "%c(SPEC) %s: ", 2, STRING( pEntity->v.netname ) );
else if ( teamonly )
sprintf( text, "%c(TEAM) %s: ", 2, STRING( pEntity->v.netname ) );
else
sprintf( text, "%c%s: ", 2, STRING( pEntity->v.netname ) );
j = sizeof(text) - 2 - strlen(text); // -2 for /n and null terminator
if ( (int)strlen(p) > j )
p[j] = 0;
strcat( text, p );
strcat( text, "\n" );
player->m_flNextChatTime = gpGlobals->time + CHAT_INTERVAL;
// loop through all players
// Start with the first player.
// This may return the world in single player if the client types something between levels or during spawn
// so check it, or it will infinite loop
client = NULL;
while ( ((client = (CBasePlayer*)UTIL_FindEntityByClassname( client, "player" )) != NULL) && (!FNullEnt(client->edict())) )
{
if ( !client->pev )
continue;
if ( client->edict() == pEntity )
continue;
if ( !(client->IsNetClient()) ) // Not a client ? (should never be true)
continue;
// can the receiver hear the sender? or has he muted him?
if ( g_VoiceGameMgr.PlayerHasBlockedPlayer( client, player ) )
continue;
if ( !player->IsObserver() && teamonly && g_pGameRules->PlayerRelationship(client, CBaseEntity::Instance(pEntity)) != GR_TEAMMATE )
continue;
// Spectators can only talk to other specs
if ( player->IsObserver() && teamonly )
if ( !client->IsObserver() )
continue;
MESSAGE_BEGIN( MSG_ONE, gmsgSayText, NULL, client->pev );
WRITE_BYTE( ENTINDEX(pEntity) );
WRITE_STRING( text );
MESSAGE_END();
}
// print to the sending client
MESSAGE_BEGIN( MSG_ONE, gmsgSayText, NULL, &pEntity->v );
WRITE_BYTE( ENTINDEX(pEntity) );
WRITE_STRING( text );
MESSAGE_END();
// echo to server console
g_engfuncs.pfnServerPrint( text );
char * temp;
if ( teamonly )
temp = "say_team";
else
temp = "say";
// team match?
if ( g_teamplay )
{
UTIL_LogPrintf( "\"%s<%i><%s><%s>\" %s \"%s\"\n",
STRING( pEntity->v.netname ),
GETPLAYERUSERID( pEntity ),
GETPLAYERAUTHID( pEntity ),
g_engfuncs.pfnInfoKeyValue( g_engfuncs.pfnGetInfoKeyBuffer( pEntity ), "model" ),
temp,
p );
}
else
{
UTIL_LogPrintf( "\"%s<%i><%s><%i>\" %s \"%s\"\n",
STRING( pEntity->v.netname ),
GETPLAYERUSERID( pEntity ),
GETPLAYERAUTHID( pEntity ),
GETPLAYERUSERID( pEntity ),
temp,
p );
}
}
/*
===========
ClientCommand
called each time a player uses a "cmd" command
============
*/
extern float g_flWeaponCheat;
// Use CMD_ARGV, CMD_ARGV, and CMD_ARGC to get pointers the character string command.
void ClientCommand( edict_t *pEntity )
{
const char *pcmd = CMD_ARGV(0);
const char *pstr;
// Is the client spawned yet?
if ( !pEntity->pvPrivateData )
return;
entvars_t *pev = &pEntity->v;
if ( FStrEq(pcmd, "say" ) )
{
Host_Say( pEntity, 0 );
}
else if ( FStrEq(pcmd, "say_team" ) )
{
Host_Say( pEntity, 1 );
}
else if ( FStrEq(pcmd, "fullupdate" ) )
{
GetClassPtr((CBasePlayer *)pev)->ForceClientDllUpdate();
}
else if ( FStrEq(pcmd, "give" ) )
{
if ( g_flWeaponCheat != 0.0)
{
int iszItem = ALLOC_STRING( CMD_ARGV(1) ); // Make a copy of the classname
GetClassPtr((CBasePlayer *)pev)->GiveNamedItem( STRING(iszItem) );
}
}
else if ( FStrEq(pcmd, "drop" ) )
{
// player is dropping an item.
GetClassPtr((CBasePlayer *)pev)->DropPlayerItem((char *)CMD_ARGV(1));
}
else if ( FStrEq(pcmd, "fov" ) )
{
if ( g_flWeaponCheat && CMD_ARGC() > 1)
{
GetClassPtr((CBasePlayer *)pev)->m_iFOV = atoi( CMD_ARGV(1) );
}
else
{
CLIENT_PRINTF( pEntity, print_console, UTIL_VarArgs( "\"fov\" is \"%d\"\n", (int)GetClassPtr((CBasePlayer *)pev)->m_iFOV ) );
}
}
else if ( FStrEq(pcmd, "use" ) )
{
GetClassPtr((CBasePlayer *)pev)->SelectItem((char *)CMD_ARGV(1));
}
else if (((pstr = strstr(pcmd, "weapon_")) != NULL) && (pstr == pcmd))
{
GetClassPtr((CBasePlayer *)pev)->SelectItem(pcmd);
}
else if (FStrEq(pcmd, "lastinv" ))
{
GetClassPtr((CBasePlayer *)pev)->SelectLastItem();
}
else if ( FStrEq( pcmd, "spectate" ) ) // clients wants to become a spectator
{
// always allow proxies to become a spectator
if ( (pev->flags & FL_PROXY) || allow_spectators.value )
{
CBasePlayer * pPlayer = GetClassPtr((CBasePlayer *)pev);
edict_t *pentSpawnSpot = g_pGameRules->GetPlayerSpawnSpot( pPlayer );
pPlayer->StartObserver( pev->origin, VARS(pentSpawnSpot)->angles);
// notify other clients of player switching to spectator mode
UTIL_ClientPrintAll( HUD_PRINTNOTIFY, UTIL_VarArgs( "%s switched to spectator mode\n",
( pev->netname && STRING(pev->netname)[0] != 0 ) ? STRING(pev->netname) : "unconnected" ) );
}
else
ClientPrint( pev, HUD_PRINTCONSOLE, "Spectator mode is disabled.\n" );
}
else if ( FStrEq( pcmd, "specmode" ) ) // new spectator mode
{
CBasePlayer * pPlayer = GetClassPtr((CBasePlayer *)pev);
if ( pPlayer->IsObserver() )
pPlayer->Observer_SetMode( atoi( CMD_ARGV(1) ) );
}
else if ( FStrEq(pcmd, "closemenus" ) )
{
// just ignore it
}
else if ( FStrEq( pcmd, "follownext" ) ) // follow next player
{
CBasePlayer * pPlayer = GetClassPtr((CBasePlayer *)pev);
if ( pPlayer->IsObserver() )
pPlayer->Observer_FindNextPlayer( atoi( CMD_ARGV(1) )?true:false );
}
else if ( g_pGameRules->ClientCommand( GetClassPtr((CBasePlayer *)pev), pcmd ) )
{
// MenuSelect returns true only if the command is properly handled, so don't print a warning
}
else
{
// tell the user they entered an unknown command
char command[128];
// check the length of the command (prevents crash)
// max total length is 192 ...and we're adding a string below ("Unknown command: %s\n")
strncpy( command, pcmd, 127 );
command[127] = '\0';
// tell the user they entered an unknown command
ClientPrint( &pEntity->v, HUD_PRINTCONSOLE, UTIL_VarArgs( "Unknown command: %s\n", command ) );
}
}
/*
========================
ClientUserInfoChanged
called after the player changes
userinfo - gives dll a chance to modify it before
it gets sent into the rest of the engine.
========================
*/
void ClientUserInfoChanged( edict_t *pEntity, char *infobuffer )
{
// Is the client spawned yet?
if ( !pEntity->pvPrivateData )
return;
// msg everyone if someone changes their name, and it isn't the first time (changing no name to current name)
if ( pEntity->v.netname && STRING(pEntity->v.netname)[0] != 0 && !FStrEq( STRING(pEntity->v.netname), g_engfuncs.pfnInfoKeyValue( infobuffer, "name" )) )
{
char sName[256];
char *pName = g_engfuncs.pfnInfoKeyValue( infobuffer, "name" );
strncpy( sName, pName, sizeof(sName) - 1 );
sName[ sizeof(sName) - 1 ] = '\0';
// First parse the name and remove any %'s
for ( char *pApersand = sName; pApersand != NULL && *pApersand != 0; pApersand++ )
{
// Replace it with a space
if ( *pApersand == '%' )
*pApersand = ' ';
}
// Set the name
g_engfuncs.pfnSetClientKeyValue( ENTINDEX(pEntity), infobuffer, "name", sName );
if (gpGlobals->maxClients > 1)
{
char text[256];
sprintf( text, "* %s changed name to %s\n", STRING(pEntity->v.netname), g_engfuncs.pfnInfoKeyValue( infobuffer, "name" ) );
MESSAGE_BEGIN( MSG_ALL, gmsgSayText, NULL );
WRITE_BYTE( ENTINDEX(pEntity) );
WRITE_STRING( text );
MESSAGE_END();
}
// team match?
if ( g_teamplay )
{
UTIL_LogPrintf( "\"%s<%i><%s><%s>\" changed name to \"%s\"\n",
STRING( pEntity->v.netname ),
GETPLAYERUSERID( pEntity ),
GETPLAYERAUTHID( pEntity ),
g_engfuncs.pfnInfoKeyValue( infobuffer, "model" ),
g_engfuncs.pfnInfoKeyValue( infobuffer, "name" ) );
}
else
{
UTIL_LogPrintf( "\"%s<%i><%s><%i>\" changed name to \"%s\"\n",
STRING( pEntity->v.netname ),
GETPLAYERUSERID( pEntity ),
GETPLAYERAUTHID( pEntity ),
GETPLAYERUSERID( pEntity ),
g_engfuncs.pfnInfoKeyValue( infobuffer, "name" ) );
}
}
g_pGameRules->ClientUserInfoChanged( GetClassPtr((CBasePlayer *)&pEntity->v), infobuffer );
}
static int g_serveractive = 0;
void ServerDeactivate( void )
{
// It's possible that the engine will call this function more times than is necessary
// Therefore, only run it one time for each call to ServerActivate
if ( g_serveractive != 1 )
{
return;
}
g_serveractive = 0;
// Peform any shutdown operations here...
//
}
void ServerActivate( edict_t *pEdictList, int edictCount, int clientMax )
{
int i;
CBaseEntity *pClass;
// Every call to ServerActivate should be matched by a call to ServerDeactivate
g_serveractive = 1;
// Clients have not been initialized yet
for ( i = 0; i < edictCount; i++ )
{
if ( pEdictList[i].free )
continue;
// Clients aren't necessarily initialized until ClientPutInServer()
if ( i < clientMax || !pEdictList[i].pvPrivateData )
continue;
pClass = CBaseEntity::Instance( &pEdictList[i] );
// Activate this entity if it's got a class & isn't dormant
if ( pClass && !(pClass->pev->flags & FL_DORMANT) )
{
pClass->Activate();
}
else
{
ALERT( at_console, "Can't instance %s\n", STRING(pEdictList[i].v.classname) );
}
}
// Link user messages here to make sure first client can get them...
LinkUserMessages();
}
/*
================
PlayerPreThink
Called every frame before physics are run
================
*/
void PlayerPreThink( edict_t *pEntity )
{
entvars_t *pev = &pEntity->v;
CBasePlayer *pPlayer = (CBasePlayer *)GET_PRIVATE(pEntity);
if (pPlayer)
pPlayer->PreThink( );
}
/*
================
PlayerPostThink
Called every frame after physics are run
================
*/
void PlayerPostThink( edict_t *pEntity )
{
entvars_t *pev = &pEntity->v;
CBasePlayer *pPlayer = (CBasePlayer *)GET_PRIVATE(pEntity);
if (pPlayer)
pPlayer->PostThink( );
}
void ParmsNewLevel( void )
{
}
void ParmsChangeLevel( void )
{
// retrieve the pointer to the save data
SAVERESTOREDATA *pSaveData = (SAVERESTOREDATA *)gpGlobals->pSaveData;
if ( pSaveData )
pSaveData->connectionCount = BuildChangeList( pSaveData->levelList, MAX_LEVEL_CONNECTIONS );
}
//
// GLOBALS ASSUMED SET: g_ulFrameCount
//
void StartFrame( void )
{
if ( g_pGameRules )
g_pGameRules->Think();
if ( g_fGameOver )
return;
gpGlobals->teamplay = teamplay.value;
g_ulFrameCount++;
}
void ClientPrecache( void )
{
// setup precaches always needed
PRECACHE_SOUND("player/sprayer.wav"); // spray paint sound for PreAlpha
// PRECACHE_SOUND("player/pl_jumpland2.wav"); // UNDONE: play 2x step sound
PRECACHE_SOUND("player/pl_fallpain2.wav");
PRECACHE_SOUND("player/pl_fallpain3.wav");
PRECACHE_SOUND("player/pl_step1.wav"); // walk on concrete
PRECACHE_SOUND("player/pl_step2.wav");
PRECACHE_SOUND("player/pl_step3.wav");
PRECACHE_SOUND("player/pl_step4.wav");
PRECACHE_SOUND("common/npc_step1.wav"); // NPC walk on concrete
PRECACHE_SOUND("common/npc_step2.wav");
PRECACHE_SOUND("common/npc_step3.wav");
PRECACHE_SOUND("common/npc_step4.wav");
PRECACHE_SOUND("player/pl_metal1.wav"); // walk on metal
PRECACHE_SOUND("player/pl_metal2.wav");
PRECACHE_SOUND("player/pl_metal3.wav");
PRECACHE_SOUND("player/pl_metal4.wav");
PRECACHE_SOUND("player/pl_dirt1.wav"); // walk on dirt
PRECACHE_SOUND("player/pl_dirt2.wav");
PRECACHE_SOUND("player/pl_dirt3.wav");
PRECACHE_SOUND("player/pl_dirt4.wav");
PRECACHE_SOUND("player/pl_duct1.wav"); // walk in duct
PRECACHE_SOUND("player/pl_duct2.wav");
PRECACHE_SOUND("player/pl_duct3.wav");
PRECACHE_SOUND("player/pl_duct4.wav");
PRECACHE_SOUND("player/pl_grate1.wav"); // walk on grate
PRECACHE_SOUND("player/pl_grate2.wav");
PRECACHE_SOUND("player/pl_grate3.wav");
PRECACHE_SOUND("player/pl_grate4.wav");
PRECACHE_SOUND("player/pl_slosh1.wav"); // walk in shallow water
PRECACHE_SOUND("player/pl_slosh2.wav");
PRECACHE_SOUND("player/pl_slosh3.wav");
PRECACHE_SOUND("player/pl_slosh4.wav");
PRECACHE_SOUND("player/pl_tile1.wav"); // walk on tile
PRECACHE_SOUND("player/pl_tile2.wav");
PRECACHE_SOUND("player/pl_tile3.wav");
PRECACHE_SOUND("player/pl_tile4.wav");
PRECACHE_SOUND("player/pl_tile5.wav");
PRECACHE_SOUND("player/pl_swim1.wav"); // breathe bubbles
PRECACHE_SOUND("player/pl_swim2.wav");
PRECACHE_SOUND("player/pl_swim3.wav");
PRECACHE_SOUND("player/pl_swim4.wav");
PRECACHE_SOUND("player/pl_ladder1.wav"); // climb ladder rung
PRECACHE_SOUND("player/pl_ladder2.wav");
PRECACHE_SOUND("player/pl_ladder3.wav");
PRECACHE_SOUND("player/pl_ladder4.wav");
PRECACHE_SOUND("player/pl_wade1.wav"); // wade in water
PRECACHE_SOUND("player/pl_wade2.wav");
PRECACHE_SOUND("player/pl_wade3.wav");
PRECACHE_SOUND("player/pl_wade4.wav");
PRECACHE_SOUND("debris/wood1.wav"); // hit wood texture
PRECACHE_SOUND("debris/wood2.wav");
PRECACHE_SOUND("debris/wood3.wav");
PRECACHE_SOUND("plats/train_use1.wav"); // use a train
PRECACHE_SOUND("buttons/spark5.wav"); // hit computer texture
PRECACHE_SOUND("buttons/spark6.wav");
PRECACHE_SOUND("debris/glass1.wav");
PRECACHE_SOUND("debris/glass2.wav");
PRECACHE_SOUND("debris/glass3.wav");
PRECACHE_SOUND( SOUND_FLASHLIGHT_ON );
PRECACHE_SOUND( SOUND_FLASHLIGHT_OFF );
// player gib sounds
PRECACHE_SOUND("common/bodysplat.wav");
// player pain sounds
PRECACHE_SOUND("player/pl_pain2.wav");
PRECACHE_SOUND("player/pl_pain4.wav");
PRECACHE_SOUND("player/pl_pain5.wav");
PRECACHE_SOUND("player/pl_pain6.wav");
PRECACHE_SOUND("player/pl_pain7.wav");
PRECACHE_MODEL("models/player.mdl");
// hud sounds
PRECACHE_SOUND("common/wpn_hudoff.wav");
PRECACHE_SOUND("common/wpn_hudon.wav");
PRECACHE_SOUND("common/wpn_moveselect.wav");
PRECACHE_SOUND("common/wpn_select.wav");
PRECACHE_SOUND("common/wpn_denyselect.wav");
// geiger sounds
PRECACHE_SOUND("player/geiger6.wav");
PRECACHE_SOUND("player/geiger5.wav");
PRECACHE_SOUND("player/geiger4.wav");
PRECACHE_SOUND("player/geiger3.wav");
PRECACHE_SOUND("player/geiger2.wav");
PRECACHE_SOUND("player/geiger1.wav");
if (giPrecacheGrunt)
UTIL_PrecacheOther("monster_human_grunt");
}
/*
===============
GetGameDescription
Returns the descriptive name of this .dll. E.g., Half-Life, or Team Fortress 2
===============
*/
const char *GetGameDescription()
{
if ( g_pGameRules ) // this function may be called before the world has spawned, and the game rules initialized
return g_pGameRules->GetGameDescription();
else
return "Half-Life";
}
/*
================
Sys_Error
Engine is going to shut down, allows setting a breakpoint in game .dll to catch that occasion
================
*/
void Sys_Error( const char *error_string )
{
// Default case, do nothing. MOD AUTHORS: Add code ( e.g., _asm { int 3 }; here to cause a breakpoint for debugging your game .dlls
}
/*
================
PlayerCustomization
A new player customization has been registered on the server
UNDONE: This only sets the # of frames of the spray can logo
animation right now.
================
*/
void PlayerCustomization( edict_t *pEntity, customization_t *pCust )
{
entvars_t *pev = &pEntity->v;
CBasePlayer *pPlayer = (CBasePlayer *)GET_PRIVATE(pEntity);
if (!pPlayer)
{
ALERT(at_console, "PlayerCustomization: Couldn't get player!\n");
return;
}
if (!pCust)
{
ALERT(at_console, "PlayerCustomization: NULL customization!\n");
return;
}
switch (pCust->resource.type)
{
case t_decal:
pPlayer->SetCustomDecalFrames(pCust->nUserData2); // Second int is max # of frames.
break;
case t_sound:
case t_skin:
case t_model:
// Ignore for now.
break;
default:
ALERT(at_console, "PlayerCustomization: Unknown customization type!\n");
break;
}
}
/*
================
SpectatorConnect
A spectator has joined the game
================
*/
void SpectatorConnect( edict_t *pEntity )
{
entvars_t *pev = &pEntity->v;
CBaseSpectator *pPlayer = (CBaseSpectator *)GET_PRIVATE(pEntity);
if (pPlayer)
pPlayer->SpectatorConnect( );
}