]> icculus.org git repositories - divverent/darkplaces.git/blob - server.h
added generic collision functions Collision_ClipToGenericEntity, Collision_ClipToWorl...
[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         // PushMove sometimes has to move entities back from a failed move
95         // (dynamically resized)
96         prvm_edict_t **moved_edicts;
97         // some actions are only valid during load
98         server_state_t state;
99
100         sizebuf_t datagram;
101         unsigned char datagram_buf[NET_MAXMESSAGE];
102
103         // copied to all clients at end of frame
104         sizebuf_t reliable_datagram;
105         unsigned char reliable_datagram_buf[NET_MAXMESSAGE];
106
107         sizebuf_t signon;
108         // LordHavoc: increased signon message buffer from 8192
109         unsigned char signon_buf[NET_MAXMESSAGE];
110
111         // connection flood blocking
112         // note this is in server_t rather than server_static_t so that it is
113         // reset on each map command (such as New Game in singleplayer)
114         server_connectfloodaddress_t connectfloodaddresses[MAX_CONNECTFLOODADDRESSES];
115 } server_t;
116
117 // if defined this does ping smoothing, otherwise it does not
118 //#define NUM_PING_TIMES 16
119
120 #define NUM_SPAWN_PARMS 16
121
122 typedef struct client_s
123 {
124         // false = empty client slot
125         qboolean active;
126         // false = don't do ClientDisconnect on drop
127         qboolean clientconnectcalled;
128         // false = don't send datagrams
129         qboolean spawned;
130
131         // requested rate in bytes per second
132         int rate;
133
134         // realtime this client connected
135         double connecttime;
136
137         // keepalive messages must be sent periodically during signon
138         double keepalivetime;
139
140         // communications handle
141         netconn_t *netconnection;
142
143         int movesequence;
144         // movement
145         usercmd_t cmd;
146         // intended motion calced from cmd
147         vec3_t wishdir;
148
149         // PRVM_EDICT_NUM(clientnum+1)
150         prvm_edict_t *edict;
151
152 #ifdef NUM_PING_TIMES
153         float ping_times[NUM_PING_TIMES];
154         // ping_times[num_pings%NUM_PING_TIMES]
155         int num_pings;
156 #endif
157         // LordHavoc: can be used for prediction or whatever...
158         float ping;
159
160         // this is used by sv_clmovement_minping code
161         double clmovement_disabletimeout;
162         // this is used by sv_clmvoement_waitforinput code
163         int clmovement_skipphysicsframes;
164
165 // spawn parms are carried from level to level
166         float spawn_parms[NUM_SPAWN_PARMS];
167
168         // properties that are sent across the network only when changed
169         char name[64], old_name[64];
170         int colors, old_colors;
171         int frags, old_frags;
172         char playermodel[MAX_QPATH], old_model[MAX_QPATH];
173         char playerskin[MAX_QPATH], old_skin[MAX_QPATH];
174
175         // visibility state
176         float visibletime[MAX_EDICTS];
177
178         // prevent animated names
179         float nametime;
180
181         // latest received clc_ackframe (used to detect packet loss)
182         int latestframenum;
183
184         // cache weaponmodel name lookups
185         char weaponmodel[MAX_QPATH];
186         int weaponmodelindex;
187
188         entityframe_database_t *entitydatabase;
189         entityframe4_database_t *entitydatabase4;
190         entityframe5_database_t *entitydatabase5;
191
192         // information on an active download if any
193         qfile_t *download_file;
194         int download_expectedposition; // next position the client should ack
195         qboolean download_started;
196         char download_name[MAX_QPATH];
197 } client_t;
198
199
200 //=============================================================================
201
202 // edict->movetype values
203 #define MOVETYPE_NONE                   0               // never moves
204 #define MOVETYPE_ANGLENOCLIP    1
205 #define MOVETYPE_ANGLECLIP              2
206 #define MOVETYPE_WALK                   3               // gravity
207 #define MOVETYPE_STEP                   4               // gravity, special edge handling
208 #define MOVETYPE_FLY                    5
209 #define MOVETYPE_TOSS                   6               // gravity
210 #define MOVETYPE_PUSH                   7               // no clip to world, push and crush
211 #define MOVETYPE_NOCLIP                 8
212 #define MOVETYPE_FLYMISSILE             9               // extra size to monsters
213 #define MOVETYPE_BOUNCE                 10
214 #define MOVETYPE_BOUNCEMISSILE  11              // bounce w/o gravity
215 #define MOVETYPE_FOLLOW                 12              // track movement of aiment
216 #define MOVETYPE_FAKEPUSH               13              // tenebrae's push that doesn't push
217
218 // edict->solid values
219 #define SOLID_NOT                               0               // no interaction with other objects
220 #define SOLID_TRIGGER                   1               // touch on edge, but not blocking
221 #define SOLID_BBOX                              2               // touch on edge, block
222 #define SOLID_SLIDEBOX                  3               // touch on edge, but not an onground
223 #define SOLID_BSP                               4               // bsp clip, touch on edge, block
224 // LordHavoc: corpse code
225 #define SOLID_CORPSE                    5               // same as SOLID_BBOX, except it behaves as SOLID_NOT against SOLID_SLIDEBOX objects (players/monsters)
226
227 // edict->deadflag values
228 #define DEAD_NO                                 0
229 #define DEAD_DYING                              1
230 #define DEAD_DEAD                               2
231
232 #define DAMAGE_NO                               0
233 #define DAMAGE_YES                              1
234 #define DAMAGE_AIM                              2
235
236 // edict->flags
237 #define FL_FLY                                  1
238 #define FL_SWIM                                 2
239 #define FL_CONVEYOR                             4
240 #define FL_CLIENT                               8
241 #define FL_INWATER                              16
242 #define FL_MONSTER                              32
243 #define FL_GODMODE                              64
244 #define FL_NOTARGET                             128
245 #define FL_ITEM                                 256
246 #define FL_ONGROUND                             512
247 #define FL_PARTIALGROUND                1024    // not all corners are valid
248 #define FL_WATERJUMP                    2048    // player jumping out of water
249 #define FL_JUMPRELEASED                 4096    // for jump debouncing
250
251 // entity effects
252
253 #define EF_BRIGHTFIELD                  1
254 #define EF_MUZZLEFLASH                  2
255 #define EF_BRIGHTLIGHT                  4
256 #define EF_DIMLIGHT                     8
257 // added EF_ effects:
258 #define EF_NODRAW                               16
259 #define EF_ADDITIVE                             32  // LordHavoc: Additive Rendering
260 #define EF_BLUE                                 64
261 #define EF_RED                                  128
262
263 #define SPAWNFLAG_NOT_EASY                      256
264 #define SPAWNFLAG_NOT_MEDIUM            512
265 #define SPAWNFLAG_NOT_HARD                      1024
266 #define SPAWNFLAG_NOT_DEATHMATCH        2048
267
268 //============================================================================
269
270 extern cvar_t teamplay;
271 extern cvar_t skill;
272 extern cvar_t deathmatch;
273 extern cvar_t coop;
274 extern cvar_t fraglimit;
275 extern cvar_t timelimit;
276 extern cvar_t pausable;
277 extern cvar_t sv_maxvelocity;
278 extern cvar_t sv_gravity;
279 extern cvar_t sv_nostep;
280 extern cvar_t sv_friction;
281 extern cvar_t sv_waterfriction;
282 extern cvar_t sv_edgefriction;
283 extern cvar_t sv_stopspeed;
284 extern cvar_t sv_maxspeed;
285 extern cvar_t sv_maxairspeed;
286 extern cvar_t sv_accelerate;
287 extern cvar_t sv_airaccelerate;
288 extern cvar_t sv_wateraccelerate;
289 extern cvar_t sv_idealpitchscale;
290 extern cvar_t sv_aim;
291 extern cvar_t sv_stepheight;
292 extern cvar_t sv_jumpstep;
293 extern cvar_t sv_public;
294 extern cvar_t sv_maxrate;
295
296 extern cvar_t sv_gameplayfix_grenadebouncedownslopes;
297 extern cvar_t sv_gameplayfix_noairborncorpse;
298 extern cvar_t sv_gameplayfix_stepdown;
299 extern cvar_t sv_gameplayfix_stepwhilejumping;
300 extern cvar_t sv_gameplayfix_swiminbmodels;
301 extern cvar_t sv_gameplayfix_setmodelrealbox;
302 extern cvar_t sv_gameplayfix_blowupfallenzombies;
303 extern cvar_t sv_gameplayfix_findradiusdistancetobox;
304 extern cvar_t sv_gameplayfix_qwplayerphysics;
305 extern cvar_t sv_gameplayfix_upwardvelocityclearsongroundflag;
306 extern cvar_t sv_gameplayfix_droptofloorstartsolid;
307
308 extern cvar_t sys_ticrate;
309 extern cvar_t sv_fixedframeratesingleplayer;
310
311 extern mempool_t *sv_mempool;
312
313 // persistant server info
314 extern server_static_t svs;
315 // local server
316 extern server_t sv;
317
318 extern client_t *host_client;
319
320 //===========================================================
321
322 void SV_Init (void);
323
324 void SV_StartParticle (vec3_t org, vec3_t dir, int color, int count);
325 void SV_StartEffect (vec3_t org, int modelindex, int startframe, int framecount, int framerate);
326 void SV_StartSound (prvm_edict_t *entity, int channel, const char *sample, int volume, float attenuation);
327
328 void SV_ConnectClient (int clientnum, netconn_t *netconnection);
329 void SV_DropClient (qboolean crash);
330
331 void SV_SendClientMessages (void);
332 void SV_ClearDatagram (void);
333
334 void SV_ReadClientMessage(void);
335
336 // precachemode values:
337 // 0 = fail if not precached,
338 // 1 = warn if not found and precache if possible
339 // 2 = precache
340 int SV_ModelIndex(const char *s, int precachemode);
341 int SV_SoundIndex(const char *s, int precachemode);
342
343 void SV_SetIdealPitch (void);
344
345 void SV_AddUpdates (void);
346
347 void SV_ClientThink (void);
348
349 void SV_ClientPrint(const char *msg);
350 void SV_ClientPrintf(const char *fmt, ...) DP_FUNC_PRINTF(1);
351 void SV_BroadcastPrint(const char *msg);
352 void SV_BroadcastPrintf(const char *fmt, ...) DP_FUNC_PRINTF(1);
353
354 void SV_Physics (void);
355 void SV_Physics_ClientEntity (prvm_edict_t *ent);
356
357 qboolean SV_PlayerCheckGround (prvm_edict_t *ent);
358 qboolean SV_CheckBottom (prvm_edict_t *ent);
359 qboolean SV_movestep (prvm_edict_t *ent, vec3_t move, qboolean relink);
360
361 // Needs to be called any time an entity changes origin, mins, maxs, or solid
362 // sets ent->v.absmin and ent->v.absmax
363 // if touchtriggers, calls prog functions for the intersected triggers
364 void SV_LinkEdict (prvm_edict_t *ent, qboolean touch_triggers);
365
366 // traces a box move against a single entity
367 // mins and maxs are relative
368 //
369 // if the entire move stays in a single solid brush, trace.allsolid will be set
370 //
371 // if the starting point is in a solid, it will be allowed to move out to an
372 // open area, and trace.startsolid will be set
373 //
374 // type is one of the MOVE_ values such as MOVE_NOMONSTERS which skips box
375 // entities, only colliding with SOLID_BSP entities (doors, lifts)
376 //
377 // passedict is excluded from clipping checks
378 struct trace_s SV_Move_ClipToEntity(prvm_edict_t *ent, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int movetype, int hitsupercontents);
379
380 // traces a box move against worldmodel and all entities in the specified area
381 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);
382
383 #define SV_PointSuperContents(point) (SV_Move((point), vec3_origin, vec3_origin, (point), sv_gameplayfix_swiminbmodels.integer ? MOVE_NOMONSTERS : MOVE_WORLDONLY, NULL).startsupercontents)
384
385 void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t *msg, int *stats);
386
387 void SV_MoveToGoal (void);
388
389 void SV_ApplyClientMove (void);
390 void SV_SaveSpawnparms (void);
391 void SV_SpawnServer (const char *server);
392
393 void SV_CheckVelocity (prvm_edict_t *ent);
394
395 void SV_SetupVM(void);
396
397 void SV_VM_Begin(void);
398 void SV_VM_End(void);
399
400 #endif
401