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