1 /* 2 Copyright (C) 1996-2001 Id Software, Inc. 3 Copyright (C) 2002-2009 John Fitzgibbons and others 4 Copyright (C) 2010-2014 QuakeSpasm developers 5 6 This program is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License 8 as published by the Free Software Foundation; either version 2 9 of the License, or (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 15 See the GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 21 */ 22 23 #ifndef _QUAKE_SERVER_H 24 #define _QUAKE_SERVER_H 25 26 // server.h 27 28 typedef struct 29 { 30 int maxclients; 31 int maxclientslimit; 32 struct client_s *clients; // [maxclients] 33 int serverflags; // episode completion information 34 qboolean changelevel_issued; // cleared when at SV_SpawnServer 35 } server_static_t; 36 37 //============================================================================= 38 39 typedef enum {ss_loading, ss_active} server_state_t; 40 41 typedef struct 42 { 43 qboolean active; // false if only a net client 44 45 qboolean paused; 46 qboolean loadgame; // handle connections specially 47 48 int lastcheck; // used by PF_checkclient 49 double lastchecktime; 50 51 qcvm_t qcvm; // Spike: entire qcvm state 52 53 char name[64]; // map name 54 char modelname[64]; // maps/<name>.bsp, for model_precache[0] 55 const char *model_precache[MAX_MODELS]; // NULL terminated 56 struct qmodel_s *models[MAX_MODELS]; 57 const char *sound_precache[MAX_SOUNDS]; // NULL terminated 58 const char *lightstyles[MAX_LIGHTSTYLES]; 59 server_state_t state; // some actions are only valid during load 60 61 sizebuf_t datagram; 62 byte datagram_buf[MAX_DATAGRAM]; 63 64 sizebuf_t reliable_datagram; // copied to all clients at end of frame 65 byte reliable_datagram_buf[MAX_DATAGRAM]; 66 67 sizebuf_t signon; 68 byte signon_buf[MAX_MSGLEN-2]; //johnfitz -- was 8192, now uses MAX_MSGLEN 69 70 unsigned protocol; //johnfitz 71 unsigned protocolflags; 72 73 sizebuf_t multicast; // selectively copied to clients by the multicast builtin 74 byte multicast_buf[MAX_DATAGRAM]; 75 76 const char *particle_precache[MAX_PARTICLETYPES]; // NULL terminated 77 78 entity_state_t *static_entities; 79 int num_statics; 80 int max_statics; 81 82 struct ambientsound_s 83 { 84 vec3_t origin; 85 unsigned int soundindex; 86 float volume; 87 float attenuation; 88 } *ambientsounds; 89 int num_ambients; 90 int max_ambients; 91 92 struct svcustomstat_s 93 { 94 int idx; 95 int type; 96 int fld; 97 eval_t *ptr; 98 } customstats[MAX_CL_STATS*2]; //strings or numeric... 99 size_t numcustomstats; 100 } server_t; 101 102 103 #define NUM_PING_TIMES 16 104 #define NUM_BASIC_SPAWN_PARMS 16 105 #define NUM_TOTAL_SPAWN_PARMS 64 106 107 typedef struct client_s 108 { 109 qboolean active; // false = client is free 110 qboolean spawned; // false = don't send datagrams (set when client acked the first entities) 111 qboolean dropasap; // has been told to go to another level 112 enum 113 { 114 PRESPAWN_DONE, 115 PRESPAWN_FLUSH=1, 116 // PRESPAWN_SERVERINFO, 117 PRESPAWN_MODELS, 118 PRESPAWN_SOUNDS, 119 PRESPAWN_PARTICLES, 120 PRESPAWN_BASELINES, 121 PRESPAWN_STATICS, 122 PRESPAWN_AMBIENTS, 123 PRESPAWN_SIGNONMSG, 124 } sendsignon; // only valid before spawned 125 int signonidx; 126 unsigned int signon_sounds; // 127 unsigned int signon_models; // 128 129 double last_message; // reliable messages must be sent 130 // periodically 131 132 struct qsocket_s *netconnection; // communications handle 133 134 usercmd_t cmd; // movement 135 vec3_t wishdir; // intended motion calced from cmd 136 137 sizebuf_t message; // can be added to at any time, 138 // copied and clear once per frame 139 byte msgbuf[MAX_MSGLEN]; 140 edict_t *edict; // EDICT_NUM(clientnum+1) 141 char name[32]; // for printing to other people 142 int colors; 143 144 float ping_times[NUM_PING_TIMES]; 145 int num_pings; // ping_times[num_pings%NUM_PING_TIMES] 146 147 // spawn parms are carried from level to level 148 float spawn_parms[NUM_TOTAL_SPAWN_PARMS]; 149 150 // client known data for deltas 151 int old_frags; 152 153 sizebuf_t datagram; 154 byte datagram_buf[MAX_DATAGRAM]; 155 156 unsigned int limit_entities; //vanilla is 600 157 unsigned int limit_unreliable; //max allowed size for unreliables 158 unsigned int limit_reliable; //max (total) size of a reliable message. 159 unsigned int limit_models; // 160 unsigned int limit_sounds; // 161 qboolean pextknown; 162 unsigned int protocol_pext1; 163 unsigned int protocol_pext2; 164 unsigned int resendstatsnum[MAX_CL_STATS/32]; //the stats which need to be resent. 165 unsigned int resendstatsstr[MAX_CL_STATS/32]; //the stats which need to be resent. 166 int oldstats_i[MAX_CL_STATS]; //previous values of stats. if these differ from the current values, reflag resendstats. 167 float oldstats_f[MAX_CL_STATS]; //previous values of stats. if these differ from the current values, reflag resendstats. 168 char *oldstats_s[MAX_CL_STATS]; 169 struct entity_num_state_s{ 170 unsigned int num; //ascending order, there can be gaps. 171 entity_state_t state; 172 } *previousentities; 173 size_t numpreviousentities; 174 size_t maxpreviousentities; 175 unsigned int snapshotresume; 176 unsigned int *pendingentities_bits; //UF_ flags for each entity 177 size_t numpendingentities; //realloc if too small 178 #define SENDFLAG_PRESENT 0x80000000u //tracks that we previously sent one of these ents (resulting in a remove if the ent gets remove()d). 179 #define SENDFLAG_REMOVE 0x40000000u //for packetloss to signal that we need to resend a remove. 180 #define SENDFLAG_USABLE 0x00ffffffu //SendFlags bits that the qc is actually able to use (don't get confused if the mod uses SendFlags=-1). 181 struct deltaframe_s 182 { //quick overview of how this stuff actually works: 183 //when the server notices a gap in the ack sequence, we walk through the dropped frames and reflag everything that was dropped. 184 //if the server isn't tracking enough frames, then we just treat those as dropped; 185 //small note: when an entity is new, it re-flags itself as new for the next packet too, this reduces the immediate impact of packetloss on new entities. 186 //reflagged state includes stats updates, entity updates, and entity removes. 187 int sequence; //to see if its stale 188 float timestamp; 189 unsigned int resendstatsnum[MAX_CL_STATS/32]; 190 unsigned int resendstatsstr[MAX_CL_STATS/32]; 191 struct 192 { 193 unsigned int num; 194 unsigned int ebits; 195 unsigned int csqcbits; 196 } *ents; 197 int numents; //doesn't contain an entry for every entity, just ones that were sent this frame. no 0 bits 198 int maxents; 199 } *frames; 200 size_t numframes; //preallocated power-of-two 201 int lastacksequence; 202 int lastmovemessage; 203 double lastmovetime; 204 qboolean knowntoqc; // putclientinserver was called 205 } client_t; 206 207 208 //============================================================================= 209 210 // edict->movetype values 211 #define MOVETYPE_NONE 0 // never moves 212 #define MOVETYPE_ANGLENOCLIP 1 213 #define MOVETYPE_ANGLECLIP 2 214 #define MOVETYPE_WALK 3 // gravity 215 #define MOVETYPE_STEP 4 // gravity, special edge handling 216 #define MOVETYPE_FLY 5 217 #define MOVETYPE_TOSS 6 // gravity 218 #define MOVETYPE_PUSH 7 // no clip to world, push and crush 219 #define MOVETYPE_NOCLIP 8 220 #define MOVETYPE_FLYMISSILE 9 // extra size to monsters 221 #define MOVETYPE_BOUNCE 10 222 #define MOVETYPE_GIB 11 // 2021 rerelease gibs 223 224 // edict->solid values 225 #define SOLID_NOT 0 // no interaction with other objects 226 #define SOLID_TRIGGER 1 // touch on edge, but not blocking 227 #define SOLID_BBOX 2 // touch on edge, block 228 #define SOLID_SLIDEBOX 3 // touch on edge, but not an onground 229 #define SOLID_BSP 4 // bsp clip, touch on edge, block 230 231 // edict->deadflag values 232 #define DEAD_NO 0 233 #define DEAD_DYING 1 234 #define DEAD_DEAD 2 235 236 #define DAMAGE_NO 0 237 #define DAMAGE_YES 1 238 #define DAMAGE_AIM 2 239 240 // edict->flags 241 #define FL_FLY 1 242 #define FL_SWIM 2 243 //#define FL_GLIMPSE 4 244 #define FL_CONVEYOR 4 245 #define FL_CLIENT 8 246 #define FL_INWATER 16 247 #define FL_MONSTER 32 248 #define FL_GODMODE 64 249 #define FL_NOTARGET 128 250 #define FL_ITEM 256 251 #define FL_ONGROUND 512 252 #define FL_PARTIALGROUND 1024 // not all corners are valid 253 #define FL_WATERJUMP 2048 // player jumping out of water 254 #define FL_JUMPRELEASED 4096 // for jump debouncing 255 256 // entity effects 257 258 #define EF_BRIGHTFIELD 1 259 #define EF_MUZZLEFLASH 2 260 #define EF_BRIGHTLIGHT 4 261 #define EF_DIMLIGHT 8 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 #define MSG_BROADCAST 0 // unreliable to all 269 #define MSG_ONE 1 // reliable to one (msg_entity) 270 #define MSG_ALL 2 // reliable to all 271 #define MSG_INIT 3 // write to the init string 272 #define MSG_EXT_MULTICAST 4 // temporary buffer that can be splurged more reliably / with more control. 273 #define MSG_EXT_ENTITY 5 // for csqc networking. we don't actually support this. I'm just defining it for completeness. 274 275 //============================================================================ 276 277 extern cvar_t teamplay; 278 extern cvar_t skill; 279 extern cvar_t deathmatch; 280 extern cvar_t coop; 281 extern cvar_t fraglimit; 282 extern cvar_t timelimit; 283 284 extern server_static_t svs; // persistant server info 285 extern server_t sv; // local server 286 287 extern client_t *host_client; 288 289 extern edict_t *sv_player; 290 291 //=========================================================== 292 293 void SV_Init (void); 294 295 void SV_StartParticle (vec3_t org, vec3_t dir, int color, int count); 296 void SV_StartSound (edict_t *entity, float *origin, int channel, 297 const char *sample, int volume, float attenuation); 298 299 void SV_DropClient (qboolean crash); 300 301 void SVFTE_Ack(client_t *client, int sequence); 302 void SVFTE_DestroyFrames(client_t *client); 303 void SV_BuildEntityState(edict_t *ent, entity_state_t *state); 304 void SV_SendClientMessages (void); 305 void SV_ClearDatagram (void); 306 307 int SV_ModelIndex (const char *name); 308 309 void SV_SetIdealPitch (void); 310 311 void SV_AddUpdates (void); 312 313 void SV_ClientThink (void); 314 void SV_AddClientToServer (struct qsocket_s *ret); 315 316 void SV_ClientPrintf (const char *fmt, ...) FUNC_PRINTF(1,2); 317 void SV_BroadcastPrintf (const char *fmt, ...) FUNC_PRINTF(1,2); 318 319 void SV_Physics (void); 320 321 qboolean SV_CheckBottom (edict_t *ent); 322 qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink); 323 324 void SV_WriteClientdataToMessage (client_t *client, sizebuf_t *msg); 325 326 void SV_MoveToGoal (void); 327 328 void SV_ConnectClient (int clientnum); //called from the netcode to add new clients. also called from pr_ext to spawn new botclients. 329 void SV_CheckForNewClients (void); 330 void SV_RunClients (void); 331 void SV_SaveSpawnparms (); 332 void SV_SpawnServer (const char *server); 333 334 #endif /* _QUAKE_SERVER_H */ 335 336