summaryrefslogtreecommitdiff
path: root/source/protocol.h
blob: 926c8fd0f1389b1b13202521f7c3ad005fd0e5b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
/*
Copyright (C) 1997-2001 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

//
// protocol.h -- communications protocols
//

#define	MAX_MSGLEN		0x8000		// max length of a message, 32k

#define	PROTOCOL_VERSION_OLD		26
#define	PROTOCOL_VERSION_DEFAULT	34
#define PROTOCOL_VERSION_R1Q2		35
#define PROTOCOL_VERSION_Q2PRO		36
#define PROTOCOL_VERSION_MVD		37 // not used for UDP connections

#define PROTOCOL_VERSION_R1Q2_MINIMUM		1903	// b6377
#define PROTOCOL_VERSION_R1Q2_UCMD		    1904	// b7387
#define PROTOCOL_VERSION_R1Q2_CURRENT		1904	// b7387
#define PROTOCOL_VERSION_Q2PRO_MINIMUM	    1011	// r161
#define PROTOCOL_VERSION_Q2PRO_UCMD	        1012	// r179
#define PROTOCOL_VERSION_Q2PRO_CLIENTFIX    1013	// r226
#define PROTOCOL_VERSION_Q2PRO_CURRENT	    1013	// r226
#define PROTOCOL_VERSION_MVD_MINIMUM		2009	// r168
#define PROTOCOL_VERSION_MVD_CURRENT		2010	// r177

#define R1Q2_SUPPORTED( x )     ( (x) >= PROTOCOL_VERSION_R1Q2_MINIMUM && \
                                  (x) <= PROTOCOL_VERSION_R1Q2_CURRENT )

#define Q2PRO_SUPPORTED( x )    ( (x) >= PROTOCOL_VERSION_Q2PRO_MINIMUM && \
                                  (x) <= PROTOCOL_VERSION_Q2PRO_CURRENT )

#define MVD_SUPPORTED( x )    ( (x) >= PROTOCOL_VERSION_MVD_MINIMUM && \
                                  (x) <= PROTOCOL_VERSION_MVD_CURRENT )

//=========================================

#define	PORT_MASTER		27900
#define	PORT_CLIENT		27901
#define	PORT_SERVER		27910
#define PORT_MAX_SEARCH	5

//=========================================

#define	UPDATE_BACKUP	16	// copies of entity_state_t to keep buffered
							// must be power of two
#define	UPDATE_MASK		( UPDATE_BACKUP - 1 )

#define	CMD_BACKUP		128		// allow a lot of command backups for very fast systems
								// increased from 64
#define CMD_MASK		( CMD_BACKUP - 1 )



#define SVCMD_BITS				5
#define SVCMD_MASK				( ( 1 << SVCMD_BITS ) - 1 )

#define	FRAMENUM_BITS			27
#define FRAMENUM_MASK			( ( 1 << FRAMENUM_BITS ) - 1 )

#define SURPRESSCOUNT_BITS		4
#define SURPRESSCOUNT_MASK		( ( 1 << SURPRESSCOUNT_BITS ) - 1 )

#define MAX_PACKET_ENTITIES		128
#define	MAX_PARSE_ENTITIES		2048	// should be MAX_PACKET_ENTITIES * UPDATE_BACKUP
#define PARSE_ENTITIES_MASK		( MAX_PARSE_ENTITIES - 1 )

#define MAX_PACKET_USERCMDS			32
#define MAX_PACKET_FRAMES			4

#define	MAX_PACKET_STRINGCMDS	8
#define	MAX_PACKET_USERINFOS	8

#define CS_BITMAP_BYTES	    (MAX_CONFIGSTRINGS/8) // 260
#define CS_BITMAP_LONGS	    (CS_BITMAP_BYTES/4)

#define MVD_MAGIC   MakeLong( 'M', 'V', 'D', '2' )

//
// server to client
//
typedef enum svc_ops_e {
	svc_bad,

	// these ops are known to the game dll
	svc_muzzleflash,
	svc_muzzleflash2,
	svc_temp_entity,
	svc_layout,
	svc_inventory,

	// the rest are private to the client and server
	svc_nop,
	svc_disconnect,
	svc_reconnect,
	svc_sound,					// <see code>
	svc_print,					// [byte] id [string] null terminated string
	svc_stufftext,				// [string] stuffed into client's console buffer
                                // should be \n terminated
	svc_serverdata,				// [long] protocol ...
	svc_configstring,			// [short] [string]
	svc_spawnbaseline,		
	svc_centerprint,			// [string] to put in center of the screen
	svc_download,				// [short] size [size bytes]
	svc_playerinfo,				// variable
	svc_packetentities,			// [...]
	svc_deltapacketentities,	// [...]
	svc_frame,

	// r1q2 specific operations
	svc_zpacket,
	svc_zdownload,
    svc_gamestate, // q2pro specific, means svc_playerupdate in r1q2
    svc_setting,

    svc_num_types
} svc_ops_t;

// MVD protocol specific operations
typedef enum mvd_ops_e {
    mvd_bad,
    mvd_nop,
    mvd_disconnect,     // reserved
    mvd_reconnect,      // reserved
    mvd_serverdata,
    mvd_configstring,
    mvd_frame,
    mvd_frame_nodelta,
	mvd_unicast,
    mvd_unicast_r,
	mvd_multicast_all,
	mvd_multicast_pvs,
	mvd_multicast_phs,
	mvd_multicast_all_r,
	mvd_multicast_pvs_r,
	mvd_multicast_phs_r,
    mvd_sound,
    mvd_print,          // reserved
    mvd_stufftext,      // reserved

    mvd_num_types
} mvd_ops_t;

//==============================================

//
// client to server
//
typedef enum clc_ops_e {
	clc_bad,
	clc_nop, 		
	clc_move,				// [usercmd_t]
	clc_userinfo,			// [userinfo string]
	clc_stringcmd,			// [string] message

	// r1q2 specific operations
	clc_setting,

	// q2pro specific operations
	clc_move_nodelta = 10,
	clc_move_batched,
	clc_userinfo_delta
} clc_ops_t;

//==============================================

// player_state_t communication

#define	PS_M_TYPE			(1<<0)
#define	PS_M_ORIGIN			(1<<1)
#define	PS_M_VELOCITY		(1<<2)
#define	PS_M_TIME			(1<<3)
#define	PS_M_FLAGS			(1<<4)
#define	PS_M_GRAVITY		(1<<5)
#define	PS_M_DELTA_ANGLES	(1<<6)

#define	PS_VIEWOFFSET		(1<<7)
#define	PS_VIEWANGLES		(1<<8)
#define	PS_KICKANGLES		(1<<9)
#define	PS_BLEND			(1<<10)
#define	PS_FOV				(1<<11)
#define	PS_WEAPONINDEX		(1<<12)
#define	PS_WEAPONFRAME		(1<<13)
#define	PS_RDFLAGS			(1<<14)
#define	PS_RESERVED			(1<<15)

#define PS_BITS				16
#define PS_MASK				( ( 1 << PS_BITS ) - 1 )

// r1q2 protocol specific extra flags
#define	EPS_GUNOFFSET		(1<<0)
#define	EPS_GUNANGLES		(1<<1)
#define	EPS_M_VELOCITY2		(1<<2)
#define	EPS_M_ORIGIN2		(1<<3)
#define	EPS_VIEWANGLE2		(1<<4)
#define	EPS_STATS			(1<<5)

// q2pro protocol specific extra flags
#define	EPS_CLIENTNUM		(1<<6)

#define EPS_BITS			7
#define EPS_MASK			( ( 1 << EPS_BITS ) - 1 )

//==============================================

// packetized player_state_t communication (MVD specific)

#define	PPS_M_TYPE			(1<<0)
#define	PPS_M_ORIGIN		(1<<1)
#define	PPS_M_ORIGIN2		(1<<2)

#define	PPS_VIEWOFFSET		(1<<3)
#define	PPS_VIEWANGLES		(1<<4)
#define	PPS_VIEWANGLE2		(1<<5)
#define	PPS_KICKANGLES		(1<<6)
#define	PPS_BLEND			(1<<7)
#define	PPS_FOV				(1<<8)
#define	PPS_WEAPONINDEX		(1<<9)
#define	PPS_WEAPONFRAME		(1<<10)
#define	PPS_GUNOFFSET	    (1<<11)
#define	PPS_GUNANGLES	    (1<<12)
#define	PPS_RDFLAGS			(1<<13)
#define	PPS_STATS		    (1<<14)
#define	PPS_REMOVE			(1<<15)

#define PPS_NUM( ps )       (ps)->pmove.pm_flags
#define PPS_INUSE( ps )     (ps)->pmove.pm_time

//==============================================

// user_cmd_t communication

// ms and light always sent, the others are optional
#define	CM_ANGLE1 	(1<<0)
#define	CM_ANGLE2 	(1<<1)
#define	CM_ANGLE3 	(1<<2)
#define	CM_FORWARD	(1<<3)
#define	CM_SIDE		(1<<4)
#define	CM_UP		(1<<5)
#define	CM_BUTTONS	(1<<6)
#define	CM_IMPULSE	(1<<7)

// r1q2 button byte hacks
#define BUTTON_MASK (BUTTON_ATTACK|BUTTON_USE|BUTTON_ANY)
#define BUTTON_FORWARD  4
#define BUTTON_SIDE     8
#define BUTTON_UP       16
#define BUTTON_ANGLE1   32
#define BUTTON_ANGLE2   64

//==============================================

// a sound without an ent or pos will be a local only sound
#define	SND_VOLUME		(1<<0)		// a byte
#define	SND_ATTENUATION	(1<<1)		// a byte
#define	SND_POS			(1<<2)		// three coordinates
#define	SND_ENT			(1<<3)		// a short 0-2: channel, 3-12: entity
#define	SND_OFFSET		(1<<4)		// a byte, msec offset from frame start

#define DEFAULT_SOUND_PACKET_VOLUME	1.0
#define DEFAULT_SOUND_PACKET_ATTENUATION 1.0

//==============================================

// entity_state_t communication

// try to pack the common update flags into the first byte
#define	U_ORIGIN1	(1<<0)
#define	U_ORIGIN2	(1<<1)
#define	U_ANGLE2	(1<<2)
#define	U_ANGLE3	(1<<3)
#define	U_FRAME8	(1<<4)		// frame is a byte
#define	U_EVENT		(1<<5)
#define	U_REMOVE	(1<<6)		// REMOVE this entity, don't add it
#define	U_MOREBITS1	(1<<7)		// read one additional byte

// second byte
#define	U_NUMBER16	(1<<8)		// NUMBER8 is implicit if not set
#define	U_ORIGIN3	(1<<9)
#define	U_ANGLE1	(1<<10)
#define	U_MODEL		(1<<11)
#define U_RENDERFX8	(1<<12)		// fullbright, etc
#define	U_EFFECTS8	(1<<14)		// autorotate, trails, etc
#define	U_MOREBITS2	(1<<15)		// read one additional byte

// third byte
#define	U_SKIN8		(1<<16)
#define	U_FRAME16	(1<<17)		// frame is a short
#define	U_RENDERFX16 (1<<18)	// 8 + 16 = 32
#define	U_EFFECTS16	(1<<19)		// 8 + 16 = 32
#define	U_MODEL2	(1<<20)		// weapons, flags, etc
#define	U_MODEL3	(1<<21)
#define	U_MODEL4	(1<<22)
#define	U_MOREBITS3	(1<<23)		// read one additional byte

// fourth byte
#define	U_OLDORIGIN	(1<<24)		// FIXME: get rid of this
#define	U_SKIN16	(1<<25)
#define	U_SOUND		(1<<26)
#define	U_SOLID		(1<<27)

// ==============================================================

#define CLIENTNUM_NONE		( MAX_CLIENTS - 1 )
#define CLIENTNUM_RESERVED	( MAX_CLIENTS - 1 )

typedef enum clientSetting_e {
	// r1q2 specific
	CLS_NOGUN,
	CLS_NOBLEND,
	CLS_RECORDING,
    CLS_PLAYERUPDATES,
    CLS_FPS,

	// q2pro specific
	CLS_NOGIBS			= 10,
	CLS_NOFOOTSTEPS,
	CLS_NOPREDICT,

	CLS_MAX
} clientSetting_t;

typedef enum serverSetting_e {
    // r1q2 specific
    SVS_PLAYERUPDATES,
    SVS_FPS,

    SVS_MAX
} serverSetting_t;

typedef enum gametype_e {
	GT_SINGLEPLAYER,
	GT_COOP,
	GT_DEATHMATCH
} gametype_t;

typedef enum {
    // these are sent by the server
    FF_SURPRESSED   = ( 1 << 0 ),
    FF_CLIENTDROP   = ( 1 << 1 ),
    FF_CLIENTPRED   = ( 1 << 2 ),

    // these are calculated by the client
    FF_SERVERDROP   = ( 1 << 4 ),
    FF_BADFRAME     = ( 1 << 5 ),
    FF_OLDFRAME     = ( 1 << 6 ),
    FF_OLDENT       = ( 1 << 7 ),
    FF_NODELTA      = ( 1 << 8 )
} frameflags_t;