-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathsv_user.c
3568 lines (3058 loc) · 89.3 KB
/
sv_user.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_user.c 782 2008-06-18 23:37:44Z qqshka $
*/
// sv_user.c -- server code for moving users
#include "qwsvdef.h"
edict_t *sv_player;
usercmd_t cmd;
cvar_t sv_spectalk = {"sv_spectalk", "1"};
cvar_t sv_sayteam_to_spec = {"sv_sayteam_to_spec", "1"};
cvar_t sv_mapcheck = {"sv_mapcheck", "1"};
cvar_t sv_minping = {"sv_minping", "0"};
cvar_t sv_enable_cmd_minping = {"sv_enable_cmd_minping", "1"};
cvar_t sv_use_internal_cmd_dl = {"sv_use_internal_cmd_dl", "1"};
cvar_t sv_kickuserinfospamtime = {"sv_kickuserinfospamtime", "3"};
cvar_t sv_kickuserinfospamcount = {"sv_kickuserinfospamcount", "30"};
cvar_t sv_maxuploadsize = {"sv_maxuploadsize", "1048576"};
#ifdef FTE_PEXT_CHUNKEDDOWNLOADS
cvar_t sv_downloadchunksperframe = {"sv_downloadchunksperframe", "2"};
#endif
extern vec3_t player_mins;
extern int fp_messages, fp_persecond, fp_secondsdead;
extern char fp_msg[];
extern cvar_t pausable;
extern cvar_t pm_bunnyspeedcap;
extern cvar_t pm_ktjump;
extern cvar_t pm_slidefix;
extern cvar_t pm_airstep;
extern cvar_t pm_pground;
extern double sv_frametime;
//bliP: init ->
extern cvar_t sv_unfake; //bliP: 24/9 kickfake to unfake
extern cvar_t sv_kicktop;
extern cvar_t sv_speedcheck; //bliP: 24/9
//<-
static qbool IsLocalIP(netadr_t a)
{
return a.ip[0] == 10 || (a.ip[0] == 172 && (a.ip[1] & 0xF0) == 16)
|| (a.ip[0] == 192 && a.ip[1] == 168) || a.ip[0] >= 224;
}
static qbool IsInetIP(netadr_t a)
{
return a.ip[0] != 127 && !IsLocalIP(a);
}
/*
============================================================
USER STRINGCMD EXECUTION
sv_client and sv_player will be valid.
============================================================
*/
/*
================
Cmd_New_f
Sends the first message from the server to a connected client.
This will be sent on the initial connection and upon each server load.
================
*/
int SV_VIPbyIP (netadr_t adr);
static void Cmd_New_f (void)
{
char *gamedir;
int playernum;
extern cvar_t sv_login;
extern cvar_t sv_serverip;
extern cvar_t sv_getrealip;
if (sv_client->state == cs_spawned)
return;
if (!sv_client->connection_started || sv_client->state == cs_connected)
sv_client->connection_started = realtime;
sv_client->spawncount = svs.spawncount;
// request protocol extensions.
if (sv_client->process_pext)
{
MSG_WriteByte (&sv_client->netchan.message, svc_stufftext);
MSG_WriteString (&sv_client->netchan.message, "cmd pext\n");
return;
}
// do not proceed if realip is unknown
if (sv_client->state == cs_preconnected && !sv_client->realip.ip[0] && (int)sv_getrealip.value)
{
char *server_ip = sv_serverip.string[0] ? sv_serverip.string : NET_AdrToString(net_local_sv_ipadr);
if (!((IsLocalIP(net_local_sv_ipadr) && IsLocalIP(sv_client->netchan.remote_address)) ||
(IsInetIP (net_local_sv_ipadr) && IsInetIP (sv_client->netchan.remote_address))) &&
sv_client->netchan.remote_address.ip[0] != 127 && !sv_serverip.string[0])
{
Sys_Printf ("WARNING: Incorrect server ip address: %s\n"
"Set hostname in your operation system or set correctly sv_serverip cvar.\n",
server_ip);
*(int *)&sv_client->realip = *(int *)&sv_client->netchan.remote_address;
sv_client->state = cs_connected;
}
else
{
if (sv_client->realip_count++ < 10)
{
sv_client->state = cs_preconnected;
MSG_WriteByte (&sv_client->netchan.message, svc_stufftext);
MSG_WriteString (&sv_client->netchan.message,
va("packet %s \"ip %d %d\"\ncmd new\n", server_ip,
sv_client - svs.clients, sv_client->realip_num));
}
if (realtime - sv_client->connection_started > 3 || sv_client->realip_count > 10)
{
if ((int)sv_getrealip.value == 2)
{
Netchan_OutOfBandPrint (NS_SERVER, net_from,
"%c\nFailed to validate client's IP.\n\n", A2C_PRINT);
sv_client->rip_vip = 2;
}
sv_client->state = cs_connected;
}
else
return;
}
}
// rip_vip means that client can be connected if he has VIP for he's real ip
// drop him if he hasn't
if (sv_client->rip_vip == 1)
{
if ((sv_client->vip = SV_VIPbyIP(sv_client->realip)) == 0)
{
Sys_Printf ("%s:full connect\n", NET_AdrToString (net_from));
Netchan_OutOfBandPrint (NS_SERVER, net_from,
"%c\nserver is full\n\n", A2C_PRINT);
}
else
sv_client->rip_vip = 0;
}
// we can be connected now, announce it, and possibly login
if (!sv_client->rip_vip)
{
if (sv_client->state == cs_preconnected)
{
// get highest VIP level
if (sv_client->vip < SV_VIPbyIP(sv_client->realip))
sv_client->vip = SV_VIPbyIP(sv_client->realip);
if (sv_client->vip && sv_client->spectator)
Sys_Printf ("VIP spectator %s connected\n", sv_client->name);
else if (sv_client->spectator)
Sys_Printf ("Spectator %s connected\n", sv_client->name);
else
Sys_Printf ("Client %s connected\n", sv_client->name);
Info_SetStar (&sv_client->_userinfo_ctx_, "*VIP", sv_client->vip ? va("%d", sv_client->vip) : "");
// now we are connected
sv_client->state = cs_connected;
}
if (!SV_Login(sv_client))
return;
if (!sv_client->logged && (int)sv_login.value)
return; // not so fast;
//bliP: cuff, mute ->
sv_client->lockedtill = SV_RestorePenaltyFilter(sv_client, ft_mute);
sv_client->cuff_time = SV_RestorePenaltyFilter(sv_client, ft_cuff);
//<-
}
// send the info about the new client to all connected clients
// SV_FullClientUpdate (sv_client, &sv.reliable_datagram);
// sv_client->sendinfo = true;
gamedir = Info_ValueForKey (svs.info, "*gamedir");
if (!gamedir[0])
gamedir = "qw";
#ifdef FTE_PEXT_FLOATCOORDS
if (msg_coordsize > 2 && !(sv_client->fteprotocolextensions & FTE_PEXT_FLOATCOORDS))
{
SV_ClientPrintf(sv_client, 2, "\n\n\n\nSorry, but your client does not appear to support FTE's bigcoords\n"
"FTE users will need to set cl_nopext to 0 and then reconnect, or to upgrade\n");
Sys_Printf("%s does not support bigcoords\n", sv_client->name);
return;
}
#endif
//NOTE: This doesn't go through ClientReliableWrite since it's before the user
//spawns. These functions are written to not overflow
if (sv_client->num_backbuf)
{
Con_Printf("WARNING %s: [SV_New] Back buffered (%d0), clearing\n",
sv_client->name, sv_client->netchan.message.cursize);
sv_client->num_backbuf = 0;
SZ_Clear(&sv_client->netchan.message);
}
// send the serverdata
MSG_WriteByte (&sv_client->netchan.message, svc_serverdata);
#ifdef PROTOCOL_VERSION_FTE
if (sv_client->fteprotocolextensions) // let the client know
{
unsigned int ext = sv_client->fteprotocolextensions;
#ifdef FTE_PEXT_FLOATCOORDS
if (msg_coordsize == 2) //we're not using float orgs on this level.
ext &= ~FTE_PEXT_FLOATCOORDS;
#endif
MSG_WriteLong (&sv_client->netchan.message, PROTOCOL_VERSION_FTE);
MSG_WriteLong (&sv_client->netchan.message, ext);
}
#endif
#ifdef PROTOCOL_VERSION_FTE2
if (sv_client->fteprotocolextensions2) // let the client know
{
MSG_WriteLong (&sv_client->netchan.message, PROTOCOL_VERSION_FTE2);
MSG_WriteLong (&sv_client->netchan.message, sv_client->fteprotocolextensions2);
}
#endif
MSG_WriteLong (&sv_client->netchan.message, PROTOCOL_VERSION);
MSG_WriteLong (&sv_client->netchan.message, svs.spawncount);
MSG_WriteString(&sv_client->netchan.message, gamedir);
playernum = NUM_FOR_EDICT(sv_client->edict)-1;
if (sv_client->spectator)
playernum |= 128;
MSG_WriteByte (&sv_client->netchan.message, playernum);
// send full levelname
if (sv_client->rip_vip)
MSG_WriteString (&sv_client->netchan.message, "");
else
MSG_WriteString (&sv_client->netchan.message,
#ifdef USE_PR2
PR2_GetString(sv.edicts->v.message)
#else
PR_GetString(sv.edicts->v.message)
#endif
);
// send the movevars
MSG_WriteFloat(&sv_client->netchan.message, movevars.gravity);
MSG_WriteFloat(&sv_client->netchan.message, movevars.stopspeed);
MSG_WriteFloat(&sv_client->netchan.message, /* sv_client->maxspeed */ movevars.maxspeed); // FIXME: this does't work, Tonik?
MSG_WriteFloat(&sv_client->netchan.message, movevars.spectatormaxspeed);
MSG_WriteFloat(&sv_client->netchan.message, movevars.accelerate);
MSG_WriteFloat(&sv_client->netchan.message, movevars.airaccelerate);
MSG_WriteFloat(&sv_client->netchan.message, movevars.wateraccelerate);
MSG_WriteFloat(&sv_client->netchan.message, movevars.friction);
MSG_WriteFloat(&sv_client->netchan.message, movevars.waterfriction);
MSG_WriteFloat(&sv_client->netchan.message, /* sv_client->entgravity */ movevars.entgravity); // FIXME: this does't work, Tonik?
if (sv_client->rip_vip)
{
SV_LogPlayer(sv_client, va("dropped %d", sv_client->rip_vip), 1);
SV_DropClient (sv_client);
return;
}
// send music
MSG_WriteByte (&sv_client->netchan.message, svc_cdtrack);
MSG_WriteByte (&sv_client->netchan.message, sv.edicts->v.sounds);
// send server info string
MSG_WriteByte (&sv_client->netchan.message, svc_stufftext);
MSG_WriteString (&sv_client->netchan.message, va("fullserverinfo \"%s\"\n", svs.info) );
//bliP: player logging
SV_LogPlayer(sv_client, "connect", 1);
}
/*
==================
Cmd_Soundlist_f
==================
*/
static void Cmd_Soundlist_f (void)
{
char **s;
unsigned n;
if (sv_client->state != cs_connected)
{
Con_Printf ("soundlist not valid -- already spawned\n");
return;
}
// handle the case of a level changing while a client was connecting
if (Q_atoi(Cmd_Argv(1)) != svs.spawncount)
{
SV_ClearReliable (sv_client);
Con_Printf ("SV_Soundlist_f from different level\n");
Cmd_New_f ();
return;
}
n = Q_atoi(Cmd_Argv(2));
if (n >= MAX_SOUNDS)
{
SV_ClearReliable (sv_client);
SV_ClientPrintf (sv_client, PRINT_HIGH,
"SV_Soundlist_f: Invalid soundlist index\n");
SV_DropClient (sv_client);
return;
}
//NOTE: This doesn't go through ClientReliableWrite since it's before the user
//spawns. These functions are written to not overflow
if (sv_client->num_backbuf)
{
Con_Printf("WARNING %s: [SV_Soundlist] Back buffered (%d0), clearing\n", sv_client->name, sv_client->netchan.message.cursize);
sv_client->num_backbuf = 0;
SZ_Clear(&sv_client->netchan.message);
}
MSG_WriteByte (&sv_client->netchan.message, svc_soundlist);
MSG_WriteByte (&sv_client->netchan.message, n);
for (s = sv.sound_precache+1 + n ;
*s && sv_client->netchan.message.cursize < (MAX_MSGLEN/2);
s++, n++)
MSG_WriteString (&sv_client->netchan.message, *s);
MSG_WriteByte (&sv_client->netchan.message, 0);
// next msg
if (*s)
MSG_WriteByte (&sv_client->netchan.message, n);
else
MSG_WriteByte (&sv_client->netchan.message, 0);
}
static char *TrimModelName (const char *full)
{
static char shortn[MAX_QPATH];
int len;
if (!strncmp(full, "progs/", 6) && !strchr(full + 6, '/'))
strlcpy (shortn, full + 6, sizeof(shortn)); // strip progs/
else
strlcpy (shortn, full, sizeof(shortn));
len = strlen(shortn);
if (len > 4 && !strcmp(shortn + len - 4, ".mdl")
&& strchr(shortn, '.') == shortn + len - 4)
{ // strip .mdl
shortn[len - 4] = '\0';
}
return shortn;
}
/*
==================
Cmd_Modellist_f
==================
*/
static void Cmd_Modellist_f (void)
{
char **s;
unsigned n;
if (sv_client->state != cs_connected)
{
Con_Printf ("modellist not valid -- already spawned\n");
return;
}
// handle the case of a level changing while a client was connecting
if (Q_atoi(Cmd_Argv(1)) != svs.spawncount)
{
SV_ClearReliable (sv_client);
Con_Printf ("SV_Modellist_f from different level\n");
Cmd_New_f ();
return;
}
n = Q_atoi(Cmd_Argv(2));
if (n >= MAX_MODELS)
{
SV_ClearReliable (sv_client);
SV_ClientPrintf (sv_client, PRINT_HIGH,
"SV_Modellist_f: Invalid modellist index\n");
SV_DropClient (sv_client);
return;
}
if (n == 0 && (sv_client->extensions & Z_EXT_VWEP) && sv.vw_model_name[0]) {
int i;
char ss[1024] = "//vwep ";
// send VWep precaches
for (i = 0, s = sv.vw_model_name; i < MAX_VWEP_MODELS; s++, i++) {
if (!*s || !**s)
break;
if (i > 0)
strlcat (ss, " ", sizeof(ss));
strlcat (ss, TrimModelName(*s), sizeof(ss));
}
strlcat (ss, "\n", sizeof(ss));
if (ss[strlen(ss)-1] == '\n') // didn't overflow?
{
ClientReliableWrite_Begin (sv_client, svc_stufftext, 2 + strlen(ss));
ClientReliableWrite_String (sv_client, ss);
}
}
//NOTE: This doesn't go through ClientReliableWrite since it's before the user
//spawns. These functions are written to not overflow
if (sv_client->num_backbuf)
{
Con_Printf("WARNING %s: [SV_Modellist] Back buffered (%d0), clearing\n", sv_client->name, sv_client->netchan.message.cursize);
sv_client->num_backbuf = 1;
SZ_Clear(&sv_client->netchan.message);
}
MSG_WriteByte (&sv_client->netchan.message, svc_modellist);
MSG_WriteByte (&sv_client->netchan.message, n);
for (s = sv.model_precache+1+n ;
*s && sv_client->netchan.message.cursize < (MAX_MSGLEN/2);
s++, n++)
MSG_WriteString (&sv_client->netchan.message, *s);
MSG_WriteByte (&sv_client->netchan.message, 0);
// next msg
if (*s)
MSG_WriteByte (&sv_client->netchan.message, n);
else
MSG_WriteByte (&sv_client->netchan.message, 0);
}
/*
==================
Cmd_PreSpawn_f
==================
*/
static void Cmd_PreSpawn_f (void)
{
unsigned int buf;
unsigned int check;
if (sv_client->state != cs_connected)
{
Con_Printf ("prespawn not valid -- already spawned\n");
return;
}
// handle the case of a level changing while a client was connecting
if (Q_atoi(Cmd_Argv(1)) != svs.spawncount)
{
SV_ClearReliable (sv_client);
Con_Printf ("SV_PreSpawn_f from different level\n");
Cmd_New_f ();
return;
}
buf = Q_atoi(Cmd_Argv(2));
if (buf >= sv.num_signon_buffers)
buf = 0;
if (!buf)
{
// should be three numbers following containing checksums
check = Q_atoi(Cmd_Argv(3));
// Con_DPrintf("Client check = %d\n", check);
if ((int)sv_mapcheck.value && check != sv.map_checksum &&
check != sv.map_checksum2)
{
SV_ClientPrintf (sv_client, PRINT_HIGH,
"Map model file does not match (%s), %i != %i/%i.\n"
"You may need a new version of the map, or the proper install files.\n",
sv.modelname, check, sv.map_checksum, sv.map_checksum2);
SV_DropClient (sv_client);
return;
}
sv_client->checksum = check;
}
//NOTE: This doesn't go through ClientReliableWrite since it's before the user
//spawns. These functions are written to not overflow
if (sv_client->num_backbuf)
{
Con_Printf("WARNING %s: [SV_PreSpawn] Back buffered (%d0), clearing\n", sv_client->name, sv_client->netchan.message.cursize);
sv_client->num_backbuf = 0;
SZ_Clear(&sv_client->netchan.message);
}
SZ_Write (&sv_client->netchan.message,
sv.signon_buffers[buf],
sv.signon_buffer_size[buf]);
buf++;
if (buf == sv.num_signon_buffers)
{ // all done prespawning
MSG_WriteByte (&sv_client->netchan.message, svc_stufftext);
MSG_WriteString (&sv_client->netchan.message, va("cmd spawn %i 0\n",svs.spawncount) );
}
else
{ // need to prespawn more
MSG_WriteByte (&sv_client->netchan.message, svc_stufftext);
MSG_WriteString (&sv_client->netchan.message,
va("cmd prespawn %i %i\n", svs.spawncount, buf) );
}
}
/*
==================
Cmd_Spawn_f
==================
*/
static void Cmd_Spawn_f (void)
{
int i;
client_t *client;
edict_t *ent;
eval_t *val;
unsigned n;
#ifdef USE_PR2
string_t savenetname;
#endif
if (sv_client->state != cs_connected)
{
Con_Printf ("Spawn not valid -- already spawned\n");
return;
}
// handle the case of a level changing while a client was connecting
if (Q_atoi(Cmd_Argv(1)) != svs.spawncount)
{
SV_ClearReliable (sv_client);
Con_Printf ("SV_Spawn_f from different level\n");
Cmd_New_f ();
return;
}
n = Q_atoi(Cmd_Argv(2));
if (n >= MAX_CLIENTS)
{
SV_ClientPrintf (sv_client, PRINT_HIGH,
"SV_Spawn_f: Invalid client start\n");
SV_DropClient (sv_client);
return;
}
// send all current names, colors, and frag counts
// FIXME: is this a good thing?
SZ_Clear (&sv_client->netchan.message);
// send current status of all other players
// normally this could overflow, but no need to check due to backbuf
for (i=n, client = svs.clients + n ; i<MAX_CLIENTS && sv_client->netchan.message.cursize < (MAX_MSGLEN/2); i++, client++)
SV_FullClientUpdateToClient (client, sv_client);
if (i < MAX_CLIENTS)
{
MSG_WriteByte (&sv_client->netchan.message, svc_stufftext);
MSG_WriteString (&sv_client->netchan.message,
va("cmd spawn %i %d\n", svs.spawncount, i) );
return;
}
// send all current light styles
for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
{
ClientReliableWrite_Begin (sv_client, svc_lightstyle,
3 + (sv.lightstyles[i] ? strlen(sv.lightstyles[i]) : 1));
ClientReliableWrite_Byte (sv_client, (char)i);
ClientReliableWrite_String (sv_client, sv.lightstyles[i]);
}
// set up the edict
ent = sv_client->edict;
if (sv.loadgame)
{
// loaded games are already fully initialized
// if this is the last client to be connected, unpause
if (sv.paused & 1)
SV_TogglePause (NULL, 1);
}
else
{
#ifdef USE_PR2
if ( sv_vm )
{
savenetname = ent->v.netname;
memset(&ent->v, 0, pr_edict_size - sizeof(edict_t) + sizeof(entvars_t));
ent->v.netname = savenetname;
// so spec will have right goalentity - if speccing someone
// qqshka {
if(sv_client->spectator && sv_client->spec_track > 0)
ent->v.goalentity = EDICT_TO_PROG(svs.clients[sv_client->spec_track-1].edict);
// }
//sv_client->name = PR2_GetString(ent->v.netname);
//strlcpy(PR2_GetString(ent->v.netname), sv_client->name, 32);
}
else
#endif
{
memset (&ent->v, 0, progs->entityfields * 4);
ent->v.netname = PR_SetString(sv_client->name);
}
ent->v.colormap = NUM_FOR_EDICT(ent);
ent->v.team = 0; // FIXME
if (pr_teamfield)
E_INT(ent, pr_teamfield) = PR_SetString(sv_client->team);
}
sv_client->entgravity = 1.0;
val =
#ifdef USE_PR2
PR2_GetEdictFieldValue(ent, "gravity");
#else
GetEdictFieldValue(ent, "gravity");
#endif
if (val)
val->_float = 1.0;
sv_client->maxspeed = sv_maxspeed.value;
val =
#ifdef USE_PR2
PR2_GetEdictFieldValue(ent, "maxspeed");
#else
GetEdictFieldValue(ent, "maxspeed");
#endif
if (val)
val->_float = sv_maxspeed.value;
//
// force stats to be updated
//
memset (sv_client->stats, 0, sizeof(sv_client->stats));
ClientReliableWrite_Begin (sv_client, svc_updatestatlong, 6);
ClientReliableWrite_Byte (sv_client, STAT_TOTALSECRETS);
ClientReliableWrite_Long (sv_client, PR_GLOBAL(total_secrets));
ClientReliableWrite_Begin (sv_client, svc_updatestatlong, 6);
ClientReliableWrite_Byte (sv_client, STAT_TOTALMONSTERS);
ClientReliableWrite_Long (sv_client, PR_GLOBAL(total_monsters));
ClientReliableWrite_Begin (sv_client, svc_updatestatlong, 6);
ClientReliableWrite_Byte (sv_client, STAT_SECRETS);
ClientReliableWrite_Long (sv_client, PR_GLOBAL(found_secrets));
ClientReliableWrite_Begin (sv_client, svc_updatestatlong, 6);
ClientReliableWrite_Byte (sv_client, STAT_MONSTERS);
ClientReliableWrite_Long (sv_client, PR_GLOBAL(killed_monsters));
// get the client to check and download skins
// when that is completed, a begin command will be issued
ClientReliableWrite_Begin (sv_client, svc_stufftext, 8);
ClientReliableWrite_String (sv_client, "skins\n" );
}
/*
==================
SV_SpawnSpectator
==================
*/
static void SV_SpawnSpectator (void)
{
int i;
edict_t *e;
VectorClear (sv_player->v.origin);
VectorClear (sv_player->v.view_ofs);
sv_player->v.view_ofs[2] = 22;
sv_player->v.fixangle = true;
sv_player->v.movetype = MOVETYPE_NOCLIP; // progs can change this to MOVETYPE_FLY, for example
// search for an info_playerstart to spawn the spectator at
for (i=MAX_CLIENTS-1 ; i<sv.num_edicts ; i++)
{
e = EDICT_NUM(i);
if (
#ifdef USE_PR2 /* phucking Linux implements strcmp as a macro */
!strcmp(PR2_GetString(e->v.classname), "info_player_start")
#else
!strcmp(PR_GetString(e->v.classname), "info_player_start")
#endif
)
{
VectorCopy (e->v.origin, sv_player->v.origin);
VectorCopy (e->v.angles, sv_player->v.angles);
return;
}
}
}
/*
==================
Cmd_Begin_f
==================
*/
static void Cmd_Begin_f (void)
{
unsigned pmodel = 0, emodel = 0;
int i;
if (sv_client->state == cs_spawned)
return; // don't begin again
// handle the case of a level changing while a client was connecting
if (Q_atoi(Cmd_Argv(1)) != svs.spawncount)
{
SV_ClearReliable (sv_client);
Con_Printf ("SV_Begin_f from different level\n");
Cmd_New_f ();
return;
}
sv_client->state = cs_spawned;
if (!sv.loadgame)
{
if (sv_client->spectator)
{
SV_SpawnSpectator ();
if (SpectatorConnect
#ifdef USE_PR2
|| sv_vm
#endif
)
{
// copy spawn parms out of the client_t
for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
(&PR_GLOBAL(parm1))[i] = sv_client->spawn_parms[i];
// call the spawn function
pr_global_struct->time = sv.time;
pr_global_struct->self = EDICT_TO_PROG(sv_player);
G_FLOAT(OFS_PARM0) = (float) sv_client->vip;
#ifdef USE_PR2
if ( sv_vm )
PR2_GameClientConnect(1);
else
#endif
PR_ExecuteProgram (SpectatorConnect);
#ifdef USE_PR2
// qqshka: seems spectator is sort of hack in QW
// I let qvm mods serve spectator like we do for normal player
if ( sv_vm )
{
pr_global_struct->time = sv.time;
pr_global_struct->self = EDICT_TO_PROG(sv_player);
PR2_GamePutClientInServer(1); // let mod know we put spec not player
}
#endif
}
}
else
{
// copy spawn parms out of the client_t
for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
(&PR_GLOBAL(parm1))[i] = sv_client->spawn_parms[i];
// call the spawn function
pr_global_struct->time = sv.time;
pr_global_struct->self = EDICT_TO_PROG(sv_player);
G_FLOAT(OFS_PARM0) = (float) sv_client->vip;
#ifdef USE_PR2
if ( sv_vm )
PR2_GameClientConnect(0);
else
#endif
PR_ExecuteProgram (PR_GLOBAL(ClientConnect));
// actually spawn the player
pr_global_struct->time = sv.time;
pr_global_struct->self = EDICT_TO_PROG(sv_player);
#ifdef USE_PR2
if ( sv_vm )
PR2_GamePutClientInServer(0);
else
#endif
PR_ExecuteProgram (PR_GLOBAL(PutClientInServer));
}
}
// clear the net statistics, because connecting gives a bogus picture
sv_client->netchan.frame_latency = 0;
sv_client->netchan.frame_rate = 0;
sv_client->netchan.drop_count = 0;
sv_client->netchan.good_count = 0;
//check he's not cheating
if (!sv_client->spectator)
{
if (!*Info_Get (&sv_client->_userinfo_ctx_, "pmodel") ||
!*Info_Get (&sv_client->_userinfo_ctx_, "emodel")) //bliP: typo? 2nd pmodel to emodel
SV_BroadcastPrintf (PRINT_HIGH, "%s WARNING: missing player/eyes model checksum\n", sv_client->name);
else
{
pmodel = Q_atoi(Info_Get (&sv_client->_userinfo_ctx_, "pmodel"));
emodel = Q_atoi(Info_Get (&sv_client->_userinfo_ctx_, "emodel"));
if (pmodel != sv.model_player_checksum || emodel != sv.eyes_player_checksum)
SV_BroadcastPrintf (PRINT_HIGH, "%s WARNING: non standard player/eyes model detected\n", sv_client->name);
}
}
// if we are paused, tell the client
if (sv.paused)
{
ClientReliableWrite_Begin (sv_client, svc_setpause, 2);
ClientReliableWrite_Byte (sv_client, sv.paused);
SV_ClientPrintf(sv_client, PRINT_HIGH, "Server is paused.\n");
}
if (sv.loadgame)
{
// send a fixangle over the reliable channel to make sure it gets there
// Never send a roll angle, because savegames can catch the server
// in a state where it is expecting the client to correct the angle
// and it won't happen if the game was just loaded, so you wind up
// with a permanent head tilt
edict_t *ent;
ent = EDICT_NUM( 1 + (sv_client - svs.clients) );
MSG_WriteByte (&sv_client->netchan.message, svc_setangle);
for (i = 0; i < 2; i++)
MSG_WriteAngle (&sv_client->netchan.message, ent->v.v_angle[i]);
MSG_WriteAngle (&sv_client->netchan.message, 0);
}
sv_client->lastservertimeupdate = -99; // update immediately
}
//=============================================================================
/*
==================
SV_DownloadNextFile
==================
*/
static qbool SV_DownloadNextFile (void)
{
int num;
char *name, n[MAX_OSPATH];
unsigned char all_demos_downloaded[] = "All demos downloaded.\n";
unsigned char incorrect_demo_number[] = "Incorrect demo number.\n";
switch (sv_client->demonum[0])
{
case 1:
if (sv_client->demolist)
{
Con_Printf((char *)Q_redtext(all_demos_downloaded));
sv_client->demolist = false;
}
sv_client->demonum[0] = 0;
case 0:
return false;
default:;
}
num = sv_client->demonum[--(sv_client->demonum[0])];
if (num == 0)
{
Con_Printf((char *)Q_redtext(incorrect_demo_number));
return SV_DownloadNextFile();
}
if (!(name = SV_MVDNum(num)))
{
Con_Printf((char *)Q_yelltext((unsigned char*)va("Demo number %d not found.\n",
(num & 0xFF000000) ? -(num >> 24) :
((num & 0x00800000) ? (num | 0xFF000000) : num) )));
return SV_DownloadNextFile();
}
//Con_Printf("downloading demos/%s\n",name);
snprintf(n, sizeof(n), "download demos/%s\n", name);
ClientReliableWrite_Begin (sv_client, svc_stufftext, strlen(n) + 2);
ClientReliableWrite_String (sv_client, n);
return true;
}
/*
==================
SV_CompleteDownoload
==================
This is a sub routine for SV_NextDownload(), called when download complete, we set up some fields for sv_client.
*/
void SV_CompleteDownoload(void)
{
unsigned char download_completed[] = "Download completed.\n";
char *val;
if (!sv_client->download)
return;
VFS_CLOSE (sv_client->download);
sv_client->download = NULL;
sv_client->file_percent = 0; //bliP: file percent
// qqshka: set normal rate
val = Info_Get (&sv_client->_userinfo_ctx_, "rate");
sv_client->netchan.rate = 1. / SV_BoundRate(false, Q_atoi(*val ? val : "99999"));
Con_Printf((char *)Q_redtext(download_completed));
if (SV_DownloadNextFile())
return;
// if map changed tell the client to reconnect
if (sv_client->spawncount != svs.spawncount)
{
char *str = "changing\nreconnect\n";
ClientReliableWrite_Begin (sv_client, svc_stufftext, strlen(str)+2);
ClientReliableWrite_String (sv_client, str);
}
}
/*
==================
Cmd_NextDownload_f
==================
*/
#ifdef FTE_PEXT_CHUNKEDDOWNLOADS
// qqshka: percent is optional, u can't relay on it
void SV_NextChunkedDownload(int chunknum, int percent, int chunked_download_number)
{
#define CHUNKSIZE 1024
char buffer[CHUNKSIZE];
int i;
sv_client->file_percent = bound(0, percent, 100); //bliP: file percent
if (chunknum < 0)
{ // qqshka: FTE's chunked download does't have any way of signaling what client complete dl-ing, so doing it this way.
SV_CompleteDownoload();
return;
}
if (sv_client->download_chunks_perframe)
{
int maxchunks = bound(1, (int)sv_downloadchunksperframe.value, 4);
// too much requests or client sent something wrong
if (sv_client->download_chunks_perframe >= maxchunks || chunked_download_number < 1)
return;
}
if (!sv_client->download_chunks_perframe) // ignore "rate" if not first packet per frame
if (sv_client->datagram.cursize + CHUNKSIZE+5+50 > sv_client->datagram.maxsize)
return; //choked!
if (VFS_SEEK(sv_client->download, chunknum*CHUNKSIZE, SEEK_SET))
return; // FIXME: ERROR of some kind