Skip to content

Commit 0efcd81

Browse files
authored
Merge pull request #38 from qw-ctf/mvd-exts
Add protocol extensions.
2 parents 63e6792 + b42be20 commit 0efcd81

File tree

5 files changed

+149
-66
lines changed

5 files changed

+149
-66
lines changed

src/netmsg_parser.c

Lines changed: 122 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -510,67 +510,74 @@ static void SetStat(mvd_info_t *mvd, int stat, int value)
510510
cp->stats[stat] = value;
511511
}
512512

513-
static void NetMsg_Parser_ParsePacketEntities(mvd_info_t *mvd, qbool delta)
513+
static void NetMsg_Parser_ParseEntityNum(unsigned int *entnum, unsigned int *bits, unsigned int *morebits)
514514
{
515-
byte from;
516-
int bits;
515+
*entnum = *bits = *morebits = 0;
517516

518-
if (delta)
519-
{
520-
from = MSG_ReadByte();
517+
*bits = MSG_ReadShort();
521518

522-
if ((outgoing_sequence - incoming_sequence - 1) >= UPDATE_MASK)
523-
{
524-
return;
525-
}
526-
}
519+
*entnum = *bits & 0x1FF;
520+
*bits &= ~0x1FF;
527521

528-
while (true)
522+
if (*bits & U_MOREBITS)
529523
{
530-
bits = MSG_ReadShort();
531-
532-
if (msg_badread)
524+
*bits |= MSG_ReadByte();
525+
if (*bits & U_FTE_EVENMORE)
533526
{
534-
// Something didn't parse right...
535-
Sys_PrintError("NetMsg_Parser_ParsePacketEntities: msg_badread in packetentities.\n");
536-
return;
537-
}
527+
*morebits = MSG_ReadByte();
528+
if (*morebits & U_FTE_YETMORE)
529+
{
530+
*morebits |= MSG_ReadByte() << 8;
531+
}
538532

539-
if (!bits)
540-
{
541-
break;
533+
if (*morebits & U_FTE_ENTITYDBL)
534+
{
535+
*entnum += 512;
536+
}
537+
if (*morebits & U_FTE_ENTITYDBL2)
538+
{
539+
*entnum += 1024;
540+
}
542541
}
542+
}
543+
}
543544

544-
bits &= ~0x1FF; // Strip the first 9 bits.
545+
static void NetMsg_Parser_ParseEntityDelta(unsigned int bits, unsigned int morebits)
546+
{
547+
if (bits & U_MODEL)
548+
MSG_ReadByte();
549+
else if (morebits & U_FTE_MODELDBL)
550+
MSG_ReadShort();
545551

546-
// Read any more bits.
547-
if (bits & U_MOREBITS)
548-
{
549-
bits |= MSG_ReadByte();
550-
}
552+
if (bits & U_FRAME)
553+
MSG_ReadByte();
554+
if (bits & U_COLORMAP)
555+
MSG_ReadByte();
556+
if (bits & U_SKIN)
557+
MSG_ReadByte();
558+
if (bits & U_EFFECTS)
559+
MSG_ReadByte();
560+
if (bits & U_ORIGIN1)
561+
MSG_ReadCoord();
562+
if (bits & U_ORIGIN2)
563+
MSG_ReadCoord();
564+
if (bits & U_ORIGIN3)
565+
MSG_ReadCoord();
566+
if (bits & U_ANGLE1)
567+
MSG_ReadAngle();
568+
if (bits & U_ANGLE2)
569+
MSG_ReadAngle();
570+
if (bits & U_ANGLE3)
571+
MSG_ReadAngle();
551572

552-
if (bits & U_MODEL)
553-
MSG_ReadByte();
554-
if (bits & U_FRAME)
555-
MSG_ReadByte();
556-
if (bits & U_COLORMAP)
557-
MSG_ReadByte();
558-
if (bits & U_SKIN)
559-
MSG_ReadByte();
560-
if (bits & U_EFFECTS)
561-
MSG_ReadByte();
562-
if (bits & U_ORIGIN1)
563-
MSG_ReadCoord();
564-
if (bits & U_ORIGIN2)
565-
MSG_ReadCoord();
566-
if (bits & U_ORIGIN3)
567-
MSG_ReadCoord();
568-
if (bits & U_ANGLE1)
569-
MSG_ReadAngle();
570-
if (bits & U_ANGLE2)
571-
MSG_ReadAngle();
572-
if (bits & U_ANGLE3)
573-
MSG_ReadAngle();
573+
if (morebits & U_FTE_TRANS)
574+
MSG_ReadByte();
575+
576+
if (morebits & U_FTE_COLOURMOD)
577+
{
578+
MSG_ReadByte(); // r
579+
MSG_ReadByte(); // g
580+
MSG_ReadByte(); // b
574581
}
575582
}
576583

@@ -958,6 +965,13 @@ static void NetMsg_Parser_Parse_svc_spawnstatic(void)
958965
}
959966
}
960967

968+
static void NetMsg_Parser_Parse_svc_fte_spawnstatic2(void)
969+
{
970+
unsigned int entnum, bits, morebits;
971+
NetMsg_Parser_ParseEntityNum(&entnum, &bits, &morebits);
972+
NetMsg_Parser_ParseEntityDelta(bits, morebits);
973+
}
974+
961975
static void NetMsg_Parser_Parse_svc_spawnbaseline(void)
962976
{
963977
int i;
@@ -975,6 +989,13 @@ static void NetMsg_Parser_Parse_svc_spawnbaseline(void)
975989
}
976990
}
977991

992+
static void NetMsg_Parser_Parse_svc_fte_spawnbaseline2(void)
993+
{
994+
unsigned int entnum, bits, morebits;
995+
NetMsg_Parser_ParseEntityNum(&entnum, &bits, &morebits);
996+
NetMsg_Parser_ParseEntityDelta(bits, morebits);
997+
}
998+
978999
static void NetMsg_Parser_Parse_svc_temp_entity(void)
9791000
{
9801001
int i;
@@ -1270,10 +1291,10 @@ static void NetMsg_Parser_Parse_svc_chokecount(void)
12701291
MSG_ReadByte();
12711292
}
12721293

1273-
static void NetMsg_Parser_Parse_svc_modellist(void)
1294+
static void NetMsg_Parser_Parse_svc_modellist(qbool extended)
12741295
{
12751296
char *str;
1276-
int model_count = MSG_ReadByte();
1297+
int model_count = extended ? MSG_ReadShort() : MSG_ReadByte();
12771298

12781299
while (true)
12791300
{
@@ -1313,6 +1334,39 @@ static void NetMsg_Parser_Parse_svc_soundlist(mvd_info_t *mvd)
13131334
MSG_ReadByte(); // Ignore.
13141335
}
13151336

1337+
static void NetMsg_Parser_ParsePacketEntities(mvd_info_t *mvd, qbool delta)
1338+
{
1339+
if (delta)
1340+
{
1341+
MSG_ReadByte();
1342+
if ((outgoing_sequence - incoming_sequence - 1) >= UPDATE_MASK)
1343+
{
1344+
return;
1345+
}
1346+
}
1347+
1348+
while (true)
1349+
{
1350+
unsigned int entnum, bits, morebits;
1351+
1352+
NetMsg_Parser_ParseEntityNum(&entnum, &bits, &morebits);
1353+
1354+
if (msg_badread)
1355+
{
1356+
// Something didn't parse right...
1357+
Sys_PrintError("NetMsg_Parser_ParsePacketEntities: msg_badread in packetentities.\n");
1358+
return;
1359+
}
1360+
1361+
if (!entnum)
1362+
{
1363+
break;
1364+
}
1365+
1366+
NetMsg_Parser_ParseEntityDelta(bits, morebits);
1367+
}
1368+
}
1369+
13161370
static void NetMsg_Parser_Parse_svc_packetentities(mvd_info_t *mvd)
13171371
{
13181372
NetMsg_Parser_ParsePacketEntities(mvd, false);
@@ -1541,7 +1595,12 @@ qbool NetMsg_Parser_StartParse(mvd_info_t *mvd)
15411595
}
15421596
case svc_modellist :
15431597
{
1544-
NetMsg_Parser_Parse_svc_modellist();
1598+
NetMsg_Parser_Parse_svc_modellist(false);
1599+
break;
1600+
}
1601+
case svc_fte_modellistshort :
1602+
{
1603+
NetMsg_Parser_Parse_svc_modellist(true);
15451604
break;
15461605
}
15471606
case svc_soundlist :
@@ -1559,6 +1618,11 @@ qbool NetMsg_Parser_StartParse(mvd_info_t *mvd)
15591618
NetMsg_Parser_Parse_svc_spawnbaseline();
15601619
break;
15611620
}
1621+
case svc_fte_spawnbaseline2 :
1622+
{
1623+
NetMsg_Parser_Parse_svc_fte_spawnbaseline2();
1624+
break;
1625+
}
15621626
case svc_updatefrags :
15631627
{
15641628
NetMsg_Parser_Parse_svc_updatefrags(mvd);
@@ -1674,6 +1738,11 @@ qbool NetMsg_Parser_StartParse(mvd_info_t *mvd)
16741738
NetMsg_Parser_Parse_svc_spawnstatic();
16751739
break;
16761740
}
1741+
case svc_fte_spawnstatic2 :
1742+
{
1743+
NetMsg_Parser_Parse_svc_fte_spawnstatic2();
1744+
break;
1745+
}
16771746
case svc_foundsecret :
16781747
{
16791748
NetMsg_Parser_Parse_svc_foundsecret();

src/qw_protocol.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ char *svc_strings[] =
3333
"svc_damage", // [byte] impact [byte] blood [vec3] from
3434

3535
"svc_spawnstatic",
36-
"OBSOLETE svc_spawnbinary",
36+
"svc_fte_spawnstatic2",
3737
"svc_spawnbaseline",
3838

3939
"svc_temp_entity", // <variable>
@@ -78,13 +78,13 @@ char *svc_strings[] =
7878
"NEW PROTOCOL",
7979
"NEW PROTOCOL",
8080
"NEW PROTOCOL",
81+
"svc_fte_modellistshort",
8182
"NEW PROTOCOL",
8283
"NEW PROTOCOL",
8384
"NEW PROTOCOL",
8485
"NEW PROTOCOL",
8586
"NEW PROTOCOL",
86-
"NEW PROTOCOL",
87-
"NEW PROTOCOL"
87+
"svc_fte_spawnbaseline2"
8888
};
8989

9090

src/qw_protocol.h

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ extern char *print_strings[]; // Contains descriptions of the print levels.
8989
#define svc_damage 19
9090

9191
#define svc_spawnstatic 20
92-
// svc_spawnbinary 21
92+
#define svc_fte_spawnstatic2 21
9393
#define svc_spawnbaseline 22
9494

9595
#define svc_temp_entity 23 // variable
@@ -138,6 +138,8 @@ extern char *print_strings[]; // Contains descriptions of the print levels.
138138
#define svc_serverinfo 52 // serverinfo
139139
#define svc_updatepl 53 // [byte] [byte]
140140
#define svc_nails2 54
141+
#define svc_fte_modellistshort 60
142+
#define svc_fte_spawnbaseline2 66
141143
#define svc_qizmovoice 83
142144

143145
//==============================================
@@ -221,14 +223,24 @@ extern char *print_strings[]; // Contains descriptions of the print levels.
221223
#define U_MOREBITS (1 << 15)
222224

223225
// if MOREBITS is set, these additional flags are read in next
224-
#define U_ANGLE1 (1 << 0)
225-
#define U_ANGLE3 (1 << 1)
226-
#define U_MODEL (1 << 2)
227-
#define U_COLORMAP (1 << 3)
228-
#define U_SKIN (1 << 4)
229-
#define U_EFFECTS (1 << 5)
230-
#define U_SOLID (1 << 6) // the entity should be solid for prediction
231-
226+
#define U_ANGLE1 (1 << 0)
227+
#define U_ANGLE3 (1 << 1)
228+
#define U_MODEL (1 << 2)
229+
#define U_COLORMAP (1 << 3)
230+
#define U_SKIN (1 << 4)
231+
#define U_EFFECTS (1 << 5)
232+
#define U_SOLID (1 << 6) // the entity should be solid for prediction
233+
#define U_FTE_EVENMORE (1 << 7)
234+
235+
// if EVENMORE is set, these additional flags are read in next
236+
#define U_FTE_TRANS (1 << 1)
237+
#define U_FTE_MODELDBL (1 << 3)
238+
#define U_FTE_ENTITYDBL (1 << 5)
239+
#define U_FTE_ENTITYDBL2 (1 << 6)
240+
#define U_FTE_YETMORE (1 << 7)
241+
242+
// if YETMORE is set, these additional flags are read in next
243+
#define U_FTE_COLOURMOD (1 << 10)
232244
//==============================================
233245

234246
// a sound with no channel is a local only sound

src/shared.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ size_t strlcpy(char *dst, const char *src, size_t siz)
156156
}
157157
#endif // LINUX & WIN32
158158

159+
#if !defined(__APPLE__)
159160
size_t strlcat(char *dst, const char *src, size_t siz)
160161
{
161162
register char *d = dst;
@@ -185,6 +186,7 @@ size_t strlcat(char *dst, const char *src, size_t siz)
185186

186187
return(dlen + (s - src)); /* count does not include NUL */
187188
}
189+
#endif
188190

189191
// Implemented in later versions of Visual Studio (https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010)
190192
#if defined(_MSC_VER) && _MSC_VER < 1900

src/sys_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <sys/wait.h>
1818
#include <sys/mman.h>
1919
#include <semaphore.h>
20-
#ifndef __FreeBSD__
20+
#if !defined(__FreeBSD__) && !defined(__APPLE__)
2121
#include <linux/rtc.h>
2222
#endif
2323
#include <sys/ioctl.h>

0 commit comments

Comments
 (0)