/* Relay -- a tool to record and play Quake2 demos Copyright (C) 2000 Conor Davis 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. Conor Davis cedavis@planetquake.com */ #ifndef __SV_LOCAL_H #define __SV_LOCAL_H #include #include #include #include "shared.h" #include "q2defines.h" #include "block.h" #include "cmd.h" #include "dm2.h" #include "endian.h" #include "mem.h" #include "menu.h" #include "net.h" #include "pak.h" #include "q2utils.h" #include "utils.h" #define FRAMETIME 0.1 // timeout settings (in milliseconds) #define CHALLENGE_TIMEOUT 3000 #define CLIENT_TIMEOUT 30000 // menu stuff enum { MENU_BAD, MENU_MAIN, MENU_DEMO, MENU_PLAYERS, MENU_SETTINGS, }; #if 0 enum { MENU_ALIGN_LEFT, MENU_ALIGN_CENTER, MENU_ALIGN_RIGHT }; #define MAX_MENU_PARMS 8 typedef struct client_s client_t; typedef struct menuitem_s { char *text; // text to be displayed int align; // left, center, right int indent; // pixels to indent to the right int param[MAX_MENU_PARMS]; // params used by the Select function void (*Select)(client_t *client, struct menuitem_s *item, int key); } menuitem_t; typedef struct menu_s { char *title; // always displayed at top int id; // ID_* menu type menuitem_t *items; // item array int num; // number of items int top; // index of first item to be displayed int cur; // current selected item int param[MAX_MENU_PARMS]; // params used by the Show function void (*Show)(client_t *client, struct menu_s *menu); void (*Close)(client_t *client, struct menu_s *menu); struct menu_s *next; } menu_t; #endif typedef struct { player_state_t ps; byte active[MAX_EDICTS/8]; } clientdelta_t; typedef struct client_s { enum { CL_UNCONNECTED, // not connected CL_CONNECTING, // successfully challenged, waiting for // "new" command CL_CONFIGSTRINGS, // receiving serverdata/configstrings CL_BASELINES, // receiving baselines CL_PRECACHING, // precaching CL_CONNECTED // ready to receive frame updates } status; net_t net; size_t timeout_time; int protocol; size_t delta_frame; char userinfo[MAX_INFO_STRING]; char netname[16]; // message packets block_t unreliable; char unreliable_buffer[MAX_MSGLEN]; block_t reliable; char reliable_buffer[MAX_MSGLEN]; block_t nextreliable; char nextreliable_buffer[MAX_MSGLEN]; clientdelta_t old[UPDATE_BACKUP]; player_state_t ps; byte active[MAX_EDICTS/8]; char layout[MAX_MSGLEN]; short inventory[MAX_ITEMS]; qboolean layout_modified; qboolean inventory_modified; int player; int flags; float dist; vec3_t origin; vec3_t velocity; vec3_t cmd_angles; int buttons; menu_t *curmenu; } client_t; typedef struct { enum {SV_IDLE, SV_RUNNING} status; char *console_commandstring; char *demo_commandstring; PFILE *infile; SOCKET socket; size_t nextcommand_time; int maxclients; int numclients; serverdata_t outsvd; byte current_connected[MAX_CLIENTS/8]; cvar_t *cvars; client_t *clients; } server_t; // // FUNCTIONS // // sv_challenge.c extern int NewChallenge(struct sockaddr_in *addr); extern qboolean FindChallenge(struct sockaddr_in *addr, int id); extern void TimeoutChallenges(); extern void FreeAllChallenges(); // sv_clcmds.c extern void ClientCommand(client_t *client); extern void CL_StringCommand(client_t *client); extern void ConnectionlessCommand(struct sockaddr_in *addr); // sv_client.c extern void InitClient(client_t *client); extern int CL_ChangePlayer(client_t *client, int index); extern void ClientDisconnect(client_t *client); extern void ClientTimeout(client_t *client); extern qboolean ClientConnect(client_t *client, const char *userinfo); extern void ClientBegin(client_t *client); extern void ClientUserinfoChanged(client_t *client, const char *userinfo); extern void ClientThink(client_t *client, const usercmd_t *cmd); extern void ClientBeginServerFrame(client_t *client); extern void UpdateClientOrigin(client_t *client); extern void ClientEndServerFrame(client_t *client); // sv_cvar.c extern cvar_t *cvar(const char *var_name, const char *value, int flags); extern void cvar_set(const char *var_name, const char *value); extern void cvar_forceset(const char *var_name, const char *value); extern void UnlatchCvars(); extern void FreeAllCvars(); // sv_dm2.c extern int PreFrame_Read(); extern int Frame_Read(); extern void CL_WriteEntities(block_t *block, client_t *client, size_t delta_frame); // sv_main.c extern server_t server; extern dm2_t dm2in; extern bsp_t map; extern cvar_t *cvar_basedir; extern cvar_t *cvar_demoname; extern cvar_t *cvar_game; extern cvar_t *cvar_hostname; extern cvar_t *cvar_mapname; extern cvar_t *cvar_maxclients; extern cvar_t *cvar_password; extern cvar_t *cvar_port; extern cvar_t *cvar_protocol; extern cvar_t *cvar_timescale; extern void SpawnServer(const char *filename); extern void KillServer(const char *message); extern void CloseProgram(int err); extern void Error(const char *fmt, ...); extern void DropClient(client_t *client, const char *fmt, ...); extern void CL_cprintf(block_t *block, int printlevel, const char *fmt, ...); extern void CL_bprintf(qboolean reliable, int printlevel, const char *fmt, ...); #if 0 // sv_menu.c extern void Menu_Close(client_t *client, qboolean update); extern void Menu_CloseAll(client_t *client, qboolean update); extern int Menu_AddItem(const char *text, const char *fmt, ...); extern void Menu_Display(client_t *client); extern void Menu_Update(client_t *client, int id); extern void Menu_UpdateAll(int id); extern void Menu_Prev(client_t *client); extern void Menu_Next(client_t *client); extern void Menu_Select(client_t *client, int key); extern void Menu_SelectOpen(client_t *client, menuitem_t *item, int key); extern void Menu_Start(menu_t *menu); extern void Menu_Finish(menu_t *menu); extern void Menu_Open(client_t *client, void (*Show)(client_t *, struct menu_s *), const char *fmt, ...); #endif // sv_menus.c extern void UpdateLayout(client_t *client); extern void OpenMenu(client_t *client, void (*Show)(menu_t *)); extern void CloseMenu(client_t *client); extern void CloseAllMenus(client_t *client); extern void MainMenu_Show(menu_t *menu); // sv_net.c extern void ReadPackets(); extern void WritePackets(); // sv_pmove.c extern void Pmove(pmove_t *pm); // sv_svcmds.c extern void FreeAllAliases(); extern qboolean RunConsoleCommand(); #endif // __SV_LOCAL_H