UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
netpack.cpp File Reference
#include "common.h"
#include "../shared/vertex_normals.h"

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. More...
 
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. More...
 
void NET_WriteFormat (dbuffer *buf, const char *format,...)
 The user-friendly version of NET_WriteFormat that writes variable arguments to buffer according to format. More...
 
int NET_ReadChar (dbuffer *buf)
 
int NET_ReadByte (dbuffer *buf)
 Reads a byte from the netchannel. More...
 
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. More...
 
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. More...
 
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. More...
 
void NET_OOB_Printf (struct net_stream *s, const char *format,...)
 Out of band print. More...
 
void NET_WriteMsg (struct net_stream *s, dbuffer &buf)
 Enqueue the buffer in the net stream for ONE client. More...
 
void NET_WriteConstMsg (struct net_stream *s, const dbuffer &buf)
 Enqueue the buffer in the net stream for MULTIPLE clients. More...
 
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

void NET_OOB_Printf ( struct net_stream s,
const char *  format,
  ... 
)
int NET_PeekByte ( const dbuffer buf)

Definition at line 251 of file netpack.cpp.

References dbuffer::get().

Referenced by CL_ActorDoMoveTime().

int NET_PeekLong ( const dbuffer buf)

Definition at line 273 of file netpack.cpp.

References dbuffer::get(), LittleLong, and v.

Referenced by CL_ActorDoMove(), and CL_ActorDoMoveTime().

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 dbuffer::get(), LittleShort, and v.

Referenced by CL_CheckDefault().

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.

float NET_ReadAngle ( dbuffer buf)

Definition at line 383 of file netpack.cpp.

References NET_ReadChar().

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

float NET_ReadAngle16 ( dbuffer buf)

Definition at line 388 of file netpack.cpp.

References NET_ReadShort(), and SHORT2ANGLE.

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.

References dbuffer::extract().

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

int NET_ReadChar ( dbuffer buf)

returns -1 if no more characters are available

Definition at line 221 of file netpack.cpp.

References dbuffer::extract().

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

float NET_ReadCoord ( dbuffer buf)

Definition at line 347 of file netpack.cpp.

References NET_ReadLong().

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

Definition at line 394 of file netpack.cpp.

References i, len, and NET_ReadByte().

Referenced by SV_ReadData().

void NET_ReadDir ( dbuffer buf,
vec3_t  dir 
)

Definition at line 400 of file netpack.cpp.

References bytedirs, Com_Error(), ERR_DROP, lengthof, NET_ReadByte(), and VectorCopy.

Referenced by NET_SkipFormat(), NET_vReadFormat(), and SV_ReadDir().

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_SkipFormat(), NET_vReadFormat(), and SV_ReadGPos().

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_SkipFormat(), NET_vReadFormat(), and SV_ReadPos().

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 NET_ReadByte().

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

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

Definition at line 328 of file netpack.cpp.

References NET_ReadByte().

Referenced by CL_ConnectionlessPacket(), GAME_GetImportData(), and SV_ConnectionlessPacket().

void NET_SkipFormat ( dbuffer buf,
const char *  format 
)
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 dbuffer::add(), len, and Q_vsnprintf().

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

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, i, length, NET_ReadAngle(), NET_ReadByte(), NET_ReadChar(), NET_ReadDir(), NET_ReadGPos(), NET_ReadLong(), NET_ReadPos(), NET_ReadShort(), and NET_ReadString().

Referenced by NET_ReadFormat(), and SV_ReadFormat().

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, 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().

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.

void NET_WriteAngle ( dbuffer buf,
float  f 
)

Definition at line 110 of file netpack.cpp.

References NET_WriteByte().

Referenced by NET_vWriteFormat(), and SV_WriteAngle().

void NET_WriteAngle16 ( dbuffer buf,
float  f 
)

Definition at line 115 of file netpack.cpp.

References ANGLE2SHORT, and NET_WriteShort().

void NET_WriteChar ( dbuffer buf,
char  c 
)

Definition at line 33 of file netpack.cpp.

References dbuffer::add(), Com_ByteToBinary(), Com_DPrintf(), and DEBUG_EVENTSYS.

Referenced by NET_vWriteFormat(), and SV_WriteChar().

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 dbuffer::getAt(), len, dbuffer::length(), LittleLong, and NET_StreamEnqueue().

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

void NET_WriteCoord ( dbuffer buf,
float  f 
)

Definition at line 79 of file netpack.cpp.

References NET_WriteLong().

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().

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 NET_vWriteFormat().

Referenced by GAME_NetSendItem(), and MSG_Write_PA().

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().

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().

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 dbuffer::add(), Com_DPrintf(), and DEBUG_EVENTSYS.

Referenced by SVC_Status(), and SVC_TeamInfo().

Variable Documentation

const vec3_t bytedirs[]
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().