forked from Iceman12k/ezquake-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cl_parse.c
4524 lines (3833 loc) · 113 KB
/
cl_parse.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: cl_parse.c,v 1.135 2007-10-28 19:56:44 qqshka Exp $
*/
#include "quakedef.h"
#include "gl_model.h"
#include "cdaudio.h"
#include "ignore.h"
#include "fchecks.h"
#include "config_manager.h"
#include "utils.h"
#include "localtime.h"
#include "sbar.h"
#include "textencoding.h"
#include "vx_stuff.h"
#include "gl_model.h"
#include "teamplay.h"
#include "tp_triggers.h"
#include "pmove.h"
#include "stats_grid.h"
#include "qsound.h"
#include "menu.h"
#include "keys.h"
#include "hud.h"
#include "hud_common.h"
#include "mvd_utils.h"
#include "input.h"
#include "qtv.h"
#include "r_brushmodel_sky.h"
#include "central.h"
int CL_LoginImageId(const char* name);
#ifdef MVD_PEXT1_SERVERSIDEWEAPON
void IN_ServerSideWeaponSelectionResponse(const char* s);
#endif
#ifdef MVD_PEXT1_HIDDEN_MESSAGES
static void CL_ParseAntilagPosition(int size);
static void CL_ParseDemoInfo(int size);
static void CL_ParseDemoWeapon(int size, qbool server_side);
static void CL_ParseDamageDone(int size);
static void CL_ParseDemoWeaponInstruction(int size);
static void CL_ParseUserCommand(int size);
#endif // MVD_PEXT1_HIDDEN_MESSAGES
void R_TranslatePlayerSkin (int playernum);
char *svc_strings[] = {
"svc_bad",
"svc_nop",
"svc_disconnect",
"svc_updatestat",
"svc_version", // [long] server version
"svc_setview", // [short] entity number
"svc_sound", // <see code>
"svc_time", // [float] server time
"svc_print", // [string] null terminated string
"svc_stufftext", // [string] stuffed into client's console buffer
// the string should be \n terminated
"svc_setangle", // [vec3] set the view angle to this absolute value
"svc_serverdata", // [long] version ...
"svc_lightstyle", // [byte] [string]
"svc_updatename", // [byte] [string]
"svc_updatefrags", // [byte] [short]
"svc_clientdata", // <shortbits + data>
"svc_stopsound", // <see code>
"svc_updatecolors", // [byte] [byte]
"svc_particle", // [vec3] <variable>
"svc_damage", // [byte] impact [byte] blood [vec3] from
"svc_spawnstatic",
"OBSOLETE svc_spawnbinary",
"svc_spawnbaseline",
"svc_temp_entity", // <variable>
"svc_setpause",
"svc_signonnum",
"svc_centerprint",
"svc_killedmonster",
"svc_foundsecret",
"svc_spawnstaticsound",
"svc_intermission",
"svc_finale",
"svc_cdtrack",
"svc_sellscreen",
"svc_smallkick",
"svc_bigkick",
"svc_updateping",
"svc_updateentertime",
"svc_updatestatlong",
"svc_muzzleflash",
"svc_updateuserinfo",
"svc_download",
"svc_playerinfo",
"svc_nails",
"svc_choke",
"svc_modellist",
"svc_soundlist",
"svc_packetentities",
"svc_deltapacketentities",
"svc_maxspeed",
"svc_entgravity",
"svc_setinfo",
"svc_serverinfo",
"svc_updatepl",
"svc_nails2",
"NEW PROTOCOL",
"NEW PROTOCOL",
"NEW PROTOCOL",
"NEW PROTOCOL",
"NEW PROTOCOL",
"NEW PROTOCOL",
"NEW PROTOCOL",
"NEW PROTOCOL",
"NEW PROTOCOL",
"NEW PROTOCOL",
"NEW PROTOCOL",
"NEW PROTOCOL"
};
const int num_svc_strings = sizeof(svc_strings)/sizeof(svc_strings[0]);
//=========================================================
// Cl_Messages, just some simple network statistics/profiling
//=========================================================
#define NUMMSG 256 // for svc_xxx used one byte, so its in range...
typedef struct cl_message_s
{
int msgs;
int size;
int svc; // well, its helpful after qsort
} cl_message_t;
static cl_message_t cl_messages[NUMMSG];
static void CL_Messages_f(void);
static void CL_InitialiseDemoMessageIfRequired(void);
void Cl_Messages_Init(void)
{
int i;
memset(cl_messages, 0, sizeof(cl_messages));
for (i = 0; i < NUMMSG; i++)
cl_messages[i].svc = i; // well, its helpful after qsort
Cmd_AddCommand ("cl_messages", CL_Messages_f);
}
static int CL_Messages_qsort(const void *a, const void *b)
{
cl_message_t *msg1 = (cl_message_t*)a;
cl_message_t *msg2 = (cl_message_t*)b;
if ( msg1->size < msg2->size )
return -1;
if ( msg1->size > msg2->size )
return 1;
return 0;
}
static void CL_Messages_f(void)
{
cl_message_t messages[NUMMSG]; // local copy of cl_messages[] for qsorting
int i, svc, total;
char *svc_name;
memcpy(messages, cl_messages, sizeof(messages)); // copy it
qsort(messages, NUMMSG, sizeof(messages[0]), CL_Messages_qsort); // qsort it
Com_Printf("Received msgs:\n");
for (i = 0, total = 0; i < NUMMSG; i++)
{
if (messages[i].msgs < 1)
continue;
svc = messages[i].svc;
if (svc < 0 || svc >= NUMMSG) {
Sys_Error("CL_Messages_f: svc < 0 || svc >= NUMMSG");
return;
}
svc_name = ( svc < num_svc_strings ? svc_strings[svc] : "unknown" );
Com_Printf("%2d:%s: %d msgs: %0.2fk\n", svc, svc_name, messages[i].msgs, (float)(messages[i].size)/1024);
total += messages[i].size;
}
Com_Printf("Total size: %d\n", total);
}
//=============================================================================
packet_info_t network_stats[NETWORK_STATS_SIZE];
int packet_latency[NET_TIMINGS];
int CL_CalcNet (void)
{
int a, i, j, lost, packetcount;
frame_t *frame;
static cvar_t * netgraph_inframes = NULL;
extern hud_t * hud_netgraph;
static int last_calculated_outgoing;
static int last_calculated_incoming;
static int last_lost;
if (last_calculated_incoming == cls.netchan.incoming_sequence &&
last_calculated_outgoing == cls.netchan.outgoing_sequence)
return last_lost;
last_calculated_outgoing = cls.netchan.outgoing_sequence;
last_calculated_incoming = cls.netchan.incoming_sequence;
if (netgraph_inframes == NULL)
netgraph_inframes = HUD_FindVar(hud_netgraph, "inframes");
for (i = cls.netchan.outgoing_sequence-UPDATE_BACKUP + 1; i <= cls.netchan.outgoing_sequence; i++)
{
frame = &cl.frames[i & UPDATE_MASK];
j = i & NETWORK_STATS_MASK;
if (frame->receivedtime == -1)
{
packet_latency[i & NET_TIMINGSMASK] = 9999; // dropped
network_stats[j].status = packet_dropped;
}
else if (frame->receivedtime == -2)
{
packet_latency[i & NET_TIMINGSMASK] = 10000; // choked
network_stats[j].status = packet_choked;
}
else if (frame->receivedtime == -3)
{
packet_latency[i & NET_TIMINGSMASK] = -1; // choked by c2spps
network_stats[j].status = packet_netlimit;
}
else if (frame->invalid)
{
packet_latency[i & NET_TIMINGSMASK] = 9998; // invalid delta
network_stats[j].status = packet_delta;
}
else
{
double l;
if (netgraph_inframes->value) // [frames]
l = 2*(frame->seq_when_received-i);
else // [miliseconds]
l = min((frame->receivedtime - frame->senttime)*1000, 1000);
packet_latency[i&NET_TIMINGSMASK] = (int)l;
network_stats[j].status = packet_ok;
}
}
lost = packetcount = 0;
for (a = 0; a < NET_TIMINGS; a++)
{
// fix for packetloss on high ping
if (a < UPDATE_BACKUP && (cls.realtime -
cl.frames[(cls.netchan.outgoing_sequence-a)&UPDATE_MASK].senttime) < cls.latency)
continue;
i = (cls.netchan.outgoing_sequence-a) & NET_TIMINGSMASK;
if (packet_latency[i] == 9999)
lost++;
if (packet_latency[i] != -1) // don't count packets choked by c2spps
packetcount++;
}
last_lost = packetcount ? lost * 100 / packetcount : 100;
return last_lost;
}
// More network statistics
int CL_CalcNetStatistics(
/* in */
float period, // period of time
packet_info_t *samples, // statistics table
int num_samples, // table size
/* out */
net_stat_result_t *res)
{
int i, p, q; // calc fom p to q
float ping_min, ping_max, ping_avg, ping_dev, ping_sum, ping_dev_sum;
float f_min, f_max, f_avg, f_dev, f_sum, f_dev_sum;
int lost_lost, lost_rate, lost_delta, lost_netlimit;
int size_sent, size_received;
int samples_received, samples_sent, samples_delta;
if (cls.netchan.outgoing_sequence - cls.netchan.incoming_sequence > NETWORK_STATS_SIZE/2)
return (res->samples = 0);
// find boundaries
q = cls.netchan.incoming_sequence - 1;
p = q - 1;
while (p > cls.netchan.outgoing_sequence - NETWORK_STATS_SIZE + 1 &&
samples[q&NETWORK_STATS_MASK].senttime - samples[p&NETWORK_STATS_MASK].senttime < period)
{
p--;
}
// init values
samples_sent = 0;
samples_received = 0;
samples_delta = 0; // packets with delta compression applied
ping_sum = 0;
ping_min = 99999999;
ping_max = -99999999;
ping_dev_sum = 0;
f_sum = 0;
f_min = 99999999;
f_max = -99999999;
f_dev_sum = 0;
lost_lost = 0;
lost_rate = 0;
lost_netlimit = 0;
lost_delta = 0;
size_sent = 0;
size_received = 0;
for (i=p; i < q; i++)
{
int a = i & NETWORK_STATS_MASK;
if (samples[a].status == packet_netlimit)
{
// not even sent
lost_netlimit++;
continue;
}
// packet was sent
samples_sent++;
size_sent += samples[a].sentsize;
switch (samples[a].status)
{
case packet_delta:
lost_delta++;
samples_delta++;
break;
case packet_choked:
lost_rate++;
break;
case packet_dropped:
lost_lost++;
break;
case packet_ok:
// packet received
{
float ping;
int frames;
samples_received++;
frames = samples[a].seq_diff;
ping = 1000*(samples[a].receivedtime - samples[a].senttime);
if (ping < ping_min) ping_min = ping;
if (ping > ping_max) ping_max = ping;
if (frames < f_min) f_min = frames;
if (frames > f_max) f_max = frames;
ping_sum += ping;
f_sum += frames;
size_received += samples[a].receivedsize;
if (samples[a].delta)
samples_delta++;
}
default:
break;
}
// end of loop
}
if (samples_sent <= 0 || samples_received <= 0)
return (res->samples = 0);
ping_avg = ping_sum / samples_received;
f_avg = f_sum / samples_received;
// loop again to calc standard deviation
for (i=p; i < q; i++)
{
int a = i & NETWORK_STATS_MASK;
if (samples[a].status == packet_ok)
{
float ping;
int frames;
frames = samples[a].seq_diff;
ping = 1000*(samples[a].receivedtime - samples[a].senttime);
ping_dev_sum += (ping - ping_avg) * (ping - ping_avg);
f_dev_sum += (frames - f_avg) * (frames - f_avg);
}
}
ping_dev = sqrt(ping_dev_sum / samples_received);
f_dev = sqrt(f_dev_sum / samples_received);
// fill-in result struct
res->ping_min = ping_min;
res->ping_max = ping_max;
res->ping_avg = ping_avg;
res->ping_dev = ping_dev;
res->ping_f_min = f_min;
res->ping_f_max = f_max;
res->ping_f_avg = f_avg;
res->ping_f_dev = f_dev;
res->lost_netlimit = lost_netlimit * 100.0 / (q-p);
res->lost_lost = lost_lost * 100.0 / samples_sent;
res->lost_rate = lost_rate * 100.0 / samples_sent;
res->bandwidth_in = lost_delta * 100.0 / samples_sent;
res->size_out = size_sent / (float)samples_sent;
res->size_in = size_received / (float)samples_received;
res->bandwidth_out = size_sent / period;
res->bandwidth_in = size_received / period;
res->delta = (samples_delta > 0) ? 1 : 0;
res->samples = q-p;
return res->samples;
}
//=============================================================================
// Returns true if the file exists, otherwise it attempts to start a download from the server.
qbool CL_CheckOrDownloadFile(char *filename)
{
vfsfile_t *f;
char *tmp;
if (strstr(filename, "..") || !strcmp(filename, "") || filename[0] == '/' || strchr(filename, '\\') || strchr(filename, ':') || strstr(filename, "//")) {
Com_Printf("Warning: Invalid characters in filename \"%s\"\n", filename);
return true;
}
if ((tmp = strrchr(filename, '.')) && (!strcasecmp(tmp, ".dll") || !strcasecmp(tmp, ".so"))) {
Com_Printf("Warning: Non-allowed file \"%s\" skipped\n", filename);
return true;
}
f = FS_OpenVFS(filename, "rb", FS_ANY);
if (f) {
VFS_CLOSE(f);
return true;
}
// Can't download when playback, except qtv which support download
if (cls.demoplayback)
{
if (cls.mvdplayback == QTV_PLAYBACK)
{
if (!(cls.qtv_ezquake_ext & QTV_EZQUAKE_EXT_DOWNLOAD))
{
Com_Printf ("Unable to download %s, this QTV does't support download\n", filename);
return true;
}
}
else
return true;
}
if (cls.state < ca_connected)
{
Com_DPrintf ("Unable to download %s, not connected\n", filename);
return true;
}
snprintf (cls.downloadname, sizeof(cls.downloadname), "%s/%s", cls.gamedir, filename);
Com_Printf ("Downloading %s...\n", filename);
// download to a temp name, and only rename
// to the real name when done, so if interrupted
// a runt file wont be left
cls.downloadmethod = DL_QW; // by default its DL_QW, if server support DL_QWCHUNKED it will be changed.
cls.downloadstarttime = Sys_DoubleTime();
COM_StripExtension (cls.downloadname, cls.downloadtempname, sizeof(cls.downloadtempname));
strlcat (cls.downloadtempname, ".tmp", sizeof(cls.downloadtempname));
if (cls.mvdplayback == QTV_PLAYBACK)
{
QTV_Cmd_Printf(QTV_EZQUAKE_EXT_DOWNLOAD, "download \"%s\"", filename);
}
else
{
MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
MSG_WriteString (&cls.netchan.message, va("download \"%s\"", filename));
}
cls.downloadnumber++;
return false;
}
void CL_FindModelNumbers (void)
{
int i, j;
for (i = 0; i < cl_num_modelindices; i++)
cl_modelindices[i] = -1;
for (i = 0; i < MAX_MODELS; i++)
{
for (j = 0; j < cl_num_modelindices; j++)
{
if (!strcmp(cl_modelnames[j], cl.model_name[i]))
{
cl_modelindices[j] = i;
break;
}
}
}
}
void CL_ProxyEnter (void)
{
if (!strcmp(cl.levelname, "Qizmo menu") || // qizmo detection
strstr(cl.serverinfo, "*QTV")) // fteqtv detection
{
// If we are connected only to the proxy frontend
// we presume that the menu is on.
M_EnterProxyMenu();
}
else if (key_dest == key_menu && m_state == m_proxy)
{
// This happens when we connect to a server using a proxy.
M_LeaveMenus();
}
// If we used console to connect to a server via proxy,
// cancel return to the proxy menu, because it's not there.
if (key_dest_beforecon == key_menu)
key_dest_beforecon = key_game;
}
static void CL_TransmitModelCrc (int index, char *info_key)
{
if (index != -1)
{
struct model_s *model = cl.model_precache[index];
unsigned short crc = model->crc;
MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
MSG_WriteString (&cls.netchan.message, va("setinfo %s %d", info_key, (int) crc));
Info_SetValueForKey(cls.userinfo, info_key, va("%d", (int) crc), MAX_INFO_STRING);
}
}
void CL_Prespawn (void)
{
cl.worldmodel = cl.model_precache[1];
if (!cl.worldmodel)
Host_Error ("Model_NextDownload: NULL worldmodel");
CL_FindModelNumbers ();
R_NewMap (false);
TP_NewMap();
MT_NewMap();
Stats_NewMap();
CL_ProxyEnter();
MVD_Stats_Cleanup();
// Reset the status grid.
StatsGrid_Remove(&stats_grid);
StatsGrid_ResetHoldItems();
HUD_NewMap();
Hunk_Check(); // make sure nothing is hurt
CL_TransmitModelCrc (cl_modelindices[mi_player], "pmodel");
CL_TransmitModelCrc (cl_modelindices[mi_eyes], "emodel");
#if 0
//TEI: loading entitys from map, at clientside,
// will be usefull to locate more eyecandy and cameras
if (cl.worldmodel->entities)
{
CL_PR_LoadProgs();
CL_ED_LoadFromFile (cl.worldmodel->entities);
}
#endif
// done with modellist, request first of static signon messages, in case of qtv it different
if (cls.mvdplayback == QTV_PLAYBACK)
{
QTV_Cmd_Printf(QTV_EZQUAKE_EXT_DOWNLOAD, "qtvspawn %i", cl.servercount);
}
else
{
MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
MSG_WriteString (&cls.netchan.message, va("prespawn %i 0 %i", cl.servercount, cl.map_checksum2));
}
}
/*
=================
VWepModel_NextDownload
=================
*/
void CL_ParseVWepPrecache (char *str);
void VWepModel_NextDownload (void)
{
int i;
extern cvar_t cl_novweps;
if (((!(cl.z_ext & Z_EXT_VWEP) || !cl.vw_model_name[0][0]) && !cls.mvdplayback)
|| cl_novweps.value)
{
// no vwep support, go straight to prespawn
CL_Prespawn ();
return;
}
if (cls.mvdplayback && cls.downloadnumber == 0)
{
CL_ParseVWepPrecache ("//vwep vwplayer w_axe w_shot w_shot2 w_nail w_nail2 w_rock w_rock2 w_light");
}
if (cls.downloadnumber == 0)
{
if (!com_serveractive || developer.value)
Com_DPrintf ("Checking vwep models...\n");
//cls.downloadnumber = 0;
}
cls.downloadtype = dl_vwep_model;
for ( ; cls.downloadnumber < MAX_VWEP_MODELS; cls.downloadnumber++)
{
if (!cl.vw_model_name[cls.downloadnumber][0] ||
cl.vw_model_name[cls.downloadnumber][0] == '-')
continue;
if (!CL_CheckOrDownloadFile(cl.vw_model_name[cls.downloadnumber]))
return; // started a download
}
for (i = 0; i < MAX_VWEP_MODELS; i++)
{
if (!cl.vw_model_name[i][0])
continue;
if (strcmp(cl.vw_model_name[i], "-"))
cl.vw_model_precache[i] = Mod_ForName (cl.vw_model_name[i], false);
if (!cl.vw_model_precache[i])
{
// never mind
// Com_Printf ("Warning: model %s could not be found\n", cl.vw_model_name[i]);
}
}
if (!strcmp(cl.vw_model_name[0], "-") || cl.vw_model_precache[0])
cl.vwep_enabled = true;
else
{
// if the vwep player model is required but not present,
// don't enable vwep support
}
// all done
CL_Prespawn ();
}
void Model_NextDownload (void)
{
int i;
char *s;
char mapname[MAX_QPATH];
if (cls.downloadnumber == 0)
{
if (!com_serveractive || developer.value)
Com_DPrintf ("Checking models...\n");
cls.downloadnumber = 1;
}
cls.downloadtype = dl_model;
for ( ; cl.model_name[cls.downloadnumber][0]; cls.downloadnumber++)
{
s = cl.model_name[cls.downloadnumber];
if (s[0] == '*')
continue; // inline brush model
if (!CL_CheckOrDownloadFile(s))
return; // started a download
}
cl.clipmodels[1] = CM_LoadMap (cl.model_name[1], true, NULL, &cl.map_checksum2);
COM_StripExtension (COM_SkipPath(cl.model_name[1]), mapname, sizeof(mapname));
cl.map_checksum2 = Com_TranslateMapChecksum (mapname, cl.map_checksum2);
R_NewMapPreLoad();
for (i = 1; i < MAX_MODELS; i++) {
if (!cl.model_name[i][0]) {
break;
}
cl.model_precache[i] = Mod_ForName(cl.model_name[i], false);
if (!cl.model_precache[i]) {
Com_Printf("\n&cf22Couldn't load model:&r %s\n", cl.model_name[i]);
Host_EndGame();
return;
}
if (cl.model_name[i][0] == '*') {
cl.clipmodels[i] = CM_InlineModel(cl.model_name[i]);
}
}
// Done with normal models, request vwep models if necessary
cls.downloadtype = dl_vwep_model;
cls.downloadnumber = 0;
VWepModel_NextDownload ();
}
void Sound_NextDownload (void)
{
char *s;
int i;
if (cls.downloadnumber == 0)
{
if (!com_serveractive || developer.value)
Com_DPrintf ("Checking sounds...\n");
cls.downloadnumber = 1;
}
cls.downloadtype = dl_sound;
for ( ; cl.sound_name[cls.downloadnumber][0]; cls.downloadnumber++)
{
s = cl.sound_name[cls.downloadnumber];
if (!CL_CheckOrDownloadFile(va("sound/%s",s)))
return; // started a download
}
for (i = 1; i < MAX_SOUNDS; i++)
{
if (!cl.sound_name[i][0])
break;
cl.sound_precache[i] = S_PrecacheSound (cl.sound_name[i]);
}
// Done with sound downloads, go for models
cls.downloadnumber = 0;
cls.downloadtype = dl_model;
Model_NextDownload ();
}
#ifdef FTE_PEXT_CHUNKEDDOWNLOADS
//
// FTE's chunked download
//
extern void CL_RequestNextDownload (void);
#define MAXBLOCKS 1024 // Must be power of 2
#define DLBLOCKSIZE 1024
int chunked_download_number = 0; // Never reset, bumped up.
int downloadsize;
int receivedbytes;
int recievedblock[MAXBLOCKS];
int firstblock;
int blockcycle;
int CL_RequestADownloadChunk(void)
{
int i;
int b;
if (cls.downloadmethod != DL_QWCHUNKS) // Paranoia!
Host_Error("download not initiated\n");
for (i = 0; i < MAXBLOCKS; i++)
{
blockcycle++;
b = ((blockcycle) & (MAXBLOCKS-1)) + firstblock;
if (!recievedblock[b&(MAXBLOCKS-1)]) // Don't ask for ones we've already got.
{
if (b >= (downloadsize+DLBLOCKSIZE-1)/DLBLOCKSIZE) // Don't ask for blocks that are over the size of the file.
continue;
return b;
}
}
return -1;
}
void CL_SendChunkDownloadReq(void)
{
extern cvar_t cl_chunksperframe;
int i, j, chunks;
chunks = bound(1, cl_chunksperframe.integer, 5);
for (j = 0; j < chunks; j++)
{
if (cls.downloadmethod != DL_QWCHUNKS)
return;
i = CL_RequestADownloadChunk();
// i < 0 mean client complete download, let server know
// qqshka: download percent optional, server does't really require it, that my extension, hope does't fuck up something
if (i < 0)
{
if (strstr(Info_ValueForKey(cl.serverinfo, "*version"), "MVDSV"))
CL_SendClientCommand(true, "nextdl %d %d %d", i, cls.downloadpercent, chunked_download_number);
else
CL_SendClientCommand(true, "stopdownload");
cls.downloadpercent = 100;
CL_FinishDownload(); // this also request next dl
}
else
{
CL_SendClientCommand(false, "nextdl %d %d %d", i, cls.downloadpercent, chunked_download_number);
}
}
}
void CL_ParseDownload (void);
void CL_Parse_OOB_ChunkedDownload(void)
{
int j;
for ( j = 0; j < sizeof("\\chunk")-1; j++ )
MSG_ReadByte ();
//
// qqshka: well, this is evil.
// In case of when one file completed download and next started
// here may be some packets which travel via network,
// so we got packets from different file, that mean we may assemble wrong data,
// need somehow discard such packets, i have no idea how, so adding at least this check.
//
if (chunked_download_number != MSG_ReadLong ())
{
Com_DPrintf("Dropping OOB chunked message, out of sequence\n");
return;
}
if (MSG_ReadByte() != svc_download)
{
Com_DPrintf("Something wrong in OOB message and chunked download\n");
return;
}
CL_ParseDownload ();
}
void CL_ParseChunkedDownload(void)
{
char *svname;
int totalsize;
int chunknum;
char data[DLBLOCKSIZE];
double tm;
chunknum = MSG_ReadLong();
if (chunknum < 0)
{
totalsize = MSG_ReadLong();
svname = MSG_ReadString();
if (cls.download)
{
// Ensure FILE is closed
if (totalsize != -3) // -3 = dl stopped, so this known issue, do not warn
Com_Printf ("cls.download shouldn't have been set\n");
fclose (cls.download);
cls.download = NULL;
cls.downloadpercent = 0;
}
if (cls.demoplayback)
return;
if (totalsize < 0)
{
switch (totalsize)
{
case -3: Com_DPrintf("Server cancel downloading file %s\n", svname); break;
case -2: Com_Printf("Server permissions deny downloading file %s\n", svname); break;
default: Com_Printf("Couldn't find file %s on the server\n", svname); break;
}
CL_FinishDownload(); // this also request next dl
return;
}
if (cls.downloadmethod == DL_QWCHUNKS)
Host_Error("Received second download - \"%s\"\n", svname);
// FIXME: damn, fixme!!!!!
// if (strcasecmp(cls.downloadname, svname))
// Host_Error("Server sent the wrong download - \"%s\" instead of \"%s\"\n", svname, cls.downloadname);
// Start the new download
FS_CreatePath (cls.downloadtempname);
if ( !(cls.download = fopen (cls.downloadtempname, "wb")) )
{
Com_Printf ("Failed to open %s\n", cls.downloadtempname);
CL_FinishDownload(); // This also requests next dl.
return;
}
cls.downloadmethod = DL_QWCHUNKS;
cls.downloadpercent = 0;
chunked_download_number++;
downloadsize = totalsize;
firstblock = 0;
receivedbytes = 0;
blockcycle = -1; //so it requests 0 first. :)
memset(recievedblock, 0, sizeof(recievedblock));
return;
}
MSG_ReadData(data, DLBLOCKSIZE);
if (!cls.download)
{
return;
}
if (cls.downloadmethod != DL_QWCHUNKS)
Host_Error("cls.downloadmethod != DL_QWCHUNKS\n");
if (cls.demoplayback)
{
// Err, yeah, when playing demos we don't actually pay any attention to this.
return;
}
if (chunknum < firstblock)
{
return;
}