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