1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 */
20 
21 //
22 // protocol.h -- communications protocols
23 //
24 
25 #ifdef _WIN32_WCE
26 #define	MAX_MSGLEN		0x4000
27 #else
28 #define	MAX_MSGLEN		0x8000		// max length of a message, 32k
29 #endif
30 
31 #define	PROTOCOL_VERSION_OLD		26
32 #define	PROTOCOL_VERSION_DEFAULT	34
33 #define PROTOCOL_VERSION_R1Q2		35
34 #define PROTOCOL_VERSION_Q2PRO		36
35 #define PROTOCOL_VERSION_MVD		37
36 
37 #define PROTOCOL_VERSION_R1Q2_MINOR		1903	// r1q2-b6377
38 #define PROTOCOL_VERSION_Q2PRO_MINOR	1008	// q2pro r107
39 #define PROTOCOL_VERSION_MVD_MINOR		2004	// q2pro r142
40 
41 //=========================================
42 
43 #define	PORT_MASTER		27900
44 #define	PORT_CLIENT		27901
45 #define	PORT_SERVER		27910
46 #define PORT_MAX_SEARCH	5
47 
48 //=========================================
49 
50 #define	UPDATE_BACKUP	16	// copies of entity_state_t to keep buffered
51 							// must be power of two
52 #define	UPDATE_MASK		( UPDATE_BACKUP - 1 )
53 
54 #define	CMD_BACKUP		128		// allow a lot of command backups for very fast systems
55 								// increased from 64
56 #define CMD_MASK		( CMD_BACKUP - 1 )
57 
58 
59 
60 #define SVCMD_BITS				5
61 #define SVCMD_MASK				( ( 1 << SVCMD_BITS ) - 1 )
62 
63 #define	FRAMENUM_BITS			27
64 #define FRAMENUM_MASK			( ( 1 << FRAMENUM_BITS ) - 1 )
65 
66 #define SURPRESSCOUNT_BITS		4
67 #define SURPRESSCOUNT_MASK		( ( 1 << SURPRESSCOUNT_BITS ) - 1 )
68 
69 #define MAX_PACKET_ENTITIES		128
70 #define	MAX_PARSE_ENTITIES		2048	// should be MAX_PACKET_ENTITIES * UPDATE_BACKUP
71 #define PARSE_ENTITIES_MASK		( MAX_PARSE_ENTITIES - 1 )
72 
73 #define MAX_PACKET_USERCMDS			32
74 #define MAX_PACKET_FRAMES			4
75 
76 #define	MAX_PACKET_STRINGCMDS	8
77 #define	MAX_PACKET_USERINFOS	8
78 
79 //
80 // server to client
81 //
82 typedef enum svc_ops_e {
83 	svc_bad,
84 
85 	// these ops are known to the game dll
86 	svc_muzzleflash,
87 	svc_muzzleflash2,
88 	svc_temp_entity,
89 	svc_layout,
90 	svc_inventory,
91 
92 	// the rest are private to the client and server
93 	svc_nop,
94 	svc_disconnect,
95 	svc_reconnect,
96 	svc_sound,					// <see code>
97 	svc_print,					// [byte] id [string] null terminated string
98 	svc_stufftext,				// [string] stuffed into client's console buffer, should be \n terminated
99 	svc_serverdata,				// [long] protocol ...
100 	svc_configstring,			// [short] [string]
101 	svc_spawnbaseline,
102 	svc_centerprint,			// [string] to put in center of the screen
103 	svc_download,				// [short] size [size bytes]
104 	svc_playerinfo,				// variable
105 	svc_packetentities,			// [...]
106 	svc_deltapacketentities,	// [...]
107 	svc_frame,
108 
109 	// r1q2 specific operations
110 	svc_zpacket,
111 	svc_zdownload,
112 
113 	// new MVD protocol specific operations
114 	// NOTE: these do not fit in SVCMD_BITS!
115 	svc_unicast = 101,				// [byte] clientNum/reliable [short] length [...] data
116 	svc_multicast					// [short] length/to [ [pos] origin ] [...] data
117 } svc_ops_t;
118 
119 //==============================================
120 
121 //
122 // client to server
123 //
124 typedef enum clc_ops_e {
125 	clc_bad,
126 	clc_nop,
127 	clc_move,				// [usercmd_t]
128 	clc_userinfo,			// [userinfo string]
129 	clc_stringcmd,			// [string] message
130 
131 	// r1q2 specific operations
132 	clc_setting,
133 
134 	// q2pro specific operations
135 	clc_move_nodelta = 10,
136 	clc_move_batched,
137 	clc_userinfo_delta
138 } clc_ops_t;
139 
140 //==============================================
141 
142 // plyer_state_t communication
143 
144 #define	PS_M_TYPE			(1<<0)
145 #define	PS_M_ORIGIN			(1<<1)
146 #define	PS_M_VELOCITY		(1<<2)
147 #define	PS_M_TIME			(1<<3)
148 #define	PS_M_FLAGS			(1<<4)
149 #define	PS_M_GRAVITY		(1<<5)
150 #define	PS_M_DELTA_ANGLES	(1<<6)
151 
152 #define	PS_VIEWOFFSET		(1<<7)
153 #define	PS_VIEWANGLES		(1<<8)
154 #define	PS_KICKANGLES		(1<<9)
155 #define	PS_BLEND			(1<<10)
156 #define	PS_FOV				(1<<11)
157 #define	PS_WEAPONINDEX		(1<<12)
158 #define	PS_WEAPONFRAME		(1<<13)
159 #define	PS_RDFLAGS			(1<<14)
160 #define	PS_REMOVE			(1<<15)	// only used in MVDs
161 
162 #define PS_BITS				16
163 #define PS_MASK				( ( 1 << PS_BITS ) - 1 )
164 
165 /* r1q2 protocol specific extra flags */
166 #define	EPS_GUNOFFSET		(1<<0)
167 #define	EPS_GUNANGLES		(1<<1)
168 #define	EPS_M_VELOCITY2		(1<<2)
169 #define	EPS_M_ORIGIN2		(1<<3)
170 #define	EPS_VIEWANGLE2		(1<<4)
171 #define	EPS_STATS			(1<<5)
172 
173 /* q2pro protocol specific extra flags */
174 #define	EPS_CLIENTNUM		(1<<6)
175 
176 #define EPS_BITS			7
177 #define EPS_MASK			( ( 1 << EPS_BITS ) - 1 )
178 
179 //==============================================
180 
181 // user_cmd_t communication
182 
183 // ms and light always sent, the others are optional
184 #define	CM_ANGLE1 	(1<<0)
185 #define	CM_ANGLE2 	(1<<1)
186 #define	CM_ANGLE3 	(1<<2)
187 #define	CM_FORWARD	(1<<3)
188 #define	CM_SIDE		(1<<4)
189 #define	CM_UP		(1<<5)
190 #define	CM_BUTTONS	(1<<6)
191 #define	CM_IMPULSE	(1<<7)
192 
193 /* q2pro protocol specific extra flag */
194 #define ECM_LIGHTLEVEL	(1<<0)
195 
196 //==============================================
197 
198 // a sound without an ent or pos will be a local only sound
199 #define	SND_VOLUME		(1<<0)		// a byte
200 #define	SND_ATTENUATION	(1<<1)		// a byte
201 #define	SND_POS			(1<<2)		// three coordinates
202 #define	SND_ENT			(1<<3)		// a short 0-2: channel, 3-12: entity
203 #define	SND_OFFSET		(1<<4)		// a byte, msec offset from frame start
204 
205 #define DEFAULT_SOUND_PACKET_VOLUME	1.0
206 #define DEFAULT_SOUND_PACKET_ATTENUATION 1.0
207 
208 //==============================================
209 
210 // entity_state_t communication
211 
212 // try to pack the common update flags into the first byte
213 #define	U_ORIGIN1	(1<<0)
214 #define	U_ORIGIN2	(1<<1)
215 #define	U_ANGLE2	(1<<2)
216 #define	U_ANGLE3	(1<<3)
217 #define	U_FRAME8	(1<<4)		// frame is a byte
218 #define	U_EVENT		(1<<5)
219 #define	U_REMOVE	(1<<6)		// REMOVE this entity, don't add it
220 #define	U_MOREBITS1	(1<<7)		// read one additional byte
221 
222 // second byte
223 #define	U_NUMBER16	(1<<8)		// NUMBER8 is implicit if not set
224 #define	U_ORIGIN3	(1<<9)
225 #define	U_ANGLE1	(1<<10)
226 #define	U_MODEL		(1<<11)
227 #define U_RENDERFX8	(1<<12)		// fullbright, etc
228 #define	U_EFFECTS8	(1<<14)		// autorotate, trails, etc
229 #define	U_MOREBITS2	(1<<15)		// read one additional byte
230 
231 // third byte
232 #define	U_SKIN8		(1<<16)
233 #define	U_FRAME16	(1<<17)		// frame is a short
234 #define	U_RENDERFX16 (1<<18)	// 8 + 16 = 32
235 #define	U_EFFECTS16	(1<<19)		// 8 + 16 = 32
236 #define	U_MODEL2	(1<<20)		// weapons, flags, etc
237 #define	U_MODEL3	(1<<21)
238 #define	U_MODEL4	(1<<22)
239 #define	U_MOREBITS3	(1<<23)		// read one additional byte
240 
241 // fourth byte
242 #define	U_OLDORIGIN	(1<<24)		// FIXME: get rid of this
243 #define	U_SKIN16	(1<<25)
244 #define	U_SOUND		(1<<26)
245 #define	U_SOLID		(1<<27)
246 
247 // ==============================================================
248 
249 #define CLIENTNUM_NONE		( MAX_CLIENTS - 1 )
250 #define CLIENTNUM_ANY		( MAX_CLIENTS - 2 )
251 #define CLIENTNUM_RESERVED	( MAX_CLIENTS - 2 )
252 
253 typedef struct {
254 	player_state_t	ps;
255 	int				number;		/* real server slot number, never changes */
256 	int				clientNum;	/* number corresponding to current client view,
257 								 * may change if following another client, etc
258 								 */
259 } playerStateEx_t;
260 
261 typedef enum attractLoop_e {
262 	ATR_NONE,
263 	ATR_DEMO,
264 	ATR_SERVERRECORD,
265 	ATR_UNKNOWN
266 } attractLoop_t;
267 
268 typedef enum clientSetting_e {
269 	/* r1q2 specific */
270 	CLS_NOGUN,
271 	CLS_NOBLEND,
272 	CLS_RECORDING,
273 
274 	/* q2pro specific */
275 	CLS_NOGIBS			= 10,
276 	CLS_NOFOOTSTEPS,
277 	CLS_NOPREDICT,
278 	CLS_LOCALFOV,
279 
280 	CLS_MAX
281 } clientSetting_t;
282 
283 typedef enum gametype_e {
284 	GT_SINGLEPLAYER,
285 	GT_COOP,
286 	GT_DEATHMATCH
287 } gametype_t;
288 
289 
290