forked from haithun/CoD4X17a_testing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsv_client.c
2365 lines (1874 loc) · 65.5 KB
/
sv_client.c
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) 2010-2013 Ninja and TheKelm of the IceOps-Team
Copyright (C) 1999-2005 Id Software, Inc.
This file is part of CoD4X17a-Server source code.
CoD4X17a-Server source code is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
CoD4X17a-Server source code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
===========================================================================
*/
#include "q_shared.h"
#include "qcommon_io.h"
#include "qcommon_mem.h"
#include "qcommon.h"
#include "huffman.h"
#include "msg.h"
#include "server.h"
#include "net_game_conf.h"
#include "misc.h"
#include "g_sv_shared.h"
#include "plugin_handler.h"
#include "q_platform.h"
#include "sys_main.h"
#include "punkbuster.h"
#include "scr_vm.h"
#include "cmd.h"
#include "sys_thread.h"
#include "hl2rcon.h"
#include <stdint.h>
#include <stdarg.h>
#include <string.h>
//AntiDoS
/*
int SV_ChallengeCookies(netadr_t from){
char string[128];
int var_01 = svs.time & 0xff000000;
Com_sprintf(string, sizeof(string), "");
return var_01;
}
*/
/*
=================
SV_GetChallenge
A "getchallenge" OOB command has been received
Returns a challenge number that can be used
in a subsequent connectResponse command.
We do this to prevent denial of service attacks that
flood the server with invalid connection IPs. With a
challenge, they must give a valid IP address.
If we are authorizing, a challenge request will cause a packet
to be sent to the authorize server.
When an authorizeip is returned, a challenge response will be
sent to that ip.
ioquake3: we added a possibility for clients to add a challenge
to their packets, to make it more difficult for malicious servers
to hi-jack client connections.
Also, the auth stuff is completely disabled for com_standalone games
as well as IPv6 connections, since there is no way to use the
v4-only auth server for these new types of connections.
=================
*/
__optimize3 __regparm1 void SV_GetChallenge(netadr_t *from)
{
int i;
int oldest;
int oldestTime;
int oldestClientTime;
int clientChallenge;
challenge_t *challenge;
oldest = 0;
oldestClientTime = oldestTime = 0x7fffffff;
// see if we already have a challenge for this ip
challenge = &svse.challenges[0];
clientChallenge = atoi(SV_Cmd_Argv(1));
for(i = 0 ; i < MAX_CHALLENGES ; i++, challenge++)
{
if(NET_CompareAdr(from, &challenge->adr))
{
if(challenge->connected){
Com_Memset(challenge, 0 ,sizeof(challenge_t));
continue;
}
if(challenge->time < oldestClientTime)
oldestClientTime = challenge->time;
break;
}
if(challenge->time < oldestTime)
{
oldestTime = challenge->time;
oldest = i;
}
}
if (i == MAX_CHALLENGES)
{
// this is the first time this client has asked for a challenge
challenge = &svse.challenges[oldest];
challenge->clientChallenge = clientChallenge;
challenge->adr = *from;
challenge->firstTime = svs.time;
challenge->connected = qfalse;
challenge->pbguid[31] = 0;
Q_strncpyz(challenge->pbguid, SV_Cmd_Argv(2),33);
challenge->ipAuthorize = 0;
challenge->challenge = ( (rand() << 16) ^ rand() ) ^ svs.time;
}
challenge->time = svs.time;
// Drop the authorize stuff if this client is coming in via IPv6 as the auth server does not support ipv6.
// Drop also for addresses coming in on local LAN and for stand-alone games independent from id's assets.
if(challenge->adr.type == NA_IP && svse.authorizeAddress.type != NA_DOWN && !Sys_IsLANAddress(from) && sv_authorizemode->integer != -1)
{
// look up the authorize server's IP
if(svse.authorizeAddress.type == NA_BAD)
{
Com_Printf( "Resolving %s\n", AUTHORIZE_SERVER_NAME );
if (NET_StringToAdr(AUTHORIZE_SERVER_NAME, &svse.authorizeAddress, NA_IP))
{
svse.authorizeAddress.port = BigShort( PORT_AUTHORIZE );
Com_Printf( "%s resolved to %s\n", AUTHORIZE_SERVER_NAME, NET_AdrToString(&svse.authorizeAddress));
}
}
// we couldn't contact the auth server, let them in.
if(svse.authorizeAddress.type == NA_BAD){
Com_Printf("Couldn't resolve auth server address\n");
svse.authorizeAddress.type = NA_DOWN;
return;
}
if(svse.authorizeAddress.type == NA_IP && challenge->adr.type == NA_IP && NET_CompareBaseAdr(from, &svse.authorizeAddress)){
//Reset the default socket so that this is forwarded to all sockets
if(NET_GetDefaultCommunicationSocket() == NULL){
NET_RegisterDefaultCommunicationSocket(from);
svse.authorizeAddress.sock = from->sock;
}
from->port = BigShort(PORT_AUTHORIZE);
NET_OutOfBandPrint( NS_SERVER, from, "getIpAuthorize %i %s \"\" 0", challenge->challenge, NET_AdrToStringShort(from));
return;
}
// if they have been challenging for a long time and we
// haven't heard anything from the authorize server, go ahead and
// let them in, assuming the id server is down
else if(svs.time - challenge->firstTime > AUTHORIZE_TIMEOUT)
Com_PrintWarning( "Activisions authorize server timed out - Accept client without validating him\n" );
else
{
if(!challenge->pbguid[31]){
return;
}
// otherwise send their ip to the authorize server
Com_DPrintf( "sending getIpAuthorize for %s\n", NET_AdrToString( from ));
// the 0 is for backwards compatibility with obsolete sv_allowanonymous flags
// getIpAuthorize <challenge> <IP> <game> 0 <auth-flag>
NET_OutOfBandPrint( NS_SERVER, from, "needcdkey");
NET_OutOfBandPrint( NS_SERVER, &svse.authorizeAddress,
"getIpAuthorize %i %s \"\" 0 PB \"%s\"",challenge->challenge, NET_AdrToStringShort(from), challenge->pbguid );
return;
}
}
if(!challenge->pbguid[31]){
return;
}
challenge->pingTime = com_frameTime;
NET_OutOfBandPrint(NS_SERVER, &challenge->adr, "challengeResponse %d %d",
challenge->challenge, clientChallenge);
}
/*
====================
SV_AuthorizeIpPacket
A packet has been returned from the authorize server.
If we have a challenge adr for that ip, send the
challengeResponse to it
====================
*/
__optimize3 __regparm1 void SV_AuthorizeIpPacket( netadr_t *from ) {
int challenge;
int i;
char *s;
char *r;
char *p;
if ( !NET_CompareBaseAdr( from, &svse.authorizeAddress )) {
Com_Printf( "SV_AuthorizeIpPacket: not from authorize server\n" );
return;
}
//This binds the serveraddress to a specific socket - No longer will this server be contacted over all sockets
if(NET_GetDefaultCommunicationSocket() == NULL){
NET_RegisterDefaultCommunicationSocket(from);
}
challenge = atoi( SV_Cmd_Argv( 1 ) );
for (i = 0 ; i < MAX_CHALLENGES ; i++) {
if ( svse.challenges[i].challenge == challenge ) {
break;
}
}
if ( i == MAX_CHALLENGES ) {
Com_Printf( "SV_AuthorizeIpPacket: challenge not found\n" );
return;
}
if(svse.challenges[i].connected){
return;
}
// send a packet back to the original client
s = SV_Cmd_Argv( 2 );
r = SV_Cmd_Argv( 3 ); // reason
p = SV_Cmd_Argv( 5 ); //pbguid
if ( !Q_stricmp( s, "demo" ) ) {
// they are a demo client trying to connect to a real server
NET_OutOfBandPrint( NS_SERVER, &svse.challenges[i].adr, "error\nServer is not a demo server\n" );
// clear the challenge record so it won't timeout and let them through
Com_Memset( &svse.challenges[i], 0, sizeof( svse.challenges[i] ) );
return;
}
if ( !Q_stricmp( s, "accept" )) {
if(Q_stricmp( p, svse.challenges[i].pbguid)){
NET_OutOfBandPrint( NS_SERVER, &svse.challenges[i].adr, "error\nEXE_ERR_BAD_CDKEY");
Com_Memset( &svse.challenges[i], 0, sizeof( svse.challenges[i] ));
return;
}else{
NET_OutOfBandPrint( NS_SERVER, &svse.challenges[i].adr, "challengeResponse %i", svse.challenges[i].challenge);
svse.challenges[i].pingTime = com_frameTime;
NET_OutOfBandPrint( NS_SERVER, &svse.challenges[i].adr, "print\n^2Success...");
svse.challenges[i].ipAuthorize = 1; //CD-KEY was valid
return;
}
}
if (!Q_stricmp( s, "deny" )) {
svse.challenges[i].ipAuthorize = -1;
if(!Q_stricmp(r, "CLIENT_UNKNOWN_TO_AUTH")){
NET_OutOfBandPrint( NS_SERVER, &svse.challenges[i].adr, "print\nUnkown how to auth client\n");
if(sv_authorizemode->integer < 1){
if(svs.time - svse.challenges[i].firstTime > AUTHORIZE_TIMEOUT){
NET_OutOfBandPrint( NS_SERVER, &svse.challenges[i].adr, "challengeResponse %i", svse.challenges[i].challenge);
}
return;
}
} else if(sv_authorizemode->integer < 1) {
NET_OutOfBandPrint( NS_SERVER, &svse.challenges[i].adr, "print\n^1Failed. ^5Trying something else...");
NET_OutOfBandPrint( NS_SERVER, &svse.challenges[i].adr, "challengeResponse %i", svse.challenges[i].challenge);
svse.challenges[i].pingTime = com_frameTime;
svse.challenges[i].ipAuthorize = -1; //CD-KEY was invalid
return;
} else if(!Q_stricmp(r, "INVALID_CDKEY")){
NET_OutOfBandPrint( NS_SERVER, &svse.challenges[i].adr, "error\n^1Someone is using this CD Key");
} else if(r){
NET_OutOfBandPrint( NS_SERVER, &svse.challenges[i].adr, "error\n^1Authorization Failed:\n%s\n", r );
}else{
NET_OutOfBandPrint( NS_SERVER, &svse.challenges[i].adr, "error\n^1Someone is using this CD Key\n" );
}
Com_Memset( &svse.challenges[i], 0, sizeof( svse.challenges[i] ) );
return;
}
NET_OutOfBandPrint( NS_SERVER, &svse.challenges[i].adr, "print\n^1Someone is using this CD Key\n" );
if(sv_authorizemode->integer < 1) {
NET_OutOfBandPrint( NS_SERVER, &svse.challenges[i].adr, "print\n^1Failed. ^5Trying something else...");
NET_OutOfBandPrint( NS_SERVER, &svse.challenges[i].adr, "challengeResponse %i", svse.challenges[i].challenge);
svse.challenges[i].pingTime = com_frameTime;
svse.challenges[i].ipAuthorize = -1; //CD-KEY was invalid
}else{
Com_Memset( &svse.challenges[i], 0, sizeof( svse.challenges[i] ) );
}
}
/*
==================
SV_DirectConnect
A "connect" OOB command has been received
==================
*/
#define PB_MESSAGE "PunkBuster Q_strncpyz( userinfo, Cmd_Argv(1), sizeof(userinfo) );Anti-Cheat software must be installed " \
"and Enabled in order to join this server. An updated game patch can be downloaded from " \
"www.idsoftware.com"
__optimize3 __regparm1 void SV_DirectConnect( netadr_t *from ) {
char userinfo[MAX_INFO_STRING];
int reconnectTime;
int c;
int j;
int i;
client_t *cl, *newcl;
int count;
char nick[33];
char ip_str[128];
int clientNum;
int version;
int qport;
int challenge;
char *password;
const char *denied;
const char *PunkBusterStatus;
Q_strncpyz( userinfo, SV_Cmd_Argv(1), sizeof(userinfo) );
challenge = atoi( Info_ValueForKey( userinfo, "challenge" ) );
qport = atoi( Info_ValueForKey( userinfo, "qport" ) );
// see if the challenge is valid
int ping;
for (c=0 ; c < MAX_CHALLENGES ; c++) {
if (NET_CompareAdr(from, &svse.challenges[c].adr)) {
if ( challenge == svse.challenges[c].challenge ) {
break; // good
}
}
}
if (c == MAX_CHALLENGES || challenge == 0) {
NET_OutOfBandPrint( NS_SERVER, from, "error\nNo or bad challenge for address.\n" );
return;
}
newcl = NULL;
// quick reject
for (j=0, cl=svs.clients ; j < sv_maxclients->integer ; j++, cl++) {
if ( NET_CompareBaseAdr( from, &cl->netchan.remoteAddress ) && (cl->netchan.qport == qport || from->port == cl->netchan.remoteAddress.port )){
reconnectTime = (svs.time - cl->lastConnectTime);
if (reconnectTime < (sv_reconnectlimit->integer * 1000)) {
Com_Printf("%s -> reconnect rejected : too soon\n", NET_AdrToString (from));
NET_OutOfBandPrint( NS_SERVER, from, "print\nReconnect limit in effect... (%i)\n",
(sv_reconnectlimit->integer - (reconnectTime / 1000)));
return;
}else{
if(cl->state > CS_ZOMBIE){ //Free up used CGame-Resources first
SV_FreeClient( cl );
}
newcl = cl;
Com_Printf("reconnected: %s\n", NET_AdrToString(from));
cl->lastConnectTime = svs.time;
break;
}
}else if ( NET_CompareBaseAdr( from, &cl->netchan.remoteAddress ) && cl->state == CS_CONNECTED){
NET_OutOfBandPrint( NS_SERVER, from,
"error\nConnection refused:\nAn uncompleted connection from %s has been detected\nPlease try again later\n",
NET_AdrToString(&cl->netchan.remoteAddress));
Com_Printf("Rejected connection from %s. This is a Fake-Player-DoS protection\n", NET_AdrToString(&cl->netchan.remoteAddress));
Com_Memset( &svse.challenges[c], 0, sizeof( svse.challenges[c] ));
return;
}
}
// force the IP key/value pair so the game can filter based on ip
Com_sprintf(ip_str, sizeof(ip_str), "%s", NET_AdrToConnectionString( from ));
Info_SetValueForKey( userinfo, "ip", ip_str );
if(!newcl && svse.challenges[c].pingTime){
ping = com_frameTime - svse.challenges[c].pingTime;
Com_Printf( "Client %i connecting with %i challenge ping\n", c, ping );
svse.challenges[c].pingTime = 0;
if ( sv_minPing->integer && ping < sv_minPing->integer ) {
// don't let them keep trying until they get a big delay
NET_OutOfBandPrint( NS_SERVER, from, "error\nServer is for high ping players only minping: %i ms but your ping was: %i ms\n",sv_minPing->integer, ping);
Com_Printf("Client %i rejected on a too low ping\n", c);
// reset the address otherwise their ping will keep increasing
// with each connect message and they'd eventually be able to connect
svse.challenges[c].adr.port = 0;
Com_Memset( &svse.challenges[c], 0, sizeof( svse.challenges[c] ));
return;
}
if ( sv_maxPing->integer && ping > sv_maxPing->integer ) {
NET_OutOfBandPrint( NS_SERVER, from, "error\nServer is for low ping players only maxping: %i ms but your ping was: %i ms\n",sv_maxPing->integer, ping);
Com_Printf("Client %i rejected on a too high ping\n", c);
Com_Memset( &svse.challenges[c], 0, sizeof( svse.challenges[c] ));
return;
}
}
Q_strncpyz(nick, Info_ValueForKey( userinfo, "name" ),33);
denied = SV_PlayerBannedByip(from);
if(denied){
NET_OutOfBandPrint( NS_SERVER, from, "error\n%s\n", denied);
Com_Memset( &svse.challenges[c], 0, sizeof( svse.challenges[c] ));
return;
}
if(strlen(svse.challenges[c].pbguid) < 10){
NET_OutOfBandPrint( NS_SERVER, from, "error\nConnection rejected: No or invalid GUID found/provided.\n" );
Com_Printf("Rejected a connection: No or invalid GUID found/provided. Length: %i\n",
strlen(svse.challenges[c].pbguid));
Com_Memset( &svse.challenges[c], 0, sizeof( svse.challenges[c] ));
return;
}
version = atoi( Info_ValueForKey( userinfo, "protocol" ));
if ( version != PROTOCOL_VERSION ) {
NET_OutOfBandPrint( NS_SERVER, from, "error\nServer uses a different protocol version: %i\n You have to install the update to Call of Duty 4 v1.7", PROTOCOL_VERSION );
Com_Printf("rejected connect from version %i\n", version);
Com_Memset( &svse.challenges[c], 0, sizeof( svse.challenges[c] ));
return;
}
// find a client slot:
// if "sv_privateClients" is set > 0, then that number
// of client slots will be reserved for connections that
// have "password" set to the value of "sv_privatePassword"
// Info requests will report the maxclients as if the private
// slots didn't exist, to prevent people from trying to connect
// to a full server.
// This is to allow us to reserve a couple slots here on our
// servers so we can play without having to kick people.
//Get new slot for client
// check for privateClient password
password = Info_ValueForKey( userinfo, "password" );
if(!newcl){
if ( !strcmp( password, sv_privatePassword->string ) ) {
for ( j = 0; j < sv_privateClients->integer ; j++) {
cl = &svs.clients[j];
if (cl->state == CS_FREE) {
newcl = cl;
break;
}
}
}
}
if(*sv_password->string && Q_strncmp(sv_password->string, password, 32)){
NET_OutOfBandPrint( NS_SERVER, from, "error\nThis server has set a join-password\n^1Invalid Password\n");
Com_Printf("Connection rejected from %s - Invalid Password\n", NET_AdrToString(from));
Com_Memset( &svse.challenges[c], 0, sizeof( svse.challenges[c] ));
return;
}
//Process queue
for(i = 0 ; i < 10 ; i++){//Purge all older players from queue
if(svse.connectqueue[i].lasttime+21 < Com_GetRealtime()){
svse.connectqueue[i].lasttime = 0;
svse.connectqueue[i].firsttime = 0;
svse.connectqueue[i].challengeslot = 0;
svse.connectqueue[i].attempts = 0;
}
}
for(i = 0 ; i < 10 ; i++){//Move waiting players up in queue if there is a purged slot
if(svse.connectqueue[i].lasttime != 0){
if(svse.connectqueue[i+1].challengeslot == svse.connectqueue[i].challengeslot){
svse.connectqueue[i+1].lasttime = 0;
svse.connectqueue[i+1].firsttime = 0;
svse.connectqueue[i+1].challengeslot = 0;
svse.connectqueue[i+1].attempts = 0;
}
}else{
Com_Memcpy(&svse.connectqueue[i],&svse.connectqueue[i+1],(9-i)*sizeof(connectqueue_t));
}
}
for(i = 0 ; i < 10 ; i++){//Find highest slot or the one which is already assigned to this player
if(svse.connectqueue[i].firsttime == 0 || svse.connectqueue[i].challengeslot == c){
break;
}
}
if(i == 0 && !newcl){
for ( j = sv_privateClients->integer; j < sv_maxclients->integer ; j++) {
cl = &svs.clients[j];
if (cl->state == CS_FREE) {
newcl = cl;
svse.connectqueue[0].lasttime = 0;
svse.connectqueue[0].firsttime = 0;
svse.connectqueue[0].challengeslot = 0;
svse.connectqueue[0].attempts = 0;
break;
}
}
}
if ( !newcl ) {
if(i == 10){
NET_OutOfBandPrint( NS_SERVER, from, "error\nServer is full. More than 10 players are in queue.\n" );
return;
}else{
NET_OutOfBandPrint( NS_SERVER, from, "print\nServer is full. %i players wait before you.\n",i);
}
if(svse.connectqueue[i].attempts > 30){
NET_OutOfBandPrint( NS_SERVER, from, "error\nServer is full. %i players wait before you.\n",i);
svse.connectqueue[i].attempts = 0;
}else if(svse.connectqueue[i].attempts > 15 && i > 1){
NET_OutOfBandPrint( NS_SERVER, from, "error\nServer is full. %i players wait before you.\n",i);
svse.connectqueue[i].attempts = 0;
}else if(svse.connectqueue[i].attempts > 5 && i > 3){
NET_OutOfBandPrint( NS_SERVER, from, "error\nServer is full. %i players wait before you.\n",i);
svse.connectqueue[i].attempts = 0;
}
if(svse.connectqueue[i].firsttime == 0){
svse.connectqueue[i].firsttime = Com_GetRealtime();
}
svse.connectqueue[i].attempts++;
svse.connectqueue[i].lasttime = Com_GetRealtime();
svse.connectqueue[i].challengeslot = c;
return;
}
//gotnewcl:
Com_Memset(newcl, 0x00, sizeof(client_t));
newcl->authentication = svse.challenges[c].ipAuthorize;
newcl->power = 0; //Sets the default power for the client
newcl->challenge = svse.challenges[c].challenge; // save the challenge
// (build a new connection
// accept the new client
// this is the only place a client_t is ever initialized)
clientNum = newcl - svs.clients;
Q_strncpyz(cl->originguid, svse.challenges[c].pbguid, 33);
Q_strncpyz(cl->pbguid, svse.challenges[c].pbguid, 33); // save the pbguid
if(psvs.useuids != 1){
if(newcl->authentication != 1 && sv_authorizemode->integer != -1){
Com_Memset(newcl->pbguid, '0', 8);
}
}else{
char ret[33];
Com_sprintf(ret,sizeof(ret),"NoGUID*%.2x%.2x%.2x%.2x%.4x",from->ip[0],from->ip[1],from->ip[2],from->ip[3],from->port);
Q_strncpyz(newcl->pbguid, ret, sizeof(newcl->pbguid)); // save the pbguid
}
denied = NULL;
// save the userinfo
Q_strncpyz(newcl->userinfo, userinfo, 1024 );
PHandler_Event(PLUGINS_ONPLAYERCONNECT, clientNum, from, newcl->originguid, userinfo, newcl->authentication, &denied);
if(!psvs.useuids)
denied = SV_PlayerIsBanned(0, newcl->pbguid, from);
else if(newcl->uid != 0)
denied = SV_PlayerIsBanned(newcl->uid, NULL, from);
if(denied){
NET_OutOfBandPrint( NS_SERVER, from, "error\n%s", denied);
Com_Memset( &svse.challenges[c], 0, sizeof( svse.challenges[c] ));
svse.connectqueue[i].lasttime = 0;
svse.connectqueue[i].firsttime = 0;
svse.connectqueue[i].challengeslot = 0;
svse.connectqueue[i].attempts = 0;
return;
}
if(strstr(Cvar_GetVariantString("noPbGuids"), newcl->originguid) && 32 == strlen(newcl->originguid) && newcl->authentication == 1){
newcl->noPb = qtrue;
}
if(newcl->noPb == qfalse){
PunkBusterStatus = PbAuthClient(NET_AdrToString(from), atoi(Info_ValueForKey( userinfo, "cl_punkbuster" )), newcl->pbguid);
if(PunkBusterStatus){
NET_OutOfBandPrint( NS_SERVER, from, "%s", PunkBusterStatus);
Com_Memset( &svse.challenges[c], 0, sizeof( svse.challenges[c] ));
return;
}
}
newcl->unknowndirectconnect1 = 0; //Whatever it is ???
newcl->hasVoip = 1;
newcl->gentity = SV_GentityNum(clientNum);
newcl->clscriptid = Scr_AllocArray();
// get the game a chance to reject this connection or modify the userinfo
denied = ClientConnect(clientNum, newcl->clscriptid);
if ( denied ) {
NET_OutOfBandPrint( NS_SERVER, from, "error\n%s\n", denied );
Com_Printf("Game rejected a connection: %s\n", denied);
SV_FreeClientScriptId(newcl);
Com_Memset( &svse.challenges[c], 0, sizeof( svse.challenges[c] ));
return;
}
svse.challenges[c].connected = qtrue;
Com_Printf( "Going from CS_FREE to CS_CONNECTED for %s num %i guid %s from: %s\n", nick, clientNum, newcl->pbguid, NET_AdrToConnectionString(from));
// save the addressgamestateMessageNum
// init the netchan queue
Netchan_Setup( NS_SERVER, &newcl->netchan, *from, qport,
newcl->unsentBuffer, sizeof(newcl->unsentBuffer),
newcl->fragmentBuffer, sizeof(newcl->fragmentBuffer));
/* for(index = 0; index < MAX_RELIABLE_COMMANDS; index++ ){
// if(index < MAX_RELIABLE_COMMANDS / 2){
cl->reliableCommands[index] = &cl->lowReliableCommands[index & (MAX_RELIABLE_COMMANDS - 1)];
// } else {
// cl->reliableCommands[index] = &svse.extclients[j].highReliableCommands[index & (MAX_RELIABLE_COMMANDS - 1)];
// }
}*/
newcl->state = CS_CONNECTED;
newcl->nextSnapshotTime = svs.time;
newcl->lastPacketTime = svs.time;
newcl->lastConnectTime = svs.time;
SV_UserinfoChanged(newcl);
// send the connect packet to the client
if(sv_modStats->boolean){
NET_OutOfBandPrint( NS_SERVER, from, "connectResponse %s", fs_game->string);
}else{
NET_OutOfBandPrint( NS_SERVER, from, "connectResponse");
}
// when we receive the first packet from the client, we will
// notice that it is from a different serverid and that the
// gamestate message was not just sent, forcing a retransmit
newcl->gamestateMessageNum = -1; //newcl->gamestateMessageNum = -1;
// if this was the first client on the server, or the last client
// the server can hold, send a heartbeat to the master.
for (j=0, cl=svs.clients, count=0; j < sv_maxclients->integer; j++, cl++) {
if (cl->state >= CS_CONNECTED ) {
count++;
}
}
if ( count == 1 || count == sv_maxclients->integer ) {
SV_Heartbeat_f();
}
}
__optimize3 __regparm2 void SV_ReceiveStats(netadr_t *from, msg_t* msg){
short qport;
qport = MSG_ReadShort( msg );// & 0xffff;
client_t *cl;
int i;
byte curstatspacket;
byte var_02;
int buffersize;
// find which client the message is from
for ( i = 0, cl = svs.clients ; i < sv_maxclients->integer ; i++,cl++ ) {
if ( cl->state == CS_FREE ) {
continue;
}
if ( !NET_CompareBaseAdr( from, &cl->netchan.remoteAddress ) ) {
continue;
}
// it is possible to have multiple clients from a single IP
// address, so they are differentiated by the qport variable
if ( cl->netchan.qport != qport ) {
continue;
}
// the IP port can't be used to differentiate them, because
// some address translating routers periodically change UDP
// port assignments
if ( cl->netchan.remoteAddress.port != from->port ) {
Com_Printf( "SV_ReceiveStats: fixing up a translated port\n" );
cl->netchan.remoteAddress.port = from->port;
}
curstatspacket = MSG_ReadByte(msg);
if(curstatspacket > 6){
Com_Printf("Invalid stat packet %i of stats data\n", curstatspacket);
return;
}
Com_Printf("Received packet %i of stats data\n", curstatspacket);
if((curstatspacket+1)*1240 >= sizeof(cl->stats)){
buffersize = sizeof(cl->stats)-(curstatspacket*1240);
}else{
buffersize = 1240;
}
MSG_ReadData(msg, &cl->stats[1240*curstatspacket], buffersize);
cl->receivedstats |= (1 << curstatspacket);
var_02 = cl->receivedstats;
var_02 = ~var_02;
var_02 = var_02 & 127;
cl->lastPacketTime = svs.time;
NET_OutOfBandPrint( NS_SERVER, from, "statResponse %i", var_02 );
return;
}
Com_DPrintf("SV_ReceiveStats: Received statspacket from disconnected remote client: %s qport: %d\n", NET_AdrToString(from), qport);
}
/*
=================
SV_UserinfoChanged
Pull specific info from a newly changed userinfo string
into a more C friendly form.
=================
*/
void SV_UserinfoChanged( client_t *cl ) {
char *val;
char ip[128];
int i;
int len;
// name for C code
Q_strncpyz( cl->name, Info_ValueForKey (cl->userinfo, "name"), sizeof(cl->name) );
if(!Q_isprintstring(cl->name) || strstr(cl->name,"ID_") || Q_PrintStrlen(cl->name) < 3){
if(cl->state == CS_ACTIVE){
if(!Q_isprintstring(cl->name)) SV_SendServerCommand(cl, "c \"^5Playernames can not contain advanced ASCII-characters\"");
if(strlen(cl->name) < 3) SV_SendServerCommand(cl, "c \"^5Playernames can not be shorter than 3 characters\"");
}
if(cl->uid <= 0){
Com_sprintf(cl->name, 16, "ID_UNKNOWN_%i", cl - svs.clients);
cl->usernamechanged = UN_NEEDUID;
} else {
Com_sprintf(cl->name, 16, "ID_%i:%i", cl->uid / 100000000, cl->uid % 100000000);
cl->usernamechanged = UN_OK;
}
Info_SetValueForKey( cl->userinfo, "name", cl->name);
}else{
cl->usernamechanged = UN_VERIFYNAME;
}
Q_strncpyz(cl->shortname, cl->name, sizeof(cl->shortname));
// rate command
// if the client is on the same subnet as the server and we aren't running an
// internet public server, assume they don't need a rate choke
if ( Sys_IsLANAddress( &cl->netchan.remoteAddress )) {
cl->rate = 1048576; // lans should not rate limit
} else {
val = Info_ValueForKey (cl->userinfo, "rate");
if (strlen(val)) {
i = atoi(val);
cl->rate = i;
if (cl->rate < 2500) {
cl->rate = 2500;
} else if (cl->rate >= 25000) {
cl->rate = sv_maxRate->integer;
}
} else {
cl->rate = 2500;
}
}
// snaps command
val = Info_ValueForKey (cl->userinfo, "snaps");
if(strlen(val))
{
i = atoi(val);
if(i < 10)
i = 10;
else if(i > sv_fps->integer)
i = sv_fps->integer;
else if(i == 30)
i = sv_fps->integer;
cl->snapshotMsec = 1000 / i;
}
else
cl->snapshotMsec = 50;
val = Info_ValueForKey(cl->userinfo, "cl_voice");
cl->hasVoip = atoi(val);
// TTimo
// maintain the IP information
// the banning code relies on this being consistently present
if( NET_IsLocalAddress(cl->netchan.remoteAddress) )
Q_strncpyz(ip, "localhost", sizeof(ip));
else
Com_sprintf(ip, sizeof(ip), "%s", NET_AdrToConnectionString( &cl->netchan.remoteAddress ));
val = Info_ValueForKey( cl->userinfo, "ip" );
if( val[0] )
len = strlen( ip ) - strlen( val ) + strlen( cl->userinfo );
else
len = strlen( ip ) + 4 + strlen( cl->userinfo );
if( len >= MAX_INFO_STRING )
SV_DropClient( cl, "userinfo string length exceeded" );
else
Info_SetValueForKey( cl->userinfo, "ip", ip );
cl->wwwDownload = qfalse;
if(Info_ValueForKey(cl->userinfo, "cl_wwwDownload"))
cl->wwwDownload = qtrue;
}
/*
==================
SV_UpdateUserinfo_f
==================
*//*
static void SV_UpdateUserinfo_f( client_t *cl ) {
Q_strncpyz( cl->userinfo, Cmd_Argv(1), sizeof(cl->userinfo) );
SV_UserinfoChanged( cl );
// call prog code to allow overrides
VM_Call( gvm, GAME_CLIENT_USERINFO_CHANGED, cl - &svs.clients );
}*/
/*
=====================
SV_DropClient
Called when the player is totally leaving the server, either willingly
or unwillingly. This is NOT called if the entire server is quiting
or crashing -- SV_FinalMessage() will handle that
=====================
*/
__cdecl void SV_DropClient( client_t *drop, const char *reason ) {
int i;
int clientnum;
char var_01[2];
char dropmsg[1024];
const char *dropreason;
char clientName[16];
challenge_t *challenge;
if ( drop->state <= CS_ZOMBIE ) {
return; // already dropped
}
if(drop->demorecording)
{
SV_StopRecord(drop);
}
Q_strncpyz(clientName, drop->name, sizeof(clientName));
clientnum = drop - svs.clients;
if(drop->uid > 0 && strlen(drop->pbguid) == 32)
SV_EnterLeaveLog("^4Client %s %s ^4left this server from slot %d with uid %d guid %s", drop->name, NET_AdrToString(&drop->netchan.remoteAddress), clientnum, drop->uid, drop->pbguid);
else if(drop->uid > 0)
SV_EnterLeaveLog("^4Client %s %s ^4left this server from slot %d with uid %d", drop->name, NET_AdrToString(&drop->netchan.remoteAddress), clientnum, drop->uid);
else if(strlen(drop->pbguid) == 32)
SV_EnterLeaveLog("^4Client %s %s ^4left this server from slot %d with guid %s", drop->name, NET_AdrToString(&drop->netchan.remoteAddress), clientnum, drop->pbguid);
SV_FreeClient(drop);
G_DestroyAdsForPlayer(drop);
if ( !drop->gentity ) {
// see if we already (maybe still ??) have a challenge for this ip
challenge = &svse.challenges[0];
for ( i = 0 ; i < MAX_CHALLENGES ; i++, challenge++ ) {
if ( NET_CompareAdr( &drop->netchan.remoteAddress, &challenge->adr ) ) {
Com_Memset(challenge, 0, sizeof(challenge_t));
break;
}
}
}
clientnum = drop - svs.clients;
if(!reason)
reason = "";
if(!Q_stricmp(reason, "silent")){
//Just disconnect him and don't tell anyone about it
Com_Printf("Player %s^7, %i dropped: %s\n", clientName, clientnum, reason);
drop->state = CS_ZOMBIE; // become free in a few seconds
HL2Rcon_EventClientLeave(clientnum);
PHandler_Event(PLUGINS_ONPLAYERDC,(void*)drop); // Plugin event
return;
}
if(SEH_StringEd_GetString( reason )){
var_01[0] = 0x14;
var_01[1] = 0;
}else{
var_01[0] = 0;
}
if(!Q_stricmp(reason, "EXE_DISCONNECTED")){
dropreason = "EXE_LEFTGAME";
} else {
dropreason = reason;
}
// tell everyone why they got dropped
SV_SendServerCommand(NULL, "%c \"\x15%s^7 %s%s\"\0", 0x65, clientName, var_01, dropreason);
Com_Printf("Player %s^7, %i dropped: %s\n", clientName, clientnum, dropreason);
SV_SendServerCommand(NULL, "%c %d", 0x4b, clientnum);
// add the disconnect command
drop->reliableSequence = drop->reliableAcknowledge; //Reset unsentBuffer and Sequence to ommit the outstanding junk from beeing transmitted
drop->netchan.unsentFragments = qfalse;
// SV_SendServerCommand( drop, "%c \"%s\" PB\0", 0x77, dropreason);
Com_sprintf(dropmsg, sizeof(dropmsg), "%c \"%s\" PB\0", 0x77, dropreason);
SV_AddServerCommand_old( drop, 1, dropmsg);
if(drop->netchan.remoteAddress.type == NA_BOT){
drop->state = CS_FREE; // become free now
drop->netchan.remoteAddress.type = 0; //Reset the botflag
Com_DPrintf( "Going to CS_FREE for Bot %s\n", clientName );
}else{
drop->state = CS_ZOMBIE; // become free in a few seconds
Com_DPrintf( "Going to CS_ZOMBIE for %s\n", clientName );
}
HL2Rcon_EventClientLeave(clientnum);
PHandler_Event(PLUGINS_ONPLAYERDC,(void*)drop); // Plugin event
// if this was the last client on the server, send a heartbeat
// to the master so it is known the server is empty
// send a heartbeat now so the master will get up to date info
// if there is already a slot for this ip, reuse it
for ( i = 0 ; i < sv_maxclients->integer ; i++ ) {
if ( svs.clients[i].state >= CS_CONNECTED ) {
break;
}
}
if ( i == sv_maxclients->integer ) {
SV_Heartbeat_f();
}
}
/*
==================
SV_UserMove
The message usually contains all the movement commands
that were in the last three packets, so that the information
in dropped packets can be recovered.