-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathsv_main.c
4021 lines (3293 loc) · 92.8 KB
/
sv_main.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) 1996-1997 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
$Id: sv_main.c 775 2008-03-20 13:39:47Z disconn3ct $
*/
#include "qwsvdef.h"
//quakeparms_t host_parms;
int telnetport = 0; // FIXME, perhaps just remove rest of telnet code
qbool host_initialized; // true if into command execution (compatability)
qbool host_everything_loaded; // true if OnChange() applied to every var, end of Host_Init()
double realtime; // without any filtering or bounding
int host_hunklevel;
int current_skill; // for entity spawnflags checking
client_t *sv_client; // current client
char master_rcon_password[128] = ""; //bliP: password for remote server commands
cvar_t sv_cpserver = {"sv_cpserver", "0"}; // some cp servers couse lags on map changes
cvar_t sv_mintic = {"sv_mintic","0.013"}; // bound the size of the
cvar_t sv_maxtic = {"sv_maxtic","0.1"}; // physics time tic
//cvar_t developer = {"developer", "0"}; // show extra messages
cvar_t timeout = {"timeout", "65"}; // seconds without any message
cvar_t zombietime = {"zombietime", "2"}; // seconds to sink messages
// after disconnect
cvar_t sv_cullentities = {"sv_cullentities", "0"};
extern cvar_t rcon_password;
extern cvar_t password;
cvar_t sv_hashpasswords = {"sv_hashpasswords", "1"}; // 0 - plain passwords; 1 - hashed passwords
cvar_t telnet_password = {"telnet_password", ""}; // password for login via telnet
cvar_t not_auth_timeout = {"not_auth_timeout", "20"};
// if no password is sent (telnet_password) in "n" seconds the server refuses connection
// If set to 0, no timeout will occur
cvar_t auth_timeout = {"auth_timeout", "3600"};
// the server will close the connection "n" seconds after the authentication is completed
// If set to 0, no timeout will occur
cvar_t sv_crypt_rcon = {"sv_crypt_rcon", "1"}; // use SHA1 for encryption of rcon_password and using timestamps
// Time in seconds during which in rcon command this encryption is valid (change only with master_rcon_password).
cvar_t sv_timestamplen = {"sv_timestamplen", "60"};
cvar_t sv_rconlim = {"sv_rconlim", "10"}; // rcon bandwith limit: requests per second
//bliP: telnet log level
//cvar_t telnet_log_level = {"telnet_log_level", "0"}; // logging level telnet console
void OnChange_telnetloglevel_var (cvar_t *var, char *string, qbool *cancel);
cvar_t telnet_log_level = {"telnet_log_level", "0", 0, OnChange_telnetloglevel_var};
//<-
cvar_t frag_log_type = {"frag_log_type", "0"};
// frag log type:
// 0 - old style ( qwsv - v0.165)
// 1 - new style (v0.168 - v0.172)
void OnChange_qconsolelogsay_var (cvar_t *var, char *string, qbool *cancel);
cvar_t qconsole_log_say = {"qconsole_log_say", "0", 0, OnChange_qconsolelogsay_var};
// logging "say" and "say_team" messages to the qconsole_PORT.log file
cvar_t sys_command_line = {"sys_command_line", "", CVAR_ROM};
cvar_t sv_use_dns = {"sv_use_dns", "0"}; // 1 - use DNS lookup in status command, 0 - don't use
cvar_t spectator_password = {"spectator_password", ""}; // password for entering as a sepctator
cvar_t vip_password = {"vip_password", ""}; // password for entering as a VIP sepctator
cvar_t vip_values = {"vip_values", ""};
cvar_t allow_download = {"allow_download", "1"};
cvar_t allow_download_skins = {"allow_download_skins", "1"};
cvar_t allow_download_models = {"allow_download_models", "1"};
cvar_t allow_download_sounds = {"allow_download_sounds", "1"};
cvar_t allow_download_maps = {"allow_download_maps", "1"};
cvar_t allow_download_pakmaps = {"allow_download_pakmaps", "1"};
cvar_t allow_download_demos = {"allow_download_demos", "1"};
cvar_t allow_download_other = {"allow_download_other", "0"};
//bliP: init ->
cvar_t download_map_url = {"download_map_url", ""};
cvar_t sv_specprint = {"sv_specprint", "0"};
cvar_t sv_reconnectlimit = {"sv_reconnectlimit", "0"};
void OnChange_admininfo_var (cvar_t *var, char *string, qbool *cancel);
cvar_t sv_admininfo = {"sv_admininfo", "", 0, OnChange_admininfo_var};
cvar_t sv_unfake = {"sv_unfake", "1"}; //bliP: 24/9 kickfake to unfake
cvar_t sv_kicktop = {"sv_kicktop", "1"};
cvar_t sv_allowlastscores = {"sv_allowlastscores", "1"};
cvar_t sv_maxlogsize = {"sv_maxlogsize", "0"};
//bliP: 24/9 ->
void OnChange_logdir_var (cvar_t *var, char *string, qbool *cancel);
cvar_t sv_logdir = {"sv_logdir", ".", 0, OnChange_logdir_var};
cvar_t sv_speedcheck = {"sv_speedcheck", "1"};
//<-
//<-
//cvar_t sv_highchars = {"sv_highchars", "1"};
cvar_t sv_phs = {"sv_phs", "1"};
cvar_t pausable = {"pausable", "0"};
cvar_t sv_maxrate = {"sv_maxrate", "0"};
cvar_t sv_getrealip = {"sv_getrealip", "1"};
cvar_t sv_serverip = {"sv_serverip", ""};
cvar_t sv_forcespec_onfull = {"sv_forcespec_onfull", "2"};
cvar_t sv_maxdownloadrate = {"sv_maxdownloadrate", "0"};
cvar_t sv_loadentfiles = {"sv_loadentfiles", "1"}; //loads .ent files by default if there
cvar_t sv_default_name = {"sv_default_name", "unnamed"};
void sv_mod_msg_file_OnChange(cvar_t *cvar, char *value, qbool *cancel);
cvar_t sv_mod_msg_file = {"sv_mod_msg_file", "", CVAR_NONE, sv_mod_msg_file_OnChange};
cvar_t sv_qwfwd_port = {"sv_qwfwd_port", "30000"};
//
// game rules mirrored in svs.info
//
cvar_t fraglimit = {"fraglimit","0",CVAR_SERVERINFO};
cvar_t timelimit = {"timelimit","0",CVAR_SERVERINFO};
cvar_t teamplay = {"teamplay","0",CVAR_SERVERINFO};
cvar_t maxclients = {"maxclients","24",CVAR_SERVERINFO};
cvar_t maxspectators = {"maxspectators","8",CVAR_SERVERINFO};
cvar_t maxvip_spectators = {"maxvip_spectators","0"/*,CVAR_SERVERINFO*/};
cvar_t deathmatch = {"deathmatch","3",CVAR_SERVERINFO};
cvar_t watervis = {"watervis","0",CVAR_SERVERINFO};
cvar_t serverdemo = {"serverdemo","",CVAR_SERVERINFO | CVAR_ROM};
cvar_t samelevel = {"samelevel","1"}; // dont delete this variable - it used by mods
cvar_t skill = {"skill", "1"}; // dont delete this variable - it used by mods
cvar_t coop = {"coop", "0"}; // dont delete this variable - it used by mods
//cvar_t version = {"version", full_version, CVAR_ROM};
cvar_t sv_paused = {"sv_paused", "0", CVAR_ROM};
cvar_t hostname = {"hostname", "unnamed", CVAR_SERVERINFO};
cvar_t sv_forcenick = {"sv_forcenick", "0"}; //0 - don't force; 1 - as login;
cvar_t sv_registrationinfo = {"sv_registrationinfo", ""}; // text shown before "enter login"
cvar_t registered = {"registered", "1", CVAR_ROM};
// We need this cvar, because ktpro didn't allow to go at some placeses of, for example, start map.
cvar_t sv_ktpro_mode = {"sv_ktpro_mode", "auto"};
cvar_t sv_halflifebsp = {"halflifebsp", "0", CVAR_ROM};
#ifdef FTE_PEXT_FLOATCOORDS
cvar_t sv_bigcoords = {"sv_bigcoords", "", CVAR_SERVERINFO};
#endif
qbool sv_error = false;
qbool server_cfg_done = false;
client_t *WatcherId = NULL; // QW262
void SV_AcceptClient (netadr_t adr, int userid, char *userinfo);
//============================================================================
qbool GameStarted(void)
{
mvddest_t *d;
for (d = demo.dest; d; d = d->nextdest)
if (d->desttype != DEST_STREAM) // oh, its not stream, treat as "game is started"
break;
return (d || strncasecmp(Info_ValueForKey(svs.info, "status"), "Standby", 8));
}
/*
================
SV_Shutdown
Quake calls this before calling Sys_Quit or Sys_Error
================
*/
void SV_Shutdown (char *finalmsg)
{
int i;
if (sv.state)
Com_Printf("%s\n", finalmsg);
Master_Shutdown ();
if (telnetport)
SV_Write_Log(TELNET_LOG, 1, "Server shutdown.\n");
for (i = MIN_LOG; i < MAX_LOG; ++i)
{
if (logs[i].sv_logfile)
{
fclose (logs[i].sv_logfile);
logs[i].sv_logfile = NULL;
}
}
if (sv.mvdrecording)
SV_MVDStop_f();
// NET_Shutdown ();
#ifdef USE_PR2
if ( sv_vm )
{
PR2_GameShutDown();
VM_Unload( sv_vm );
sv_vm = NULL;
}
#endif
memset (&sv, 0, sizeof(sv));
sv.state = ss_dead;
com_serveractive = false;
memset (svs.clients, 0, sizeof(svs.clients));
svs.lastuserid = 0;
}
/*
================
SV_Error
Sends a datagram to all the clients informing them of the server crash,
then exits
================
*/
void SV_Error (char *error, ...)
{
static qbool inerror = false;
static char string[1024];
va_list argptr;
sv_error = true;
if (inerror)
Sys_Error ("SV_Error: recursively entered (%s)", string);
inerror = true;
va_start (argptr, error);
vsnprintf (string, sizeof (string), error, argptr);
va_end (argptr);
Con_Printf ("SV_Error: %s\n", string);
// SV_FinalMessage (va ("server crashed: %s\n", string));
// SV_Shutdown ("SV_Error\n");
Sys_Error ("SV_Error: %s", string);
}
static void SV_FreeHeadDelayedPacket(client_t *cl) {
if (cl->packets) {
packet_t *next = cl->packets->next;
cl->packets->next = svs.free_packets;
svs.free_packets = cl->packets;
cl->packets = next;
}
}
void SV_FreeDelayedPackets (client_t *cl) {
while (cl->packets)
SV_FreeHeadDelayedPacket(cl);
}
/*
==================
SV_FinalMessage
Used by SV_Error and SV_Quit_f to send a final message to all connected
clients before the server goes down. The messages are sent immediately,
not just stuck on the outgoing message list, because the server is going
to totally exit after returning from this function.
==================
*/
void SV_FinalMessage (const char *message)
{
client_t *cl;
int i;
SZ_Clear (&net_message);
MSG_WriteByte (&net_message, svc_print);
MSG_WriteByte (&net_message, PRINT_HIGH);
MSG_WriteString (&net_message, message);
MSG_WriteByte (&net_message, svc_disconnect);
for (i=0, cl = svs.clients ; i<MAX_CLIENTS ; i++, cl++)
if (cl->state >= cs_spawned)
Netchan_Transmit (&cl->netchan, net_message.cursize
, net_message.data);
}
/*
=====================
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.
=====================
*/
#ifdef USE_PR2
void RemoveBot(client_t *cl);
#endif
void SV_DropClient (client_t *drop)
{
//bliP: cuff, mute ->
SV_SavePenaltyFilter (drop, ft_mute, drop->lockedtill);
SV_SavePenaltyFilter (drop, ft_cuff, drop->cuff_time);
//<-
//bliP: player logging
if (drop->name[0])
SV_LogPlayer(drop, "disconnect", 1);
//<-
// add the disconnect
#ifdef USE_PR2
if( drop->isBot )
{
RemoveBot(drop);
return;
}
#endif
MSG_WriteByte (&drop->netchan.message, svc_disconnect);
if (drop->state == cs_spawned)
{
if (!drop->spectator)
{
// call the prog function for removing a client
// this will set the body to a dead frame, among other things
pr_global_struct->self = EDICT_TO_PROG(drop->edict);
#ifdef USE_PR2
if ( sv_vm )
PR2_GameClientDisconnect(0);
else
#endif
PR_ExecuteProgram (PR_GLOBAL(ClientDisconnect));
}
else if (SpectatorDisconnect
#ifdef USE_PR2
|| ( sv_vm )
#endif
)
{
// call the prog function for removing a client
// this will set the body to a dead frame, among other things
pr_global_struct->self = EDICT_TO_PROG(drop->edict);
#ifdef USE_PR2
if ( sv_vm )
PR2_GameClientDisconnect(1);
else
#endif
PR_ExecuteProgram (SpectatorDisconnect);
}
}
if (drop->spectator)
Con_Printf ("Spectator %s removed\n",drop->name);
else
Con_Printf ("Client %s removed\n",drop->name);
if (drop->download)
{
VFS_CLOSE(drop->download);
drop->download = NULL;
}
if (drop->upload)
{
fclose (drop->upload);
drop->upload = NULL;
}
*drop->uploadfn = 0;
SV_Logout(drop);
drop->state = cs_zombie; // become free in a few seconds
drop->connection_started = realtime; // for zombie timeout
// MD -->
if (drop == WatcherId)
WatcherId = NULL;
// <-- MD
drop->old_frags = 0;
drop->edict->v.frags = 0.0;
drop->name[0] = 0;
Info_RemoveAll(&drop->_userinfo_ctx_);
Info_RemoveAll(&drop->_userinfoshort_ctx_);
// send notification to all remaining clients
SV_FullClientUpdate (drop, &sv.reliable_datagram);
}
//====================================================================
/*
===================
SV_CalcPing
===================
*/
int SV_CalcPing (client_t *cl)
{
register client_frame_t *frame;
int count, i;
float ping;
//bliP: 999 ping for connecting players
if (cl->state != cs_spawned)
return 999;
//<-
ping = 0;
count = 0;
#ifdef USE_PR2
if( cl->isBot )
return ((int) (sv_mintic.value * 1000));
#endif
for (frame = cl->frames, i=0 ; i<UPDATE_BACKUP ; i++, frame++)
{
if (frame->ping_time > 0)
{
ping += frame->ping_time;
count++;
}
}
if (!count)
return 9999;
ping /= count;
return ping*1000;
}
/*
===================
SV_FullClientUpdate
Writes all update values to a sizebuf
===================
*/
void SV_FullClientUpdate (client_t *client, sizebuf_t *buf)
{
char info[MAX_EXT_INFO_STRING];
int i;
i = client - svs.clients;
//Sys_Printf("SV_FullClientUpdate: Updated frags for client %d\n", i);
MSG_WriteByte (buf, svc_updatefrags);
MSG_WriteByte (buf, i);
MSG_WriteShort (buf, client->old_frags);
MSG_WriteByte (buf, svc_updateping);
MSG_WriteByte (buf, i);
MSG_WriteShort (buf, SV_CalcPing (client));
MSG_WriteByte (buf, svc_updatepl);
MSG_WriteByte (buf, i);
MSG_WriteByte (buf, client->lossage);
MSG_WriteByte (buf, svc_updateentertime);
MSG_WriteByte (buf, i);
MSG_WriteFloat (buf, realtime - client->connection_started);
Info_ReverseConvert(&client->_userinfoshort_ctx_, info, sizeof(info));
Info_RemovePrefixedKeys (info, '_'); // server passwords, etc
MSG_WriteByte (buf, svc_updateuserinfo);
MSG_WriteByte (buf, i);
MSG_WriteLong (buf, client->userid);
MSG_WriteString (buf, info);
}
/*
===================
SV_FullClientUpdateToClient
Writes all update values to a client's reliable stream
===================
*/
void SV_FullClientUpdateToClient (client_t *client, client_t *cl)
{
char info[MAX_EXT_INFO_STRING];
Info_ReverseConvert(&client->_userinfoshort_ctx_, info, sizeof(info));
ClientReliableCheckBlock(cl, 24 + strlen(info));
if (cl->num_backbuf)
{
SV_FullClientUpdate (client, &cl->backbuf);
ClientReliable_FinishWrite(cl);
}
else
SV_FullClientUpdate (client, &cl->netchan.message);
}
//Returns a unique userid in [1..MAXUSERID] range
#define MAXUSERID 99
int SV_GenerateUserID (void)
{
client_t *cl;
int i;
do {
svs.lastuserid++;
if (svs.lastuserid == 1 + MAXUSERID)
svs.lastuserid = 1;
for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++)
if (cl->state != cs_free && cl->userid == svs.lastuserid)
break;
} while (i != MAX_CLIENTS);
return svs.lastuserid;
}
/*
==============================================================================
CONNECTIONLESS COMMANDS
==============================================================================
*/
/*
================
SVC_Status
Responds with all the info that qplug or qspy can see
This message can be up to around 5k with worst case string lengths.
================
*/
#define STATUS_OLDSTYLE 0
#define STATUS_SERVERINFO 1
#define STATUS_PLAYERS 2
#define STATUS_SPECTATORS 4
#define STATUS_SPECTATORS_AS_PLAYERS 8 //for ASE - change only frags: show as "S"
#define STATUS_SHOWTEAMS 16
static void SVC_Status (void)
{
int top, bottom, ping, i, opt = 0;
char *name, *frags;
client_t *cl;
if (Cmd_Argc() > 1)
opt = Q_atoi(Cmd_Argv(1));
SV_BeginRedirect (RD_PACKET);
if (opt == STATUS_OLDSTYLE || (opt & STATUS_SERVERINFO))
Con_Printf ("%s\n", svs.info);
if (opt == STATUS_OLDSTYLE || (opt & (STATUS_PLAYERS | STATUS_SPECTATORS)))
for (i = 0; i < MAX_CLIENTS; i++)
{
cl = &svs.clients[i];
if ( (cl->state >= cs_preconnected/* || cl->state == cs_spawned */) &&
( (!cl->spectator && ((opt & STATUS_PLAYERS) || opt == STATUS_OLDSTYLE)) ||
( cl->spectator && ( opt & STATUS_SPECTATORS)) ) )
{
top = Q_atoi(Info_Get (&cl->_userinfo_ctx_, "topcolor"));
bottom = Q_atoi(Info_Get (&cl->_userinfo_ctx_, "bottomcolor"));
top = (top < 0) ? 0 : ((top > 13) ? 13 : top);
bottom = (bottom < 0) ? 0 : ((bottom > 13) ? 13 : bottom);
ping = SV_CalcPing (cl);
name = cl->name;
if (cl->spectator)
{
if (opt & STATUS_SPECTATORS_AS_PLAYERS)
frags = "S";
else
{
ping = -ping;
frags = "-9999";
name = va("\\s\\%s", name);
}
}
else
frags = va("%i", cl->old_frags);
Con_Printf ("%i %s %i %i \"%s\" \"%s\" %i %i", cl->userid, frags,
(int)(realtime - cl->connection_started)/60, ping, name,
Info_Get (&cl->_userinfo_ctx_, "skin"), top, bottom);
if (opt & STATUS_SHOWTEAMS)
Con_Printf (" \"%s\"\n", cl->team);
else
Con_Printf ("\n");
}
}
SV_EndRedirect ();
}
/*
===================
SVC_LastScores
===================
*/
void SV_LastScores_f (void);
static void SVC_LastScores (void)
{
if(!(int)sv_allowlastscores.value)
return;
SV_BeginRedirect (RD_PACKET);
SV_LastScores_f ();
SV_EndRedirect ();
}
/*
===================
SVC_DemoList
SVC_DemoListRegex
===================
*/
void SV_DemoList_f (void);
static void SVC_DemoList (void)
{
SV_BeginRedirect (RD_PACKET);
SV_DemoList_f ();
SV_EndRedirect ();
}
void SV_DemoListRegex_f (void);
static void SVC_DemoListRegex (void)
{
SV_BeginRedirect (RD_PACKET);
SV_DemoListRegex_f ();
SV_EndRedirect ();
}
/*
===================
SV_CheckLog
===================
*/
#define LOG_HIGHWATER (MAX_DATAGRAM - 128)
#define LOG_FLUSH 10*60
static void SV_CheckLog (void)
{
sizebuf_t *sz;
if (sv.state != ss_active)
return;
sz = &svs.log[svs.logsequence&1];
// bump sequence if allmost full, or ten minutes have passed and
// there is something still sitting there
if (sz->cursize > LOG_HIGHWATER
|| (realtime - svs.logtime > LOG_FLUSH && sz->cursize) )
{
// swap buffers and bump sequence
svs.logtime = realtime;
svs.logsequence++;
sz = &svs.log[svs.logsequence&1];
sz->cursize = 0;
Con_DPrintf ("beginning fraglog sequence %i\n", svs.logsequence);
}
}
/*
================
SVC_Log
Responds with all the logged frags for ranking programs.
If a sequence number is passed as a parameter and it is
the same as the current sequence, an A2A_NACK will be returned
instead of the data.
================
*/
static void SVC_Log (void)
{
char data[MAX_DATAGRAM+64];
int seq;
if (Cmd_Argc() == 2)
seq = Q_atoi(Cmd_Argv(1));
else
seq = -1;
if (seq == svs.logsequence-1 || !logs[FRAG_LOG].sv_logfile)
{ // they already have this data, or we aren't logging frags
data[0] = A2A_NACK;
NET_SendPacket (NS_SERVER, 1, data, net_from);
return;
}
Con_DPrintf ("sending log %i to %s\n", svs.logsequence-1, NET_AdrToString(net_from));
snprintf (data, MAX_DATAGRAM + 64, "stdlog %i\n", svs.logsequence-1);
strlcat (data, (char *)svs.log_buf[((svs.logsequence-1)&1)], MAX_DATAGRAM + 64);
NET_SendPacket (NS_SERVER, strlen(data)+1, data, net_from);
}
/*
================
SVC_Ping
Just responds with an acknowledgement
================
*/
static void SVC_Ping (void)
{
char data = A2A_ACK;
NET_SendPacket (NS_SERVER, 1, &data, net_from);
}
/*
=================
SVC_GetChallenge
Returns a challenge number that can be used
in a subsequent client_connect 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.
=================
*/
static void SVC_GetChallenge (void)
{
int oldestTime, oldest, i;
char buf[256], *over;
oldest = 0;
oldestTime = 0x7fffffff;
// see if we already have a challenge for this ip
for (i = 0 ; i < MAX_CHALLENGES ; i++)
{
if (NET_CompareBaseAdr (net_from, svs.challenges[i].adr))
break;
if (svs.challenges[i].time < oldestTime)
{
oldestTime = svs.challenges[i].time;
oldest = i;
}
}
if (i == MAX_CHALLENGES)
{
// overwrite the oldest
svs.challenges[oldest].challenge = (rand() << 16) ^ rand();
svs.challenges[oldest].adr = net_from;
svs.challenges[oldest].time = realtime;
i = oldest;
}
// send it back
snprintf(buf, sizeof(buf), "%c%i", S2C_CHALLENGE, svs.challenges[i].challenge);
over = buf + strlen(buf) + 1;
#ifdef PROTOCOL_VERSION_FTE
//tell the client what fte extensions we support
if (svs.fteprotocolextensions)
{
int lng;
lng = LittleLong(PROTOCOL_VERSION_FTE);
memcpy(over, &lng, sizeof(int)); // FIXME sizeof(int) or sizeof(long)??? -> sizeof(int) is correct, the function should really be named LittleInt - hexum
over += 4;
lng = LittleLong(svs.fteprotocolextensions);
memcpy(over, &lng, sizeof(int));
over += 4;
}
#endif // PROTOCOL_VERSION_FTE
#ifdef PROTOCOL_VERSION_FTE2
//tell the client what fte extensions2 we support
if (svs.fteprotocolextensions2)
{
int lng;
lng = LittleLong(PROTOCOL_VERSION_FTE2);
memcpy(over, &lng, sizeof(int)); // FIXME sizeof(int) or sizeof(long)??? -> sizeof(int) is correct, the function should really be named LittleInt - hexum
over += 4;
lng = LittleLong(svs.fteprotocolextensions2);
memcpy(over, &lng, sizeof(int));
over += 4;
}
#endif // PROTOCOL_VERSION_FTE2
Netchan_OutOfBand(NS_SERVER, net_from, over-buf, (byte*) buf);
}
static qbool ValidateUserInfo (char *userinfo)
{
while (*userinfo)
{
if (*userinfo == '\\')
userinfo++;
if (*userinfo++ == '\\')
return false;
while (*userinfo && *userinfo != '\\')
userinfo++;
}
return true;
}
//==============================================
void FixMaxClientsCvars(void)
{
if ((int)maxclients.value > MAX_CLIENTS)
Cvar_SetValue (&maxclients, MAX_CLIENTS);
if ((int)maxspectators.value > MAX_CLIENTS)
Cvar_SetValue (&maxspectators, MAX_CLIENTS);
if ((int)maxvip_spectators.value > MAX_CLIENTS)
Cvar_SetValue (&maxvip_spectators, MAX_CLIENTS);
if ((int)maxspectators.value + maxclients.value > MAX_CLIENTS)
Cvar_SetValue (&maxspectators, MAX_CLIENTS - (int)maxclients.value);
if ((int)maxspectators.value + maxclients.value + maxvip_spectators.value > MAX_CLIENTS)
Cvar_SetValue (&maxvip_spectators, MAX_CLIENTS - (int)maxclients.value - (int)maxspectators.value);
}
//==============================================
// see if the challenge is valid
qbool CheckChallange( int challenge )
{
int i;
if (net_from.type == NA_LOOPBACK)
return true; // local client do not need challenge
for (i = 0; i < MAX_CHALLENGES; i++)
{
if (NET_CompareBaseAdr (net_from, svs.challenges[i].adr))
{
if (challenge == svs.challenges[i].challenge)
break; // good
Netchan_OutOfBandPrint (NS_SERVER, net_from, "%c\nBad challenge.\n", A2C_PRINT);
return false;
}
}
if (i == MAX_CHALLENGES)
{
Netchan_OutOfBandPrint (NS_SERVER, net_from, "%c\nNo challenge for address.\n", A2C_PRINT);
return false;
}
return true;
}
//==============================================
qbool CheckProtocol( int ver )
{
if (ver != PROTOCOL_VERSION)
{
// Netchan_OutOfBandPrint (NS_SERVER, net_from, "%c\nServer is version %4.2f.\n", A2C_PRINT, QW_VERSION);
Netchan_OutOfBandPrint (NS_SERVER, net_from, "%c\nServer is version " QW_VERSION ".\n", A2C_PRINT);
Con_Printf ("* rejected connect from version %i\n", ver);
return false;
}
return true;
}
//==============================================
qbool CheckUserinfo( char *userinfobuf, unsigned int bufsize, char *userinfo )
{
strlcpy (userinfobuf, userinfo, bufsize);
// and now validate userinfo
if ( !ValidateUserInfo( userinfobuf ) )
{
Netchan_OutOfBandPrint (NS_SERVER, net_from, "%c\nInvalid userinfo. Restart your qwcl\n", A2C_PRINT);
return false;
}
return true;
}
//==============================================
int SV_VIPbyIP(netadr_t adr);
int SV_VIPbyPass (char *pass);
qbool CheckPasswords( char *userinfo, int userinfo_size, qbool *spass_ptr, qbool *vip_ptr, int *spectator_ptr )
{
int spectator;
qbool spass, vip;
char *s = Info_ValueForKey (userinfo, "spectator");
char *pwd;
spass = vip = spectator = false;
if (s[0] && strcmp(s, "0"))
{
spass = true;
// first the pass, then ip
if ( !( vip = SV_VIPbyPass( s ) ) )
{
if ( !( vip = SV_VIPbyPass( Info_ValueForKey( userinfo, "password") ) ) )
{
vip = SV_VIPbyIP( net_from );
}
}
pwd = spectator_password.string;
if (pwd[0] && strcasecmp(pwd, "none") && strcmp(pwd, s))
{
spass = false; // failed
}
if (!vip && !spass)
{
Con_Printf ("%s:spectator password failed\n", NET_AdrToString (net_from));
Netchan_OutOfBandPrint (NS_SERVER, net_from, "%c\nrequires a spectator password\n\n", A2C_PRINT);
return false;
}
Info_RemoveKey (userinfo, "spectator"); // remove passwd
Info_SetValueForStarKey (userinfo, "*spectator", "1", userinfo_size);
spectator = Q_atoi(s);
if (!spectator)
spectator = true;
}
else
{
s = Info_ValueForKey (userinfo, "password");
// first the pass, then ip
if (!(vip = SV_VIPbyPass(s)))
{
vip = SV_VIPbyIP(net_from);
}
pwd = password.string;
if (!vip && pwd[0] && strcasecmp(pwd, "none") && strcmp(pwd, s))
{
Con_Printf ("%s:password failed\n", NET_AdrToString (net_from));
Netchan_OutOfBandPrint (NS_SERVER, net_from, "%c\nserver requires a password\n\n", A2C_PRINT);
return false;
}
Info_RemoveKey (userinfo, "spectator"); // remove "spectator 0" for example
spectator = false;