1 /* 2 * hwsv/server.h 3 * $Id: server.h 5787 2017-01-03 22:22:34Z sezero $ 4 * 5 * Copyright (C) 1996-1997 Id Software, Inc. 6 * Copyright (C) 1997-1998 Raven Software Corp. 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or (at 11 * your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, but 14 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 * 17 * See the GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License along 20 * with this program; if not, write to the Free Software Foundation, Inc., 21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 */ 23 24 #ifndef __H2W_SERVER_H 25 #define __H2W_SERVER_H 26 27 #define QW_SERVER 28 29 #define MAX_MASTERS 8 // max recipients for heartbeat packets 30 31 #define MAX_SIGNON_BUFFERS 8 32 33 typedef enum 34 { 35 ss_dead, // no map loaded 36 ss_loading, // spawning level edicts 37 ss_active // actively running 38 } server_state_t; 39 40 // some qc commands are only valid before the server has finished 41 // initializing (precache commands, static sounds / objects, etc) 42 43 typedef struct 44 { 45 qboolean active; // false when server is going down 46 server_state_t state; // precache commands are only valid during load 47 48 double time; 49 50 int lastcheck; // used by PF_checkclient 51 double lastchecktime; // for monster ai 52 double next_PIV_time; // Last Player In View time 53 54 char name[64]; // map name 55 char midi_name[128]; // midi file name 56 byte cd_track; // cd track number 57 int current_skill; 58 59 char startspot[64]; 60 char modelname[MAX_QPATH]; // maps/<name>.bsp, for model_precache[0] 61 struct qmodel_s *worldmodel; 62 const char *model_precache[MAX_MODELS]; // NULL terminated 63 const char *sound_precache[MAX_SOUNDS]; // NULL terminated 64 const char *lightstyles[MAX_LIGHTSTYLES]; 65 struct qmodel_s *models[MAX_MODELS]; 66 67 struct EffectT Effects[MAX_EFFECTS]; 68 69 int num_edicts; // increases towards MAX_EDICTS 70 edict_t *edicts; // can NOT be array indexed, because 71 // edict_t is variable sized, but can 72 // be used to reference the world ent 73 74 byte *pvs, *phs; // fully expanded and decompressed 75 76 // added to every client's unreliable buffer each frame, then cleared 77 sizebuf_t datagram; 78 byte datagram_buf[MAX_DATAGRAM]; 79 80 // added to every client's reliable buffer each frame, then cleared 81 sizebuf_t reliable_datagram; 82 byte reliable_datagram_buf[MAX_MSGLEN]; 83 84 // the multicast buffer is used to send a message to a set of clients 85 sizebuf_t multicast; 86 byte multicast_buf[MAX_MSGLEN]; 87 88 // the master buffer is used for building log packets 89 sizebuf_t master; 90 byte master_buf[MAX_DATAGRAM]; 91 92 // the signon buffer will be sent to each client as they connect 93 // includes the entity baselines, the static entities, etc 94 // large levels will have >MAX_DATAGRAM sized signons, so 95 // multiple signon messages are kept 96 sizebuf_t signon; 97 int num_signon_buffers; 98 int signon_buffer_size[MAX_SIGNON_BUFFERS]; 99 byte signon_buffers[MAX_SIGNON_BUFFERS][MAX_DATAGRAM]; 100 } server_t; 101 102 103 #define NUM_SPAWN_PARMS 16 104 105 typedef enum 106 { 107 cs_free, // can be reused for a new connection 108 cs_zombie, // client has been disconnected, but don't reuse 109 // connection for a couple seconds 110 111 cs_connected, // has been assigned to a client_t, but not in game yet 112 cs_spawned // client is fully in game 113 } client_state_t; 114 115 typedef struct 116 { 117 // received from client 118 119 // reply 120 double senttime; 121 float ping_time; 122 packet_entities_t entities; 123 } client_frame_t; 124 125 typedef struct client_s 126 { 127 client_state_t state; 128 129 int protocol; 130 131 int spectator; // non-interactive 132 133 qboolean sendinfo; // at end of frame, send info to all 134 // this prevents malicious multiple broadcasts 135 qboolean portals; // They have portals mission pack installed 136 int userid; // identifying number 137 char userinfo[MAX_INFO_STRING]; // infostring 138 139 usercmd_t lastcmd; // for filling in big drops and partial predictions 140 double localtime; // of last message 141 int oldbuttons; 142 143 float maxspeed; // localized maxspeed 144 float entgravity; // localized ent gravity 145 146 edict_t *edict; // EDICT_NUM(clientnum+1) 147 char name[32]; // for printing to other people 148 // extracted from userinfo 149 int playerclass; 150 int siege_team; 151 int next_playerclass; 152 int messagelevel; // for filtering printed messages 153 154 // the datagram is written to after every frame, but only cleared 155 // when it is sent out to the client. overflow is tolerated. 156 sizebuf_t datagram; 157 byte datagram_buf[MAX_DATAGRAM]; 158 159 double connection_started; // or time of disconnect for zombies 160 qboolean send_message; // set on frames a datagram arived on 161 162 // spawn parms are carried from level to level 163 float spawn_parms[NUM_SPAWN_PARMS]; 164 165 // client known data for deltas 166 int old_frags; 167 168 int stats[MAX_CL_STATS]; 169 170 client_frame_t frames[UPDATE_BACKUP]; // updates can be deltad from here 171 172 FILE *download; // file being downloaded 173 int downloadsize; // total bytes 174 int downloadcount; // bytes sent 175 176 int spec_track; // entnum of player tracking 177 178 double whensaid[10]; // JACK: For floodprots 179 int whensaidhead; // Head value for floodprots 180 double lockedtill; 181 182 //===== NETWORK ============ 183 int chokecount; 184 int delta_sequence; // -1 = no compression 185 netchan_t netchan; 186 187 entvars_t old_v; 188 qboolean send_all_v; 189 190 unsigned int PIV, LastPIV; // people in view 191 qboolean skipsend; // Skip sending this frame, guaranteed to send next frame 192 } client_t; 193 194 // a client can leave the server in one of four ways: 195 // dropping properly by quiting or disconnecting 196 // timing out if no valid messages are received for timeout.value seconds 197 // getting kicked off by the server operator 198 // a program error, like an overflowed reliable buffer 199 200 //============================================================================= 201 202 203 #define STATFRAMES 100 204 typedef struct 205 { 206 double active; 207 double idle; 208 int count; 209 int packets; 210 211 double latched_active; 212 double latched_idle; 213 int latched_packets; 214 } svstats_t; 215 216 217 typedef struct 218 { 219 int spawncount; // number of servers spawned since start, 220 // used to check late spawns 221 client_t clients[MAX_CLIENTS]; 222 int serverflags; // episode completion information 223 qboolean changelevel_issued; // cleared when at SV_SpawnServer 224 225 double last_heartbeat; 226 int heartbeat_sequence; 227 svstats_t stats; 228 229 char info[MAX_SERVERINFO_STRING]; 230 231 // log messages are used so that fraglog processes can get stats 232 int logsequence; // the message currently being filled 233 double logtime; // time of last swap 234 sizebuf_t log[2]; 235 byte log_buf[2][MAX_DATAGRAM]; 236 } server_static_t; 237 238 //============================================================================= 239 240 // 241 // edict->movetype values 242 // 243 #define MOVETYPE_NONE 0 // never moves 244 #define MOVETYPE_ANGLENOCLIP 1 245 #define MOVETYPE_ANGLECLIP 2 246 #define MOVETYPE_WALK 3 // gravity 247 #define MOVETYPE_STEP 4 // gravity, special edge handling 248 #define MOVETYPE_FLY 5 249 #define MOVETYPE_TOSS 6 // gravity 250 #define MOVETYPE_PUSH 7 // no clip to world, push and crush 251 #define MOVETYPE_NOCLIP 8 252 #define MOVETYPE_FLYMISSILE 9 // extra size to monsters 253 #define MOVETYPE_BOUNCE 10 254 //#ifdef QUAKE2 255 #define MOVETYPE_BOUNCEMISSILE 11 // bounce w/o gravity 256 #define MOVETYPE_FOLLOW 12 // track movement of aiment 257 //#endif 258 #define MOVETYPE_PUSHPULL 13 // pushable/pullable object 259 #define MOVETYPE_SWIM 14 // should keep the object in water 260 261 // 262 // edict->solid values 263 // 264 #define SOLID_NOT 0 // no interaction with other objects 265 #define SOLID_TRIGGER 1 // touch on edge, but not blocking 266 #define SOLID_BBOX 2 // touch on edge, block 267 #define SOLID_SLIDEBOX 3 // touch on edge, but not an onground 268 #define SOLID_BSP 4 // bsp clip, touch on edge, block 269 #define SOLID_PHASE 5 // won't slow down when hitting entities flagged as FL_MONSTER 270 271 // 272 // edict->deadflag values 273 // 274 #define DEAD_NO 0 275 #define DEAD_DYING 1 276 #define DEAD_DEAD 2 277 278 #define DAMAGE_NO 0 // Cannot be damaged 279 #define DAMAGE_YES 1 // Can be damaged 280 281 // 282 // edict->flags 283 // 284 #define FL_FLY 1 285 #define FL_SWIM 2 286 #define FL_CONVEYOR 4 287 #define FL_CLIENT 8 288 #define FL_INWATER 16 289 #define FL_MONSTER 32 290 #define FL_GODMODE 64 291 #define FL_NOTARGET 128 292 #define FL_ITEM 256 293 #define FL_ONGROUND 512 294 #define FL_PARTIALGROUND 1024 // not all corners are valid 295 #define FL_WATERJUMP 2048 // player jumping out of water 296 #define FL_JUMPRELEASED 4096 // for jump debouncing 297 #define FL_FLASHLIGHT 8192 298 #define FL_ARCHIVE_OVERRIDE 1048576 299 #define FL_ARTIFACTUSED 16384 300 #define FL_MOVECHAIN_ANGLE 32768 // when in a move chain, will update the angle 301 302 #define FL_CLASS_DEPENDENT 2097152 // model will appear different to each player 303 #define FL_SPECIAL_ABILITY1 4194304 // has 1st special ability 304 #define FL_SPECIAL_ABILITY2 8388608 // has 2nd special ability 305 306 #define FL2_CROUCHED 4096 307 308 // 309 // Built-in Spawn Flags 310 // 311 #define SPAWNFLAG_NOT_PALADIN 0x00000100 312 #define SPAWNFLAG_NOT_CLERIC 0x00000200 313 #define SPAWNFLAG_NOT_NECROMANCER 0x00000400 314 #define SPAWNFLAG_NOT_THEIF 0x00000800 315 #define SPAWNFLAG_NOT_EASY 0x00001000 316 #define SPAWNFLAG_NOT_MEDIUM 0x00002000 317 #define SPAWNFLAG_NOT_HARD 0x00004000 318 #define SPAWNFLAG_NOT_DEATHMATCH 0x00008000 319 #define SPAWNFLAG_NOT_COOP 0x00010000 320 #define SPAWNFLAG_NOT_SINGLE 0x00020000 321 322 // 323 // server flags 324 // 325 #define SFL_EPISODE_1 1 326 #define SFL_EPISODE_2 2 327 #define SFL_EPISODE_3 4 328 #define SFL_EPISODE_4 8 329 #define SFL_NEW_UNIT 16 330 #define SFL_NEW_EPISODE 32 331 #define SFL_CROSS_TRIGGERS 65280 332 333 #define MULTICAST_ALL 0 334 #define MULTICAST_PHS 1 335 #define MULTICAST_PVS 2 336 337 #define MULTICAST_ALL_R 3 338 #define MULTICAST_PHS_R 4 339 #define MULTICAST_PVS_R 5 340 341 //============================================================================ 342 343 extern cvar_t sv_mintic, sv_maxtic; 344 extern cvar_t sv_maxspeed; 345 extern cvar_t sv_highchars; 346 347 extern netadr_t master_adr[MAX_MASTERS]; // address of the master server 348 349 extern cvar_t spawn; 350 extern cvar_t teamplay; 351 extern cvar_t skill; 352 extern cvar_t deathmatch; 353 extern cvar_t coop; 354 extern cvar_t randomclass; 355 extern cvar_t maxclients; 356 extern cvar_t damageScale; 357 extern cvar_t meleeDamScale; 358 extern cvar_t shyRespawn; 359 extern cvar_t spartanPrint; 360 extern cvar_t manaScale; 361 extern cvar_t tomeMode; 362 extern cvar_t tomeRespawn; 363 extern cvar_t w2Respawn; 364 extern cvar_t altRespawn; 365 extern cvar_t fixedLevel; 366 extern cvar_t autoItems; 367 extern cvar_t dmMode; 368 extern cvar_t easyFourth; 369 extern cvar_t patternRunner; 370 extern cvar_t fraglimit; 371 extern cvar_t timelimit; 372 extern cvar_t noexit; 373 374 extern server_static_t svs; // persistant server info 375 extern server_t sv; // local server 376 377 extern client_t *host_client; 378 379 extern edict_t *sv_player; 380 381 extern char localmodels[MAX_MODELS][8]; // inline model names for precache 382 383 extern char localinfo[MAX_LOCALINFO_STRING+1]; 384 385 extern int host_hunklevel; 386 extern FILE *sv_logfile; 387 extern FILE *sv_fraglogfile; 388 389 extern unsigned int defLosses; // Defenders losses in Siege 390 extern unsigned int attLosses; // Attackers Losses in Siege 391 #define SV_PROGS_HAVE_SIEGE (sv_globals.defLosses) /* progs have siege fields: >= v0.14 */ 392 393 //=========================================================== 394 395 // 396 // sv_main.c 397 // 398 void SV_Shutdown (void); 399 void SV_Frame (float time); 400 void SV_FinalMessage (const char *message); 401 void SV_DropClient (client_t *drop); 402 403 int SV_CalcPing (client_t *cl); 404 void SV_FullClientUpdate (client_t *client, sizebuf_t *buf); 405 406 int SV_ModelIndex (const char *name); 407 408 qboolean SV_CheckBottom (edict_t *ent); 409 qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink, qboolean noenemy, qboolean set_trace); 410 411 void SV_WriteClientdataToMessage (client_t *client, sizebuf_t *msg); 412 413 void SV_MoveToGoal (void); 414 415 void SV_SaveSpawnparms (void); 416 417 void SV_Physics_Client (edict_t *ent); 418 419 void SV_ExecuteUserCommand (const char *s); 420 void SV_InitOperatorCommands (void); 421 422 void SV_SendServerinfo (client_t *client); 423 void SV_ExtractFromUserinfo (client_t *cl); 424 425 426 void Master_Heartbeat (void); 427 void Master_Packet (void); 428 429 // 430 // sv_init.c 431 // 432 void SV_SpawnServer (const char *server, const char *startspot); 433 void SV_FlushSignon (void); 434 435 const char *SV_GetLevelname (void); 436 437 // 438 // sv_phys.c 439 // 440 void SV_ProgStartFrame (void); 441 void SV_Physics (void); 442 void SV_CheckVelocity (edict_t *ent); 443 void SV_AddGravity (edict_t *ent, float scale); 444 qboolean SV_RunThink (edict_t *ent); 445 void SV_Physics_Toss (edict_t *ent); 446 void SV_RunNewmis (void); 447 void SV_Impact (edict_t *e1, edict_t *e2); 448 void SV_SetMoveVars (void); 449 450 // 451 // sv_send.c 452 // 453 extern unsigned int clients_multicast; 454 455 void SV_SendClientMessages (void); 456 457 void SV_Multicast (vec3_t origin, int to); 458 void SV_MulticastSpecific (unsigned int clients, qboolean reliable); 459 void SV_StartSound (edict_t *entity, int channel, const char *sample, int volume, float attenuation); 460 void SV_StopSound (edict_t *entity, int channel); 461 void SV_UpdateSoundPos (edict_t *entity, int channel); 462 void SV_StartParticle (vec3_t org, vec3_t dir, int color, int count); 463 void SV_StartParticle2 (vec3_t org, vec3_t dmin, vec3_t dmax, int color, int effect, int count); 464 void SV_StartParticle3 (vec3_t org, vec3_t box, int color, int effect, int count); 465 void SV_StartParticle4 (vec3_t org, float radius, int color, int effect, int count); 466 void SV_StartRainEffect (vec3_t org, vec3_t e_size, int x_dir, int y_dir, int color, int count); 467 void SV_ClientPrintf (client_t *cl, int level, const char *fmt, ...) FUNC_PRINTF(3,4); 468 void SV_BroadcastPrintf (int level, const char *fmt, ...) FUNC_PRINTF(2,3); 469 void SV_BroadcastCommand (const char *fmt, ...) FUNC_PRINTF(1,2); 470 void SV_SendMessagesToAll (void); 471 void SV_FindModelNumbers (void); 472 473 // 474 // sv_user.c 475 // 476 void SV_ExecuteClientMessage (client_t *cl); 477 void SV_UserInit (void); 478 479 // 480 // svonly.c 481 // 482 typedef enum 483 { 484 RD_NONE, 485 RD_CLIENT, 486 RD_PACKET 487 } redirect_t; 488 489 void SV_BeginRedirect (redirect_t rd); 490 void SV_EndRedirect (void); 491 492 // 493 // sv_ccmds.c 494 // 495 //void SV_Status_f (void); 496 497 // 498 // sv_ents.c 499 // 500 void SV_WriteEntitiesToClient (client_t *client, sizebuf_t *msg); 501 void SV_WriteInventory (client_t *host_cl, edict_t *ent, sizebuf_t *msg); 502 503 // 504 // sv_effect.c 505 // 506 void SV_ParseEffect (sizebuf_t *sb); 507 void SV_SendEffect (sizebuf_t *sb, int idx); 508 void SV_SaveEffects (FILE *FH); 509 void SV_LoadEffects (FILE *FH); 510 511 #endif /* __H2W_SERVER_H */ 512 513