server.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. // server.h
  16. #define QW_SERVER
  17. #define MAX_MASTERS 8 // max recipients for heartbeat packets
  18. #define MAX_SIGNON_BUFFERS 8
  19. typedef enum {
  20. ss_dead, // no map loaded
  21. ss_loading, // spawning level edicts
  22. ss_active // actively running
  23. } server_state_t;
  24. // some qc commands are only valid before the server has finished
  25. // initializing (precache commands, static sounds / objects, etc)
  26. typedef struct
  27. {
  28. qboolean active; // false when server is going down
  29. server_state_t state; // precache commands are only valid during load
  30. double time;
  31. int lastcheck; // used by PF_checkclient
  32. double lastchecktime; // for monster ai
  33. qboolean paused; // are we paused?
  34. //check player/eyes models for hacks
  35. unsigned model_player_checksum;
  36. unsigned eyes_player_checksum;
  37. char name[64]; // map name
  38. char modelname[MAX_QPATH]; // maps/<name>.bsp, for model_precache[0]
  39. struct model_s *worldmodel;
  40. char *model_precache[MAX_MODELS]; // NULL terminated
  41. char *sound_precache[MAX_SOUNDS]; // NULL terminated
  42. char *lightstyles[MAX_LIGHTSTYLES];
  43. struct model_s *models[MAX_MODELS];
  44. int num_edicts; // increases towards MAX_EDICTS
  45. edict_t *edicts; // can NOT be array indexed, because
  46. // edict_t is variable sized, but can
  47. // be used to reference the world ent
  48. byte *pvs, *phs; // fully expanded and decompressed
  49. // added to every client's unreliable buffer each frame, then cleared
  50. sizebuf_t datagram;
  51. byte datagram_buf[MAX_DATAGRAM];
  52. // added to every client's reliable buffer each frame, then cleared
  53. sizebuf_t reliable_datagram;
  54. byte reliable_datagram_buf[MAX_MSGLEN];
  55. // the multicast buffer is used to send a message to a set of clients
  56. sizebuf_t multicast;
  57. byte multicast_buf[MAX_MSGLEN];
  58. // the master buffer is used for building log packets
  59. sizebuf_t master;
  60. byte master_buf[MAX_DATAGRAM];
  61. // the signon buffer will be sent to each client as they connect
  62. // includes the entity baselines, the static entities, etc
  63. // large levels will have >MAX_DATAGRAM sized signons, so
  64. // multiple signon messages are kept
  65. sizebuf_t signon;
  66. int num_signon_buffers;
  67. int signon_buffer_size[MAX_SIGNON_BUFFERS];
  68. byte signon_buffers[MAX_SIGNON_BUFFERS][MAX_DATAGRAM];
  69. } server_t;
  70. #define NUM_SPAWN_PARMS 16
  71. typedef enum
  72. {
  73. cs_free, // can be reused for a new connection
  74. cs_zombie, // client has been disconnected, but don't reuse
  75. // connection for a couple seconds
  76. cs_connected, // has been assigned to a client_t, but not in game yet
  77. cs_spawned // client is fully in game
  78. } client_state_t;
  79. typedef struct
  80. {
  81. // received from client
  82. // reply
  83. double senttime;
  84. float ping_time;
  85. packet_entities_t entities;
  86. } client_frame_t;
  87. #define MAX_BACK_BUFFERS 4
  88. typedef struct client_s
  89. {
  90. client_state_t state;
  91. int spectator; // non-interactive
  92. qboolean sendinfo; // at end of frame, send info to all
  93. // this prevents malicious multiple broadcasts
  94. float lastnametime; // time of last name change
  95. int lastnamecount; // time of last name change
  96. unsigned checksum; // checksum for calcs
  97. qboolean drop; // lose this guy next opportunity
  98. int lossage; // loss percentage
  99. int userid; // identifying number
  100. char userinfo[MAX_INFO_STRING]; // infostring
  101. usercmd_t lastcmd; // for filling in big drops and partial predictions
  102. double localtime; // of last message
  103. int oldbuttons;
  104. float maxspeed; // localized maxspeed
  105. float entgravity; // localized ent gravity
  106. edict_t *edict; // EDICT_NUM(clientnum+1)
  107. char name[32]; // for printing to other people
  108. // extracted from userinfo
  109. int messagelevel; // for filtering printed messages
  110. // the datagram is written to after every frame, but only cleared
  111. // when it is sent out to the client. overflow is tolerated.
  112. sizebuf_t datagram;
  113. byte datagram_buf[MAX_DATAGRAM];
  114. // back buffers for client reliable data
  115. sizebuf_t backbuf;
  116. int num_backbuf;
  117. int backbuf_size[MAX_BACK_BUFFERS];
  118. byte backbuf_data[MAX_BACK_BUFFERS][MAX_MSGLEN];
  119. double connection_started; // or time of disconnect for zombies
  120. qboolean send_message; // set on frames a datagram arived on
  121. // spawn parms are carried from level to level
  122. float spawn_parms[NUM_SPAWN_PARMS];
  123. // client known data for deltas
  124. int old_frags;
  125. int stats[MAX_CL_STATS];
  126. client_frame_t frames[UPDATE_BACKUP]; // updates can be deltad from here
  127. FILE *download; // file being downloaded
  128. int downloadsize; // total bytes
  129. int downloadcount; // bytes sent
  130. int spec_track; // entnum of player tracking
  131. double whensaid[10]; // JACK: For floodprots
  132. int whensaidhead; // Head value for floodprots
  133. double lockedtill;
  134. qboolean upgradewarn; // did we warn him?
  135. FILE *upload;
  136. char uploadfn[MAX_QPATH];
  137. netadr_t snap_from;
  138. qboolean remote_snap;
  139. //===== NETWORK ============
  140. int chokecount;
  141. int delta_sequence; // -1 = no compression
  142. netchan_t netchan;
  143. } client_t;
  144. // a client can leave the server in one of four ways:
  145. // dropping properly by quiting or disconnecting
  146. // timing out if no valid messages are received for timeout.value seconds
  147. // getting kicked off by the server operator
  148. // a program error, like an overflowed reliable buffer
  149. //=============================================================================
  150. #define STATFRAMES 100
  151. typedef struct
  152. {
  153. double active;
  154. double idle;
  155. int count;
  156. int packets;
  157. double latched_active;
  158. double latched_idle;
  159. int latched_packets;
  160. } svstats_t;
  161. // MAX_CHALLENGES is made large to prevent a denial
  162. // of service attack that could cycle all of them
  163. // out before legitimate users connected
  164. #define MAX_CHALLENGES 1024
  165. typedef struct
  166. {
  167. netadr_t adr;
  168. int challenge;
  169. int time;
  170. } challenge_t;
  171. typedef struct
  172. {
  173. int spawncount; // number of servers spawned since start,
  174. // used to check late spawns
  175. client_t clients[MAX_CLIENTS];
  176. int serverflags; // episode completion information
  177. double last_heartbeat;
  178. int heartbeat_sequence;
  179. svstats_t stats;
  180. char info[MAX_SERVERINFO_STRING];
  181. // log messages are used so that fraglog processes can get stats
  182. int logsequence; // the message currently being filled
  183. double logtime; // time of last swap
  184. sizebuf_t log[2];
  185. byte log_buf[2][MAX_DATAGRAM];
  186. challenge_t challenges[MAX_CHALLENGES]; // to prevent invalid IPs from connecting
  187. } server_static_t;
  188. //=============================================================================
  189. // edict->movetype values
  190. #define MOVETYPE_NONE 0 // never moves
  191. #define MOVETYPE_ANGLENOCLIP 1
  192. #define MOVETYPE_ANGLECLIP 2
  193. #define MOVETYPE_WALK 3 // gravity
  194. #define MOVETYPE_STEP 4 // gravity, special edge handling
  195. #define MOVETYPE_FLY 5
  196. #define MOVETYPE_TOSS 6 // gravity
  197. #define MOVETYPE_PUSH 7 // no clip to world, push and crush
  198. #define MOVETYPE_NOCLIP 8
  199. #define MOVETYPE_FLYMISSILE 9 // extra size to monsters
  200. #define MOVETYPE_BOUNCE 10
  201. // edict->solid values
  202. #define SOLID_NOT 0 // no interaction with other objects
  203. #define SOLID_TRIGGER 1 // touch on edge, but not blocking
  204. #define SOLID_BBOX 2 // touch on edge, block
  205. #define SOLID_SLIDEBOX 3 // touch on edge, but not an onground
  206. #define SOLID_BSP 4 // bsp clip, touch on edge, block
  207. // edict->deadflag values
  208. #define DEAD_NO 0
  209. #define DEAD_DYING 1
  210. #define DEAD_DEAD 2
  211. #define DAMAGE_NO 0
  212. #define DAMAGE_YES 1
  213. #define DAMAGE_AIM 2
  214. // edict->flags
  215. #define FL_FLY 1
  216. #define FL_SWIM 2
  217. #define FL_GLIMPSE 4
  218. #define FL_CLIENT 8
  219. #define FL_INWATER 16
  220. #define FL_MONSTER 32
  221. #define FL_GODMODE 64
  222. #define FL_NOTARGET 128
  223. #define FL_ITEM 256
  224. #define FL_ONGROUND 512
  225. #define FL_PARTIALGROUND 1024 // not all corners are valid
  226. #define FL_WATERJUMP 2048 // player jumping out of water
  227. // entity effects
  228. //define EF_BRIGHTFIELD 1
  229. //define EF_MUZZLEFLASH 2
  230. #define EF_BRIGHTLIGHT 4
  231. #define EF_DIMLIGHT 8
  232. #define SPAWNFLAG_NOT_EASY 256
  233. #define SPAWNFLAG_NOT_MEDIUM 512
  234. #define SPAWNFLAG_NOT_HARD 1024
  235. #define SPAWNFLAG_NOT_DEATHMATCH 2048
  236. #define MULTICAST_ALL 0
  237. #define MULTICAST_PHS 1
  238. #define MULTICAST_PVS 2
  239. #define MULTICAST_ALL_R 3
  240. #define MULTICAST_PHS_R 4
  241. #define MULTICAST_PVS_R 5
  242. //============================================================================
  243. extern cvar_t sv_mintic, sv_maxtic;
  244. extern cvar_t sv_maxspeed;
  245. extern netadr_t master_adr[MAX_MASTERS]; // address of the master server
  246. extern cvar_t spawn;
  247. extern cvar_t teamplay;
  248. extern cvar_t deathmatch;
  249. extern cvar_t fraglimit;
  250. extern cvar_t timelimit;
  251. extern server_static_t svs; // persistant server info
  252. extern server_t sv; // local server
  253. extern client_t *host_client;
  254. extern edict_t *sv_player;
  255. extern char localmodels[MAX_MODELS][5]; // inline model names for precache
  256. extern char localinfo[MAX_LOCALINFO_STRING+1];
  257. extern int host_hunklevel;
  258. extern FILE *sv_logfile;
  259. extern FILE *sv_fraglogfile;
  260. //===========================================================
  261. //
  262. // sv_main.c
  263. //
  264. void SV_Shutdown (void);
  265. void SV_Frame (float time);
  266. void SV_FinalMessage (char *message);
  267. void SV_DropClient (client_t *drop);
  268. int SV_CalcPing (client_t *cl);
  269. void SV_FullClientUpdate (client_t *client, sizebuf_t *buf);
  270. int SV_ModelIndex (char *name);
  271. qboolean SV_CheckBottom (edict_t *ent);
  272. qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink);
  273. void SV_WriteClientdataToMessage (client_t *client, sizebuf_t *msg);
  274. void SV_MoveToGoal (void);
  275. void SV_SaveSpawnparms (void);
  276. void SV_Physics_Client (edict_t *ent);
  277. void SV_ExecuteUserCommand (char *s);
  278. void SV_InitOperatorCommands (void);
  279. void SV_SendServerinfo (client_t *client);
  280. void SV_ExtractFromUserinfo (client_t *cl);
  281. void Master_Heartbeat (void);
  282. void Master_Packet (void);
  283. //
  284. // sv_init.c
  285. //
  286. void SV_SpawnServer (char *server);
  287. void SV_FlushSignon (void);
  288. //
  289. // sv_phys.c
  290. //
  291. void SV_ProgStartFrame (void);
  292. void SV_Physics (void);
  293. void SV_CheckVelocity (edict_t *ent);
  294. void SV_AddGravity (edict_t *ent, float scale);
  295. qboolean SV_RunThink (edict_t *ent);
  296. void SV_Physics_Toss (edict_t *ent);
  297. void SV_RunNewmis (void);
  298. void SV_Impact (edict_t *e1, edict_t *e2);
  299. void SV_SetMoveVars(void);
  300. //
  301. // sv_send.c
  302. //
  303. void SV_SendClientMessages (void);
  304. void SV_Multicast (vec3_t origin, int to);
  305. void SV_StartSound (edict_t *entity, int channel, char *sample, int volume,
  306. float attenuation);
  307. void SV_ClientPrintf (client_t *cl, int level, char *fmt, ...);
  308. void SV_BroadcastPrintf (int level, char *fmt, ...);
  309. void SV_BroadcastCommand (char *fmt, ...);
  310. void SV_SendMessagesToAll (void);
  311. void SV_FindModelNumbers (void);
  312. //
  313. // sv_user.c
  314. //
  315. void SV_ExecuteClientMessage (client_t *cl);
  316. void SV_UserInit (void);
  317. void SV_TogglePause (const char *msg);
  318. //
  319. // svonly.c
  320. //
  321. typedef enum {RD_NONE, RD_CLIENT, RD_PACKET} redirect_t;
  322. void SV_BeginRedirect (redirect_t rd);
  323. void SV_EndRedirect (void);
  324. //
  325. // sv_ccmds.c
  326. //
  327. void SV_Status_f (void);
  328. //
  329. // sv_ents.c
  330. //
  331. void SV_WriteEntitiesToClient (client_t *client, sizebuf_t *msg);
  332. //
  333. // sv_nchan.c
  334. //
  335. void ClientReliableCheckBlock(client_t *cl, int maxsize);
  336. void ClientReliable_FinishWrite(client_t *cl);
  337. void ClientReliableWrite_Begin(client_t *cl, int c, int maxsize);
  338. void ClientReliableWrite_Angle(client_t *cl, float f);
  339. void ClientReliableWrite_Angle16(client_t *cl, float f);
  340. void ClientReliableWrite_Byte(client_t *cl, int c);
  341. void ClientReliableWrite_Char(client_t *cl, int c);
  342. void ClientReliableWrite_Float(client_t *cl, float f);
  343. void ClientReliableWrite_Coord(client_t *cl, float f);
  344. void ClientReliableWrite_Long(client_t *cl, int c);
  345. void ClientReliableWrite_Short(client_t *cl, int c);
  346. void ClientReliableWrite_String(client_t *cl, char *s);
  347. void ClientReliableWrite_SZ(client_t *cl, void *data, int len);