This repository has been archived on 2022-06-27. You can view files and clone it, but cannot push or open issues or pull requests.
Xash3DArchive/engine/server/server.h

377 lines
12 KiB
C
Raw Normal View History

2007-06-21 22:00:00 +02:00
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// server.h
2007-09-16 22:00:00 +02:00
#ifndef SERVER_H
#define SERVER_H
2007-09-06 22:00:00 +02:00
2007-09-16 22:00:00 +02:00
#include "progsvm.h"
#include "vm_cmds.h"
2007-06-21 22:00:00 +02:00
//=============================================================================
2007-09-16 22:00:00 +02:00
#define MAX_MASTERS 8 // max recipients for heartbeat packets
#define LATENCY_COUNTS 16
#define RATE_MESSAGES 10
2007-09-06 22:00:00 +02:00
2007-09-16 22:00:00 +02:00
typedef enum
{
ss_dead, // no map loaded
ss_loading, // spawning level edicts
ss_game, // actively running
2007-06-21 22:00:00 +02:00
ss_cinematic,
ss_demo,
2007-09-16 22:00:00 +02:00
2007-11-04 22:00:00 +01:00
} sv_state_t;
2007-09-16 22:00:00 +02:00
typedef enum
{
cs_free, // can be reused for a new connection
cs_zombie, // client has been disconnected, but don't reuse connection for a couple seconds
2007-11-04 22:00:00 +01:00
cs_connected, // has been assigned to a client_state_t, but not in game yet
2007-09-16 22:00:00 +02:00
cs_spawned // client is fully in game
2007-11-04 22:00:00 +01:00
} cl_state_t;
2007-06-21 22:00:00 +02:00
typedef struct
{
2007-11-04 22:00:00 +01:00
sv_state_t state; // precache commands are only valid during load
2007-06-21 22:00:00 +02:00
2007-09-16 22:00:00 +02:00
bool attractloop; // running cinematics and demos for the local system only
bool loadgame; // client begins should reuse existing entity
2007-09-06 22:00:00 +02:00
2007-09-16 22:00:00 +02:00
float time; // always sv.framenum * 100 msec
2007-09-07 22:00:00 +02:00
int framenum;
float frametime;
2007-06-21 22:00:00 +02:00
2007-09-16 22:00:00 +02:00
char name[MAX_QPATH]; // map name, or cinematic name
struct cmodel_s *models[MAX_MODELS];
2007-06-21 22:00:00 +02:00
char configstrings[MAX_CONFIGSTRINGS][MAX_QPATH];
entity_state_t baselines[MAX_EDICTS];
2007-09-17 22:00:00 +02:00
edict_t **moved_edicts; // [MAX_EDICTS]
2007-06-21 22:00:00 +02:00
// the multicast buffer is used to send a message to a set of clients
2007-08-19 22:00:00 +02:00
// it is only used to marshall data until SV_Message is called
2007-09-16 22:00:00 +02:00
sizebuf_t multicast;
2007-06-21 22:00:00 +02:00
byte multicast_buf[MAX_MSGLEN];
// demo server information
file_t *demofile;
2007-09-06 22:00:00 +02:00
bool timedemo; // don't time sync
2007-09-16 22:00:00 +02:00
float lastchecktime;
int lastcheck;
2007-06-21 22:00:00 +02:00
2007-09-16 22:00:00 +02:00
bool autosaved;
} server_t;
2007-06-21 22:00:00 +02:00
typedef struct
{
2007-09-16 22:00:00 +02:00
int areabytes;
byte areabits[MAX_MAP_AREAS/8]; // portalarea visibility bits
player_state_t ps;
int num_entities;
int first_entity; // into the circular sv_packet_entities[]
float senttime; // for ping calculations
2007-06-21 22:00:00 +02:00
2007-09-16 22:00:00 +02:00
} client_frame_t;
2007-06-21 22:00:00 +02:00
2007-11-04 22:00:00 +01:00
typedef struct client_state_s
2007-06-21 22:00:00 +02:00
{
2007-11-04 22:00:00 +01:00
cl_state_t state;
2007-06-21 22:00:00 +02:00
2007-09-16 22:00:00 +02:00
char userinfo[MAX_INFO_STRING]; // name, etc
2007-06-21 22:00:00 +02:00
2007-09-16 22:00:00 +02:00
int lastframe; // for delta compression
2007-09-06 22:00:00 +02:00
usercmd_t lastcmd; // for filling in big drops
2007-09-02 22:00:00 +02:00
2007-09-09 22:00:00 +02:00
int commandMsec; // every seconds this is reset, if user
2007-09-16 22:00:00 +02:00
// commands exhaust it, assume time cheating
2007-06-21 22:00:00 +02:00
2007-09-09 22:00:00 +02:00
int frame_latency[LATENCY_COUNTS];
int ping;
2007-06-21 22:00:00 +02:00
2007-09-09 22:00:00 +02:00
int message_size[RATE_MESSAGES]; // used to rate drop packets
int rate;
int surpressCount; // number of messages rate supressed
2007-06-21 22:00:00 +02:00
2007-09-16 22:00:00 +02:00
edict_t *edict; // EDICT_NUM(clientnum+1)
2007-09-09 22:00:00 +02:00
char name[32]; // extracted from userinfo, high bits masked
int messagelevel; // for filtering printed messages
2007-06-21 22:00:00 +02:00
// The datagram is written to by sound calls, prints, temp ents, etc.
// It can be harmlessly overflowed.
2007-09-06 22:00:00 +02:00
sizebuf_t datagram;
2007-09-09 22:00:00 +02:00
byte datagram_buf[MAX_MSGLEN];
2007-06-21 22:00:00 +02:00
2007-09-06 22:00:00 +02:00
client_frame_t frames[UPDATE_BACKUP]; // updates can be delta'd from here
2007-06-21 22:00:00 +02:00
2007-09-16 22:00:00 +02:00
byte *download; // file being downloaded
2007-09-09 22:00:00 +02:00
int downloadsize; // total bytes (can't use EOF because of paks)
int downloadcount; // bytes sent
2007-06-21 22:00:00 +02:00
2007-09-09 22:00:00 +02:00
float lastmessage; // sv.framenum when packet was last received
float lastconnect;
2007-06-21 22:00:00 +02:00
2007-09-16 22:00:00 +02:00
int challenge; // challenge of this user, randomly generated
2007-06-21 22:00:00 +02:00
2007-09-06 22:00:00 +02:00
netchan_t netchan;
2007-11-04 22:00:00 +01:00
} client_state_t;
2007-06-21 22:00:00 +02:00
2007-09-16 22:00:00 +02:00
/*
=============================================================================
a client can leave the server in one of four ways:
dropping properly by quiting or disconnecting
timing out if no valid messages are received for timeout.value seconds
getting kicked off by the server operator
a program error, like an overflowed reliable buffer
=============================================================================
*/
2007-06-21 22:00:00 +02:00
// MAX_CHALLENGES is made large to prevent a denial
// of service attack that could cycle all of them
// out before legitimate users connected
#define MAX_CHALLENGES 1024
typedef struct
{
2007-09-09 22:00:00 +02:00
netadr_t adr;
int challenge;
float time;
2007-06-21 22:00:00 +02:00
2007-09-16 22:00:00 +02:00
} challenge_t;
2007-06-21 22:00:00 +02:00
typedef struct
{
2007-09-16 22:00:00 +02:00
bool initialized; // sv_init has completed
float realtime; // always increasing, no clamping, etc
2007-06-21 22:00:00 +02:00
char mapcmd[MAX_TOKEN_CHARS]; // ie: *intro.cin+base
2007-07-22 22:00:00 +02:00
char comment[MAX_TOKEN_CHARS]; // map name, e.t.c.
2007-06-21 22:00:00 +02:00
2007-09-16 22:00:00 +02:00
int spawncount; // incremented each server start
// used to check late spawns
2007-09-17 22:00:00 +02:00
gclient_t *gclients; // [maxclients->value]
2007-11-04 22:00:00 +01:00
client_state_t *clients; // [maxclients->value]
2007-09-06 22:00:00 +02:00
int num_client_entities; // maxclients->value*UPDATE_BACKUP*MAX_PACKET_ENTITIES
2007-07-22 22:00:00 +02:00
int next_client_entities; // next client_entity to use
2007-06-21 22:00:00 +02:00
entity_state_t *client_entities; // [num_client_entities]
2007-09-09 22:00:00 +02:00
float last_heartbeat;
2007-06-21 22:00:00 +02:00
challenge_t challenges[MAX_CHALLENGES]; // to prevent invalid IPs from connecting
// serverrecord values
file_t *demofile;
2007-09-09 22:00:00 +02:00
sizebuf_t demo_multicast;
2007-06-21 22:00:00 +02:00
byte demo_multicast_buf[MAX_MSGLEN];
} server_static_t;
//=============================================================================
extern netadr_t net_from;
extern sizebuf_t net_message;
2007-09-16 22:00:00 +02:00
extern netadr_t master_adr[MAX_MASTERS]; // address of the master server
2007-06-21 22:00:00 +02:00
2007-09-16 22:00:00 +02:00
extern server_static_t svs; // persistant server info
extern server_t sv; // local server
2007-06-21 22:00:00 +02:00
extern cvar_t *sv_paused;
2007-09-06 22:00:00 +02:00
extern cvar_t *maxclients;
2007-09-16 22:00:00 +02:00
extern cvar_t *sv_noreload; // don't reload level state when reentering
2007-06-21 22:00:00 +02:00
extern cvar_t *sv_airaccelerate; // don't reload level state when reentering
2007-09-06 22:00:00 +02:00
extern cvar_t *sv_maxvelocity;
extern cvar_t *sv_gravity;
2007-09-16 22:00:00 +02:00
// development tool
2007-06-21 22:00:00 +02:00
extern cvar_t *sv_enforcetime;
2007-11-04 22:00:00 +01:00
extern client_state_t *sv_client;
2007-09-06 22:00:00 +02:00
extern edict_t *sv_player;
2007-06-21 22:00:00 +02:00
2007-09-16 22:00:00 +02:00
//===========================================================
2007-06-21 22:00:00 +02:00
//
// sv_main.c
//
void SV_FinalMessage (char *message, bool reconnect);
2007-11-04 22:00:00 +01:00
void SV_DropClient (client_state_t *drop);
2007-06-21 22:00:00 +02:00
2007-09-16 22:00:00 +02:00
int SV_ModelIndex (const char *name);
int SV_SoundIndex (const char *name);
int SV_ImageIndex (const char *name);
2007-09-29 22:00:00 +02:00
int SV_DecalIndex (const char *name);
2007-06-21 22:00:00 +02:00
2007-11-04 22:00:00 +01:00
void SV_WriteClientdataToMessage (client_state_t *client, sizebuf_t *msg);
2007-06-21 22:00:00 +02:00
void SV_ExecuteUserCommand (char *s);
void SV_InitOperatorCommands (void);
2007-11-04 22:00:00 +01:00
void SV_SendServerinfo (client_state_t *client);
void SV_UserinfoChanged (client_state_t *cl);
2007-06-21 22:00:00 +02:00
void Master_Heartbeat (void);
void Master_Packet (void);
//
// sv_init.c
//
void SV_InitGame (void);
2007-07-23 22:00:00 +02:00
void SV_Map (bool attractloop, char *levelstring, char *savename, bool loadgame);
2007-09-29 22:00:00 +02:00
int SV_FindIndex (const char *name, int start, int end, bool create);
2007-09-16 22:00:00 +02:00
void SV_VM_Setup(void);
void SV_VM_Begin(void);
void SV_VM_End(void);
2007-06-21 22:00:00 +02:00
//
// sv_phys.c
//
void SV_PrepWorldFrame (void);
2007-09-06 22:00:00 +02:00
void SV_Physics (edict_t *ent);
void SV_DropToFloor (edict_t *ent);
void SV_CheckGround (edict_t *ent);
2007-09-28 22:00:00 +02:00
bool SV_MoveStep (edict_t *ent, vec3_t move, bool relink);
2007-09-29 22:00:00 +02:00
void SV_CheckVelocity (edict_t *ent);
bool SV_CheckBottom (edict_t *ent);
2007-06-21 22:00:00 +02:00
//
// sv_send.c
//
typedef enum {RD_NONE, RD_CLIENT, RD_PACKET} redirect_t;
#define SV_OUTPUTBUF_LENGTH (MAX_MSGLEN - 16)
2007-09-16 22:00:00 +02:00
extern char sv_outputbuf[SV_OUTPUTBUF_LENGTH];
2007-06-21 22:00:00 +02:00
void SV_FlushRedirect (int sv_redirected, char *outputbuf);
void SV_DemoCompleted (void);
void SV_SendClientMessages (void);
2007-09-16 22:00:00 +02:00
void SV_StartSound (vec3_t origin, edict_t *entity, int channel, int index, float vol, float attn, float timeofs);
2007-11-04 22:00:00 +01:00
void SV_ClientPrintf (client_state_t *cl, int level, char *fmt, ...);
2007-06-21 22:00:00 +02:00
void SV_BroadcastPrintf (int level, char *fmt, ...);
void SV_BroadcastCommand (char *fmt, ...);
//
// sv_user.c
//
void SV_Nextserver (void);
2007-11-04 22:00:00 +01:00
void SV_ExecuteClientMessage (client_state_t *cl);
2007-06-21 22:00:00 +02:00
//
// sv_ccmds.c
//
void SV_Status_f (void);
//
// sv_ents.c
//
2007-11-04 22:00:00 +01:00
void SV_WriteFrameToClient (client_state_t *client, sizebuf_t *msg);
2007-06-21 22:00:00 +02:00
void SV_RecordDemoMessage (void);
2007-11-04 22:00:00 +01:00
void SV_BuildClientFrame (client_state_t *client);
2007-09-18 22:00:00 +02:00
void SV_UpdateEntityState( edict_t *ent);
2007-09-16 22:00:00 +02:00
void SV_FatPVS ( vec3_t org );
2007-06-21 22:00:00 +02:00
void SV_Error (char *error, ...);
2007-09-06 22:00:00 +02:00
//
// sv_game.c
//
void SV_InitGameProgs (void);
void SV_ShutdownGameProgs (void);
void SV_InitEdict (edict_t *e);
2007-09-16 22:00:00 +02:00
void SV_ConfigString (int index, const char *val);
void SV_SetModel (edict_t *ent, const char *name);
2007-06-21 22:00:00 +02:00
2007-06-22 22:00:00 +02:00
//
// sv_studio.c
//
2007-09-06 22:00:00 +02:00
byte *SV_GetModelPtr(edict_t *ent);
2007-06-22 22:00:00 +02:00
int SV_StudioExtractBbox( studiohdr_t *phdr, int sequence, float *mins, float *maxs );
2007-06-21 22:00:00 +02:00
2007-09-06 22:00:00 +02:00
//
// sv_spawn.c
//
void SV_SpawnEntities (char *mapname, char *entities, char *spawnpoint);
2007-09-29 22:00:00 +02:00
void SV_StartParticle (vec3_t org, vec3_t dir, int color, int count);
2007-10-27 22:00:00 +02:00
void SV_Transform( sv_edict_t *ed, vec3_t origin, vec3_t angles );
2007-09-06 22:00:00 +02:00
void SV_FreeEdict (edict_t *ed);
void SV_InitEdict (edict_t *e);
edict_t *SV_Spawn (void);
void SV_RunFrame (void);
void SV_ClientUserinfoChanged (edict_t *ent, char *userinfo);
bool SV_ClientConnect (edict_t *ent, char *userinfo);
void SV_ClientBegin (edict_t *ent);
void ClientThink (edict_t *ent, usercmd_t *ucmd);
void SV_ClientDisconnect (edict_t *ent);
void SV_ClientCommand (edict_t *ent);
void SV_TouchTriggers (edict_t *ent);
2007-06-25 22:00:00 +02:00
//
// sv_save.c
//
2007-07-23 22:00:00 +02:00
void SV_WriteSaveFile( char *name );
void SV_ReadSaveFile( char *name );
void SV_ReadLevelFile( char *name );
2007-06-21 22:00:00 +02:00
//============================================================
//
// high level object sorting to reduce interaction tests
//
void SV_ClearWorld (void);
// called after the world model has been loaded, before linking any entities
2007-09-06 22:00:00 +02:00
void SV_UnlinkEdict (edict_t *ent);
2007-06-21 22:00:00 +02:00
// call before removing an entity, and before trying to move one,
// so it doesn't clip against itself
2007-09-06 22:00:00 +02:00
void SV_LinkEdict (edict_t *ent);
2007-06-21 22:00:00 +02:00
// Needs to be called any time an entity changes origin, mins, maxs,
// or solid. Automatically unlinks if needed.
// sets ent->v.absmin and ent->v.absmax
// sets ent->leafnums[] for pvs determination even if the entity
// is not solid
2007-09-06 22:00:00 +02:00
int SV_AreaEdicts (vec3_t mins, vec3_t maxs, edict_t **list, int maxcount, int areatype);
2007-06-21 22:00:00 +02:00
// fills in a table of edict pointers with edicts that have bounding boxes
// that intersect the given area. It is possible for a non-axial bmodel
// to be returned that doesn't actually intersect the area on an exact
// test.
// returns the number of pointers filled in
// ??? does this always return the world?
//===================================================================
//
// functions that interact with everything apropriate
//
int SV_PointContents (vec3_t p);
// returns the CONTENTS_* value from the world at the given point.
// Quake 2 extends this to also check entities, to allow moving liquids
2007-09-17 22:00:00 +02:00
trace_t SV_ClipMoveToEntity(edict_t *ent, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int contentsmask );
2007-09-06 22:00:00 +02:00
trace_t SV_Trace (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passedict, int contentmask);
2007-09-29 22:00:00 +02:00
trace_t SV_TraceToss (edict_t *tossent, edict_t *ignore);
2007-06-21 22:00:00 +02:00
// mins and maxs are relative
// if the entire move stays in a solid volume, trace.allsolid will be set,
// trace.startsolid will be set, and trace.fraction will be 0
// if the starting point is in a solid, it will be allowed to move out
// to an open area
2007-09-16 22:00:00 +02:00
// passedict is explicitly excluded from clipping checks (normally NULL)
#endif//SERVER_H