]> icculus.org git repositories - divverent/darkplaces.git/blob - server.h
moved almost all server cvars to sv_main.c and added corresponding
[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 } 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
144         // requested rate in bytes per second
145         int rate;
146
147         // realtime this client connected
148         double connecttime;
149
150         // keepalive messages must be sent periodically during signon
151         double keepalivetime;
152
153         // communications handle
154         netconn_t *netconnection;
155
156         int movesequence;
157         // movement
158         usercmd_t cmd;
159         // intended motion calced from cmd
160         vec3_t wishdir;
161
162         // PRVM_EDICT_NUM(clientnum+1)
163         prvm_edict_t *edict;
164
165 #ifdef NUM_PING_TIMES
166         float ping_times[NUM_PING_TIMES];
167         // ping_times[num_pings%NUM_PING_TIMES]
168         int num_pings;
169 #endif
170         // LordHavoc: can be used for prediction or whatever...
171         float ping;
172
173         // this is used by sv_clmovement_minping code
174         double clmovement_disabletimeout;
175         // this is used by sv_clmvoement_waitforinput code
176         int clmovement_skipphysicsframes;
177
178 // spawn parms are carried from level to level
179         float spawn_parms[NUM_SPAWN_PARMS];
180
181         // properties that are sent across the network only when changed
182         char name[64], old_name[64];
183         int colors, old_colors;
184         int frags, old_frags;
185         char playermodel[MAX_QPATH], old_model[MAX_QPATH];
186         char playerskin[MAX_QPATH], old_skin[MAX_QPATH];
187
188         // netaddress support
189         char netaddress[MAX_QPATH];
190
191         // visibility state
192         float visibletime[MAX_EDICTS];
193
194         // version number of csqc-based entity to decide whether to send it
195         unsigned char csqcentityversion[MAX_EDICTS];
196
197         // prevent animated names
198         float nametime;
199
200         // latest received clc_ackframe (used to detect packet loss)
201         int latestframenum;
202
203         // cache weaponmodel name lookups
204         char weaponmodel[MAX_QPATH];
205         int weaponmodelindex;
206
207         entityframe_database_t *entitydatabase;
208         entityframe4_database_t *entitydatabase4;
209         entityframe5_database_t *entitydatabase5;
210
211         // delta compression of stats
212         unsigned char statsdeltabits[(MAX_CL_STATS+7)/8];
213         int stats[MAX_CL_STATS];
214
215         unsigned char unreliablemsg_data[NET_MAXMESSAGE];
216         sizebuf_t unreliablemsg;
217         int unreliablemsg_splitpoints;
218         int unreliablemsg_splitpoint[NET_MAXMESSAGE/16];
219
220         // information on an active download if any
221         qfile_t *download_file;
222         int download_expectedposition; // next position the client should ack
223         qboolean download_started;
224         char download_name[MAX_QPATH];
225
226         // fixangle data
227         qboolean fixangle_angles_set;
228         vec3_t fixangle_angles;
229 } client_t;
230
231
232 //=============================================================================
233
234 // edict->movetype values
235 #define MOVETYPE_NONE                   0               // never moves
236 #define MOVETYPE_ANGLENOCLIP    1
237 #define MOVETYPE_ANGLECLIP              2
238 #define MOVETYPE_WALK                   3               // gravity
239 #define MOVETYPE_STEP                   4               // gravity, special edge handling
240 #define MOVETYPE_FLY                    5
241 #define MOVETYPE_TOSS                   6               // gravity
242 #define MOVETYPE_PUSH                   7               // no clip to world, push and crush
243 #define MOVETYPE_NOCLIP                 8
244 #define MOVETYPE_FLYMISSILE             9               // extra size to monsters
245 #define MOVETYPE_BOUNCE                 10
246 #define MOVETYPE_BOUNCEMISSILE  11              // bounce w/o gravity
247 #define MOVETYPE_FOLLOW                 12              // track movement of aiment
248 #define MOVETYPE_FAKEPUSH               13              // tenebrae's push that doesn't push
249
250 // edict->solid values
251 #define SOLID_NOT                               0               // no interaction with other objects
252 #define SOLID_TRIGGER                   1               // touch on edge, but not blocking
253 #define SOLID_BBOX                              2               // touch on edge, block
254 #define SOLID_SLIDEBOX                  3               // touch on edge, but not an onground
255 #define SOLID_BSP                               4               // bsp clip, touch on edge, block
256 // LordHavoc: corpse code
257 #define SOLID_CORPSE                    5               // same as SOLID_BBOX, except it behaves as SOLID_NOT against SOLID_SLIDEBOX objects (players/monsters)
258
259 // edict->deadflag values
260 #define DEAD_NO                                 0
261 #define DEAD_DYING                              1
262 #define DEAD_DEAD                               2
263
264 #define DAMAGE_NO                               0
265 #define DAMAGE_YES                              1
266 #define DAMAGE_AIM                              2
267
268 // edict->flags
269 #define FL_FLY                                  1
270 #define FL_SWIM                                 2
271 #define FL_CONVEYOR                             4
272 #define FL_CLIENT                               8
273 #define FL_INWATER                              16
274 #define FL_MONSTER                              32
275 #define FL_GODMODE                              64
276 #define FL_NOTARGET                             128
277 #define FL_ITEM                                 256
278 #define FL_ONGROUND                             512
279 #define FL_PARTIALGROUND                1024    // not all corners are valid
280 #define FL_WATERJUMP                    2048    // player jumping out of water
281 #define FL_JUMPRELEASED                 4096    // for jump debouncing
282
283 #define SPAWNFLAG_NOT_EASY                      256
284 #define SPAWNFLAG_NOT_MEDIUM            512
285 #define SPAWNFLAG_NOT_HARD                      1024
286 #define SPAWNFLAG_NOT_DEATHMATCH        2048
287
288 //============================================================================
289
290 extern cvar_t coop;
291 extern cvar_t deathmatch;
292 extern cvar_t fraglimit;
293 extern cvar_t gamecfg;
294 extern cvar_t noexit;
295 extern cvar_t nomonsters;
296 extern cvar_t pausable;
297 extern cvar_t pr_checkextension;
298 extern cvar_t samelevel;
299 extern cvar_t saved1;
300 extern cvar_t saved2;
301 extern cvar_t saved3;
302 extern cvar_t saved4;
303 extern cvar_t savedgamecfg;
304 extern cvar_t scratch1;
305 extern cvar_t scratch2;
306 extern cvar_t scratch3;
307 extern cvar_t scratch4;
308 extern cvar_t skill;
309 extern cvar_t slowmo;
310 extern cvar_t sv_accelerate;
311 extern cvar_t sv_aim;
312 extern cvar_t sv_airaccel_qw;
313 extern cvar_t sv_airaccel_sideways_friction;
314 extern cvar_t sv_airaccelerate;
315 extern cvar_t sv_allowdownloads;
316 extern cvar_t sv_allowdownloads_archive;
317 extern cvar_t sv_allowdownloads_config;
318 extern cvar_t sv_allowdownloads_dlcache;
319 extern cvar_t sv_allowdownloads_inarchive;
320 extern cvar_t sv_areagrid_mingridsize;
321 extern cvar_t sv_checkforpacketsduringsleep;
322 extern cvar_t sv_clmovement_enable;
323 extern cvar_t sv_clmovement_minping;
324 extern cvar_t sv_clmovement_minping_disabletime;
325 extern cvar_t sv_clmovement_waitforinput;
326 extern cvar_t sv_cullentities_nevercullbmodels;
327 extern cvar_t sv_cullentities_pvs;
328 extern cvar_t sv_cullentities_stats;
329 extern cvar_t sv_cullentities_trace;
330 extern cvar_t sv_cullentities_trace_delay;
331 extern cvar_t sv_cullentities_trace_enlarge;
332 extern cvar_t sv_cullentities_trace_prediction;
333 extern cvar_t sv_cullentities_trace_samples;
334 extern cvar_t sv_cullentities_trace_samples_extra;
335 extern cvar_t sv_debugmove;
336 extern cvar_t sv_echobprint;
337 extern cvar_t sv_edgefriction;
338 extern cvar_t sv_entpatch;
339 extern cvar_t sv_fixedframeratesingleplayer;
340 extern cvar_t sv_freezenonclients;
341 extern cvar_t sv_friction;
342 extern cvar_t sv_gameplayfix_blowupfallenzombies;
343 extern cvar_t sv_gameplayfix_droptofloorstartsolid;
344 extern cvar_t sv_gameplayfix_findradiusdistancetobox;
345 extern cvar_t sv_gameplayfix_grenadebouncedownslopes;
346 extern cvar_t sv_gameplayfix_noairborncorpse;
347 extern cvar_t sv_gameplayfix_qwplayerphysics;
348 extern cvar_t sv_gameplayfix_setmodelrealbox;
349 extern cvar_t sv_gameplayfix_stepdown;
350 extern cvar_t sv_gameplayfix_stepwhilejumping;
351 extern cvar_t sv_gameplayfix_swiminbmodels;
352 extern cvar_t sv_gameplayfix_upwardvelocityclearsongroundflag;
353 extern cvar_t sv_gravity;
354 extern cvar_t sv_idealpitchscale;
355 extern cvar_t sv_jumpstep;
356 extern cvar_t sv_jumpvelocity;
357 extern cvar_t sv_maxairspeed;
358 extern cvar_t sv_maxrate;
359 extern cvar_t sv_maxspeed;
360 extern cvar_t sv_maxvelocity;
361 extern cvar_t sv_newflymove;
362 extern cvar_t sv_nostep;
363 extern cvar_t sv_playerphysicsqc;
364 extern cvar_t sv_progs;
365 extern cvar_t sv_protocolname;
366 extern cvar_t sv_random_seed;
367 extern cvar_t sv_ratelimitlocalplayer;
368 extern cvar_t sv_sound_land;
369 extern cvar_t sv_sound_watersplash;
370 extern cvar_t sv_stepheight;
371 extern cvar_t sv_stopspeed;
372 extern cvar_t sv_wallfriction;
373 extern cvar_t sv_wateraccelerate;
374 extern cvar_t sv_waterfriction;
375 extern cvar_t sys_ticrate;
376 extern cvar_t teamplay;
377 extern cvar_t temp1;
378 extern cvar_t timelimit;
379
380 extern mempool_t *sv_mempool;
381
382 // persistant server info
383 extern server_static_t svs;
384 // local server
385 extern server_t sv;
386
387 extern client_t *host_client;
388
389 //===========================================================
390
391 void SV_Init (void);
392
393 void SV_StartParticle (vec3_t org, vec3_t dir, int color, int count);
394 void SV_StartEffect (vec3_t org, int modelindex, int startframe, int framecount, int framerate);
395 void SV_StartSound (prvm_edict_t *entity, int channel, const char *sample, int volume, float attenuation);
396
397 void SV_ConnectClient (int clientnum, netconn_t *netconnection);
398 void SV_DropClient (qboolean crash);
399
400 void SV_SendClientMessages (void);
401
402 void SV_ReadClientMessage(void);
403
404 // precachemode values:
405 // 0 = fail if not precached,
406 // 1 = warn if not found and precache if possible
407 // 2 = precache
408 int SV_ModelIndex(const char *s, int precachemode);
409 int SV_SoundIndex(const char *s, int precachemode);
410
411 int SV_ParticleEffectIndex(const char *name);
412
413 void SV_SetIdealPitch (void);
414
415 void SV_AddUpdates (void);
416
417 void SV_ClientThink (void);
418
419 void SV_ClientPrint(const char *msg);
420 void SV_ClientPrintf(const char *fmt, ...) DP_FUNC_PRINTF(1);
421 void SV_BroadcastPrint(const char *msg);
422 void SV_BroadcastPrintf(const char *fmt, ...) DP_FUNC_PRINTF(1);
423
424 void SV_Physics (void);
425 void SV_Physics_ClientMove (void);
426 void SV_Physics_ClientEntity (prvm_edict_t *ent);
427
428 qboolean SV_PlayerCheckGround (prvm_edict_t *ent);
429 qboolean SV_CheckBottom (prvm_edict_t *ent);
430 qboolean SV_movestep (prvm_edict_t *ent, vec3_t move, qboolean relink, qboolean noenemy, qboolean settrace);
431
432 // Needs to be called any time an entity changes origin, mins, maxs, or solid
433 // sets ent->v.absmin and ent->v.absmax
434 // if touchtriggers, calls prog functions for the intersected triggers
435 void SV_LinkEdict (prvm_edict_t *ent, qboolean touch_triggers);
436
437 // calculates hitsupercontentsmask for a generic qc entity
438 int SV_GenericHitSuperContentsMask(const prvm_edict_t *edict);
439 // traces a box move against worldmodel and all entities in the specified area
440 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);
441
442 #define SV_PointSuperContents(point) (SV_Move((point), vec3_origin, vec3_origin, (point), sv_gameplayfix_swiminbmodels.integer ? MOVE_NOMONSTERS : MOVE_WORLDONLY, NULL, 0).startsupercontents)
443
444 void SV_FlushBroadcastMessages(void);
445 void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t *msg, int *stats);
446
447 void SV_MoveToGoal (void);
448
449 void SV_ApplyClientMove (void);
450 void SV_SaveSpawnparms (void);
451 void SV_SpawnServer (const char *server);
452
453 void SV_CheckVelocity (prvm_edict_t *ent);
454
455 void SV_SetupVM(void);
456
457 void SV_VM_Begin(void);
458 void SV_VM_End(void);
459
460 #endif
461