DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
protocol.c File Reference
#include "quakedef.h"
+ Include dependency graph for protocol.c:

Go to the source code of this file.

Data Structures

struct  protocolversioninfo_s
 

Functions

protocolversion_t Protocol_EnumForName (const char *s)
 
protocolversion_t Protocol_EnumForNumber (int n)
 
const char * Protocol_NameForEnum (protocolversion_t p)
 
void Protocol_Names (char *buffer, size_t buffersize)
 
int Protocol_NumberForEnum (protocolversion_t p)
 
void Protocol_UpdateClientStats (const int *stats)
 
void Protocol_WriteStatsReliable (void)
 

Variables

entity_state_t defaultstate
 
struct protocolversioninfo_s protocolversioninfo []
 
static const int sendquakestats []
 

Function Documentation

◆ Protocol_EnumForName()

protocolversion_t Protocol_EnumForName ( const char * s)

Definition at line 68 of file protocol.c.

69{
70 int i;
71 for (i = 0;protocolversioninfo[i].name;i++)
72 if (!strcasecmp(s, protocolversioninfo[i].name))
74 return PROTOCOL_UNKNOWN;
75}
@ PROTOCOL_UNKNOWN
Definition common.h:133
const GLchar * name
Definition glquake.h:601
struct protocolversioninfo_s protocolversioninfo[]
int i
protocolversion_t version
Definition protocol.c:45
const char * name
Definition protocol.c:46

References i, name, protocolversioninfo_s::name, PROTOCOL_UNKNOWN, protocolversioninfo, and protocolversioninfo_s::version.

Referenced by SV_SpawnServer().

◆ Protocol_EnumForNumber()

protocolversion_t Protocol_EnumForNumber ( int n)

Definition at line 86 of file protocol.c.

87{
88 int i;
89 for (i = 0;protocolversioninfo[i].name;i++)
90 if (protocolversioninfo[i].number == n)
92 return PROTOCOL_UNKNOWN;
93}
#define n(x, y)

References i, n, protocolversioninfo_s::name, PROTOCOL_UNKNOWN, protocolversioninfo, and protocolversioninfo_s::version.

Referenced by CL_ParseServerInfo(), and CL_ParseServerMessage().

◆ Protocol_NameForEnum()

const char * Protocol_NameForEnum ( protocolversion_t p)

Definition at line 77 of file protocol.c.

78{
79 int i;
80 for (i = 0;protocolversioninfo[i].name;i++)
83 return "UNKNOWN";
84}
static int const char * version
Definition fs.c:479

References i, protocolversioninfo_s::name, protocolversioninfo, and version.

Referenced by CL_ParseServerInfo(), and SV_Status_f().

◆ Protocol_Names()

void Protocol_Names ( char * buffer,
size_t buffersize )

Definition at line 104 of file protocol.c.

105{
106 int i;
107 if (buffersize < 1)
108 return;
109 buffer[0] = 0;
110 for (i = 0;protocolversioninfo[i].name;i++)
111 {
112 if (i > 0)
113 dp_strlcat(buffer, " ", buffersize);
115 }
116}
#define dp_strlcat(dst, src, dsize)
Definition common.h:304
GLuint buffer
Definition glquake.h:630

References buffer, dp_strlcat, i, name, protocolversioninfo_s::name, and protocolversioninfo.

Referenced by NetConn_ClientParsePacket(), and SV_SpawnServer().

◆ Protocol_NumberForEnum()

int Protocol_NumberForEnum ( protocolversion_t p)

Definition at line 95 of file protocol.c.

96{
97 int i;
98 for (i = 0;protocolversioninfo[i].name;i++)
101 return 0;
102}

References i, protocolversioninfo_s::name, protocolversioninfo_s::number, protocolversioninfo, and version.

Referenced by SV_SendServerinfo(), and SV_Status_f().

◆ Protocol_UpdateClientStats()

void Protocol_UpdateClientStats ( const int * stats)

Definition at line 118 of file protocol.c.

119{
120 int i;
121 // update the stats array and set deltabits for any changed stats
122 for (i = 0;i < MAX_CL_STATS;i++)
123 {
124 if (host_client->stats[i] != stats[i])
125 {
126 host_client->statsdeltabits[i >> 3] |= 1 << (i & 7);
127 host_client->stats[i] = stats[i];
128 }
129 }
130}
#define MAX_CL_STATS
Definition qstats.h:7
client_t * host_client
Definition sv_main.c:29
int stats[MAX_CL_STATS]
Definition server.h:278
unsigned char statsdeltabits[(MAX_CL_STATS+7)/8]
Definition server.h:277

References host_client, i, MAX_CL_STATS, client_t::stats, and client_t::statsdeltabits.

Referenced by SV_SendClientDatagram().

◆ Protocol_WriteStatsReliable()

void Protocol_WriteStatsReliable ( void )

Definition at line 151 of file protocol.c.

152{
153 int i, j;
155 return;
156 // detect changes in stats and write reliable messages
157 // this only deals with 32 stats because the older protocols which use
158 // this function can only cope with 32 stats,
159 // they also do not support svc_updatestatubyte which was introduced in
160 // DP6 protocol (except for QW)
161 for (j = 0;sendquakestats[j] >= 0;j++)
162 {
163 i = sendquakestats[j];
164 // check if this bit is set
165 if (host_client->statsdeltabits[i >> 3] & (1 << (i & 7)))
166 {
167 host_client->statsdeltabits[i >> 3] -= (1 << (i & 7));
168 // send the stat as a byte if possible
170 {
171 if (host_client->stats[i] >= 0 && host_client->stats[i] < 256)
172 {
176 }
177 else
178 {
182 }
183 }
184 else
185 {
186 // this could make use of svc_updatestatubyte in DP6 and later
187 // protocols but those protocols do not use this function
191 }
192 }
193 }
194}
void MSG_WriteLong(sizebuf_t *sb, int c)
Definition com_msg.c:147
void MSG_WriteByte(sizebuf_t *sb, int c)
Definition com_msg.c:130
@ PROTOCOL_QUAKEWORLD
quakeworld protocol
Definition common.h:145
static const int sendquakestats[]
Definition protocol.c:135
#define qw_svc_updatestat
Definition protocol.h:909
#define svc_updatestat
Definition protocol.h:217
#define qw_svc_updatestatlong
Definition protocol.h:936
server_t sv
local server
Definition sv_main.c:223
netconn_t * netconnection
communications handle
Definition server.h:210
sizebuf_t message
writing buffer to send to peer as the next reliable message can be added to at any time,...
Definition netconn.h:161
protocolversion_t protocol
one of the PROTOCOL_ values
Definition server.h:74

References host_client, i, netconn_t::message, MSG_WriteByte(), MSG_WriteLong(), client_t::netconnection, server_t::protocol, PROTOCOL_QUAKEWORLD, qw_svc_updatestat, qw_svc_updatestatlong, sendquakestats, client_t::stats, client_t::statsdeltabits, sv, and svc_updatestat.

Referenced by SV_WriteEntitiesToClient().

Variable Documentation

◆ defaultstate

entity_state_t defaultstate

Definition at line 4 of file protocol.c.

5{
6 // ! means this is not sent to client
7 0,//double time; // ! time this state was built (used on client for interpolation)
8 {0,0,0},//float netcenter[3]; // ! for network prioritization, this is the center of the bounding box (which may differ from the origin)
9 {0,0,0},//float origin[3];
10 {0,0,0},//float angles[3];
11 0,//int effects;
12 0,//unsigned int customizeentityforclient; // !
13 0,//unsigned short number; // entity number this state is for
14 0,//unsigned short modelindex;
15 0,//unsigned short frame;
16 0,//unsigned short tagentity;
17 0,//unsigned short specialvisibilityradius; // ! larger if it has effects/light
18 0,//unsigned short viewmodelforclient; // !
19 0,//unsigned short exteriormodelforclient; // ! not shown if first person viewing from this entity, shown in all other cases
20 0,//unsigned short nodrawtoclient; // !
21 0,//unsigned short drawonlytoclient; // !
22 0,//unsigned short traileffectnum;
23 {0,0,0,0},//unsigned short light[4]; // color*256 (0.00 to 255.996), and radius*1
24 ACTIVE_NOT,//unsigned char active; // true if a valid state
25 0,//unsigned char lightstyle;
26 0,//unsigned char lightpflags;
27 0,//unsigned char colormap;
28 0,//unsigned char skin; // also chooses cubemap for rtlights if lightpflags & LIGHTPFLAGS_FULLDYNAMIC
29 255,//unsigned char alpha;
30 16,//unsigned char scale;
31 0,//unsigned char glowsize;
32 254,//unsigned char glowcolor;
33 0,//unsigned char flags;
34 0,//unsigned char internaleffects; // INTEF_FLAG1QW and so on
35 0,//unsigned char tagindex;
36 {32, 32, 32},//unsigned char colormod[3];
37 {32, 32, 32},//unsigned char glowmod[3];
38};
@ ACTIVE_NOT
Definition protocol.h:432

Referenced by CL_ClearState(), CL_ExpandEntities(), CL_ParseBaseline(), CL_UpdateViewModel(), EntityFrame4_AckFrame(), EntityFrame4_CL_ReadFrame(), EntityFrame4_GetReferenceEntity(), EntityFrame4_ResetDatabase(), EntityFrame4_WriteFrame(), EntityFrame5_AllocDatabase(), EntityFrame5_CL_ReadFrame(), EntityFrame5_WriteFrame(), EntityFrame_CL_ReadFrame(), EntityFrame_WriteFrame(), EntityFrameQuake_ISeeDeadEntities(), EntityState5_ReadUpdate(), EntityState_DeltaBits(), EntityStateQW_ReadPlayerUpdate(), SV_CreateBaseline(), and SV_PrepareEntityForSending().

◆ protocolversioninfo

struct protocolversioninfo_s protocolversioninfo[]
Initial value:
=
{
{ 3505, PROTOCOL_DARKPLACES8 , "DP8"},
{ 3504, PROTOCOL_DARKPLACES7 , "DP7"},
{ 3503, PROTOCOL_DARKPLACES6 , "DP6"},
{ 3502, PROTOCOL_DARKPLACES5 , "DP5"},
{ 3501, PROTOCOL_DARKPLACES4 , "DP4"},
{ 3500, PROTOCOL_DARKPLACES3 , "DP3"},
{ 97, PROTOCOL_DARKPLACES2 , "DP2"},
{ 96, PROTOCOL_DARKPLACES1 , "DP1"},
{ 15, PROTOCOL_QUAKEDP , "QUAKEDP"},
{ 15, PROTOCOL_QUAKE , "QUAKE"},
{ 28, PROTOCOL_QUAKEWORLD , "QW"},
{ 250, PROTOCOL_NEHAHRAMOVIE, "NEHAHRAMOVIE"},
{10000, PROTOCOL_NEHAHRABJP , "NEHAHRABJP"},
{10001, PROTOCOL_NEHAHRABJP2 , "NEHAHRABJP2"},
{10002, PROTOCOL_NEHAHRABJP3 , "NEHAHRABJP3"},
}
@ PROTOCOL_DARKPLACES2
various changes
Definition common.h:140
@ PROTOCOL_DARKPLACES4
various changes
Definition common.h:138
@ PROTOCOL_NEHAHRABJP2
same as NEHAHRABJP but with 16bit soundindex
Definition common.h:147
@ PROTOCOL_DARKPLACES3
uses EntityFrame4 entity snapshot encoder/decoder which is broken, this attempted to do partial snaps...
Definition common.h:139
@ PROTOCOL_NEHAHRABJP
same as QUAKEDP but with 16bit modelindex
Definition common.h:146
@ PROTOCOL_DARKPLACES5
uses EntityFrame5 entity snapshot encoder/decoder which is based on a Tribes networking article at ht...
Definition common.h:137
@ PROTOCOL_DARKPLACES7
added QuakeWorld-style movement protocol to allow more consistent prediction
Definition common.h:135
@ PROTOCOL_QUAKEDP
darkplaces extended quake protocol (used by TomazQuake and others), backwards compatible as long as n...
Definition common.h:142
@ PROTOCOL_DARKPLACES6
various changes
Definition common.h:136
@ PROTOCOL_QUAKE
quake (aka netquake/normalquake/nq) protocol
Definition common.h:144
@ PROTOCOL_DARKPLACES8
added parting messages. WIP
Definition common.h:134
@ PROTOCOL_NEHAHRABJP3
same as NEHAHRABJP2 but with some changes
Definition common.h:148
@ PROTOCOL_NEHAHRAMOVIE
Nehahra movie protocol, a big nasty hack dating back to early days of the Quake Standards Group (but ...
Definition common.h:143
@ PROTOCOL_DARKPLACES1
uses EntityFrame entity snapshot encoder/decoder which is a QuakeWorld-like entity snapshot delta com...
Definition common.h:141
#define NULL
Definition qtypes.h:12

Referenced by Protocol_EnumForName(), Protocol_EnumForNumber(), Protocol_NameForEnum(), Protocol_Names(), and Protocol_NumberForEnum().

◆ sendquakestats

const int sendquakestats[]
static
Initial value:
=
{
-1,
}
#define STAT_TOTALMONSTERS
Definition qstats.h:20
#define STAT_MONSTERS
bumped by svc_killedmonster
Definition qstats.h:22
#define STAT_SECRETS
bumped on client side by svc_foundsecret
Definition qstats.h:21
#define STAT_TOTALSECRETS
Definition qstats.h:19
#define STAT_VIEWZOOM
DP.
Definition qstats.h:27
#define STAT_VIEWHEIGHT
FTE, DP.
Definition qstats.h:24

Definition at line 135 of file protocol.c.

136{
137// quake did not send these secrets/monsters stats in this way, but doing so
138// allows a mod to increase STAT_TOTALMONSTERS during the game, and ensures
139// that STAT_SECRETS and STAT_MONSTERS are always correct (even if a client
140// didn't receive an svc_foundsecret or svc_killedmonster), which may be most
141// valuable if randomly seeking around in a demo
142STAT_TOTALSECRETS, // never changes during game
143STAT_TOTALMONSTERS, // changes in some mods
144STAT_SECRETS, // this makes svc_foundsecret unnecessary
145STAT_MONSTERS, // this makes svc_killedmonster unnecessary
146STAT_VIEWHEIGHT, // sent just for FTEQW clients
147STAT_VIEWZOOM, // this rarely changes
148-1,
149};

Referenced by Protocol_WriteStatsReliable().