fteqw/fteqtv/msg.c
Spoike a97007ae5a dpp7: Treat 'dropped' c2s packets as choked when using dpp7 protocols. This is because the protocol provides no way to disambiguate, and I don't like false reports of packetloss (only reliables loss can be detected, and that's not frequent enough to be meaningful). Pings can still be determined with dpp7, for those few packets which are acked.
package manager: reworked to enable/disable plugins when downloaded, which can also be present-but-disabled.
package manager: display a confirmation prompt before applying changes. do not allow other changes to be made while applying. prompt may be skipped with 'pkg apply' in dedicated servers.
sv: downloads are no longer forced to lower case.
sv: added sv_demoAutoCompress cvar. set to 1 to directly record to *.mvd.gz
cl: properly support directly playing .mvd.gz files
menus: reworked to separate mouse and keyboard focus. mouse focus becomes keyboard focus only on mouse clicks. tooltips follow mouse cursors.
menus: cleaned up menu heirachy a little. now simpler.
server browser: changed 'hide *' filters to 'show *' instead. I felt it was more logical.
deluxmapping: changed to disabled, load, generate, like r_loadlit is.
render targets api now supports negative formats to mean nearest filtering, where filtering is part of texture state.
drawrotpic fixed, now batches and interacts with drawpic correctly.
drawline fixed, no interacts with draw* correctly, but still does not batch.
fixed saving games.
provide proper userinfo to nq clients, where supported.
qcc: catch string table overflows safely, giving errors instead of crashes. switch to 32bit statements if some over-sized function requires it.
qtv: some bigcoords support tweaks

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5073 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-03-21 05:27:07 +00:00

187 lines
No EOL
3.4 KiB
C

#include "qtv.h"
void InitNetMsg(netmsg_t *b, void *buffer, int bufferlength)
{
b->data = buffer;
b->maxsize = bufferlength;
b->readpos = 0;
b->cursize = 0;
}
unsigned char ReadByte(netmsg_t *b)
{
if (b->readpos >= b->cursize)
{
b->readpos = b->cursize+1;
return 0;
}
return ((unsigned char *)b->data)[b->readpos++];
}
unsigned short ReadShort(netmsg_t *b)
{
int b1, b2;
b1 = ReadByte(b);
b2 = ReadByte(b);
return b1 | (b2<<8);
}
unsigned int ReadLong(netmsg_t *b)
{
int s1, s2;
s1 = ReadShort(b);
s2 = ReadShort(b);
return s1 | (s2<<16);
}
unsigned int BigLong(unsigned int val)
{
union {
unsigned int i;
unsigned char c[4];
} v;
v.i = val;
return (v.c[0]<<24) | (v.c[1] << 16) | (v.c[2] << 8) | (v.c[3] << 0);
}
unsigned int SwapLong(unsigned int val)
{
union {
unsigned int i;
unsigned char c[4];
} v;
unsigned char s;
v.i = val;
s = v.c[0];
v.c[0] = v.c[3];
v.c[3] = s;
s = v.c[1];
v.c[1] = v.c[2];
v.c[2] = s;
return v.i;
}
float ReadFloat(netmsg_t *b)
{
union {
unsigned int i;
float f;
} u;
u.i = ReadLong(b);
return u.f;
}
void ReadString(netmsg_t *b, char *string, int maxlen)
{
maxlen--; //for null terminator
while(maxlen)
{
*string = ReadByte(b);
if (!*string)
return;
string++;
maxlen--;
}
*string++ = '\0'; //add the null
printf("ReadString: buffer is too small\n");
while(ReadByte(b)) //finish reading the string, even if we will loose part of it
;
}
float ReadCoord(netmsg_t *b, unsigned int pext)
{
if (pext & PEXT_FLOATCOORDS)
return ReadFloat(b);
else
return ReadShort(b) / 8.0;
}
float ReadAngle(netmsg_t *b, unsigned int pext)
{
if (pext & PEXT_FLOATCOORDS)
return (ReadShort(b) * 360.0) / 0x10000;
else
return (ReadByte(b) * 360.0) / 0x100;
}
void WriteByte(netmsg_t *b, unsigned char c)
{
if (b->cursize>=b->maxsize)
return;
((unsigned char*)b->data)[b->cursize++] = c;
}
void WriteShort(netmsg_t *b, unsigned short l)
{
WriteByte(b, (l&0x00ff)>>0);
WriteByte(b, (l&0xff00)>>8);
}
void WriteLong(netmsg_t *b, unsigned int l)
{
WriteByte(b, (l&0x000000ff)>>0);
WriteByte(b, (l&0x0000ff00)>>8);
WriteByte(b, (l&0x00ff0000)>>16);
WriteByte(b, (l&0xff000000)>>24);
}
void WriteFloat(netmsg_t *b, float f)
{
union {
unsigned int i;
float f;
} u;
u.f = f;
WriteLong(b, u.i);
}
void WriteCoord(netmsg_t *b, float c, unsigned int pext)
{
if (pext & PEXT_FLOATCOORDS)
WriteFloat(b, c);
else
WriteShort(b, c*8);
}
void WriteAngle(netmsg_t *b, float a, unsigned int pext)
{
if (pext & PEXT_FLOATCOORDS)
WriteShort(b, (a/360.0)*0x10000);
else
WriteByte(b, (a/360.0)*0x100 + 0.49); //round better, to avoid rounding bias
}
void WriteString2(netmsg_t *b, const char *str)
{ //no null terminator, convienience function.
while(*str)
WriteByte(b, *str++);
}
void WriteString(netmsg_t *b, const char *str)
{
while(*str)
WriteByte(b, *str++);
WriteByte(b, 0);
}
void WriteData(netmsg_t *b, const void *data, int length)
{
int i;
unsigned char *buf;
if (b->cursize + length > b->maxsize) //urm, that's just too big. :(
return;
buf = (unsigned char*)b->data+b->cursize;
for (i = 0; i < length; i++)
*buf++ = ((unsigned char*)data)[i];
b->cursize+=length;
}
void WriteCoordf(netmsg_t *b, unsigned int pext, float fl)
{
if (pext & PEXT_FLOATCOORDS)
WriteFloat(b, fl);
else
WriteShort(b, fl*8);
}
void WriteAnglef(netmsg_t *b, unsigned int pext, float fl)
{
if (pext & PEXT_FLOATCOORDS)
WriteShort(b, (fl/360)*0x10000);
else
WriteByte(b, (fl/360)*0x100);
}