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;
57 // independent server thread (when running client)
58 qboolean threaded; // true if server is running on separate thread
59 qboolean volatile threadstop;
64 //=============================================================================
66 typedef enum server_state_e {ss_loading, ss_active} server_state_t;
68 #define MAX_CONNECTFLOODADDRESSES 16
69 typedef struct server_connectfloodaddress_s
72 lhnetaddress_t address;
74 server_connectfloodaddress_t;
76 typedef struct server_s
78 /// false if only a net client
83 /// handle connections specially
86 /// one of the PROTOCOL_ values
87 protocolversion_t protocol;
93 // used by PF_checkclient
97 // crc of clientside progs at time of level start
98 int csqc_progcrc; // -1 = no progs
99 int csqc_progsize; // -1 = no progs
100 char csqc_progname[MAX_QPATH]; // copied from csqc_progname at level start
102 /// collision culling data
106 char name[64]; // %s followed by entrance name
107 // variants of map name
108 char worldmessage[40]; // map title (not related to filename)
109 char worldbasename[MAX_QPATH]; // %s
110 char worldname[MAX_QPATH]; // maps/%s.bsp
111 char worldnamenoextension[MAX_QPATH]; // maps/%s
112 struct model_s *worldmodel;
114 // LordHavoc: precaches are now MAX_QPATH rather than a pointer
115 // updated by SV_ModelIndex
116 char model_precache[MAX_MODELS][MAX_QPATH];
117 struct model_s *models[MAX_MODELS];
119 // LordHavoc: precaches are now MAX_QPATH rather than a pointer
120 // updated by SV_SoundIndex
121 char sound_precache[MAX_SOUNDS][MAX_QPATH];
122 char lightstyles[MAX_LIGHTSTYLES][64];
123 /// some actions are only valid during load
124 server_state_t state;
127 unsigned char datagram_buf[NET_MAXMESSAGE];
129 // copied to all clients at end of frame
130 sizebuf_t reliable_datagram;
131 unsigned char reliable_datagram_buf[NET_MAXMESSAGE];
134 /// LordHavoc: increased signon message buffer from 8192
135 unsigned char signon_buf[NET_MAXMESSAGE];
137 /// connection flood blocking
138 /// note this is in server_t rather than server_static_t so that it is
139 /// reset on each map command (such as New Game in singleplayer)
140 server_connectfloodaddress_t connectfloodaddresses[MAX_CONNECTFLOODADDRESSES];
142 #define SV_MAX_PARTICLEEFFECTNAME 256
143 qboolean particleeffectnamesloaded;
144 char particleeffectname[SV_MAX_PARTICLEEFFECTNAME][MAX_QPATH];
146 int writeentitiestoclient_stats_culled_pvs;
147 int writeentitiestoclient_stats_culled_trace;
148 int writeentitiestoclient_stats_visibleentities;
149 int writeentitiestoclient_stats_totalentities;
150 int writeentitiestoclient_cliententitynumber;
151 int writeentitiestoclient_clientnumber;
152 sizebuf_t *writeentitiestoclient_msg;
153 vec3_t writeentitiestoclient_eyes[MAX_CLIENTNETWORKEYES];
154 int writeentitiestoclient_numeyes;
155 int writeentitiestoclient_pvsbytes;
156 unsigned char writeentitiestoclient_pvs[MAX_MAP_LEAFS/8];
157 const entity_state_t *writeentitiestoclient_sendstates[MAX_EDICTS];
158 unsigned short writeentitiestoclient_csqcsendstates[MAX_EDICTS];
161 entity_state_t sendentities[MAX_EDICTS];
162 entity_state_t *sendentitiesindex[MAX_EDICTS];
164 int sententitiesmark;
165 int sententities[MAX_EDICTS];
166 int sententitiesconsideration[MAX_EDICTS];
168 /// legacy support for self.Version based csqc entity networking
169 unsigned char csqcentityversion[MAX_EDICTS]; // legacy
172 #define NUM_CSQCENTITIES_PER_FRAME 256
173 typedef struct csqcentityframedb_s
177 unsigned short entno[NUM_CSQCENTITIES_PER_FRAME];
178 int sendflags[NUM_CSQCENTITIES_PER_FRAME];
179 } csqcentityframedb_t;
181 // if defined this does ping smoothing, otherwise it does not
182 //#define NUM_PING_TIMES 16
184 #define NUM_SPAWN_PARMS 16
186 typedef struct client_s
188 /// false = empty client slot
190 /// false = don't do ClientDisconnect on drop
191 qboolean clientconnectcalled;
192 /// false = don't send datagrams
194 /// 1 = send svc_serverinfo and advance to 2, 2 doesn't send, then advances to 0 (allowing unlimited sending) when prespawn is received
197 /// requested rate in bytes per second
200 /// realtime this client connected
203 /// keepalive messages must be sent periodically during signon
204 double keepalivetime;
206 /// communications handle
207 netconn_t *netconnection;
210 signed char movement_count[NETGRAPH_PACKETS];
211 int movement_highestsequence_seen; // not the same as movesequence if prediction is off
214 /// intended motion calced from cmd
217 /// PRVM_EDICT_NUM(clientnum+1)
220 #ifdef NUM_PING_TIMES
221 float ping_times[NUM_PING_TIMES];
222 /// ping_times[num_pings%NUM_PING_TIMES]
225 /// LordHavoc: can be used for prediction or whatever...
228 /// this is used by sv_clmovement_minping code
229 double clmovement_disabletimeout;
230 /// this is used by sv_clmovement_inputtimeout code
231 float clmovement_inputtimeout;
233 /// spawn parms are carried from level to level
234 float spawn_parms[NUM_SPAWN_PARMS];
236 // properties that are sent across the network only when changed
237 char name[MAX_SCOREBOARDNAME], old_name[MAX_SCOREBOARDNAME];
238 int colors, old_colors;
239 int frags, old_frags;
240 char playermodel[MAX_QPATH], old_model[MAX_QPATH];
241 char playerskin[MAX_QPATH], old_skin[MAX_QPATH];
243 /// netaddress support
244 char netaddress[MAX_QPATH];
247 float visibletime[MAX_EDICTS];
249 // scope is whether an entity is currently being networked to this client
250 // sendflags is what properties have changed on the entity since the last
251 // update that was sent
253 unsigned char csqcentityscope[MAX_EDICTS];
254 unsigned int csqcentitysendflags[MAX_EDICTS];
256 #define NUM_CSQCENTITYDB_FRAMES 256
257 unsigned char csqcentityglobalhistory[MAX_EDICTS]; // set to 1 if the entity was ever csqc networked to the client, and never reset back to 0
258 csqcentityframedb_t csqcentityframehistory[NUM_CSQCENTITYDB_FRAMES];
259 int csqcentityframehistory_next;
260 int csqcentityframe_lastreset;
262 /// prevent animated names
265 /// latest received clc_ackframe (used to detect packet loss)
268 /// cache weaponmodel name lookups
269 char weaponmodel[MAX_QPATH];
270 int weaponmodelindex;
272 /// clientcamera (entity to use as camera)
275 entityframe_database_t *entitydatabase;
276 entityframe4_database_t *entitydatabase4;
277 entityframe5_database_t *entitydatabase5;
279 // delta compression of stats
280 unsigned char statsdeltabits[(MAX_CL_STATS+7)/8];
281 int stats[MAX_CL_STATS];
283 unsigned char unreliablemsg_data[NET_MAXMESSAGE];
284 sizebuf_t unreliablemsg;
285 int unreliablemsg_splitpoints;
286 int unreliablemsg_splitpoint[NET_MAXMESSAGE/16];
288 // information on an active download if any
289 qfile_t *download_file;
290 int download_expectedposition; ///< next position the client should ack
291 qboolean download_started;
292 char download_name[MAX_QPATH];
293 qboolean download_deflate;
296 qboolean fixangle_angles_set;
297 vec3_t fixangle_angles;
300 qfile_t *sv_demo_file;
302 // number of skipped entity frames
303 // if it exceeds a limit, an empty entity frame is sent
304 int num_skippedentityframes;
306 // last sent move sequence
307 // if the move sequence changed, an empty entity frame is sent
308 int lastmovesequence;
312 //=============================================================================
314 // edict->movetype values
315 #define MOVETYPE_NONE 0 ///< never moves
316 #define MOVETYPE_ANGLENOCLIP 1
317 #define MOVETYPE_ANGLECLIP 2
318 #define MOVETYPE_WALK 3 ///< gravity
319 #define MOVETYPE_STEP 4 ///< gravity, special edge handling
320 #define MOVETYPE_FLY 5
321 #define MOVETYPE_TOSS 6 ///< gravity
322 #define MOVETYPE_PUSH 7 ///< no clip to world, push and crush
323 #define MOVETYPE_NOCLIP 8
324 #define MOVETYPE_FLYMISSILE 9 ///< extra size to monsters
325 #define MOVETYPE_BOUNCE 10
326 #define MOVETYPE_BOUNCEMISSILE 11 ///< bounce w/o gravity
327 #define MOVETYPE_FOLLOW 12 ///< track movement of aiment
328 #define MOVETYPE_FAKEPUSH 13 ///< tenebrae's push that doesn't push
329 #define MOVETYPE_PHYSICS 32 ///< indicates this object is physics controlled
330 #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...
332 // edict->solid values
333 #define SOLID_NOT 0 ///< no interaction with other objects
334 #define SOLID_TRIGGER 1 ///< touch on edge, but not blocking
335 #define SOLID_BBOX 2 ///< touch on edge, block
336 #define SOLID_SLIDEBOX 3 ///< touch on edge, but not an onground
337 #define SOLID_BSP 4 ///< bsp clip, touch on edge, block
338 // LordHavoc: corpse code
339 #define SOLID_CORPSE 5 ///< same as SOLID_BBOX, except it behaves as SOLID_NOT against SOLID_SLIDEBOX objects (players/monsters)
340 // LordHavoc: physics
341 // VorteX: now these fields are deprecated, as geomtype is more flexible
342 #define SOLID_PHYSICS_BOX 32 ///< physics object (mins, maxs, mass, origin, axis_forward, axis_left, axis_up, velocity, spinvelocity)
343 #define SOLID_PHYSICS_SPHERE 33 ///< physics object (mins, maxs, mass, origin, axis_forward, axis_left, axis_up, velocity, spinvelocity)
344 #define SOLID_PHYSICS_CAPSULE 34 ///< physics object (mins, maxs, mass, origin, axis_forward, axis_left, axis_up, velocity, spinvelocity)
345 #define SOLID_PHYSICS_TRIMESH 35 ///< physics object (mins, maxs, mass, origin, axis_forward, axis_left, axis_up, velocity, spinvelocity)
346 #define SOLID_PHYSICS_CYLINDER 36 ///< physics object (mins, maxs, mass, origin, axis_forward, axis_left, axis_up, velocity, spinvelocity)
348 // edict->deadflag values
360 #define FL_CONVEYOR 4
362 #define FL_INWATER 16
363 #define FL_MONSTER 32
364 #define FL_GODMODE 64
365 #define FL_NOTARGET 128
367 #define FL_ONGROUND 512
368 #define FL_PARTIALGROUND 1024 ///< not all corners are valid
369 #define FL_WATERJUMP 2048 ///< player jumping out of water
370 #define FL_JUMPRELEASED 4096 ///< for jump debouncing
372 #define SPAWNFLAG_NOT_EASY 256
373 #define SPAWNFLAG_NOT_MEDIUM 512
374 #define SPAWNFLAG_NOT_HARD 1024
375 #define SPAWNFLAG_NOT_DEATHMATCH 2048
377 //============================================================================
380 extern cvar_t deathmatch;
381 extern cvar_t fraglimit;
382 extern cvar_t gamecfg;
383 extern cvar_t noexit;
384 extern cvar_t nomonsters;
385 extern cvar_t pausable;
386 extern cvar_t pr_checkextension;
387 extern cvar_t samelevel;
388 extern cvar_t saved1;
389 extern cvar_t saved2;
390 extern cvar_t saved3;
391 extern cvar_t saved4;
392 extern cvar_t savedgamecfg;
393 extern cvar_t scratch1;
394 extern cvar_t scratch2;
395 extern cvar_t scratch3;
396 extern cvar_t scratch4;
398 extern cvar_t slowmo;
399 extern cvar_t sv_accelerate;
400 extern cvar_t sv_aim;
401 extern cvar_t sv_airaccel_qw;
402 extern cvar_t sv_airaccel_sideways_friction;
403 extern cvar_t sv_airaccelerate;
404 extern cvar_t sv_airstopaccelerate;
405 extern cvar_t sv_airstrafeaccelerate;
406 extern cvar_t sv_maxairstrafespeed;
407 extern cvar_t sv_airstrafeaccel_qw;
408 extern cvar_t sv_aircontrol;
409 extern cvar_t sv_aircontrol_power;
410 extern cvar_t sv_aircontrol_penalty;
411 extern cvar_t sv_airspeedlimit_nonqw;
412 extern cvar_t sv_allowdownloads;
413 extern cvar_t sv_allowdownloads_archive;
414 extern cvar_t sv_allowdownloads_config;
415 extern cvar_t sv_allowdownloads_dlcache;
416 extern cvar_t sv_allowdownloads_inarchive;
417 extern cvar_t sv_areagrid_mingridsize;
418 extern cvar_t sv_checkforpacketsduringsleep;
419 extern cvar_t sv_clmovement_enable;
420 extern cvar_t sv_clmovement_minping;
421 extern cvar_t sv_clmovement_minping_disabletime;
422 extern cvar_t sv_clmovement_inputtimeout;
423 extern cvar_t sv_clmovement_maxnetfps;
424 extern cvar_t sv_cullentities_nevercullbmodels;
425 extern cvar_t sv_cullentities_pvs;
426 extern cvar_t sv_cullentities_stats;
427 extern cvar_t sv_cullentities_trace;
428 extern cvar_t sv_cullentities_trace_delay;
429 extern cvar_t sv_cullentities_trace_enlarge;
430 extern cvar_t sv_cullentities_trace_prediction;
431 extern cvar_t sv_cullentities_trace_samples;
432 extern cvar_t sv_cullentities_trace_samples_extra;
433 extern cvar_t sv_debugmove;
434 extern cvar_t sv_echobprint;
435 extern cvar_t sv_edgefriction;
436 extern cvar_t sv_entpatch;
437 extern cvar_t sv_fixedframeratesingleplayer;
438 extern cvar_t sv_freezenonclients;
439 extern cvar_t sv_friction;
440 extern cvar_t sv_gameplayfix_blowupfallenzombies;
441 extern cvar_t sv_gameplayfix_consistentplayerprethink;
442 extern cvar_t sv_gameplayfix_delayprojectiles;
443 extern cvar_t sv_gameplayfix_droptofloorstartsolid;
444 extern cvar_t sv_gameplayfix_droptofloorstartsolid_nudgetocorrect;
445 extern cvar_t sv_gameplayfix_easierwaterjump;
446 extern cvar_t sv_gameplayfix_findradiusdistancetobox;
447 extern cvar_t sv_gameplayfix_gravityunaffectedbyticrate;
448 extern cvar_t sv_gameplayfix_grenadebouncedownslopes;
449 extern cvar_t sv_gameplayfix_multiplethinksperframe;
450 extern cvar_t sv_gameplayfix_noairborncorpse;
451 extern cvar_t sv_gameplayfix_noairborncorpse_allowsuspendeditems;
452 extern cvar_t sv_gameplayfix_nudgeoutofsolid;
453 extern cvar_t sv_gameplayfix_nudgeoutofsolid_separation;
454 extern cvar_t sv_gameplayfix_q2airaccelerate;
455 extern cvar_t sv_gameplayfix_nogravityonground;
456 extern cvar_t sv_gameplayfix_setmodelrealbox;
457 extern cvar_t sv_gameplayfix_slidemoveprojectiles;
458 extern cvar_t sv_gameplayfix_stepdown;
459 extern cvar_t sv_gameplayfix_stepwhilejumping;
460 extern cvar_t sv_gameplayfix_stepmultipletimes;
461 extern cvar_t sv_gameplayfix_nostepmoveonsteepslopes;
462 extern cvar_t sv_gameplayfix_swiminbmodels;
463 extern cvar_t sv_gameplayfix_upwardvelocityclearsongroundflag;
464 extern cvar_t sv_gameplayfix_downtracesupportsongroundflag;
465 extern cvar_t sv_gameplayfix_q1bsptracelinereportstexture;
466 extern cvar_t sv_gameplayfix_unstickplayers;
467 extern cvar_t sv_gameplayfix_unstickentities;
468 extern cvar_t sv_gameplayfix_fixedcheckwatertransition;
469 extern cvar_t sv_gravity;
470 extern cvar_t sv_idealpitchscale;
471 extern cvar_t sv_jumpstep;
472 extern cvar_t sv_jumpvelocity;
473 extern cvar_t sv_maxairspeed;
474 extern cvar_t sv_maxrate;
475 extern cvar_t sv_maxspeed;
476 extern cvar_t sv_maxvelocity;
477 extern cvar_t sv_nostep;
478 extern cvar_t sv_playerphysicsqc;
479 extern cvar_t sv_progs;
480 extern cvar_t sv_protocolname;
481 extern cvar_t sv_random_seed;
482 extern cvar_t sv_ratelimitlocalplayer;
483 extern cvar_t sv_sound_land;
484 extern cvar_t sv_sound_watersplash;
485 extern cvar_t sv_stepheight;
486 extern cvar_t sv_stopspeed;
487 extern cvar_t sv_wallfriction;
488 extern cvar_t sv_wateraccelerate;
489 extern cvar_t sv_waterfriction;
490 extern cvar_t sv_areadebug;
491 extern cvar_t sys_ticrate;
492 extern cvar_t teamplay;
494 extern cvar_t timelimit;
496 extern mempool_t *sv_mempool;
498 /// persistant server info
499 extern server_static_t svs;
503 extern client_t *host_client;
505 //===========================================================
509 void SV_StartParticle (vec3_t org, vec3_t dir, int color, int count);
510 void SV_StartEffect (vec3_t org, int modelindex, int startframe, int framecount, int framerate);
511 void SV_StartSound (prvm_edict_t *entity, int channel, const char *sample, int volume, float attenuation, qboolean reliable, float speed);
512 void SV_StartPointSound (vec3_t origin, const char *sample, int volume, float attenuation, float speed);
514 void SV_ConnectClient (int clientnum, netconn_t *netconnection);
515 void SV_DropClient (qboolean crash);
517 void SV_SendClientMessages(void);
519 void SV_ReadClientMessage(void);
521 // precachemode values:
522 // 0 = fail if not precached,
523 // 1 = warn if not found and precache if possible
525 int SV_ModelIndex(const char *s, int precachemode);
526 int SV_SoundIndex(const char *s, int precachemode);
528 int SV_ParticleEffectIndex(const char *name);
530 dp_model_t *SV_GetModelByIndex(int modelindex);
531 dp_model_t *SV_GetModelFromEdict(prvm_edict_t *ed);
533 void SV_SetIdealPitch (void);
535 void SV_AddUpdates (void);
537 void SV_ClientThink (void);
539 void SV_ClientPrint(const char *msg);
540 void SV_ClientPrintf(const char *fmt, ...) DP_FUNC_PRINTF(1);
541 void SV_BroadcastPrint(const char *msg);
542 void SV_BroadcastPrintf(const char *fmt, ...) DP_FUNC_PRINTF(1);
544 void SV_Physics (void);
545 void SV_Physics_ClientMove (void);
546 //void SV_Physics_ClientEntity (prvm_edict_t *ent);
548 qboolean SV_PlayerCheckGround (prvm_edict_t *ent);
549 qboolean SV_CheckBottom (prvm_edict_t *ent);
550 qboolean SV_movestep (prvm_edict_t *ent, vec3_t move, qboolean relink, qboolean noenemy, qboolean settrace);
552 /*! Needs to be called any time an entity changes origin, mins, maxs, or solid
553 * sets ent->v.absmin and ent->v.absmax
554 * call TouchAreaGrid as well to fire triggers that overlap the box
556 void SV_LinkEdict(prvm_edict_t *ent);
557 void SV_LinkEdict_TouchAreaGrid(prvm_edict_t *ent);
558 void SV_LinkEdict_TouchAreaGrid_Call(prvm_edict_t *touch, prvm_edict_t *ent); // if we detected a touch from another source
560 /*! move an entity that is stuck by small amounts in various directions to try to nudge it back into the collision hull
561 * returns true if it found a better place
563 qboolean SV_UnstickEntity (prvm_edict_t *ent);
565 /// calculates hitsupercontentsmask for a generic qc entity
566 int SV_GenericHitSuperContentsMask(const prvm_edict_t *edict);
567 /// traces a box move against worldmodel and all entities in the specified area
568 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);
569 trace_t SV_TraceLine(const vec3_t start, const vec3_t end, int type, prvm_edict_t *passedict, int hitsupercontentsmask);
570 trace_t SV_TracePoint(const vec3_t start, int type, prvm_edict_t *passedict, int hitsupercontentsmask);
571 int SV_EntitiesInBox(const vec3_t mins, const vec3_t maxs, int maxedicts, prvm_edict_t **resultedicts);
573 qboolean SV_CanSeeBox(int numsamples, vec_t enlarge, vec3_t eye, vec3_t entboxmins, vec3_t entboxmaxs);
575 int SV_PointSuperContents(const vec3_t point);
577 void SV_FlushBroadcastMessages(void);
578 void SV_WriteClientdataToMessage (client_t *client, prvm_edict_t *ent, sizebuf_t *msg, int *stats);
580 void VM_SV_MoveToGoal(prvm_prog_t *prog);
582 void SV_ApplyClientMove (void);
583 void SV_SaveSpawnparms (void);
584 void SV_SpawnServer (const char *server);
586 void SV_CheckVelocity (prvm_edict_t *ent);
588 void SV_SetupVM(void);
590 const char *Host_TimingReport(char *buf, size_t buflen); ///< for output in Host_Status_f
592 int SV_GetPitchSign(prvm_prog_t *prog, prvm_edict_t *ent);
593 void SV_GetEntityMatrix(prvm_prog_t *prog, prvm_edict_t *ent, matrix4x4_t *out, qboolean viewmatrix);
595 void SV_StartThread(void);
596 void SV_StopThread(void);
597 #define SV_LockThreadMutex() (void)(svs.threaded ? Thread_LockMutex(svs.threadmutex) : 0)
598 #define SV_UnlockThreadMutex() (void)(svs.threaded ? Thread_UnlockMutex(svs.threadmutex) : 0)
600 void VM_CustomStats_Clear(void);
601 void VM_SV_UpdateCustomStats(client_t *client, prvm_edict_t *ent, sizebuf_t *msg, int *stats);
602 void Host_Savegame_to(prvm_prog_t *prog, const char *name);
603 void SV_SendServerinfo(client_t *client);