-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathsv_send.c
1338 lines (1105 loc) · 30.5 KB
/
sv_send.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_send.c 772 2008-03-08 23:57:13Z qqshka $
*/
#include "qwsvdef.h"
#define CHAN_AUTO 0
#define CHAN_WEAPON 1
#define CHAN_VOICE 2
#define CHAN_ITEM 3
#define CHAN_BODY 4
/*
=============================================================================
Con_Printf redirection
=============================================================================
*/
char outputbuf[OUTPUTBUF_SIZE];
redirect_t sv_redirected;
static int sv_redirectbufcount;
extern cvar_t sv_phs;
/*
==================
SV_FlushRedirect
==================
*/
void SV_FlushRedirect (void)
{
char send1[OUTPUTBUF_SIZE + 6];
if (sv_redirected == RD_PACKET)
{
send1[0] = 0xff;
send1[1] = 0xff;
send1[2] = 0xff;
send1[3] = 0xff;
send1[4] = A2C_PRINT;
memcpy (send1 + 5, outputbuf, strlen(outputbuf) + 1);
NET_SendPacket (NS_SERVER, strlen(send1) + 1, send1, net_from);
}
else if (sv_redirected == RD_CLIENT && sv_redirectbufcount < MAX_REDIRECTMESSAGES)
{
ClientReliableWrite_Begin (sv_client, svc_print, strlen(outputbuf)+3);
ClientReliableWrite_Byte (sv_client, PRINT_HIGH);
ClientReliableWrite_String (sv_client, outputbuf);
sv_redirectbufcount++;
}
else if (sv_redirected == RD_MOD)
{
//return;
}
else if (sv_redirected > RD_MOD && sv_redirectbufcount < MAX_REDIRECTMESSAGES)
{
client_t *cl;
cl = svs.clients + sv_redirected - RD_MOD - 1;
if (cl->state == cs_spawned)
{
ClientReliableWrite_Begin (cl, svc_print, strlen(outputbuf)+3);
ClientReliableWrite_Byte (cl, PRINT_HIGH);
ClientReliableWrite_String (cl, outputbuf);
sv_redirectbufcount++;
}
}
// clear it
outputbuf[0] = 0;
}
/*
==================
SV_BeginRedirect
Send Con_Printf data to the remote client
instead of the console
==================
*/
void SV_BeginRedirect (redirect_t rd)
{
sv_redirected = rd;
outputbuf[0] = 0;
sv_redirectbufcount = 0;
}
void SV_EndRedirect (void)
{
SV_FlushRedirect ();
sv_redirected = RD_NONE;
}
#if 0
/*
================
Con_Printf
Handles cursor positioning, line wrapping, etc
================
*/
#define MAXPRINTMSG 4096
void Con_Printf (char *fmt, ...)
{
va_list argptr;
char msg[MAXPRINTMSG];
va_start (argptr,fmt);
vsnprintf (msg, MAXPRINTMSG, fmt, argptr);
va_end (argptr);
// add to redirected message
if (sv_redirected)
{
if (strlen (msg) + strlen(outputbuf) > /*sizeof(outputbuf) - 1*/ MAX_MSGLEN - 10)
SV_FlushRedirect ();
strlcat (outputbuf, msg, sizeof(outputbuf));
return;
}
Sys_Printf ("%s", msg); // also echo to debugging console
SV_Write_Log(CONSOLE_LOG, 0, msg);
// dumb error message to log file if
if (sv_error)
SV_Write_Log(ERROR_LOG, 1, msg);
}
/*
================
Con_DPrintf
A Con_Printf that only shows up if the "developer" cvar is set
================
*/
void Con_DPrintf (char *fmt, ...)
{
va_list argptr;
char msg[MAXPRINTMSG];
if (!(int)developer.value)
return;
va_start (argptr,fmt);
vsnprintf (msg, MAXPRINTMSG, fmt, argptr);
va_end (argptr);
Con_Printf ("%s", msg);
}
#endif
/*
=============================================================================
EVENT MESSAGES
=============================================================================
*/
static void SV_PrintToClient(client_t *cl, int level, char *string)
{
ClientReliableWrite_Begin (cl, svc_print, strlen(string)+3);
ClientReliableWrite_Byte (cl, level);
ClientReliableWrite_String (cl, string);
}
/*
=================
SV_ClientPrintf
Sends text across to be displayed if the level passes
=================
*/
void SV_ClientPrintf (client_t *cl, int level, char *fmt, ...)
{
va_list argptr;
char string[1024];
if (level < cl->messagelevel)
return;
va_start (argptr,fmt);
vsnprintf (string, sizeof(string), fmt, argptr);
va_end (argptr);
if (sv.mvdrecording)
{
if (MVDWrite_Begin (dem_single, cl - svs.clients, strlen(string)+3))
{
MVD_MSG_WriteByte (svc_print);
MVD_MSG_WriteByte (level);
MVD_MSG_WriteString (string);
}
}
SV_PrintToClient(cl, level, string);
}
void SV_ClientPrintf2 (client_t *cl, int level, char *fmt, ...)
{
va_list argptr;
char string[1024];
if (level < cl->messagelevel)
return;
va_start (argptr,fmt);
vsnprintf (string, sizeof(string), fmt, argptr);
va_end (argptr);
SV_PrintToClient(cl, level, string);
}
/*
=================
SV_BroadcastPrintf
Sends text to all active clients
=================
*/
char *parse_mod_string(char *str);
void SV_DoBroadcastPrintf (int level, int flags, char *string)
{
char *fraglog;
static char string2[1024] = {0};
client_t *cl;
int i;
if (!(flags & BPRINT_IGNORECONSOLE))
Sys_Printf ("%s", string); // print to the console
if (!(flags & BPRINT_IGNORECLIENTS))
{
for (i=0, cl = svs.clients ; i<MAX_CLIENTS ; i++, cl++)
{
if (level < cl->messagelevel)
continue;
if (cl->state < cs_connected)
continue;
SV_PrintToClient(cl, level, string); // this does't go to mvd demo
}
}
if (!(flags & BPRINT_IGNOREINDEMO))
{
if (flags & BPRINT_QTVONLY)
{
sizebuf_t msg;
byte msg_buf[1024];
SZ_InitEx(&msg, msg_buf, sizeof(msg_buf), true);
MSG_WriteByte (&msg, svc_print);
MSG_WriteByte (&msg, level);
MSG_WriteString (&msg, string);
DemoWriteQTV(&msg);
}
else
{
if (sv.mvdrecording)
{
if (MVDWrite_Begin (dem_all, 0, strlen(string)+3))
{
MVD_MSG_WriteByte (svc_print);
MVD_MSG_WriteByte (level);
MVD_MSG_WriteString (string);
}
}
}
}
// SV_Write_Log(MOD_FRAG_LOG, 1, "=== SV_BroadcastPrintf ===\n");
// SV_Write_Log(MOD_FRAG_LOG, 1, va("%d\n===>", time(NULL)));
// SV_Write_Log(MOD_FRAG_LOG, 1, string);
// SV_Write_Log(MOD_FRAG_LOG, 1, "<===\n");
if (string[0] && logs[MOD_FRAG_LOG].sv_logfile)
{
if (string[strlen(string) - 1] == '\n')
{
strlcat(string2, string, sizeof(string2));
// SV_Write_Log(MOD_FRAG_LOG, 1, "=== SV_BroadcastPrintf ==={\n");
// SV_Write_Log(MOD_FRAG_LOG, 1, string2);
// SV_Write_Log(MOD_FRAG_LOG, 1, "}==========================\n");
if ((fraglog = parse_mod_string(string2)))
{
SV_Write_Log(MOD_FRAG_LOG, 1, fraglog);
Q_free(fraglog);
}
string2[0] = 0;
}
else
strlcat(string2, string, sizeof(string2));
}
// SV_Write_Log(MOD_FRAG_LOG, 1, "==========================\n\n");
}
void SV_BroadcastPrintf (int level, char *fmt, ...)
{
va_list argptr;
char string[1024];
va_start (argptr,fmt);
vsnprintf (string, sizeof(string), fmt, argptr);
va_end (argptr);
SV_DoBroadcastPrintf (level, 0, string);
}
void SV_BroadcastPrintfEx (int level, int flags, char *fmt, ...)
{
va_list argptr;
char string[1024];
va_start (argptr,fmt);
vsnprintf (string, sizeof(string), fmt, argptr);
va_end (argptr);
SV_DoBroadcastPrintf (level, flags, string);
}
/*
=================
SV_BroadcastCommand
Sends text to all active clients
=================
*/
void SV_BroadcastCommand (char *fmt, ...)
{
va_list argptr;
char string[1024];
if (!sv.state)
return;
va_start (argptr,fmt);
vsnprintf (string, sizeof(string), fmt, argptr);
va_end (argptr);
MSG_WriteByte (&sv.reliable_datagram, svc_stufftext);
MSG_WriteString (&sv.reliable_datagram, string);
}
/*
=================
SV_Multicast
Sends the contents of sv.multicast to a subset of the clients,
then clears sv.multicast.
MULTICAST_ALL same as broadcast
MULTICAST_PVS send to clients potentially visible from org
MULTICAST_PHS send to clients potentially hearable from org
=================
*/
void SV_Multicast (vec3_t origin, int to)
{
client_t *client;
byte *mask;
int leafnum;
int j;
qbool reliable;
vec3_t vieworg;
reliable = false;
switch (to)
{
case MULTICAST_ALL_R:
reliable = true; // intentional fallthrough
case MULTICAST_ALL:
mask = NULL; // everything
break;
case MULTICAST_PHS_R:
reliable = true; // intentional fallthrough
case MULTICAST_PHS:
mask = CM_LeafPHS (CM_PointInLeaf(origin));
break;
case MULTICAST_PVS_R:
reliable = true; // intentional fallthrough
case MULTICAST_PVS:
mask = CM_LeafPVS (CM_PointInLeaf (origin));
break;
default:
mask = NULL;
SV_Error ("SV_Multicast: bad to:%i", to);
}
// send the data to all relevent clients
for (j = 0, client = svs.clients; j < MAX_CLIENTS; j++, client++)
{
if (client->state != cs_spawned)
continue;
if (!mask)
goto inrange; // multicast to all
VectorAdd (client->edict->v.origin, client->edict->v.view_ofs, vieworg);
if (to == MULTICAST_PHS_R || to == MULTICAST_PHS)
{
vec3_t delta;
VectorSubtract(origin, vieworg, delta);
if (VectorLength(delta) <= 1024)
goto inrange;
}
leafnum = CM_Leafnum(CM_PointInLeaf(vieworg));
if (leafnum)
{
// -1 is because pvs rows are 1 based, not 0 based like leafs
leafnum = leafnum - 1;
if ( !(mask[leafnum>>3] & (1<<(leafnum&7)) ) )
{
// Con_Printf ("supressed multicast\n");
continue;
}
}
inrange:
if (reliable)
{
ClientReliableCheckBlock(client, sv.multicast.cursize);
ClientReliableWrite_SZ(client, sv.multicast.data, sv.multicast.cursize);
}
else
SZ_Write (&client->datagram, sv.multicast.data, sv.multicast.cursize);
}
if (sv.mvdrecording)
{
if (reliable)
{
if (MVDWrite_Begin(dem_all, 0, sv.multicast.cursize))
{
MVD_SZ_Write(sv.multicast.data, sv.multicast.cursize);
}
}
else
SZ_Write(&demo.datagram, sv.multicast.data, sv.multicast.cursize);
}
SZ_Clear (&sv.multicast);
}
void SV_StartParticle (vec3_t org, vec3_t dir, int color, int count,
int replacement_te, int replacement_count)
{
int i, v;
qbool send_count;
//if (AllClientsWantSVCParticle())
if (0)
{
MSG_WriteByte (&sv.multicast, nq_svc_particle);
MSG_WriteCoord (&sv.multicast, org[0]);
MSG_WriteCoord (&sv.multicast, org[1]);
MSG_WriteCoord (&sv.multicast, org[2]);
for (i=0 ; i<3 ; i++)
{
v = dir[i]*16;
if (v > 127)
v = 127;
else if (v < -128)
v = -128;
MSG_WriteChar (&sv.multicast, v);
}
MSG_WriteByte (&sv.multicast, count);
MSG_WriteByte (&sv.multicast, color);
}
else
{
if (replacement_te == TE_EXPLOSION || replacement_te == TE_LIGHTNINGBLOOD)
send_count = false;
else if (replacement_te == TE_BLOOD || replacement_te == TE_GUNSHOT)
send_count = true;
else
return; // don't send anything
MSG_WriteByte (&sv.multicast, svc_temp_entity);
MSG_WriteByte (&sv.multicast, replacement_te);
if (send_count)
MSG_WriteByte (&sv.multicast, replacement_count);
MSG_WriteCoord (&sv.multicast, org[0]);
MSG_WriteCoord (&sv.multicast, org[1]);
MSG_WriteCoord (&sv.multicast, org[2]);
}
SV_Multicast (org, MULTICAST_PVS);
}
/*
==================
SV_StartSound
Each entity can have eight independant sound sources, like voice,
weapon, feet, etc.
Channel 0 is an auto-allocate channel, the others override anything
already running on that entity/channel pair.
An attenuation of 0 will play full volume everywhere in the level.
Larger attenuations will drop off. (max 4 attenuation)
==================
*/
void SV_StartSound (edict_t *entity, int channel, char *sample, int volume,
float attenuation)
{
int sound_num;
int i;
int ent;
vec3_t origin;
qbool use_phs;
qbool reliable = false;
if (volume < 0 || volume > 255)
SV_Error ("SV_StartSound: volume = %i", volume);
if (attenuation < 0 || attenuation > 4)
SV_Error ("SV_StartSound: attenuation = %f", attenuation);
if (channel < 0 || channel > 15)
SV_Error ("SV_StartSound: channel = %i", channel);
// find precache number for sound
for (sound_num=1 ; sound_num<MAX_SOUNDS
&& sv.sound_precache[sound_num] ; sound_num++)
if (!strcmp(sample, sv.sound_precache[sound_num]))
break;
if ( sound_num == MAX_SOUNDS || !sv.sound_precache[sound_num] )
{
Con_Printf ("SV_StartSound: %s not precacheed\n", sample);
return;
}
ent = NUM_FOR_EDICT(entity);
if ((channel & 8) || !(int)sv_phs.value) // no PHS flag
{
if (channel & 8)
reliable = true; // sounds that break the phs are reliable
use_phs = false;
channel &= 7;
}
else
use_phs = true;
// if (channel == CHAN_BODY || channel == CHAN_VOICE)
// reliable = true;
channel = (ent<<3) | channel;
if (volume != DEFAULT_SOUND_PACKET_VOLUME)
channel |= SND_VOLUME;
if (attenuation != DEFAULT_SOUND_PACKET_ATTENUATION)
channel |= SND_ATTENUATION;
// use the entity origin unless it is a bmodel
if (entity->v.solid == SOLID_BSP)
{
for (i=0 ; i<3 ; i++)
origin[i] = entity->v.origin[i]+0.5*(entity->v.mins[i]+entity->v.maxs[i]);
}
else
{
VectorCopy (entity->v.origin, origin);
}
MSG_WriteByte (&sv.multicast, svc_sound);
MSG_WriteShort (&sv.multicast, channel);
if (channel & SND_VOLUME)
MSG_WriteByte (&sv.multicast, volume);
if (channel & SND_ATTENUATION)
MSG_WriteByte (&sv.multicast, attenuation*64);
MSG_WriteByte (&sv.multicast, sound_num);
for (i=0 ; i<3 ; i++)
MSG_WriteCoord (&sv.multicast, origin[i]);
if (use_phs)
SV_Multicast (origin, reliable ? MULTICAST_PHS_R : MULTICAST_PHS);
else
SV_Multicast (origin, reliable ? MULTICAST_ALL_R : MULTICAST_ALL);
}
/*
===============================================================================
FRAME UPDATES
===============================================================================
*/
int sv_nailmodel, sv_supernailmodel, sv_playermodel;
void SV_FindModelNumbers (void)
{
int i;
sv_nailmodel = -1;
sv_supernailmodel = -1;
sv_playermodel = -1;
for (i=0 ; i<MAX_MODELS ; i++)
{
if (!sv.model_precache[i])
break;
if (!strcmp(sv.model_precache[i],"progs/spike.mdl"))
sv_nailmodel = i;
if (!strcmp(sv.model_precache[i],"progs/s_spike.mdl"))
sv_supernailmodel = i;
if (!strcmp(sv.model_precache[i],"progs/player.mdl"))
sv_playermodel = i;
}
}
/*
==================
SV_WriteClientdataToMessage
==================
*/
void SV_WriteClientdataToMessage (client_t *client, sizebuf_t *msg)
{
int i, clnum;
edict_t *other;
edict_t *ent;
ent = client->edict;
clnum = NUM_FOR_EDICT(ent) - 1;
// send the chokecount for r_netgraph
if (client->chokecount)
{
MSG_WriteByte (msg, svc_chokecount);
MSG_WriteByte (msg, client->chokecount);
client->chokecount = 0;
}
// send a damage message if the player got hit this frame
if (ent->v.dmg_take || ent->v.dmg_save)
{
other = PROG_TO_EDICT(ent->v.dmg_inflictor);
MSG_WriteByte (msg, svc_damage);
MSG_WriteByte (msg, ent->v.dmg_save);
MSG_WriteByte (msg, ent->v.dmg_take);
for (i=0 ; i<3 ; i++)
MSG_WriteCoord (msg, other->v.origin[i] + 0.5*(other->v.mins[i] + other->v.maxs[i]));
ent->v.dmg_take = 0;
ent->v.dmg_save = 0;
}
// add this to server demo
if (sv.mvdrecording && msg->cursize)
{
if (MVDWrite_Begin(dem_single, clnum, msg->cursize))
{
MVD_SZ_Write(msg->data, msg->cursize);
}
}
// a fixangle might get lost in a dropped packet. Oh well.
if (ent->v.fixangle)
{
ent->v.fixangle = 0;
demo.fixangle[clnum] = true;
MSG_WriteByte (msg, svc_setangle);
for (i=0 ; i < 3 ; i++)
MSG_WriteAngle (msg, ent->v.angles[i] );
if (sv.mvdrecording)
{
MSG_WriteByte (&demo.datagram, svc_setangle);
MSG_WriteByte (&demo.datagram, clnum);
for (i=0 ; i < 3 ; i++)
MSG_WriteAngle (&demo.datagram, ent->v.angles[i] );
}
}
// Z_EXT_TIME protocol extension
// every now and then, send an update so that extrapolation
// on client side doesn't stray too far off
#ifdef FTE_PEXT_ACCURATETIMINGS
if (client->fteprotocolextensions & FTE_PEXT_ACCURATETIMINGS)
{ //the fte pext causes the server to send out accurate timings, allowing for perfect interpolation.
if (sv.physicstime - client->lastservertimeupdate > 0)
{
MSG_WriteByte(msg, svc_updatestatlong);
MSG_WriteByte(msg, STAT_TIME);
MSG_WriteLong(msg, (int)(sv.physicstime * 1000));
client->lastservertimeupdate = sv.physicstime;
}
}
else
#endif
if ((SERVER_EXTENSIONS & Z_EXT_SERVERTIME) && (client->extensions & Z_EXT_SERVERTIME))
{ //the zquake ext causes the server to send out peridoic timings, allowing for moderatly accurate game time.
if (realtime - client->lastservertimeupdate > 5)
{
MSG_WriteByte(msg, svc_updatestatlong);
MSG_WriteByte(msg, STAT_TIME);
MSG_WriteLong(msg, (int) (sv.time * 1000));
client->lastservertimeupdate = realtime;
}
}
}
/*
=======================
SV_UpdateClientStats
Performs a delta update of the stats array. This should only be performed
when a reliable message can be delivered this frame.
=======================
*/
void SV_UpdateClientStats (client_t *client)
{
edict_t *ent;
int stats[MAX_CL_STATS], i;
ent = client->edict;
memset (stats, 0, sizeof(stats));
// if we are a spectator and we are tracking a player, we get his stats
// so our status bar reflects his
if (client->spectator && client->spec_track > 0)
ent = svs.clients[client->spec_track - 1].edict;
stats[STAT_HEALTH] = ent->v.health;
stats[STAT_WEAPON] = SV_ModelIndex(
#ifdef USE_PR2
PR2_GetString(ent->v.weaponmodel)
#else
PR_GetString(ent->v.weaponmodel)
#endif
);
stats[STAT_AMMO] = ent->v.currentammo;
stats[STAT_ARMOR] = ent->v.armorvalue;
stats[STAT_SHELLS] = ent->v.ammo_shells;
stats[STAT_NAILS] = ent->v.ammo_nails;
stats[STAT_ROCKETS] = ent->v.ammo_rockets;
stats[STAT_CELLS] = ent->v.ammo_cells;
if (!client->spectator || client->spec_track > 0)
stats[STAT_ACTIVEWEAPON] = ent->v.weapon;
// stuff the sigil bits into the high bits of items for sbar
stats[STAT_ITEMS] = (int) ent->v.items | ((int) PR_GLOBAL(serverflags) << 28);
if (fofs_items2) // ZQ_ITEMS2 extension
stats[STAT_ITEMS] |= (int)EdictFieldFloat(ent, fofs_items2) << 23;
if (ent->v.health > 0 || client->spectator) // viewheight for PF_DEAD & PF_GIB is hardwired
stats[STAT_VIEWHEIGHT] = ent->v.view_ofs[2];
for (i=0 ; i<MAX_CL_STATS ; i++)
if (stats[i] != client->stats[i])
{
client->stats[i] = stats[i];
if (stats[i] >=0 && stats[i] <= 255)
{
ClientReliableWrite_Begin(client, svc_updatestat, 3);
ClientReliableWrite_Byte(client, i);
ClientReliableWrite_Byte(client, stats[i]);
}
else
{
ClientReliableWrite_Begin(client, svc_updatestatlong, 6);
ClientReliableWrite_Byte(client, i);
ClientReliableWrite_Long(client, stats[i]);
}
}
}
/*
=======================
SV_SendClientDatagram
=======================
*/
void SV_SendClientDatagram (client_t *client, int client_num)
{
byte buf[MAX_DATAGRAM];
sizebuf_t msg;
// packet_t *pack;
msg.data = buf;
msg.maxsize = sizeof(buf);
msg.cursize = 0;
msg.allowoverflow = true;
msg.overflowed = false;
// for faster downloading skip half the frames
/*if (client->download && client->netchan.outgoing_sequence & 1)
{
// we're sending fake invalid delta update, so that client won't update screen
MSG_WriteByte (&msg, svc_deltapacketentities);
MSG_WriteByte (&msg, 0);
MSG_WriteShort (&msg, 0);
Netchan_Transmit (&client->netchan, msg.cursize, buf);
}
*/
// add the client specific data to the datagram
SV_WriteClientdataToMessage (client, &msg);
// send over all the objects that are in the PVS
// this will include clients, a packetentities, and
// possibly a nails update
SV_WriteEntitiesToClient (client, &msg, false);
// copy the accumulated multicast datagram
// for this client out to the message
if (client->datagram.overflowed)
Con_Printf ("WARNING: datagram overflowed for %s\n", client->name);
else
SZ_Write (&msg, client->datagram.data, client->datagram.cursize);
SZ_Clear (&client->datagram);
// send deltas over reliable stream
if (Netchan_CanReliable (&client->netchan))
SV_UpdateClientStats (client);
if (msg.overflowed)
{
Con_Printf ("WARNING: msg overflowed for %s\n", client->name);
SZ_Clear (&msg);
}
// send the datagram
Netchan_Transmit (&client->netchan, msg.cursize, buf);
}
/*
=======================
SV_UpdateToReliableMessages
=======================
*/
static void SV_UpdateToReliableMessages (void)
{
int i, j;
client_t *client;
edict_t *ent;
// check for changes to be sent over the reliable streams to all clients
for (i=0, sv_client = svs.clients ; i<MAX_CLIENTS ; i++, sv_client++)
{
if (sv_client->state != cs_spawned)
continue;
if (sv_client->sendinfo)
{
sv_client->sendinfo = false;
SV_FullClientUpdate (sv_client, &sv.reliable_datagram);
}
ent = sv_client->edict;
if (sv_client->old_frags != (int)ent->v.frags)
{
for (j=0, client = svs.clients ; j<MAX_CLIENTS ; j++, client++)
{
if (client->state < cs_preconnected)
continue;
ClientReliableWrite_Begin(client, svc_updatefrags, 4);
ClientReliableWrite_Byte(client, i);
ClientReliableWrite_Short(client, (int) ent->v.frags);
}
if (sv.mvdrecording)
{
if (MVDWrite_Begin(dem_all, 0, 4))
{
MVD_MSG_WriteByte(svc_updatefrags);
MVD_MSG_WriteByte(i);
MVD_MSG_WriteShort((int)ent->v.frags);
}
}
sv_client->old_frags = (int) ent->v.frags;
}
// maxspeed/entgravity changes
if (fofs_gravity && sv_client->entgravity != EdictFieldFloat(ent, fofs_gravity))
{
sv_client->entgravity = EdictFieldFloat(ent, fofs_gravity);
ClientReliableWrite_Begin(sv_client, svc_entgravity, 5);
ClientReliableWrite_Float(sv_client, sv_client->entgravity);
if (sv.mvdrecording)
{
if (MVDWrite_Begin(dem_single, i, 5))
{
MVD_MSG_WriteByte(svc_entgravity);
MVD_MSG_WriteFloat(sv_client->entgravity);
}
}
}
if (fofs_maxspeed && sv_client->maxspeed != EdictFieldFloat(ent, fofs_maxspeed))
{
sv_client->maxspeed = EdictFieldFloat(ent, fofs_maxspeed);
ClientReliableWrite_Begin(sv_client, svc_maxspeed, 5);
ClientReliableWrite_Float(sv_client, sv_client->maxspeed);
if (sv.mvdrecording)
{
if (MVDWrite_Begin(dem_single, i, 5))
{
MVD_MSG_WriteByte(svc_maxspeed);
MVD_MSG_WriteFloat(sv_client->maxspeed);
}
}
}
}
if (sv.datagram.overflowed)
SZ_Clear (&sv.datagram);
// append the broadcast messages to each client messages
for (j=0, client = svs.clients ; j<MAX_CLIENTS ; j++, client++)
{
if (client->state < cs_preconnected)
continue; // reliables go to all connected or spawned
ClientReliableCheckBlock(client, sv.reliable_datagram.cursize);
ClientReliableWrite_SZ(client, sv.reliable_datagram.data, sv.reliable_datagram.cursize);
if (client->state != cs_spawned)
continue; // datagrams only go to spawned
SZ_Write (&client->datagram, sv.datagram.data, sv.datagram.cursize);
}
if (sv.mvdrecording && sv.reliable_datagram.cursize)
{
if (MVDWrite_Begin(dem_all, 0, sv.reliable_datagram.cursize))
{
MVD_SZ_Write(sv.reliable_datagram.data, sv.reliable_datagram.cursize);
}
}
if (sv.mvdrecording)
SZ_Write(&demo.datagram, sv.datagram.data, sv.datagram.cursize); // FIXME: ???
SZ_Clear (&sv.reliable_datagram);
SZ_Clear (&sv.datagram);
}
//#ifdef _WIN32
//#pragma optimize( "", off )
//#endif
/*
=======================
SV_SendClientMessages
=======================
*/
void SV_SendClientMessages (void)
{