2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
25 typedef struct server_static_s
27 /// number of svs.clients slots (updated by maxplayers command)
28 int maxclients, maxclients_next;
30 struct client_s *clients;
31 /// episode completion information
33 /// cleared when at SV_SpawnServer
34 qboolean changelevel_issued;
36 char serverinfo[MAX_SERVERINFO_STRING];
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;
47 float perf_acc_offset;
48 float perf_acc_offset_squared;
49 float perf_acc_offset_max;
50 int perf_acc_offset_samples;
53 unsigned char *csqc_progdata;
54 size_t csqc_progsize_deflated;
55 unsigned char *csqc_progdata_deflated;
58 //=============================================================================
60 typedef enum server_state_e {ss_loading, ss_active} server_state_t;
62 #define MAX_CONNECTFLOODADDRESSES 16
63 typedef struct server_connectfloodaddress_s
66 lhnetaddress_t address;
68 server_connectfloodaddress_t;
70 typedef struct server_s
72 /// false if only a net client
77 /// handle connections specially
80 /// one of the PROTOCOL_ values
81 protocolversion_t protocol;
87 // used by PF_checkclient
91 // crc of clientside progs at time of level start
92 int csqc_progcrc; // -1 = no progs
93 int csqc_progsize; // -1 = no progs
94 char csqc_progname[MAX_QPATH]; // copied from csqc_progname at level start
96 /// collision culling data
100 char name[64]; // %s followed by entrance name
101 // variants of map name
102 char worldmessage[40]; // map title (not related to filename)
103 char worldbasename[MAX_QPATH]; // %s
104 char worldname[MAX_QPATH]; // maps/%s.bsp
105 char worldnamenoextension[MAX_QPATH]; // maps/%s
106 struct model_s *worldmodel;
108 // LordHavoc: precaches are now MAX_QPATH rather than a pointer
109 // updated by SV_ModelIndex
110 char model_precache[MAX_MODELS][MAX_QPATH];
111 struct model_s *models[MAX_MODELS];
113 // LordHavoc: precaches are now MAX_QPATH rather than a pointer
114 // updated by SV_SoundIndex
115 char sound_precache[MAX_SOUNDS][MAX_QPATH];
116 char lightstyles[MAX_LIGHTSTYLES][64];
117 /// some actions are only valid during load
118 server_state_t state;
121 unsigned char datagram_buf[NET_MAXMESSAGE];
123 // copied to all clients at end of frame
124 sizebuf_t reliable_datagram;
125 unsigned char reliable_datagram_buf[NET_MAXMESSAGE];
128 /// LordHavoc: increased signon message buffer from 8192
129 unsigned char signon_buf[NET_MAXMESSAGE];
131 /// connection flood blocking
132 /// note this is in server_t rather than server_static_t so that it is
133 /// reset on each map command (such as New Game in singleplayer)
134 server_connectfloodaddress_t connectfloodaddresses[MAX_CONNECTFLOODADDRESSES];
136 #define SV_MAX_PARTICLEEFFECTNAME 256
137 qboolean particleeffectnamesloaded;
138 char particleeffectname[SV_MAX_PARTICLEEFFECTNAME][MAX_QPATH];
140 int writeentitiestoclient_stats_culled_pvs;
141 int writeentitiestoclient_stats_culled_trace;
142 int writeentitiestoclient_stats_visibleentities;
143 int writeentitiestoclient_stats_totalentities;
144 int writeentitiestoclient_cliententitynumber;
145 int writeentitiestoclient_clientnumber;
146 sizebuf_t *writeentitiestoclient_msg;
147 vec3_t writeentitiestoclient_eyes[MAX_CLIENTNETWORKEYES];
148 int writeentitiestoclient_numeyes;
149 int writeentitiestoclient_pvsbytes;
150 unsigned char writeentitiestoclient_pvs[MAX_MAP_LEAFS/8];
151 const entity_state_t *writeentitiestoclient_sendstates[MAX_EDICTS];
152 unsigned short writeentitiestoclient_csqcsendstates[MAX_EDICTS];
155 entity_state_t sendentities[MAX_EDICTS];
156 entity_state_t *sendentitiesindex[MAX_EDICTS];
158 int sententitiesmark;
159 int sententities[MAX_EDICTS];
160 int sententitiesconsideration[MAX_EDICTS];
162 /// legacy support for self.Version based csqc entity networking
163 unsigned char csqcentityversion[MAX_EDICTS]; // legacy
166 #define NUM_CSQCENTITIES_PER_FRAME 256
167 typedef struct csqcentityframedb_s
171 unsigned short entno[NUM_CSQCENTITIES_PER_FRAME];
172 int sendflags[NUM_CSQCENTITIES_PER_FRAME];
173 } csqcentityframedb_t;
175 // if defined this does ping smoothing, otherwise it does not
176 //#define NUM_PING_TIMES 16
178 #define NUM_SPAWN_PARMS 16
180 typedef struct client_s
182 /// false = empty client slot
184 /// false = don't do ClientDisconnect on drop
185 qboolean clientconnectcalled;
186 /// false = don't send datagrams
188 /// 1 = send svc_serverinfo and advance to 2, 2 doesn't send, then advances to 0 (allowing unlimited sending) when prespawn is received
191 /// requested rate in bytes per second
194 /// realtime this client connected
197 /// keepalive messages must be sent periodically during signon
198 double keepalivetime;
200 /// communications handle
201 netconn_t *netconnection;
204 signed char movement_count[NETGRAPH_PACKETS];
205 int movement_highestsequence_seen; // not the same as movesequence if prediction is off
208 /// intended motion calced from cmd
211 /// PRVM_EDICT_NUM(clientnum+1)
214 #ifdef NUM_PING_TIMES
215 float ping_times[NUM_PING_TIMES];
216 /// ping_times[num_pings%NUM_PING_TIMES]
219 /// LordHavoc: can be used for prediction or whatever...
222 /// this is used by sv_clmovement_minping code
223 double clmovement_disabletimeout;
224 /// this is used by sv_clmovement_inputtimeout code
225 float clmovement_inputtimeout;
227 /// spawn parms are carried from level to level
228 float spawn_parms[NUM_SPAWN_PARMS];
230 // properties that are sent across the network only when changed
231 char name[MAX_SCOREBOARDNAME], old_name[MAX_SCOREBOARDNAME];
232 int colors, old_colors;
233 int frags, old_frags;
234 char playermodel[MAX_QPATH], old_model[MAX_QPATH];
235 char playerskin[MAX_QPATH], old_skin[MAX_QPATH];
237 /// netaddress support
238 char netaddress[MAX_QPATH];
241 float visibletime[MAX_EDICTS];
243 // scope is whether an entity is currently being networked to this client
244 // sendflags is what properties have changed on the entity since the last
245 // update that was sent
247 unsigned char csqcentityscope[MAX_EDICTS];
248 unsigned int csqcentitysendflags[MAX_EDICTS];
250 #define NUM_CSQCENTITYDB_FRAMES 256
251 unsigned char csqcentityglobalhistory[MAX_EDICTS]; // set to 1 if the entity was ever csqc networked to the client, and never reset back to 0
252 csqcentityframedb_t csqcentityframehistory[NUM_CSQCENTITYDB_FRAMES];
253 int csqcentityframehistory_next;
254 int csqcentityframe_lastreset;
256 /// prevent animated names
259 /// latest received clc_ackframe (used to detect packet loss)
262 /// cache weaponmodel name lookups
263 char weaponmodel[MAX_QPATH];
264 int weaponmodelindex;
266 /// clientcamera (entity to use as camera)
269 entityframe_database_t *entitydatabase;
270 entityframe4_database_t *entitydatabase4;
271 entityframe5_database_t *entitydatabase5;
273 // delta compression of stats
274 unsigned char statsdeltabits[(MAX_CL_STATS+7)/8];
275 int stats[MAX_CL_STATS];
277 unsigned char unreliablemsg_data[NET_MAXMESSAGE];
278 sizebuf_t unreliablemsg;
279 int unreliablemsg_splitpoints;
280 int unreliablemsg_splitpoint[NET_MAXMESSAGE/16];
282 // information on an active download if any
283 qfile_t *download_file;
284 int download_expectedposition; ///< next position the client should ack
285 qboolean download_started;
286 char download_name[MAX_QPATH];
287 qboolean download_deflate;
290 qboolean fixangle_angles_set;
291 vec3_t fixangle_angles;
294 qfile_t *sv_demo_file;
296 // number of skipped entity frames
297 // if it exceeds a limit, an empty entity frame is sent
298 int num_skippedentityframes;
302 //=============================================================================
304 // edict->movetype values
305 #define MOVETYPE_NONE 0 ///< never moves
306 #define MOVETYPE_ANGLENOCLIP 1
307 #define MOVETYPE_ANGLECLIP 2
308 #define MOVETYPE_WALK 3 ///< gravity
309 #define MOVETYPE_STEP 4 ///< gravity, special edge handling
310 #define MOVETYPE_FLY 5
311 #define MOVETYPE_TOSS 6 ///< gravity
312 #define MOVETYPE_PUSH 7 ///< no clip to world, push and crush
313 #define MOVETYPE_NOCLIP 8
314 #define MOVETYPE_FLYMISSILE 9 ///< extra size to monsters
315 #define MOVETYPE_BOUNCE 10
316 #define MOVETYPE_BOUNCEMISSILE 11 ///< bounce w/o gravity
317 #define MOVETYPE_FOLLOW 12 ///< track movement of aiment
318 #define MOVETYPE_FAKEPUSH 13 ///< tenebrae's push that doesn't push
319 #define MOVETYPE_PHYSICS 32 ///< indicates this object is physics controlled
320 #define MOVETYPE_FLY_WORLDONLY 33 ///< like MOVETYPE_FLY, but uses MOVE_WORLDONLY for all its traces; objects of this movetype better be SOLID_NOT or SOLID_TRIGGER please, or else...
322 // edict->solid values
323 #define SOLID_NOT 0 ///< no interaction with other objects
324 #define SOLID_TRIGGER 1 ///< touch on edge, but not blocking
325 #define SOLID_BBOX 2 ///< touch on edge, block
326 #define SOLID_SLIDEBOX 3 ///< touch on edge, but not an onground
327 #define SOLID_BSP 4 ///< bsp clip, touch on edge, block
328 // LordHavoc: corpse code
329 #define SOLID_CORPSE 5 ///< same as SOLID_BBOX, except it behaves as SOLID_NOT against SOLID_SLIDEBOX objects (players/monsters)
330 // LordHavoc: physics
331 #define SOLID_PHYSICS_BOX 32 ///< physics object (mins, maxs, mass, origin, axis_forward, axis_left, axis_up, velocity, spinvelocity)
332 #define SOLID_PHYSICS_SPHERE 33 ///< physics object (mins, maxs, mass, origin, axis_forward, axis_left, axis_up, velocity, spinvelocity)
333 #define SOLID_PHYSICS_CAPSULE 34 ///< physics object (mins, maxs, mass, origin, axis_forward, axis_left, axis_up, velocity, spinvelocity)
334 #define SOLID_PHYSICS_TRIMESH 35 ///< physics object (mins, maxs, mass, origin, axis_forward, axis_left, axis_up, velocity, spinvelocity)
336 // edict->deadflag values
348 #define FL_CONVEYOR 4
350 #define FL_INWATER 16
351 #define FL_MONSTER 32
352 #define FL_GODMODE 64
353 #define FL_NOTARGET 128
355 #define FL_ONGROUND 512
356 #define FL_PARTIALGROUND 1024 ///< not all corners are valid
357 #define FL_WATERJUMP 2048 ///< player jumping out of water
358 #define FL_JUMPRELEASED 4096 ///< for jump debouncing
360 #define SPAWNFLAG_NOT_EASY 256
361 #define SPAWNFLAG_NOT_MEDIUM 512
362 #define SPAWNFLAG_NOT_HARD 1024
363 #define SPAWNFLAG_NOT_DEATHMATCH 2048
365 //============================================================================
368 extern cvar_t deathmatch;
369 extern cvar_t fraglimit;
370 extern cvar_t gamecfg;
371 extern cvar_t noexit;
372 extern cvar_t nomonsters;
373 extern cvar_t pausable;
374 extern cvar_t pr_checkextension;
375 extern cvar_t samelevel;
376 extern cvar_t saved1;
377 extern cvar_t saved2;
378 extern cvar_t saved3;
379 extern cvar_t saved4;
380 extern cvar_t savedgamecfg;
381 extern cvar_t scratch1;
382 extern cvar_t scratch2;
383 extern cvar_t scratch3;
384 extern cvar_t scratch4;
386 extern cvar_t slowmo;
387 extern cvar_t sv_accelerate;
388 extern cvar_t sv_aim;
389 extern cvar_t sv_airaccel_qw;
390 extern cvar_t sv_airaccel_sideways_friction;
391 extern cvar_t sv_airaccelerate;
392 extern cvar_t sv_airstopaccelerate;
393 extern cvar_t sv_airstrafeaccelerate;
394 extern cvar_t sv_maxairstrafespeed;
395 extern cvar_t sv_airstrafeaccel_qw;
396 extern cvar_t sv_aircontrol;
397 extern cvar_t sv_aircontrol_power;
398 extern cvar_t sv_aircontrol_penalty;
399 extern cvar_t sv_airspeedlimit_nonqw;
400 extern cvar_t sv_allowdownloads;
401 extern cvar_t sv_allowdownloads_archive;
402 extern cvar_t sv_allowdownloads_config;
403 extern cvar_t sv_allowdownloads_dlcache;
404 extern cvar_t sv_allowdownloads_inarchive;
405 extern cvar_t sv_areagrid_mingridsize;
406 extern cvar_t sv_checkforpacketsduringsleep;
407 extern cvar_t sv_clmovement_enable;
408 extern cvar_t sv_clmovement_minping;
409 extern cvar_t sv_clmovement_minping_disabletime;
410 extern cvar_t sv_clmovement_inputtimeout;
411 extern cvar_t sv_clmovement_maxnetfps;
412 extern cvar_t sv_cullentities_nevercullbmodels;
413 extern cvar_t sv_cullentities_pvs;
414 extern cvar_t sv_cullentities_stats;
415 extern cvar_t sv_cullentities_trace;
416 extern cvar_t sv_cullentities_trace_delay;
417 extern cvar_t sv_cullentities_trace_enlarge;
418 extern cvar_t sv_cullentities_trace_prediction;
419 extern cvar_t sv_cullentities_trace_samples;
420 extern cvar_t sv_cullentities_trace_samples_extra;
421 extern cvar_t sv_debugmove;
422 extern cvar_t sv_echobprint;
423 extern cvar_t sv_edgefriction;
424 extern cvar_t sv_entpatch;
425 extern cvar_t sv_fixedframeratesingleplayer;
426 extern cvar_t sv_freezenonclients;
427 extern cvar_t sv_friction;
428 extern cvar_t sv_gameplayfix_blowupfallenzombies;
429 extern cvar_t sv_gameplayfix_consistentplayerprethink;
430 extern cvar_t sv_gameplayfix_delayprojectiles;
431 extern cvar_t sv_gameplayfix_droptofloorstartsolid;
432 extern cvar_t sv_gameplayfix_droptofloorstartsolid_nudgetocorrect;
433 extern cvar_t sv_gameplayfix_easierwaterjump;
434 extern cvar_t sv_gameplayfix_findradiusdistancetobox;
435 extern cvar_t sv_gameplayfix_gravityunaffectedbyticrate;
436 extern cvar_t sv_gameplayfix_grenadebouncedownslopes;
437 extern cvar_t sv_gameplayfix_multiplethinksperframe;
438 extern cvar_t sv_gameplayfix_noairborncorpse;
439 extern cvar_t sv_gameplayfix_noairborncorpse_allowsuspendeditems;
440 extern cvar_t sv_gameplayfix_nudgeoutofsolid;
441 extern cvar_t sv_gameplayfix_nudgeoutofsolid_separation;
442 extern cvar_t sv_gameplayfix_q2airaccelerate;
443 extern cvar_t sv_gameplayfix_nogravityonground;
444 extern cvar_t sv_gameplayfix_setmodelrealbox;
445 extern cvar_t sv_gameplayfix_slidemoveprojectiles;
446 extern cvar_t sv_gameplayfix_stepdown;
447 extern cvar_t sv_gameplayfix_stepwhilejumping;
448 extern cvar_t sv_gameplayfix_stepmultipletimes;
449 extern cvar_t sv_gameplayfix_nostepmoveonsteepslopes;
450 extern cvar_t sv_gameplayfix_swiminbmodels;
451 extern cvar_t sv_gameplayfix_upwardvelocityclearsongroundflag;
452 extern cvar_t sv_gameplayfix_downtracesupportsongroundflag;
453 extern cvar_t sv_gameplayfix_q1bsptracelinereportstexture;
454 extern cvar_t sv_gameplayfix_unstickplayers;
455 extern cvar_t sv_gameplayfix_unstickentities;
456 extern cvar_t sv_gravity;
457 extern cvar_t sv_idealpitchscale;
458 extern cvar_t sv_jumpstep;
459 extern cvar_t sv_jumpvelocity;
460 extern cvar_t sv_maxairspeed;
461 extern cvar_t sv_maxrate;
462 extern cvar_t sv_maxspeed;
463 extern cvar_t sv_maxvelocity;
464 extern cvar_t sv_nostep;
465 extern cvar_t sv_playerphysicsqc;
466 extern cvar_t sv_progs;
467 extern cvar_t sv_protocolname;
468 extern cvar_t sv_random_seed;
469 extern cvar_t sv_ratelimitlocalplayer;
470 extern cvar_t sv_sound_land;
471 extern cvar_t sv_sound_watersplash;
472 extern cvar_t sv_stepheight;
473 extern cvar_t sv_stopspeed;
474 extern cvar_t sv_wallfriction;
475 extern cvar_t sv_wateraccelerate;
476 extern cvar_t sv_waterfriction;
477 extern cvar_t sys_ticrate;
478 extern cvar_t teamplay;
480 extern cvar_t timelimit;
482 extern mempool_t *sv_mempool;
484 /// persistant server info
485 extern server_static_t svs;
489 extern client_t *host_client;
491 //===========================================================
495 void SV_StartParticle (vec3_t org, vec3_t dir, int color, int count);
496 void SV_StartEffect (vec3_t org, int modelindex, int startframe, int framecount, int framerate);
497 void SV_StartSound (prvm_edict_t *entity, int channel, const char *sample, int volume, float attenuation, qboolean reliable);
498 void SV_StartPointSound (vec3_t origin, const char *sample, int volume, float attenuation);
500 void SV_ConnectClient (int clientnum, netconn_t *netconnection);
501 void SV_DropClient (qboolean crash);
503 void SV_SendClientMessages (void);
505 void SV_ReadClientMessage(void);
507 // precachemode values:
508 // 0 = fail if not precached,
509 // 1 = warn if not found and precache if possible
511 int SV_ModelIndex(const char *s, int precachemode);
512 int SV_SoundIndex(const char *s, int precachemode);
514 int SV_ParticleEffectIndex(const char *name);
516 dp_model_t *SV_GetModelByIndex(int modelindex);
517 dp_model_t *SV_GetModelFromEdict(prvm_edict_t *ed);
519 void SV_SetIdealPitch (void);
521 void SV_AddUpdates (void);
523 void SV_ClientThink (void);
525 void SV_ClientPrint(const char *msg);
526 void SV_ClientPrintf(const char *fmt, ...) DP_FUNC_PRINTF(1);
527 void SV_BroadcastPrint(const char *msg);
528 void SV_BroadcastPrintf(const char *fmt, ...) DP_FUNC_PRINTF(1);
530 void SV_Physics (void);
531 void SV_Physics_ClientMove (void);
532 //void SV_Physics_ClientEntity (prvm_edict_t *ent);
534 qboolean SV_PlayerCheckGround (prvm_edict_t *ent);
535 qboolean SV_CheckBottom (prvm_edict_t *ent);
536 qboolean SV_movestep (prvm_edict_t *ent, vec3_t move, qboolean relink, qboolean noenemy, qboolean settrace);
538 /*! Needs to be called any time an entity changes origin, mins, maxs, or solid
539 * sets ent->v.absmin and ent->v.absmax
540 * call TouchAreaGrid as well to fire triggers that overlap the box
542 void SV_LinkEdict(prvm_edict_t *ent);
543 void SV_LinkEdict_TouchAreaGrid(prvm_edict_t *ent);
544 void SV_LinkEdict_TouchAreaGrid_Call(prvm_edict_t *touch, prvm_edict_t *ent); // if we detected a touch from another source
546 /*! move an entity that is stuck by small amounts in various directions to try to nudge it back into the collision hull
547 * returns true if it found a better place
549 qboolean SV_UnstickEntity (prvm_edict_t *ent);
551 /// calculates hitsupercontentsmask for a generic qc entity
552 int SV_GenericHitSuperContentsMask(const prvm_edict_t *edict);
553 /// traces a box move against worldmodel and all entities in the specified area
554 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);
555 trace_t SV_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_t *passedict, int hitsupercontentsmask);
556 trace_t SV_TracePoint(const vec3_t start, int type, prvm_edict_t *passedict, int hitsupercontentsmask);
558 qboolean SV_CanSeeBox(int numsamples, vec_t enlarge, vec3_t eye, vec3_t entboxmins, vec3_t entboxmaxs);
560 int SV_PointSuperContents(const vec3_t point);
562 void SV_FlushBroadcastMessages(void);
563 void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t *msg, int *stats);
565 void SV_MoveToGoal (void);
567 void SV_ApplyClientMove (void);
568 void SV_SaveSpawnparms (void);
569 void SV_SpawnServer (const char *server);
571 void SV_CheckVelocity (prvm_edict_t *ent);
573 void SV_SetupVM(void);
575 void SV_VM_Begin(void);
576 void SV_VM_End(void);
578 const char *Host_TimingReport(void); ///< for output in Host_Status_f
580 int SV_GetPitchSign(prvm_edict_t *ent);
581 void SV_GetEntityMatrix (prvm_edict_t *ent, matrix4x4_t *out, qboolean viewmatrix);