#include "../qcommon/qcommon.h"
#include "../game/game.h"
#include "../qcommon/sql.h"
#define MAX_MASTERS 8
typedef enum {
ss_dead, ss_loading, ss_game, ss_cinematic,
ss_demo,
ss_pic
} server_state_t;
typedef struct {
server_state_t state;
bool attractloop; bool loadgame;
unsigned time; int framenum;
char name[MAX_QPATH]; struct cmodel_s *models[CMODEL_COUNT][MAX_MODELS];
char configstrings[MAX_CONFIGSTRINGS][MAX_QPATH];
entity_state_t baselines[MAX_EDICTS];
sizebuf_t multicast;
byte multicast_buf[MAX_MSGLEN];
FILE *demofile;
bool timedemo; } server_t;
#define EDICT_NUM(n) ((edict_t *)((byte *)ge->edicts + ge->edict_size * (n)))
#define NUM_FOR_EDICT(e) (((byte *)(e) - (byte *)ge->edicts) / ge->edict_size)
typedef enum {
cs_free, cs_zombie, cs_connected, cs_spawned } client_state_t;
typedef struct {
int areabytes;
byte areabits[MAX_MAP_AREAS / 8]; player_state_t ps;
int num_entities;
int first_entity; int senttime; } client_frame_t;
#define LATENCY_COUNTS 16
#define RATE_MESSAGES 10
typedef struct client_s {
client_state_t state;
char userinfo[MAX_INFO_STRING];
int lastframe; usercmd_t lastcmd;
int commandMsec;
int frame_latency[LATENCY_COUNTS];
int ping;
int message_size[RATE_MESSAGES]; int rate;
int surpressCount;
edict_t *edict; char name[32]; int messagelevel;
sizebuf_t datagram;
byte datagram_buf[MAX_MSGLEN];
client_frame_t frames[UPDATE_BACKUP];
byte *download; int downloadsize; int downloadcount;
int lastmessage; int lastconnect;
int challenge;
netchan_t netchan;
} client_t;
#define MAX_CHALLENGES 1024
typedef struct {
netadr_t adr;
int challenge;
int time;
} challenge_t;
typedef struct {
bool initialized; int realtime;
char mapcmd[MAX_TOKEN_CHARS];
int spawncount;
client_t *clients; int num_client_entities; int next_client_entities; entity_state_t *client_entities;
int last_heartbeat;
challenge_t challenges[MAX_CHALLENGES];
FILE *demofile;
sizebuf_t demo_multicast;
byte demo_multicast_buf[MAX_MSGLEN];
} server_static_t;
extern netadr_t net_from;
extern sizebuf_t net_message;
extern sqlite3 *sv_database;
extern netadr_t master_adr[MAX_MASTERS];
extern server_static_t svs; extern server_t sv;
extern cvar_t *sv_paused;
extern cvar_t *maxclients;
extern cvar_t *sv_noreload; extern cvar_t *sv_airaccelerate; extern cvar_t *sv_enforcetime;
extern client_t *sv_client;
extern edict_t *sv_player;
void SV_FinalMessage(char *message, bool reconnect);
void SV_DropClient(client_t *drop);
int SV_ModelIndex(char *name);
int SV_SoundIndex(char *name);
int SV_ImageIndex(char *name);
void SV_WriteClientdataToMessage(client_t *client, sizebuf_t *msg);
void SV_ExecuteUserCommand(char *s);
void SV_InitOperatorCommands(void);
void SV_SendServerinfo(client_t *client);
void SV_UserinfoChanged(client_t *cl);
void Master_Heartbeat(void);
void Master_Packet(void);
void SV_InitGame(void);
void SV_Map(bool attractloop, char *levelstring, bool loadgame);
void SV_PrepWorldFrame(void);
typedef enum { RD_NONE, RD_CLIENT, RD_PACKET } redirect_t;
#define SV_OUTPUTBUF_LENGTH (MAX_MSGLEN - 16)
extern char sv_outputbuf[SV_OUTPUTBUF_LENGTH];
void SV_FlushRedirect(int sv_redirected, char *outputbuf);
void SV_DemoCompleted(void);
void SV_SendClientMessages(void);
void SV_Multicast(int cmodel_index, vec3_t origin, multicast_t to);
void SV_StartSound(vec3_t origin, edict_t *entity, int channel, int soundindex, float volume, float attenuation,
float timeofs);
void SV_ClientPrintf(client_t *cl, int level, char *fmt, ...);
void SV_BroadcastPrintf(int level, char *fmt, ...);
void SV_BroadcastCommand(char *fmt, ...);
void SV_Nextserver(void);
void SV_ExecuteClientMessage(client_t *cl);
void SV_ReadLevelFile(void);
void SV_Status_f(void);
void SV_WriteFrameToClient(client_t *client, sizebuf_t *msg);
void SV_RecordDemoMessage(void);
void SV_BuildClientFrame(client_t *client);
void SV_Error(char *error, ...);
extern game_export_t *ge;
void SV_InitGameProgs(void);
void SV_ShutdownGameProgs(void);
void SV_InitEdict(edict_t *e);
void SV_ClearWorld(int cmodel_index);
void SV_UnlinkEdict(edict_t *ent);
void SV_LinkEdict(edict_t *ent);
int SV_AreaEdicts(int cmodel_index, vec3_t mins, vec3_t maxs, edict_t **list, int maxcount, int areatype);
int SV_PointContents(int cmodel_index, vec3_t p);
trace_t SV_Trace(int cmodel_index, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passedict,
int contentmask);