]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - server.h
730e7fcf2347090b0044380050f8a566f92da6ec
[xonotic/darkplaces.git] / server.h
1 /*
2 Copyright (C) 1996-1997 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 // server.h
21
22 #ifndef SERVER_H
23 #define SERVER_H
24
25 typedef struct server_static_s
26 {
27         // number of svs.clients slots (updated by maxplayers command)
28         int maxclients;
29         // client slots
30         struct client_s *clients;
31         // episode completion information
32         int serverflags;
33         // cleared when at SV_SpawnServer
34         qboolean changelevel_issued;
35         // server infostring
36         char serverinfo[MAX_SERVERINFO_STRING];
37 } server_static_t;
38
39 //=============================================================================
40
41 typedef enum server_state_e {ss_loading, ss_active} server_state_t;
42
43 #define MAX_CONNECTFLOODADDRESSES 16
44 typedef struct server_connectfloodaddress_s
45 {
46         double lasttime;
47         lhnetaddress_t address;
48 }
49 server_connectfloodaddress_t;
50
51 typedef struct server_s
52 {
53         // false if only a net client
54         qboolean active;
55
56         qboolean paused;
57         // handle connections specially
58         qboolean loadgame;
59
60         // one of the PROTOCOL_ values
61         protocolversion_t protocol;
62
63         double time;
64
65         double frametime;
66
67         // used by PF_checkclient
68         int lastcheck;
69         double lastchecktime;
70
71         // crc of clientside progs at time of level start
72         int csqc_progcrc; // -1 = no progs
73         int csqc_progsize; // -1 = no progs
74         char csqc_progname[MAX_QPATH]; // copied from csqc_progname at level start
75
76         // collision culling data
77         world_t world;
78
79         // map name
80         char name[64];
81         // maps/<name>.bsp, for model_precache[0]
82         char modelname[64];
83         struct model_s *worldmodel;
84         // NULL terminated
85         // LordHavoc: precaches are now MAX_QPATH rather than a pointer
86         // updated by SV_ModelIndex
87         char model_precache[MAX_MODELS][MAX_QPATH];
88         struct model_s *models[MAX_MODELS];
89         // NULL terminated
90         // LordHavoc: precaches are now MAX_QPATH rather than a pointer
91         // updated by SV_SoundIndex
92         char sound_precache[MAX_SOUNDS][MAX_QPATH];
93         char lightstyles[MAX_LIGHTSTYLES][64];
94         // some actions are only valid during load
95         server_state_t state;
96
97         sizebuf_t datagram;
98         unsigned char datagram_buf[NET_MAXMESSAGE];
99
100         // copied to all clients at end of frame
101         sizebuf_t reliable_datagram;
102         unsigned char reliable_datagram_buf[NET_MAXMESSAGE];
103
104         sizebuf_t signon;
105         // LordHavoc: increased signon message buffer from 8192
106         unsigned char signon_buf[NET_MAXMESSAGE];
107
108         // connection flood blocking
109         // note this is in server_t rather than server_static_t so that it is
110         // reset on each map command (such as New Game in singleplayer)
111         server_connectfloodaddress_t connectfloodaddresses[MAX_CONNECTFLOODADDRESSES];
112
113 #define SV_MAX_PARTICLEEFFECTNAME 256
114         qboolean particleeffectnamesloaded;
115         char particleeffectname[SV_MAX_PARTICLEEFFECTNAME][MAX_QPATH];
116
117         int writeentitiestoclient_stats_culled_pvs;
118         int writeentitiestoclient_stats_culled_trace;
119         int writeentitiestoclient_stats_visibleentities;
120         int writeentitiestoclient_stats_totalentities;
121         int writeentitiestoclient_cliententitynumber;
122         int writeentitiestoclient_clientnumber;
123         sizebuf_t *writeentitiestoclient_msg;
124         vec3_t writeentitiestoclient_testeye;
125         int writeentitiestoclient_pvsbytes;
126         unsigned char writeentitiestoclient_pvs[MAX_MAP_LEAFS/8];
127         entity_state_t writeentitiestoclient_sendstates[MAX_EDICTS];
128 } server_t;
129
130 // if defined this does ping smoothing, otherwise it does not
131 //#define NUM_PING_TIMES 16
132
133 #define NUM_SPAWN_PARMS 16
134
135 typedef struct client_s
136 {
137         // false = empty client slot
138         qboolean active;
139         // false = don't do ClientDisconnect on drop
140         qboolean clientconnectcalled;
141         // false = don't send datagrams
142         qboolean spawned;
143         // 1 = send svc_serverinfo and advance to 2, 2 doesn't send, then advances to 0 (allowing unlimited sending) when prespawn is received
144         int sendsignon;
145
146         // requested rate in bytes per second
147         int rate;
148
149         // realtime this client connected
150         double connecttime;
151
152         // keepalive messages must be sent periodically during signon
153         double keepalivetime;
154
155         // communications handle
156         netconn_t *netconnection;
157
158         int movesequence;
159         // movement
160         usercmd_t cmd;
161         // intended motion calced from cmd
162         vec3_t wishdir;
163
164         // PRVM_EDICT_NUM(clientnum+1)
165         prvm_edict_t *edict;
166
167 #ifdef NUM_PING_TIMES
168         float ping_times[NUM_PING_TIMES];
169         // ping_times[num_pings%NUM_PING_TIMES]
170         int num_pings;
171 #endif
172         // LordHavoc: can be used for prediction or whatever...
173         float ping;
174
175         // this is used by sv_clmovement_minping code
176         double clmovement_disabletimeout;
177         // this is used by sv_clmvoement_waitforinput code
178         int clmovement_skipphysicsframes;
179
180 // spawn parms are carried from level to level
181         float spawn_parms[NUM_SPAWN_PARMS];
182
183         // properties that are sent across the network only when changed
184         char name[64], old_name[64];
185         int colors, old_colors;
186         int frags, old_frags;
187         char playermodel[MAX_QPATH], old_model[MAX_QPATH];
188         char playerskin[MAX_QPATH], old_skin[MAX_QPATH];
189
190         // netaddress support
191         char netaddress[MAX_QPATH];
192
193         // visibility state
194         float visibletime[MAX_EDICTS];
195
196         // version number of csqc-based entity to decide whether to send it
197         unsigned char csqcentityversion[MAX_EDICTS];
198
199         // prevent animated names
200         float nametime;
201
202         // latest received clc_ackframe (used to detect packet loss)
203         int latestframenum;
204
205         // cache weaponmodel name lookups
206         char weaponmodel[MAX_QPATH];
207         int weaponmodelindex;
208
209         entityframe_database_t *entitydatabase;
210         entityframe4_database_t *entitydatabase4;
211         entityframe5_database_t *entitydatabase5;
212
213         // delta compression of stats
214         unsigned char statsdeltabits[(MAX_CL_STATS+7)/8];
215         int stats[MAX_CL_STATS];
216
217         unsigned char unreliablemsg_data[NET_MAXMESSAGE];
218         sizebuf_t unreliablemsg;
219         int unreliablemsg_splitpoints;
220         int unreliablemsg_splitpoint[NET_MAXMESSAGE/16];
221
222         // information on an active download if any
223         qfile_t *download_file;
224         int download_expectedposition; // next position the client should ack
225         qboolean download_started;
226         char download_name[MAX_QPATH];
227
228         // fixangle data
229         qboolean fixangle_angles_set;
230         vec3_t fixangle_angles;
231 } client_t;
232
233
234 //=============================================================================
235
236 // edict->movetype values
237 #define MOVETYPE_NONE                   0               // never moves
238 #define MOVETYPE_ANGLENOCLIP    1
239 #define MOVETYPE_ANGLECLIP              2
240 #define MOVETYPE_WALK                   3               // gravity
241 #define MOVETYPE_STEP                   4               // gravity, special edge handling
242 #define MOVETYPE_FLY                    5
243 #define MOVETYPE_TOSS                   6               // gravity
244 #define MOVETYPE_PUSH                   7               // no clip to world, push and crush
245 #define MOVETYPE_NOCLIP                 8
246 #define MOVETYPE_FLYMISSILE             9               // extra size to monsters
247 #define MOVETYPE_BOUNCE                 10
248 #define MOVETYPE_BOUNCEMISSILE  11              // bounce w/o gravity
249 #define MOVETYPE_FOLLOW                 12              // track movement of aiment
250 #define MOVETYPE_FAKEPUSH               13              // tenebrae's push that doesn't push
251
252 // edict->solid values
253 #define SOLID_NOT                               0               // no interaction with other objects
254 #define SOLID_TRIGGER                   1               // touch on edge, but not blocking
255 #define SOLID_BBOX                              2               // touch on edge, block
256 #define SOLID_SLIDEBOX                  3               // touch on edge, but not an onground
257 #define SOLID_BSP                               4               // bsp clip, touch on edge, block
258 // LordHavoc: corpse code
259 #define SOLID_CORPSE                    5               // same as SOLID_BBOX, except it behaves as SOLID_NOT against SOLID_SLIDEBOX objects (players/monsters)
260
261 // edict->deadflag values
262 #define DEAD_NO                                 0
263 #define DEAD_DYING                              1
264 #define DEAD_DEAD                               2
265
266 #define DAMAGE_NO                               0
267 #define DAMAGE_YES                              1
268 #define DAMAGE_AIM                              2
269
270 // edict->flags
271 #define FL_FLY                                  1
272 #define FL_SWIM                                 2
273 #define FL_CONVEYOR                             4
274 #define FL_CLIENT                               8
275 #define FL_INWATER                              16
276 #define FL_MONSTER                              32
277 #define FL_GODMODE                              64
278 #define FL_NOTARGET                             128
279 #define FL_ITEM                                 256
280 #define FL_ONGROUND                             512
281 #define FL_PARTIALGROUND                1024    // not all corners are valid
282 #define FL_WATERJUMP                    2048    // player jumping out of water
283 #define FL_JUMPRELEASED                 4096    // for jump debouncing
284
285 #define SPAWNFLAG_NOT_EASY                      256
286 #define SPAWNFLAG_NOT_MEDIUM            512
287 #define SPAWNFLAG_NOT_HARD                      1024
288 #define SPAWNFLAG_NOT_DEATHMATCH        2048
289
290 //============================================================================
291
292 extern cvar_t coop;
293 extern cvar_t deathmatch;
294 extern cvar_t fraglimit;
295 extern cvar_t gamecfg;
296 extern cvar_t noexit;
297 extern cvar_t nomonsters;
298 extern cvar_t pausable;
299 extern cvar_t pr_checkextension;
300 extern cvar_t samelevel;
301 extern cvar_t saved1;
302 extern cvar_t saved2;
303 extern cvar_t saved3;
304 extern cvar_t saved4;
305 extern cvar_t savedgamecfg;
306 extern cvar_t scratch1;
307 extern cvar_t scratch2;
308 extern cvar_t scratch3;
309 extern cvar_t scratch4;
310 extern cvar_t skill;
311 extern cvar_t slowmo;
312 extern cvar_t sv_accelerate;
313 extern cvar_t sv_aim;
314 extern cvar_t sv_airaccel_qw;
315 extern cvar_t sv_airaccel_sideways_friction;
316 extern cvar_t sv_airaccelerate;
317 extern cvar_t sv_allowdownloads;
318 extern cvar_t sv_allowdownloads_archive;
319 extern cvar_t sv_allowdownloads_config;
320 extern cvar_t sv_allowdownloads_dlcache;
321 extern cvar_t sv_allowdownloads_inarchive;
322 extern cvar_t sv_areagrid_mingridsize;
323 extern cvar_t sv_checkforpacketsduringsleep;
324 extern cvar_t sv_clmovement_enable;
325 extern cvar_t sv_clmovement_minping;
326 extern cvar_t sv_clmovement_minping_disabletime;
327 extern cvar_t sv_clmovement_waitforinput;
328 extern cvar_t sv_cullentities_nevercullbmodels;
329 extern cvar_t sv_cullentities_pvs;
330 extern cvar_t sv_cullentities_stats;
331 extern cvar_t sv_cullentities_trace;
332 extern cvar_t sv_cullentities_trace_delay;
333 extern cvar_t sv_cullentities_trace_enlarge;
334 extern cvar_t sv_cullentities_trace_prediction;
335 extern cvar_t sv_cullentities_trace_samples;
336 extern cvar_t sv_cullentities_trace_samples_extra;
337 extern cvar_t sv_debugmove;
338 extern cvar_t sv_echobprint;
339 extern cvar_t sv_edgefriction;
340 extern cvar_t sv_entpatch;
341 extern cvar_t sv_fixedframeratesingleplayer;
342 extern cvar_t sv_freezenonclients;
343 extern cvar_t sv_friction;
344 extern cvar_t sv_gameplayfix_blowupfallenzombies;
345 extern cvar_t sv_gameplayfix_droptofloorstartsolid;
346 extern cvar_t sv_gameplayfix_findradiusdistancetobox;
347 extern cvar_t sv_gameplayfix_grenadebouncedownslopes;
348 extern cvar_t sv_gameplayfix_noairborncorpse;
349 extern cvar_t sv_gameplayfix_qwplayerphysics;
350 extern cvar_t sv_gameplayfix_setmodelrealbox;
351 extern cvar_t sv_gameplayfix_stepdown;
352 extern cvar_t sv_gameplayfix_stepwhilejumping;
353 extern cvar_t sv_gameplayfix_swiminbmodels;
354 extern cvar_t sv_gameplayfix_upwardvelocityclearsongroundflag;
355 extern cvar_t sv_gravity;
356 extern cvar_t sv_idealpitchscale;
357 extern cvar_t sv_jumpstep;
358 extern cvar_t sv_jumpvelocity;
359 extern cvar_t sv_maxairspeed;
360 extern cvar_t sv_maxrate;
361 extern cvar_t sv_maxspeed;
362 extern cvar_t sv_maxvelocity;
363 extern cvar_t sv_newflymove;
364 extern cvar_t sv_nostep;
365 extern cvar_t sv_playerphysicsqc;
366 extern cvar_t sv_progs;
367 extern cvar_t sv_protocolname;
368 extern cvar_t sv_random_seed;
369 extern cvar_t sv_ratelimitlocalplayer;
370 extern cvar_t sv_sound_land;
371 extern cvar_t sv_sound_watersplash;
372 extern cvar_t sv_stepheight;
373 extern cvar_t sv_stopspeed;
374 extern cvar_t sv_wallfriction;
375 extern cvar_t sv_wateraccelerate;
376 extern cvar_t sv_waterfriction;
377 extern cvar_t sys_ticrate;
378 extern cvar_t teamplay;
379 extern cvar_t temp1;
380 extern cvar_t timelimit;
381
382 extern mempool_t *sv_mempool;
383
384 // persistant server info
385 extern server_static_t svs;
386 // local server
387 extern server_t sv;
388
389 extern client_t *host_client;
390
391 //===========================================================
392
393 void SV_Init (void);
394
395 void SV_StartParticle (vec3_t org, vec3_t dir, int color, int count);
396 void SV_StartEffect (vec3_t org, int modelindex, int startframe, int framecount, int framerate);
397 void SV_StartSound (prvm_edict_t *entity, int channel, const char *sample, int volume, float attenuation);
398
399 void SV_ConnectClient (int clientnum, netconn_t *netconnection);
400 void SV_DropClient (qboolean crash);
401
402 void SV_SendClientMessages (void);
403
404 void SV_ReadClientMessage(void);
405
406 // precachemode values:
407 // 0 = fail if not precached,
408 // 1 = warn if not found and precache if possible
409 // 2 = precache
410 int SV_ModelIndex(const char *s, int precachemode);
411 int SV_SoundIndex(const char *s, int precachemode);
412
413 int SV_ParticleEffectIndex(const char *name);
414
415 void SV_SetIdealPitch (void);
416
417 void SV_AddUpdates (void);
418
419 void SV_ClientThink (void);
420
421 void SV_ClientPrint(const char *msg);
422 void SV_ClientPrintf(const char *fmt, ...) DP_FUNC_PRINTF(1);
423 void SV_BroadcastPrint(const char *msg);
424 void SV_BroadcastPrintf(const char *fmt, ...) DP_FUNC_PRINTF(1);
425
426 void SV_Physics (void);
427 void SV_Physics_ClientMove (void);
428 void SV_Physics_ClientEntity (prvm_edict_t *ent);
429
430 qboolean SV_PlayerCheckGround (prvm_edict_t *ent);
431 qboolean SV_CheckBottom (prvm_edict_t *ent);
432 qboolean SV_movestep (prvm_edict_t *ent, vec3_t move, qboolean relink, qboolean noenemy, qboolean settrace);
433
434 // Needs to be called any time an entity changes origin, mins, maxs, or solid
435 // sets ent->v.absmin and ent->v.absmax
436 // if touchtriggers, calls prog functions for the intersected triggers
437 void SV_LinkEdict (prvm_edict_t *ent, qboolean touch_triggers);
438
439 // calculates hitsupercontentsmask for a generic qc entity
440 int SV_GenericHitSuperContentsMask(const prvm_edict_t *edict);
441 // traces a box move against worldmodel and all entities in the specified area
442 trace_t SV_Move(const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int type, prvm_edict_t *passedict, int hitsupercontentsmask);
443
444 #define SV_PointSuperContents(point) (SV_Move((point), vec3_origin, vec3_origin, (point), sv_gameplayfix_swiminbmodels.integer ? MOVE_NOMONSTERS : MOVE_WORLDONLY, NULL, 0).startsupercontents)
445
446 void SV_FlushBroadcastMessages(void);
447 void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t *msg, int *stats);
448
449 void SV_MoveToGoal (void);
450
451 void SV_ApplyClientMove (void);
452 void SV_SaveSpawnparms (void);
453 void SV_SpawnServer (const char *server);
454
455 void SV_CheckVelocity (prvm_edict_t *ent);
456
457 void SV_SetupVM(void);
458
459 void SV_VM_Begin(void);
460 void SV_VM_End(void);
461
462 #endif
463