UFO: Alien Invasion
Loading...
Searching...
No Matches
netpack.cpp File Reference
#include "common.h"
#include "../shared/vertex_normals.h"
Include dependency graph for netpack.cpp:

Go to the source code of this file.

Functions

void NET_WriteChar (dbuffer *buf, char c)
void NET_WriteByte (dbuffer *buf, byte c)
void NET_WriteShort (dbuffer *buf, int c)
void NET_WriteLong (dbuffer *buf, int c)
void NET_WriteString (dbuffer *buf, const char *str)
void NET_WriteRawString (dbuffer *buf, const char *str)
 Skip the zero string terminal character. If you need it, use NET_WriteString.
void NET_WriteCoord (dbuffer *buf, float f)
void NET_Write2Pos (dbuffer *buf, const vec2_t pos)
void NET_WritePos (dbuffer *buf, const vec3_t pos)
void NET_WriteGPos (dbuffer *buf, const pos3_t pos)
void NET_WriteAngle (dbuffer *buf, float f)
void NET_WriteAngle16 (dbuffer *buf, float f)
void NET_WriteDir (dbuffer *buf, const vec3_t dir)
void NET_vWriteFormat (dbuffer *buf, const char *format, va_list ap)
 Writes to buffer according to format; version without syntactic sugar for variable arguments, to call it from other functions with variable arguments.
void NET_WriteFormat (dbuffer *buf, const char *format,...)
 The user-friendly version of NET_WriteFormat that writes variable arguments to buffer according to format.
int NET_ReadChar (dbuffer *buf)
int NET_ReadByte (dbuffer *buf)
 Reads a byte from the netchannel.
int NET_ReadShort (dbuffer *buf)
int NET_PeekByte (const dbuffer *buf)
int NET_PeekShort (const dbuffer *buf)
 Peeks into a buffer without changing it to get a short int.
int NET_PeekLong (const dbuffer *buf)
int NET_ReadLong (dbuffer *buf)
int NET_ReadString (dbuffer *buf, char *string, size_t length)
int NET_ReadStringLine (dbuffer *buf, char *string, size_t length)
float NET_ReadCoord (dbuffer *buf)
void NET_Read2Pos (dbuffer *buf, vec2_t pos)
void NET_ReadPos (dbuffer *buf, vec3_t pos)
void NET_ReadGPos (dbuffer *buf, pos3_t pos)
float NET_ReadAngle (dbuffer *buf)
float NET_ReadAngle16 (dbuffer *buf)
void NET_ReadData (dbuffer *buf, void *data, int len)
void NET_ReadDir (dbuffer *buf, vec3_t dir)
void NET_vReadFormat (dbuffer *buf, const char *format, va_list ap)
 Reads from a buffer according to format; version without syntactic sugar for variable arguments, to call it from other functions with variable arguments.
void NET_SkipFormat (dbuffer *buf, const char *format)
void NET_ReadFormat (dbuffer *buf, const char *format,...)
 The user-friendly version of NET_ReadFormat that reads variable arguments from a buffer according to format.
void NET_OOB_Printf (struct net_stream *s, const char *format,...)
 Out of band print.
void NET_WriteMsg (struct net_stream *s, dbuffer &buf)
 Enqueue the buffer in the net stream for ONE client.
void NET_WriteConstMsg (struct net_stream *s, const dbuffer &buf)
 Enqueue the buffer in the net stream for MULTIPLE clients.
void NET_VPrintf (dbuffer *buf, const char *format, va_list ap, char *str, size_t length)

Variables

const vec3_t bytedirs []
static const float POSSCALE = 32.0f

Function Documentation

◆ NET_OOB_Printf()

◆ NET_PeekByte()

int NET_PeekByte ( const dbuffer * buf)

Definition at line 251 of file netpack.cpp.

Referenced by CL_ActorDoMoveTime(), and NET_OOB_Printf().

◆ NET_PeekLong()

int NET_PeekLong ( const dbuffer * buf)

Definition at line 273 of file netpack.cpp.

References LittleLong, and v.

Referenced by CL_ActorDoMove(), CL_ActorDoMoveTime(), and NET_OOB_Printf().

◆ NET_PeekShort()

int NET_PeekShort ( const dbuffer * buf)

Peeks into a buffer without changing it to get a short int.

Parameters
bufThe buffer, returned unchanged, no need to be copied before.
Returns
The short at the beginning of the buffer, -1 if it couldn't be read.

Definition at line 264 of file netpack.cpp.

References LittleShort, and v.

Referenced by CL_CheckDefault(), and NET_OOB_Printf().

◆ NET_Read2Pos()

void NET_Read2Pos ( dbuffer * buf,
vec2_t pos )
See also
NET_Write2Pos

Definition at line 355 of file netpack.cpp.

References NET_ReadLong(), and POSSCALE.

Referenced by NET_OOB_Printf().

◆ NET_ReadAngle()

float NET_ReadAngle ( dbuffer * buf)

Definition at line 383 of file netpack.cpp.

References NET_ReadChar().

Referenced by NET_OOB_Printf(), NET_SkipFormat(), NET_vReadFormat(), and SV_ReadAngle().

◆ NET_ReadAngle16()

float NET_ReadAngle16 ( dbuffer * buf)

Definition at line 388 of file netpack.cpp.

References NET_ReadShort(), and SHORT2ANGLE.

Referenced by NET_OOB_Printf().

◆ NET_ReadByte()

int NET_ReadByte ( dbuffer * buf)

Reads a byte from the netchannel.

Note
Beware that you don't put this into a byte or short - this will overflow use an int value to store the return value when you read this via the net format strings!!!

Definition at line 234 of file netpack.cpp.

Referenced by CL_ActorDoMove(), CL_ActorDoMoveTime(), CL_DoEndRound(), CL_EndRoundAnnounce(), CL_ParseEvent(), CL_ParseResults(), CL_ParseServerMessage(), CL_ReadPackets(), CL_StartGame(), GAME_GetImportData(), cgame_import_t::int(), NET_OOB_Printf(), NET_ReadData(), NET_ReadDir(), NET_ReadGPos(), NET_ReadString(), NET_ReadStringLine(), NET_SkipFormat(), NET_vReadFormat(), SV_ReadByte(), and SV_ReadPacket().

◆ NET_ReadChar()

int NET_ReadChar ( dbuffer * buf)

returns -1 if no more characters are available

Definition at line 221 of file netpack.cpp.

Referenced by NET_OOB_Printf(), NET_ReadAngle(), NET_SkipFormat(), NET_vReadFormat(), and SV_ReadChar().

◆ NET_ReadCoord()

float NET_ReadCoord ( dbuffer * buf)

Definition at line 347 of file netpack.cpp.

References NET_ReadLong().

Referenced by NET_OOB_Printf().

◆ NET_ReadData()

void NET_ReadData ( dbuffer * buf,
void * data,
int len )

Definition at line 394 of file netpack.cpp.

References data, i, len, and NET_ReadByte().

Referenced by NET_OOB_Printf(), and SV_ReadData().

◆ NET_ReadDir()

void NET_ReadDir ( dbuffer * buf,
vec3_t dir )

◆ NET_ReadFormat()

◆ NET_ReadGPos()

void NET_ReadGPos ( dbuffer * buf,
pos3_t pos )
See also
NET_WriteGPos
NET_ReadByte
Note
pos3_t are byte values

Definition at line 376 of file netpack.cpp.

References NET_ReadByte().

Referenced by CL_ActorDoMove(), NET_OOB_Printf(), NET_SkipFormat(), NET_vReadFormat(), and SV_ReadGPos().

◆ NET_ReadLong()

◆ NET_ReadPos()

void NET_ReadPos ( dbuffer * buf,
vec3_t pos )
See also
NET_WritePos

Definition at line 364 of file netpack.cpp.

References NET_ReadLong(), and POSSCALE.

Referenced by NET_OOB_Printf(), NET_SkipFormat(), NET_vReadFormat(), and SV_ReadPos().

◆ NET_ReadShort()

◆ NET_ReadString()

int NET_ReadString ( dbuffer * buf,
char * string,
size_t length )
Note
Don't use this function in a way like char* s = NET_ReadString(sb); char* t = NET_ReadString(sb); The second reading uses the same data buffer for the string - so s is no longer the first - but the second string
See also
NET_ReadStringLine
Parameters
[in,out]bufThe input buffer to read the string data from
[out]stringThe output buffer to read the string into
[in]lengthThe size of the output buffer

Definition at line 302 of file netpack.cpp.

References length, and NET_ReadByte().

Referenced by CL_ConnectionlessPacket(), CL_ParseServerData(), CL_ParseServerMessage(), CL_SetConfigString(), GAME_GetImportData(), cgame_import_t::int(), NET_OOB_Printf(), NET_SkipFormat(), NET_vReadFormat(), SV_ExecuteClientMessage(), and SV_ReadString().

◆ NET_ReadStringLine()

int NET_ReadStringLine ( dbuffer * buf,
char * string,
size_t length )

◆ NET_SkipFormat()

void NET_SkipFormat ( dbuffer * buf,
const char * format )

◆ NET_VPrintf()

void NET_VPrintf ( dbuffer * buf,
const char * format,
va_list ap,
char * str,
size_t length )

Definition at line 603 of file netpack.cpp.

References format(), len, length, and Q_vsnprintf().

Referenced by SV_BroadcastPrintf(), SV_ClientCommand(), and SV_ClientPrintf().

◆ NET_vReadFormat()

void NET_vReadFormat ( dbuffer * buf,
const char * format,
va_list ap )

Reads from a buffer according to format; version without syntactic sugar for variable arguments, to call it from other functions with variable arguments.

See also
SV_ReadFormat
Parameters
[in]bufThe buffer we read the data from
[in]formatThe format string may not be nullptr
apThe variadic function argument list corresponding to the format string

Definition at line 415 of file netpack.cpp.

References Com_Error(), ERR_DROP, format(), i, length, NET_ReadAngle(), NET_ReadByte(), NET_ReadChar(), NET_ReadDir(), NET_ReadGPos(), NET_ReadLong(), NET_ReadPos(), NET_ReadShort(), and NET_ReadString().

Referenced by NET_OOB_Printf(), NET_ReadFormat(), and SV_ReadFormat().

◆ NET_vWriteFormat()

void NET_vWriteFormat ( dbuffer * buf,
const char * format,
va_list ap )

Writes to buffer according to format; version without syntactic sugar for variable arguments, to call it from other functions with variable arguments.

Note
short and char are promoted to int when passed to variadic functions!

Definition at line 149 of file netpack.cpp.

References Com_Error(), ERR_DROP, format(), i, NET_WriteAngle(), NET_WriteByte(), NET_WriteChar(), NET_WriteDir(), NET_WriteGPos(), NET_WriteLong(), NET_WritePos(), NET_WriteShort(), and NET_WriteString().

Referenced by MSG_Write_PA(), NET_WriteFormat(), and SV_WriteFormat().

◆ NET_Write2Pos()

void NET_Write2Pos ( dbuffer * buf,
const vec2_t pos )
See also
NET_Read2Pos

Definition at line 87 of file netpack.cpp.

References NET_WriteLong(), and POSSCALE.

◆ NET_WriteAngle()

void NET_WriteAngle ( dbuffer * buf,
float f )

Definition at line 110 of file netpack.cpp.

References f, and NET_WriteByte().

Referenced by NET_vWriteFormat(), and SV_WriteAngle().

◆ NET_WriteAngle16()

void NET_WriteAngle16 ( dbuffer * buf,
float f )

Definition at line 115 of file netpack.cpp.

References ANGLE2SHORT, f, and NET_WriteShort().

◆ NET_WriteByte()

◆ NET_WriteChar()

void NET_WriteChar ( dbuffer * buf,
char c )

Definition at line 33 of file netpack.cpp.

References Com_ByteToBinary(), Com_DPrintf(), and DEBUG_EVENTSYS.

Referenced by NET_vWriteFormat(), and SV_WriteChar().

◆ NET_WriteConstMsg()

void NET_WriteConstMsg ( struct net_stream * s,
const dbuffer & buf )

Enqueue the buffer in the net stream for MULTIPLE clients.

Note
Same as NET_WriteMsg but doesn't free the buffer, use this if you send the same buffer to more than one connected clients
Make sure that you free the msg buffer after you called this
See also
NET_WriteMsg

Definition at line 588 of file netpack.cpp.

References len, LittleLong, and NET_StreamEnqueue().

Referenced by SV_BroadcastPrintf(), SV_FinalMessage(), and SV_Multicast().

◆ NET_WriteCoord()

void NET_WriteCoord ( dbuffer * buf,
float f )

Definition at line 79 of file netpack.cpp.

References f, and NET_WriteLong().

◆ NET_WriteDir()

void NET_WriteDir ( dbuffer * buf,
const vec3_t dir )
Note
EV_ACTOR_SHOOT is using WriteDir for writing the normal, but ReadByte for reading it - keep that in mind when you change something here

Definition at line 124 of file netpack.cpp.

References bytedirs, DotProduct, i, lengthof, and NET_WriteByte().

Referenced by NET_vWriteFormat(), and SV_WriteDir().

◆ NET_WriteFormat()

void NET_WriteFormat ( dbuffer * buf,
const char * format,
... )

The user-friendly version of NET_WriteFormat that writes variable arguments to buffer according to format.

Definition at line 207 of file netpack.cpp.

References format(), and NET_vWriteFormat().

Referenced by GAME_NetSendItem(), and MSG_Write_PA().

◆ NET_WriteGPos()

void NET_WriteGPos ( dbuffer * buf,
const pos3_t pos )

Definition at line 103 of file netpack.cpp.

References NET_WriteByte().

Referenced by NET_vWriteFormat(), and SV_WriteGPos().

◆ NET_WriteLong()

◆ NET_WriteMsg()

◆ NET_WritePos()

void NET_WritePos ( dbuffer * buf,
const vec3_t pos )
See also
NET_ReadPos

Definition at line 96 of file netpack.cpp.

References NET_WriteLong(), and POSSCALE.

Referenced by NET_vWriteFormat(), SV_QueueWritePos(), and SV_WritePos().

◆ NET_WriteRawString()

void NET_WriteRawString ( dbuffer * buf,
const char * str )

Skip the zero string terminal character. If you need it, use NET_WriteString.

Definition at line 71 of file netpack.cpp.

References Com_DPrintf(), and DEBUG_EVENTSYS.

Referenced by SVC_Status(), and SVC_TeamInfo().

◆ NET_WriteShort()

◆ NET_WriteString()

Variable Documentation

◆ bytedirs

const vec3_t bytedirs[]

◆ POSSCALE

const float POSSCALE = 32.0f
static

Definition at line 31 of file netpack.cpp.

Referenced by NET_Read2Pos(), NET_ReadPos(), NET_Write2Pos(), and NET_WritePos().