]> icculus.org git repositories - divverent/darkplaces.git/blob - server.h
699b11a1be96c85625c8a8348f74bee8ed903e68
[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 teamplay;
291 extern cvar_t skill;
292 extern cvar_t deathmatch;
293 extern cvar_t coop;
294 extern cvar_t fraglimit;
295 extern cvar_t timelimit;
296 extern cvar_t pausable;
297 extern cvar_t sv_maxvelocity;
298 extern cvar_t sv_gravity;
299 extern cvar_t sv_nostep;
300 extern cvar_t sv_friction;
301 extern cvar_t sv_waterfriction;
302 extern cvar_t sv_edgefriction;
303 extern cvar_t sv_stopspeed;
304 extern cvar_t sv_maxspeed;
305 extern cvar_t sv_maxairspeed;
306 extern cvar_t sv_accelerate;
307 extern cvar_t sv_airaccelerate;
308 extern cvar_t sv_wateraccelerate;
309 extern cvar_t sv_jumpvelocity;
310 extern cvar_t sv_airaccel_qw;
311 extern cvar_t sv_airaccel_sideways_friction;
312 extern cvar_t sv_idealpitchscale;
313 extern cvar_t sv_aim;
314 extern cvar_t sv_stepheight;
315 extern cvar_t sv_jumpstep;
316 extern cvar_t sv_public;
317 extern cvar_t sv_maxrate;
318
319 extern cvar_t sv_gameplayfix_grenadebouncedownslopes;
320 extern cvar_t sv_gameplayfix_noairborncorpse;
321 extern cvar_t sv_gameplayfix_stepdown;
322 extern cvar_t sv_gameplayfix_stepwhilejumping;
323 extern cvar_t sv_gameplayfix_swiminbmodels;
324 extern cvar_t sv_gameplayfix_setmodelrealbox;
325 extern cvar_t sv_gameplayfix_blowupfallenzombies;
326 extern cvar_t sv_gameplayfix_findradiusdistancetobox;
327 extern cvar_t sv_gameplayfix_qwplayerphysics;
328 extern cvar_t sv_gameplayfix_upwardvelocityclearsongroundflag;
329 extern cvar_t sv_gameplayfix_droptofloorstartsolid;
330
331 extern cvar_t sys_ticrate;
332 extern cvar_t sv_fixedframeratesingleplayer;
333
334 extern mempool_t *sv_mempool;
335
336 // persistant server info
337 extern server_static_t svs;
338 // local server
339 extern server_t sv;
340
341 extern client_t *host_client;
342
343 //===========================================================
344
345 void SV_Init (void);
346
347 void SV_StartParticle (vec3_t org, vec3_t dir, int color, int count);
348 void SV_StartEffect (vec3_t org, int modelindex, int startframe, int framecount, int framerate);
349 void SV_StartSound (prvm_edict_t *entity, int channel, const char *sample, int volume, float attenuation);
350
351 void SV_ConnectClient (int clientnum, netconn_t *netconnection);
352 void SV_DropClient (qboolean crash);
353
354 void SV_SendClientMessages (void);
355
356 void SV_ReadClientMessage(void);
357
358 // precachemode values:
359 // 0 = fail if not precached,
360 // 1 = warn if not found and precache if possible
361 // 2 = precache
362 int SV_ModelIndex(const char *s, int precachemode);
363 int SV_SoundIndex(const char *s, int precachemode);
364
365 int SV_ParticleEffectIndex(const char *name);
366
367 void SV_SetIdealPitch (void);
368
369 void SV_AddUpdates (void);
370
371 void SV_ClientThink (void);
372
373 void SV_ClientPrint(const char *msg);
374 void SV_ClientPrintf(const char *fmt, ...) DP_FUNC_PRINTF(1);
375 void SV_BroadcastPrint(const char *msg);
376 void SV_BroadcastPrintf(const char *fmt, ...) DP_FUNC_PRINTF(1);
377
378 void SV_Physics (void);
379 void SV_Physics_ClientMove (void);
380 void SV_Physics_ClientEntity (prvm_edict_t *ent);
381
382 qboolean SV_PlayerCheckGround (prvm_edict_t *ent);
383 qboolean SV_CheckBottom (prvm_edict_t *ent);
384 qboolean SV_movestep (prvm_edict_t *ent, vec3_t move, qboolean relink, qboolean noenemy, qboolean settrace);
385
386 // Needs to be called any time an entity changes origin, mins, maxs, or solid
387 // sets ent->v.absmin and ent->v.absmax
388 // if touchtriggers, calls prog functions for the intersected triggers
389 void SV_LinkEdict (prvm_edict_t *ent, qboolean touch_triggers);
390
391 // calculates hitsupercontentsmask for a generic qc entity
392 int SV_GenericHitSuperContentsMask(const prvm_edict_t *edict);
393 // traces a box move against worldmodel and all entities in the specified area
394 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);
395
396 #define SV_PointSuperContents(point) (SV_Move((point), vec3_origin, vec3_origin, (point), sv_gameplayfix_swiminbmodels.integer ? MOVE_NOMONSTERS : MOVE_WORLDONLY, NULL, 0).startsupercontents)
397
398 void SV_FlushBroadcastMessages(void);
399 void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t *msg, int *stats);
400
401 void SV_MoveToGoal (void);
402
403 void SV_ApplyClientMove (void);
404 void SV_SaveSpawnparms (void);
405 void SV_SpawnServer (const char *server);
406
407 void SV_CheckVelocity (prvm_edict_t *ent);
408
409 void SV_SetupVM(void);
410
411 void SV_VM_Begin(void);
412 void SV_VM_End(void);
413
414 #endif
415