2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
host.c
|
|
|
|
|
2001-05-09 17:12:49 +00:00
|
|
|
host init
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996-1997 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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2003-01-15 15:31:36 +00:00
|
|
|
static __attribute__ ((unused)) const char rcsid[] =
|
|
|
|
"$Id$";
|
|
|
|
|
2002-07-31 05:19:03 +00:00
|
|
|
#include "QF/cbuf.h"
|
2002-07-31 22:03:53 +00:00
|
|
|
#include "QF/idparse.h"
|
2001-04-10 21:45:42 +00:00
|
|
|
#include "QF/cdaudio.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/cmd.h"
|
2001-04-09 21:15:09 +00:00
|
|
|
#include "QF/console.h"
|
2001-05-31 03:41:35 +00:00
|
|
|
#include "QF/cvar.h"
|
2001-05-09 22:40:51 +00:00
|
|
|
#include "QF/draw.h"
|
2001-05-09 17:12:49 +00:00
|
|
|
#include "QF/input.h"
|
2001-04-09 21:15:09 +00:00
|
|
|
#include "QF/keys.h"
|
|
|
|
#include "QF/msg.h"
|
2001-04-25 00:20:23 +00:00
|
|
|
#include "QF/plugin.h"
|
2002-01-18 19:19:33 +00:00
|
|
|
#include "QF/progs.h"
|
2001-04-09 21:15:09 +00:00
|
|
|
#include "QF/qargs.h"
|
2001-05-09 17:12:49 +00:00
|
|
|
#include "QF/screen.h"
|
2001-04-09 21:15:09 +00:00
|
|
|
#include "QF/sys.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/va.h"
|
2001-04-15 04:18:22 +00:00
|
|
|
#include "QF/vid.h"
|
2003-04-13 22:07:58 +00:00
|
|
|
#include "QF/gib.h"
|
2001-05-09 17:12:49 +00:00
|
|
|
|
2002-04-11 18:42:55 +00:00
|
|
|
#include "buildnum.h"
|
2001-05-09 17:12:49 +00:00
|
|
|
#include "chase.h"
|
2001-08-29 02:12:57 +00:00
|
|
|
#include "compat.h"
|
2001-05-09 17:12:49 +00:00
|
|
|
#include "host.h"
|
2001-10-28 04:23:37 +00:00
|
|
|
#include "r_dynamic.h"
|
2001-05-09 17:12:49 +00:00
|
|
|
#include "sbar.h"
|
|
|
|
#include "server.h"
|
2001-03-03 08:31:58 +00:00
|
|
|
#include "sv_progs.h"
|
2001-05-09 17:12:49 +00:00
|
|
|
#include "view.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-09 06:15:14 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
/*
|
2001-08-29 02:12:57 +00:00
|
|
|
A server can always be started, even if the system started out as a client
|
|
|
|
to a remote system.
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
A client can NOT be started if the system started as a dedicated server.
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
Memory is cleared/released when a server or client begins, not when they end.
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
|
|
|
|
2003-12-19 03:41:58 +00:00
|
|
|
SERVER_PLUGIN_PROTOS
|
|
|
|
static plugin_list_t server_plugin_list[] = {
|
|
|
|
SERVER_PLUGIN_LIST
|
|
|
|
};
|
|
|
|
|
2002-01-16 21:53:42 +00:00
|
|
|
CLIENT_PLUGIN_PROTOS
|
|
|
|
static plugin_list_t client_plugin_list[] = {
|
|
|
|
CLIENT_PLUGIN_LIST
|
|
|
|
};
|
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
qboolean host_initialized; // true if into command execution
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
quakeparms_t host_parms;
|
|
|
|
|
2002-07-31 05:19:03 +00:00
|
|
|
cbuf_t *host_cbuf;
|
|
|
|
|
2001-05-19 20:57:29 +00:00
|
|
|
double host_frametime;
|
|
|
|
double host_time;
|
|
|
|
double realtime; // without any filtering or bounding
|
|
|
|
double oldrealtime; // last frame run
|
2001-08-29 02:12:57 +00:00
|
|
|
|
2003-07-25 22:21:47 +00:00
|
|
|
double con_frametime;
|
|
|
|
double con_realtime;
|
|
|
|
double oldcon_realtime;
|
|
|
|
|
2001-05-19 20:57:29 +00:00
|
|
|
int host_framecount;
|
|
|
|
int host_hunklevel;
|
|
|
|
int minimum_memory;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
client_t *host_client; // current client
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-19 20:57:29 +00:00
|
|
|
jmp_buf host_abortserver;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-09-10 03:51:10 +00:00
|
|
|
byte *host_basepal;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
cvar_t *fs_globalcfg;
|
2001-05-17 07:53:22 +00:00
|
|
|
cvar_t *fs_usercfg;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-02-19 20:47:45 +00:00
|
|
|
cvar_t *host_mem_size;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
cvar_t *host_framerate;
|
|
|
|
cvar_t *host_speeds;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
cvar_t *sys_ticrate;
|
|
|
|
cvar_t *serverprofile;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-09-06 23:58:28 +00:00
|
|
|
cvar_t *cl_quakerc;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
cvar_t *fraglimit;
|
|
|
|
cvar_t *timelimit;
|
|
|
|
cvar_t *teamplay;
|
|
|
|
cvar_t *noexit;
|
2001-08-29 02:12:57 +00:00
|
|
|
cvar_t *samelevel;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
cvar_t *skill;
|
|
|
|
cvar_t *coop;
|
2001-08-29 02:12:57 +00:00
|
|
|
cvar_t *deathmatch;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
cvar_t *pausable;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
cvar_t *temp1;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2001-07-15 07:04:17 +00:00
|
|
|
Host_EndGame (const char *message, ...)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2003-07-08 22:39:45 +00:00
|
|
|
static dstring_t *str;
|
2001-08-29 02:12:57 +00:00
|
|
|
va_list argptr;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2003-07-08 22:39:45 +00:00
|
|
|
if (!str)
|
|
|
|
str = dstring_new ();
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
va_start (argptr, message);
|
2003-07-08 22:39:45 +00:00
|
|
|
dvsprintf (str, message, argptr);
|
2001-02-19 21:15:25 +00:00
|
|
|
va_end (argptr);
|
2003-07-08 22:39:45 +00:00
|
|
|
Con_DPrintf ("Host_EndGame: %s\n", str->str);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (sv.active)
|
|
|
|
Host_ShutdownServer (false);
|
|
|
|
|
|
|
|
if (cls.state == ca_dedicated)
|
2003-07-08 22:39:45 +00:00
|
|
|
Sys_Error ("Host_EndGame: %s", str->str); // dedicated servers exit
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (cls.demonum != -1)
|
|
|
|
CL_NextDemo ();
|
|
|
|
else
|
|
|
|
CL_Disconnect ();
|
|
|
|
|
|
|
|
longjmp (host_abortserver, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-05-09 17:12:49 +00:00
|
|
|
Host_Error
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-09 17:12:49 +00:00
|
|
|
This shuts down both the client and server
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2001-07-15 07:04:17 +00:00
|
|
|
Host_Error (const char *error, ...)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2003-07-08 22:39:45 +00:00
|
|
|
static dstring_t *str;
|
2001-02-26 06:48:02 +00:00
|
|
|
static qboolean inerror = false;
|
2001-08-29 02:12:57 +00:00
|
|
|
va_list argptr;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (inerror)
|
|
|
|
Sys_Error ("Host_Error: recursively entered");
|
2003-07-08 22:39:45 +00:00
|
|
|
|
|
|
|
if (!str)
|
|
|
|
str = dstring_new ();
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
inerror = true;
|
|
|
|
|
2001-05-19 20:57:29 +00:00
|
|
|
// SCR_EndLoadingPlaque (); // reenable screen updates
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
va_start (argptr, error);
|
2003-07-08 22:39:45 +00:00
|
|
|
dvsprintf (str, error, argptr);
|
2001-02-19 21:15:25 +00:00
|
|
|
va_end (argptr);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (sv.active)
|
|
|
|
Host_ShutdownServer (false);
|
|
|
|
|
|
|
|
if (cls.state == ca_dedicated)
|
2003-07-08 22:39:45 +00:00
|
|
|
Sys_Error ("Host_Error: %s", str->str); // dedicated servers exit
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-07-08 22:39:45 +00:00
|
|
|
Con_Printf ("Host_Error: %s\n", str->str);
|
2002-02-20 19:22:52 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
CL_Disconnect ();
|
|
|
|
cls.demonum = -1;
|
|
|
|
|
|
|
|
inerror = false;
|
|
|
|
|
|
|
|
longjmp (host_abortserver, 1);
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
Host_FindMaxClients (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
svs.maxclients = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
i = COM_CheckParm ("-dedicated");
|
2001-02-26 06:48:02 +00:00
|
|
|
if (i) {
|
2001-02-19 21:15:25 +00:00
|
|
|
cls.state = ca_dedicated;
|
2001-02-26 06:48:02 +00:00
|
|
|
if (i != (com_argc - 1)) {
|
|
|
|
svs.maxclients = atoi (com_argv[i + 1]);
|
|
|
|
} else
|
2001-02-19 21:15:25 +00:00
|
|
|
svs.maxclients = 8;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else
|
2001-02-19 21:15:25 +00:00
|
|
|
cls.state = ca_disconnected;
|
|
|
|
|
|
|
|
i = COM_CheckParm ("-listen");
|
2001-02-26 06:48:02 +00:00
|
|
|
if (i) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (cls.state == ca_dedicated)
|
|
|
|
Sys_Error ("Only one of -dedicated or -listen can be specified");
|
|
|
|
if (i != (com_argc - 1))
|
2001-02-26 06:48:02 +00:00
|
|
|
svs.maxclients = atoi (com_argv[i + 1]);
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
|
|
|
svs.maxclients = 8;
|
|
|
|
}
|
|
|
|
if (svs.maxclients < 1)
|
|
|
|
svs.maxclients = 8;
|
|
|
|
else if (svs.maxclients > MAX_SCOREBOARD)
|
|
|
|
svs.maxclients = MAX_SCOREBOARD;
|
|
|
|
|
|
|
|
svs.maxclientslimit = svs.maxclients;
|
|
|
|
if (svs.maxclientslimit < 4)
|
|
|
|
svs.maxclientslimit = 4;
|
2001-02-26 06:48:02 +00:00
|
|
|
svs.clients =
|
|
|
|
Hunk_AllocName (svs.maxclientslimit * sizeof (client_t), "clients");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (svs.maxclients > 1)
|
2001-02-26 06:48:02 +00:00
|
|
|
Cvar_SetValue (deathmatch, 1.0);
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-02-26 06:48:02 +00:00
|
|
|
Cvar_SetValue (deathmatch, 0.0);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
Host_InitLocal (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
Host_InitCommands ();
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
host_framerate =
|
2001-04-10 23:39:30 +00:00
|
|
|
Cvar_Get ("host_framerate", "0", CVAR_NONE, NULL,
|
|
|
|
"set for slow motion");
|
2001-02-26 06:48:02 +00:00
|
|
|
host_speeds =
|
2001-04-10 23:39:30 +00:00
|
|
|
Cvar_Get ("host_speeds", "0", CVAR_NONE, NULL,
|
|
|
|
"set for running times");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-04-10 23:39:30 +00:00
|
|
|
sys_ticrate = Cvar_Get ("sys_ticrate", "0.05", CVAR_NONE, NULL, "None");
|
|
|
|
serverprofile = Cvar_Get ("serverprofile", "0", CVAR_NONE, NULL, "None");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-09-06 23:58:28 +00:00
|
|
|
cl_quakerc = Cvar_Get ("cl_quakerc", "1", CVAR_NONE, NULL,
|
|
|
|
"exec quake.rc on startup");
|
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
fraglimit = Cvar_Get ("fraglimit", "0", CVAR_SERVERINFO, Cvar_Info,
|
|
|
|
"None");
|
|
|
|
timelimit = Cvar_Get ("timelimit", "0", CVAR_SERVERINFO, Cvar_Info,
|
|
|
|
"None");
|
2001-03-31 01:02:52 +00:00
|
|
|
teamplay = Cvar_Get ("teamplay", "0", CVAR_SERVERINFO, Cvar_Info, "None");
|
2001-04-10 23:39:30 +00:00
|
|
|
samelevel = Cvar_Get ("samelevel", "0", CVAR_NONE, NULL, "None");
|
2001-03-31 01:02:52 +00:00
|
|
|
noexit = Cvar_Get ("noexit", "0", CVAR_SERVERINFO, Cvar_Info, "None");
|
2001-04-10 23:39:30 +00:00
|
|
|
skill = Cvar_Get ("skill", "1", CVAR_NONE, NULL, "0 - 3");
|
|
|
|
deathmatch = Cvar_Get ("deathmatch", "0", CVAR_NONE, NULL, "0, 1, or 2");
|
|
|
|
coop = Cvar_Get ("coop", "0", CVAR_NONE, NULL, "0 or 1");
|
|
|
|
pausable = Cvar_Get ("pausable", "1", CVAR_NONE, NULL, "None");
|
|
|
|
temp1 = Cvar_Get ("temp1", "0", CVAR_NONE, NULL, "None");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Host_FindMaxClients ();
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-05-19 20:57:29 +00:00
|
|
|
host_time = 1.0; // so a think at time 0 won't get called
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-05-09 17:12:49 +00:00
|
|
|
Host_WriteConfiguration
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-09 17:12:49 +00:00
|
|
|
Writes key bindings and archived cvars to config.cfg
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
Host_WriteConfiguration (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-08-27 07:16:28 +00:00
|
|
|
QFile *f;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// dedicated servers initialize the host but don't parse and set the
|
|
|
|
// config.cfg cvars
|
2002-02-19 20:47:45 +00:00
|
|
|
if (host_initialized && !isDedicated && cl_writecfg->int_val) {
|
2003-02-14 22:36:10 +00:00
|
|
|
char *path = va ("%s/config.cfg", qfs_gamedir->dir.def);
|
|
|
|
f = QFS_WOpen (path, 0);
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!f) {
|
2001-02-19 21:15:25 +00:00
|
|
|
Con_Printf ("Couldn't write config.cfg.\n");
|
|
|
|
return;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
Key_WriteBindings (f);
|
|
|
|
Cvar_WriteVariables (f);
|
|
|
|
|
|
|
|
Qclose (f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-05-09 17:12:49 +00:00
|
|
|
SV_ClientPrintf
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-09 17:12:49 +00:00
|
|
|
Sends text across to be displayed
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2001-07-15 07:04:17 +00:00
|
|
|
SV_ClientPrintf (const char *fmt, ...)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2003-07-08 22:39:45 +00:00
|
|
|
static dstring_t *str;
|
2001-08-29 02:12:57 +00:00
|
|
|
va_list argptr;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2003-07-08 22:39:45 +00:00
|
|
|
if (!str)
|
|
|
|
str = dstring_new ();
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
va_start (argptr, fmt);
|
2003-07-08 22:39:45 +00:00
|
|
|
dvsprintf (str, fmt, argptr);
|
2001-02-19 21:15:25 +00:00
|
|
|
va_end (argptr);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
MSG_WriteByte (&host_client->message, svc_print);
|
2003-07-08 22:39:45 +00:00
|
|
|
MSG_WriteString (&host_client->message, str->str);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-05-09 17:12:49 +00:00
|
|
|
SV_BroadcastPrintf
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-09 17:12:49 +00:00
|
|
|
Sends text to all active clients
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2001-07-15 07:04:17 +00:00
|
|
|
SV_BroadcastPrintf (const char *fmt, ...)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2003-07-08 22:39:45 +00:00
|
|
|
static dstring_t *str;
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
2001-08-29 02:12:57 +00:00
|
|
|
va_list argptr;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2003-07-08 22:39:45 +00:00
|
|
|
if (!str)
|
|
|
|
str = dstring_new ();
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
va_start (argptr, fmt);
|
2003-07-08 22:39:45 +00:00
|
|
|
dvsprintf (str, fmt, argptr);
|
2001-02-19 21:15:25 +00:00
|
|
|
va_end (argptr);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
for (i = 0; i < svs.maxclients; i++)
|
|
|
|
if (svs.clients[i].active && svs.clients[i].spawned) {
|
2001-02-19 21:15:25 +00:00
|
|
|
MSG_WriteByte (&svs.clients[i].message, svc_print);
|
2003-07-08 22:39:45 +00:00
|
|
|
MSG_WriteString (&svs.clients[i].message, str->str);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-05-09 17:12:49 +00:00
|
|
|
Host_ClientCommands
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-09 17:12:49 +00:00
|
|
|
Send text over to the client to be executed
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2001-07-15 07:04:17 +00:00
|
|
|
Host_ClientCommands (const char *fmt, ...)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2003-07-08 22:39:45 +00:00
|
|
|
static dstring_t *str;
|
2001-08-29 02:12:57 +00:00
|
|
|
va_list argptr;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2003-07-08 22:39:45 +00:00
|
|
|
if (!str)
|
|
|
|
str = dstring_new ();
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
va_start (argptr, fmt);
|
2003-07-08 22:39:45 +00:00
|
|
|
dvsprintf (str, fmt, argptr);
|
2001-02-19 21:15:25 +00:00
|
|
|
va_end (argptr);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
MSG_WriteByte (&host_client->message, svc_stufftext);
|
2003-07-08 22:39:45 +00:00
|
|
|
MSG_WriteString (&host_client->message, str->str);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-05-09 17:12:49 +00:00
|
|
|
SV_DropClient
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-09 17:12:49 +00:00
|
|
|
Called when the player is getting totally kicked off the host
|
|
|
|
if (crash = true), don't bother sending signofs
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
SV_DropClient (qboolean crash)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
client_t *client;
|
2001-08-29 02:12:57 +00:00
|
|
|
int saveSelf, i;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!crash) {
|
2001-02-19 21:15:25 +00:00
|
|
|
// send any final messages (don't check for errors)
|
2001-02-26 06:48:02 +00:00
|
|
|
if (NET_CanSendMessage (host_client->netconnection)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
MSG_WriteByte (&host_client->message, svc_disconnect);
|
2001-08-29 02:12:57 +00:00
|
|
|
NET_SendMessage (host_client->netconnection,
|
|
|
|
&host_client->message);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
if (host_client->edict && host_client->spawned) {
|
|
|
|
// call the prog function for removing a client
|
|
|
|
// this will set the body to a dead frame, among other things
|
2001-03-03 08:31:58 +00:00
|
|
|
saveSelf = *sv_globals.self;
|
|
|
|
*sv_globals.self =
|
2001-02-26 20:52:14 +00:00
|
|
|
EDICT_TO_PROG (&sv_pr_state, host_client->edict);
|
2002-05-31 21:05:58 +00:00
|
|
|
PR_ExecuteProgram (&sv_pr_state, sv_funcs.ClientDisconnect);
|
2001-03-03 08:31:58 +00:00
|
|
|
*sv_globals.self = saveSelf;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-09-21 03:01:14 +00:00
|
|
|
Con_Printf ("Client %s removed\n", host_client->name);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-08-29 02:12:57 +00:00
|
|
|
// break the net connection
|
2001-02-19 21:15:25 +00:00
|
|
|
NET_Close (host_client->netconnection);
|
|
|
|
host_client->netconnection = NULL;
|
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// free the client (the body stays around)
|
2001-02-19 21:15:25 +00:00
|
|
|
host_client->active = false;
|
|
|
|
host_client->name[0] = 0;
|
|
|
|
host_client->old_frags = -999999;
|
|
|
|
net_activeconnections--;
|
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// send notification to all clients
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0, client = svs.clients; i < svs.maxclients; i++, client++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!client->active)
|
|
|
|
continue;
|
|
|
|
MSG_WriteByte (&client->message, svc_updatename);
|
|
|
|
MSG_WriteByte (&client->message, host_client - svs.clients);
|
|
|
|
MSG_WriteString (&client->message, "");
|
|
|
|
MSG_WriteByte (&client->message, svc_updatefrags);
|
|
|
|
MSG_WriteByte (&client->message, host_client - svs.clients);
|
|
|
|
MSG_WriteShort (&client->message, 0);
|
|
|
|
MSG_WriteByte (&client->message, svc_updatecolors);
|
|
|
|
MSG_WriteByte (&client->message, host_client - svs.clients);
|
|
|
|
MSG_WriteByte (&client->message, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-05-09 17:12:49 +00:00
|
|
|
Host_ShutdownServer
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-09 17:12:49 +00:00
|
|
|
This only happens at the end of a game, not between levels
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Host_ShutdownServer (qboolean crash)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
char message[4];
|
|
|
|
double start;
|
2001-08-29 02:12:57 +00:00
|
|
|
int count, i;
|
|
|
|
sizebuf_t buf;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!sv.active)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sv.active = false;
|
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// stop all client sounds immediately
|
2001-02-19 21:15:25 +00:00
|
|
|
if (cls.state == ca_connected)
|
|
|
|
CL_Disconnect ();
|
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// flush any pending messages - like the score!!!
|
2001-02-26 06:48:02 +00:00
|
|
|
start = Sys_DoubleTime ();
|
|
|
|
do {
|
2001-02-19 21:15:25 +00:00
|
|
|
count = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0, host_client = svs.clients; i < svs.maxclients;
|
|
|
|
i++, host_client++) {
|
|
|
|
if (host_client->active && host_client->message.cursize) {
|
|
|
|
if (NET_CanSendMessage (host_client->netconnection)) {
|
|
|
|
NET_SendMessage (host_client->netconnection,
|
|
|
|
&host_client->message);
|
2001-02-19 21:15:25 +00:00
|
|
|
SZ_Clear (&host_client->message);
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
|
|
|
NET_GetMessage (host_client->netconnection);
|
2001-02-19 21:15:25 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((Sys_DoubleTime () - start) > 3.0)
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
while (count);
|
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// make sure all the clients know we're disconnecting
|
2001-02-19 21:15:25 +00:00
|
|
|
buf.data = message;
|
|
|
|
buf.maxsize = 4;
|
|
|
|
buf.cursize = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
MSG_WriteByte (&buf, svc_disconnect);
|
|
|
|
count = NET_SendToAll (&buf, 5);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (count)
|
2001-02-26 06:48:02 +00:00
|
|
|
Con_Printf
|
|
|
|
("Host_ShutdownServer: NET_SendToAll failed for %u clients\n",
|
|
|
|
count);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0, host_client = svs.clients; i < svs.maxclients;
|
|
|
|
i++, host_client++)
|
2001-02-19 21:15:25 +00:00
|
|
|
if (host_client->active)
|
2001-02-26 06:48:02 +00:00
|
|
|
SV_DropClient (crash);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// clear structures
|
2001-02-26 06:48:02 +00:00
|
|
|
memset (&sv, 0, sizeof (sv));
|
|
|
|
memset (svs.clients, 0, svs.maxclientslimit * sizeof (client_t));
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-05-09 17:12:49 +00:00
|
|
|
Host_ClearMemory
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-09 17:12:49 +00:00
|
|
|
This clears all the memory used by both the client and server, but does
|
|
|
|
not reinitialize anything.
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Host_ClearMemory (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
Con_DPrintf ("Clearing memory\n");
|
|
|
|
D_FlushCaches ();
|
|
|
|
Mod_ClearAll ();
|
|
|
|
if (host_hunklevel)
|
|
|
|
Hunk_FreeToLowMark (host_hunklevel);
|
|
|
|
|
|
|
|
cls.signon = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
memset (&sv, 0, sizeof (sv));
|
|
|
|
memset (&cl, 0, sizeof (cl));
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-05-09 17:12:49 +00:00
|
|
|
Host_FilterTime
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-09 17:12:49 +00:00
|
|
|
Returns false if the time is too short to run a frame
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static qboolean
|
2001-02-26 06:48:02 +00:00
|
|
|
Host_FilterTime (float time)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-05-07 04:32:28 +00:00
|
|
|
float timedifference;
|
2001-09-06 04:35:02 +00:00
|
|
|
float timescale = 1.0;
|
|
|
|
|
2003-07-25 22:21:47 +00:00
|
|
|
con_realtime += time;
|
|
|
|
|
2001-09-06 04:35:02 +00:00
|
|
|
if (cls.demoplayback) {
|
2002-06-08 23:22:26 +00:00
|
|
|
timescale = max (0, demo_speed->value);
|
2001-09-06 04:35:02 +00:00
|
|
|
time *= timescale;
|
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
realtime += time;
|
|
|
|
|
2002-05-07 04:32:28 +00:00
|
|
|
//FIXME not having the framerate cap is nice, but it breaks net play
|
|
|
|
timedifference = (timescale / 72.0) - (realtime - oldrealtime);
|
|
|
|
|
|
|
|
if (!cls.timedemo && (timedifference > 0))
|
|
|
|
return false; // framerate is too high
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
host_frametime = realtime - oldrealtime;
|
|
|
|
oldrealtime = realtime;
|
|
|
|
|
2003-07-25 22:21:47 +00:00
|
|
|
con_frametime = con_realtime - oldcon_realtime;
|
|
|
|
oldcon_realtime = con_realtime;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (host_framerate->value > 0)
|
|
|
|
host_frametime = host_framerate->value;
|
2002-04-25 16:50:56 +00:00
|
|
|
else // don't allow really long or short frames
|
|
|
|
host_frametime = bound (0.001, host_frametime, 0.1);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Host_ServerFrame (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-03-03 08:31:58 +00:00
|
|
|
*sv_globals.frametime = host_frametime;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// set the time and clear the general datagram
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_ClearDatagram ();
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_CheckForNewClients ();
|
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// read client messages
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_RunClients ();
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// move things around and think
|
|
|
|
// always pause in single player if in console or menus
|
2002-02-25 22:57:17 +00:00
|
|
|
if (!sv.paused && (svs.maxclients > 1 || key_dest == key_game)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_Physics ();
|
2002-02-25 22:57:17 +00:00
|
|
|
sv.time += host_frametime;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// send all messages to the clients
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_SendClientMessages ();
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2003-08-16 05:29:02 +00:00
|
|
|
Host_ClientFrame (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-08-29 02:12:57 +00:00
|
|
|
static double time1 = 0, time2 = 0, time3 = 0;
|
2003-08-16 05:29:02 +00:00
|
|
|
int pass1, pass2, pass3;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// if running the server remotely, send intentions now after
|
|
|
|
// the incoming messages have been read
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!sv.active)
|
|
|
|
CL_SendCmd ();
|
|
|
|
|
|
|
|
host_time += host_frametime;
|
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// fetch results from server
|
2003-08-16 05:29:02 +00:00
|
|
|
if (cls.state == ca_connected)
|
2001-02-19 21:15:25 +00:00
|
|
|
CL_ReadFromServer ();
|
2003-08-16 05:29:02 +00:00
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// update video
|
2001-02-19 21:15:25 +00:00
|
|
|
if (host_speeds->int_val)
|
|
|
|
time1 = Sys_DoubleTime ();
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-05-20 20:38:51 +00:00
|
|
|
r_inhibit_viewmodel = (chase_active->int_val
|
|
|
|
|| (cl.stats[STAT_ITEMS] & IT_INVISIBILITY)
|
|
|
|
|| cl.stats[STAT_HEALTH] <= 0);
|
|
|
|
r_force_fullscreen = cl.intermission;
|
2001-05-21 00:22:35 +00:00
|
|
|
r_paused = cl.paused;
|
2001-05-23 04:05:10 +00:00
|
|
|
r_active = cls.state == ca_active;
|
2001-05-20 20:38:51 +00:00
|
|
|
r_view_model = &cl.viewent;
|
2001-05-24 19:22:35 +00:00
|
|
|
r_frametime = host_frametime;
|
2001-05-20 20:38:51 +00:00
|
|
|
|
2001-05-23 06:33:23 +00:00
|
|
|
CL_UpdateScreen (cl.time);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (host_speeds->int_val)
|
|
|
|
time2 = Sys_DoubleTime ();
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-08-29 02:12:57 +00:00
|
|
|
// update audio
|
2001-02-26 06:48:02 +00:00
|
|
|
if (cls.signon == SIGNONS) {
|
2001-02-19 21:15:25 +00:00
|
|
|
S_Update (r_origin, vpn, vright, vup);
|
2001-05-20 06:23:46 +00:00
|
|
|
R_DecayLights (host_frametime);
|
2001-02-26 06:48:02 +00:00
|
|
|
} else
|
2001-02-19 21:15:25 +00:00
|
|
|
S_Update (vec3_origin, vec3_origin, vec3_origin, vec3_origin);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
CDAudio_Update ();
|
|
|
|
|
|
|
|
if (host_speeds->int_val) {
|
|
|
|
pass1 = (time1 - time3) * 1000;
|
2001-02-19 21:15:25 +00:00
|
|
|
time3 = Sys_DoubleTime ();
|
2001-02-26 06:48:02 +00:00
|
|
|
pass2 = (time2 - time1) * 1000;
|
|
|
|
pass3 = (time3 - time2) * 1000;
|
2001-02-19 21:15:25 +00:00
|
|
|
Con_Printf ("%3i tot %3i server %3i gfx %3i snd\n",
|
2001-02-26 06:48:02 +00:00
|
|
|
pass1 + pass2 + pass3, pass1, pass2, pass3);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2003-08-16 05:29:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Host_Frame
|
|
|
|
|
|
|
|
Runs all active servers
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
_Host_Frame (float time)
|
|
|
|
{
|
2004-01-27 06:02:41 +00:00
|
|
|
static int first = 1;
|
|
|
|
|
2003-08-16 05:29:02 +00:00
|
|
|
if (setjmp (host_abortserver))
|
|
|
|
return; // something bad happened, or the
|
|
|
|
// server disconnected
|
|
|
|
|
|
|
|
rand (); // keep the random time dependent
|
|
|
|
|
|
|
|
// decide the simulation time
|
|
|
|
if (!Host_FilterTime (time))
|
|
|
|
return; // don't run too fast, or packets
|
|
|
|
// will flood out
|
|
|
|
|
|
|
|
if (cls.state != ca_dedicated)
|
|
|
|
IN_ProcessEvents ();
|
|
|
|
|
|
|
|
if (cls.state == ca_dedicated)
|
|
|
|
Con_ProcessInput ();
|
|
|
|
|
|
|
|
GIB_Thread_Execute ();
|
|
|
|
cmd_source = src_command;
|
|
|
|
Cbuf_Execute_Stack (host_cbuf);
|
|
|
|
|
2004-01-27 06:02:41 +00:00
|
|
|
if (first) {
|
|
|
|
first = 0;
|
|
|
|
|
|
|
|
if (isDedicated) {
|
|
|
|
if (!sv.active)
|
|
|
|
Cmd_ExecuteString ("map start", src_command);
|
|
|
|
if (!sv.active)
|
|
|
|
Sys_Error ("Could not initialize server");
|
|
|
|
} else {
|
|
|
|
Con_NewMap ();
|
|
|
|
}
|
|
|
|
|
|
|
|
CL_UpdateScreen (cl.time);
|
|
|
|
}
|
|
|
|
|
2003-08-16 05:29:02 +00:00
|
|
|
NET_Poll ();
|
|
|
|
|
|
|
|
if (sv.active) {
|
|
|
|
CL_SendCmd ();
|
|
|
|
Host_ServerFrame ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cls.state != ca_dedicated)
|
|
|
|
Host_ClientFrame ();
|
|
|
|
else
|
|
|
|
host_time += host_frametime; //FIXME is this needed? vcr stuff
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
host_framecount++;
|
|
|
|
fps_count++;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Host_Frame (float time)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-08-29 02:12:57 +00:00
|
|
|
double time1, time2;
|
2001-02-26 06:48:02 +00:00
|
|
|
static double timetotal;
|
2001-08-29 02:12:57 +00:00
|
|
|
int i, c, m;
|
|
|
|
static int timecount;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!serverprofile->int_val) {
|
2001-02-19 21:15:25 +00:00
|
|
|
_Host_Frame (time);
|
|
|
|
return;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
time1 = Sys_DoubleTime ();
|
|
|
|
_Host_Frame (time);
|
2001-02-26 06:48:02 +00:00
|
|
|
time2 = Sys_DoubleTime ();
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
timetotal += time2 - time1;
|
|
|
|
timecount++;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (timecount < 1000)
|
|
|
|
return;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
m = timetotal * 1000 / timecount;
|
2001-02-19 21:15:25 +00:00
|
|
|
timecount = 0;
|
|
|
|
timetotal = 0;
|
|
|
|
c = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < svs.maxclients; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (svs.clients[i].active)
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
Con_Printf ("serverprofile: %2i clients %2i msec\n", c, m);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#define VCR_SIGNATURE 0x56435231
|
|
|
|
// "VCR1"
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
Host_InitVCR (quakeparms_t *parms)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
char *p;
|
2001-08-29 02:12:57 +00:00
|
|
|
int i, len, n;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
if (COM_CheckParm ("-playback")) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (com_argc != 2)
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("No other parameters allowed with -playback");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-05-23 17:17:01 +00:00
|
|
|
vcrFile = QFS_Open ("quake.vcr", "rbz");
|
2001-03-30 23:24:57 +00:00
|
|
|
if (!vcrFile)
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("playback file not found");
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-03-30 23:24:57 +00:00
|
|
|
Qread (vcrFile, &i, sizeof (int));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (i != VCR_SIGNATURE)
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("Invalid signature in vcr file");
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-03-30 23:24:57 +00:00
|
|
|
Qread (vcrFile, &com_argc, sizeof (int));
|
2001-02-26 06:48:02 +00:00
|
|
|
com_argv = malloc (com_argc * sizeof (char *));
|
2002-05-14 06:37:28 +00:00
|
|
|
SYS_CHECKMEM (com_argv);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
com_argv[0] = parms->argv[0];
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < com_argc; i++) {
|
2001-03-30 23:24:57 +00:00
|
|
|
Qread (vcrFile, &len, sizeof (int));
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
p = malloc (len);
|
2002-05-14 06:37:28 +00:00
|
|
|
SYS_CHECKMEM (p);
|
2001-03-30 23:24:57 +00:00
|
|
|
Qread (vcrFile, p, len);
|
2001-02-26 06:48:02 +00:00
|
|
|
com_argv[i + 1] = p;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
com_argc++; /* add one for arg[0] */
|
2001-02-19 21:15:25 +00:00
|
|
|
parms->argc = com_argc;
|
|
|
|
parms->argv = com_argv;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((n = COM_CheckParm ("-record")) != 0) {
|
2003-05-23 17:17:01 +00:00
|
|
|
vcrFile = QFS_Open ("quake.vcr", "wb");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
i = VCR_SIGNATURE;
|
2001-03-30 23:24:57 +00:00
|
|
|
Qwrite (vcrFile, &i, sizeof (int));
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
i = com_argc - 1;
|
2001-03-30 23:24:57 +00:00
|
|
|
Qwrite (vcrFile, &i, sizeof (int));
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
for (i = 1; i < com_argc; i++) {
|
|
|
|
if (i == n) {
|
2001-02-19 21:15:25 +00:00
|
|
|
len = 10;
|
2001-03-30 23:24:57 +00:00
|
|
|
Qwrite (vcrFile, &len, sizeof (int));
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-03-30 23:24:57 +00:00
|
|
|
Qwrite (vcrFile, "-playback", len);
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
len = strlen (com_argv[i]) + 1;
|
2001-03-30 23:24:57 +00:00
|
|
|
Qwrite (vcrFile, &len, sizeof (int));
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-03-30 23:24:57 +00:00
|
|
|
Qwrite (vcrFile, com_argv[i], len);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-05-17 07:53:22 +00:00
|
|
|
static int
|
|
|
|
check_quakerc (void)
|
|
|
|
{
|
2001-07-15 07:04:17 +00:00
|
|
|
const char *l, *p;
|
2001-05-17 07:53:22 +00:00
|
|
|
int ret = 1;
|
2002-08-27 07:16:28 +00:00
|
|
|
QFile *f;
|
2001-05-17 07:53:22 +00:00
|
|
|
|
2003-02-14 19:46:07 +00:00
|
|
|
QFS_FOpenFile ("quake.rc", &f);
|
2001-05-17 07:53:22 +00:00
|
|
|
if (!f)
|
|
|
|
return 1;
|
|
|
|
while ((l = Qgetline (f))) {
|
|
|
|
if ((p = strstr (l, "stuffcmds"))) {
|
|
|
|
if (p == l) { // only known case so far
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Qclose (f);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-02-19 20:47:45 +00:00
|
|
|
CL_Init_Memory (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-02-19 20:47:45 +00:00
|
|
|
int mem_parm = COM_CheckParm ("-mem");
|
|
|
|
int mem_size;
|
|
|
|
void *mem_base;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (standard_quake)
|
|
|
|
minimum_memory = MINIMUM_MEMORY;
|
|
|
|
else
|
|
|
|
minimum_memory = MINIMUM_MEMORY_LEVELPAK;
|
|
|
|
|
2002-02-19 20:47:45 +00:00
|
|
|
host_mem_size = Cvar_Get ("host_mem_size", "16", CVAR_NONE, NULL,
|
|
|
|
"Amount of memory (in MB) to allocate for the "
|
|
|
|
PROGRAM " heap");
|
|
|
|
if (mem_parm)
|
|
|
|
Cvar_Set (host_mem_size, com_argv[mem_parm + 1]);
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (COM_CheckParm ("-minmemory"))
|
2002-02-19 20:47:45 +00:00
|
|
|
Cvar_SetValue (host_mem_size, minimum_memory / (1024 * 1024.0));
|
|
|
|
|
|
|
|
Cvar_SetFlags (host_mem_size, host_mem_size->flags | CVAR_ROM);
|
|
|
|
|
|
|
|
mem_size = (int) (host_mem_size->value * 1024 * 1024);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-02-19 20:47:45 +00:00
|
|
|
if (mem_size < minimum_memory)
|
|
|
|
Sys_Error ("Only %4.1f megs of memory reported, can't execute game",
|
|
|
|
mem_size / (float) 0x100000);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-02-19 20:47:45 +00:00
|
|
|
mem_base = malloc (mem_size);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-02-19 20:47:45 +00:00
|
|
|
if (!mem_base)
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("Can't allocate %d", mem_size);
|
2002-02-19 20:47:45 +00:00
|
|
|
|
|
|
|
Sys_PageIn (mem_base, mem_size);
|
|
|
|
Memory_Init (mem_base, mem_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Host_Init (void)
|
|
|
|
{
|
2005-02-14 09:08:32 +00:00
|
|
|
const char *mp;
|
|
|
|
|
2002-02-19 20:47:45 +00:00
|
|
|
Con_Printf ("Host_Init\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-08-03 06:04:00 +00:00
|
|
|
host_cbuf = Cbuf_New (&id_interp);
|
2002-07-31 05:19:03 +00:00
|
|
|
cmd_source = src_command;
|
|
|
|
|
2001-02-22 08:12:13 +00:00
|
|
|
Cvar_Init_Hash ();
|
|
|
|
Cmd_Init_Hash ();
|
2001-02-19 21:15:25 +00:00
|
|
|
Cvar_Init ();
|
2002-01-17 04:11:36 +00:00
|
|
|
Sys_Init_Cvars ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-08-20 23:04:57 +00:00
|
|
|
Sys_Init ();
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
Cmd_Init ();
|
2002-11-14 05:28:54 +00:00
|
|
|
GIB_Init (true);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// execute +set as early as possible
|
2002-07-31 05:19:03 +00:00
|
|
|
Cmd_StuffCmds (host_cbuf);
|
|
|
|
Cbuf_Execute_Sets (host_cbuf);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// execute the global configuration file if it exists
|
|
|
|
// would have been nice if Cmd_Exec_f could have been used, but it
|
|
|
|
// only reads from within the quake file system, and changing that is
|
|
|
|
// probably Not A Good Thing (tm).
|
2001-02-26 06:48:02 +00:00
|
|
|
fs_globalcfg = Cvar_Get ("fs_globalcfg", FS_GLOBALCFG,
|
2001-04-10 23:39:30 +00:00
|
|
|
CVAR_ROM, NULL, "global configuration file");
|
2002-11-08 16:39:28 +00:00
|
|
|
Cmd_Exec_File (host_cbuf, fs_globalcfg->string, 0);
|
2002-07-31 05:19:03 +00:00
|
|
|
Cbuf_Execute_Sets (host_cbuf);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-17 07:53:22 +00:00
|
|
|
// execute +set again to override the config file
|
2002-07-31 05:19:03 +00:00
|
|
|
Cmd_StuffCmds (host_cbuf);
|
|
|
|
Cbuf_Execute_Sets (host_cbuf);
|
2001-05-17 07:53:22 +00:00
|
|
|
|
|
|
|
fs_usercfg = Cvar_Get ("fs_usercfg", FS_USERCFG, CVAR_ROM, NULL,
|
|
|
|
"user configuration file");
|
2002-11-08 16:39:28 +00:00
|
|
|
Cmd_Exec_File (host_cbuf, fs_usercfg->string, 0);
|
2002-07-31 05:19:03 +00:00
|
|
|
Cbuf_Execute_Sets (host_cbuf);
|
2001-05-17 07:53:22 +00:00
|
|
|
|
|
|
|
// execute +set again to override the config file
|
2002-07-31 05:19:03 +00:00
|
|
|
Cmd_StuffCmds (host_cbuf);
|
|
|
|
Cbuf_Execute_Sets (host_cbuf);
|
2001-05-17 07:53:22 +00:00
|
|
|
|
2002-02-19 20:47:45 +00:00
|
|
|
CL_Init_Memory ();
|
2002-01-17 04:29:41 +00:00
|
|
|
|
2002-01-20 03:09:03 +00:00
|
|
|
pr_gametype = "netquake";
|
|
|
|
|
2005-02-14 09:08:32 +00:00
|
|
|
mp = Game_Init ();
|
|
|
|
QFS_Init (mp);
|
2002-01-17 04:11:36 +00:00
|
|
|
PI_Init ();
|
|
|
|
|
2001-05-19 22:26:06 +00:00
|
|
|
Chase_Init_Cvars ();
|
2001-05-16 06:01:34 +00:00
|
|
|
CL_InitCvars ();
|
2001-02-26 06:48:02 +00:00
|
|
|
IN_Init_Cvars ();
|
2001-02-19 21:15:25 +00:00
|
|
|
VID_Init_Cvars ();
|
2001-05-11 02:03:02 +00:00
|
|
|
S_Init_Cvars ();
|
|
|
|
Key_Init_Cvars ();
|
|
|
|
Con_Init_Cvars ();
|
|
|
|
PR_Init_Cvars ();
|
|
|
|
SV_Progs_Init_Cvars ();
|
2001-05-11 19:21:48 +00:00
|
|
|
R_Init_Cvars ();
|
2001-05-11 02:03:02 +00:00
|
|
|
R_Particles_Init_Cvars ();
|
|
|
|
Mod_Init_Cvars ();
|
2001-05-16 06:01:34 +00:00
|
|
|
Host_Skin_Init_Cvars ();
|
2001-05-20 00:34:40 +00:00
|
|
|
V_Init_Cvars ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-01-18 19:19:33 +00:00
|
|
|
PR_Init ();
|
|
|
|
|
2002-01-17 04:11:36 +00:00
|
|
|
V_Init ();
|
|
|
|
COM_Init ();
|
2001-04-25 00:20:23 +00:00
|
|
|
|
2003-12-19 03:41:58 +00:00
|
|
|
if (isDedicated) {
|
|
|
|
PI_RegisterPlugins (server_plugin_list);
|
2001-10-03 21:25:43 +00:00
|
|
|
Con_Init ("server");
|
2003-12-19 03:41:58 +00:00
|
|
|
} else {
|
|
|
|
PI_RegisterPlugins (client_plugin_list);
|
2001-10-03 21:25:43 +00:00
|
|
|
Con_Init ("client");
|
2003-12-19 03:41:58 +00:00
|
|
|
}
|
2002-01-16 21:53:42 +00:00
|
|
|
if (con_module) {
|
2003-07-25 22:21:47 +00:00
|
|
|
con_module->data->console->realtime = &con_realtime;
|
|
|
|
con_module->data->console->frametime = &con_frametime;
|
2002-01-20 00:04:50 +00:00
|
|
|
con_module->data->console->quit = Host_Quit_f;
|
2002-07-31 05:19:03 +00:00
|
|
|
con_module->data->console->cbuf = host_cbuf;
|
2002-01-16 21:53:42 +00:00
|
|
|
}
|
2001-10-03 21:25:43 +00:00
|
|
|
|
2002-02-19 20:47:45 +00:00
|
|
|
Host_InitVCR (&host_parms);
|
2001-02-19 21:15:25 +00:00
|
|
|
Host_InitLocal ();
|
2002-01-17 04:11:36 +00:00
|
|
|
|
2002-01-17 19:10:07 +00:00
|
|
|
NET_Init ();
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
W_LoadWadFile ("gfx.wad");
|
2002-08-19 02:48:38 +00:00
|
|
|
Key_Init (host_cbuf);
|
2002-01-17 04:11:36 +00:00
|
|
|
Mod_Init ();
|
2002-04-11 18:42:55 +00:00
|
|
|
|
2002-06-08 23:22:26 +00:00
|
|
|
CL_Demo_Init ();
|
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
SV_Progs_Init ();
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_Init ();
|
|
|
|
|
2002-02-19 20:47:45 +00:00
|
|
|
Con_Printf ("%4.1f megabyte heap\n", host_mem_size->value);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
if (cls.state != ca_dedicated) {
|
2003-02-14 19:46:07 +00:00
|
|
|
host_basepal = (byte *) QFS_LoadHunkFile ("gfx/palette.lmp");
|
2002-09-10 03:51:10 +00:00
|
|
|
if (!host_basepal)
|
2001-02-19 21:15:25 +00:00
|
|
|
Sys_Error ("Couldn't load gfx/palette.lmp");
|
2003-02-14 19:46:07 +00:00
|
|
|
vid_colormap = (byte *) QFS_LoadHunkFile ("gfx/colormap.lmp");
|
2001-04-16 20:38:51 +00:00
|
|
|
if (!vid_colormap)
|
2001-02-19 21:15:25 +00:00
|
|
|
Sys_Error ("Couldn't load gfx/colormap.lmp");
|
|
|
|
|
2002-09-10 03:51:10 +00:00
|
|
|
VID_Init (host_basepal);
|
2001-02-19 21:15:25 +00:00
|
|
|
Draw_Init ();
|
|
|
|
SCR_Init ();
|
|
|
|
R_Init ();
|
|
|
|
|
2001-10-28 04:23:37 +00:00
|
|
|
S_Init (&cl.worldmodel, &viewentity, &host_frametime);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
CDAudio_Init ();
|
|
|
|
Sbar_Init ();
|
|
|
|
CL_Init ();
|
2002-01-17 04:11:36 +00:00
|
|
|
IN_Init ();
|
|
|
|
|
2001-10-03 17:25:21 +00:00
|
|
|
CL_SetState (ca_disconnected);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2002-01-03 06:26:57 +00:00
|
|
|
Host_Skin_Init ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-10-11 03:40:41 +00:00
|
|
|
CL_UpdateScreen (cl.time);
|
|
|
|
CL_UpdateScreen (cl.time);
|
|
|
|
|
2001-10-03 21:25:43 +00:00
|
|
|
if (!isDedicated && cl_quakerc->int_val)
|
2002-07-31 05:19:03 +00:00
|
|
|
Cbuf_InsertText (host_cbuf, "exec quake.rc\n");
|
2002-11-08 16:39:28 +00:00
|
|
|
Cmd_Exec_File (host_cbuf, fs_usercfg->string, 0);
|
2001-05-17 07:53:22 +00:00
|
|
|
// reparse the command line for + commands other than set
|
|
|
|
// (sets still done, but it doesn't matter)
|
2001-10-05 19:21:23 +00:00
|
|
|
if (isDedicated || (cl_quakerc->int_val && check_quakerc ()))
|
2002-07-31 05:19:03 +00:00
|
|
|
Cmd_StuffCmds (host_cbuf);
|
2001-05-17 07:53:22 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
Hunk_AllocName (0, "-HOST_HUNKLEVEL-");
|
|
|
|
host_hunklevel = Hunk_LowMark ();
|
|
|
|
|
2002-04-11 18:42:55 +00:00
|
|
|
Con_Printf ("\nVersion %s (build %04d)\n\n", VERSION,
|
|
|
|
build_number ());
|
|
|
|
|
2004-02-06 01:23:05 +00:00
|
|
|
Con_Printf ("\x80\x81\x81\x82 %s initialized \x80\x81\x81\x82\n", PROGRAM);
|
2004-01-07 06:29:34 +00:00
|
|
|
|
|
|
|
host_initialized = true;
|
|
|
|
|
2001-05-23 06:33:23 +00:00
|
|
|
CL_UpdateScreen (cl.time);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-05-09 17:12:49 +00:00
|
|
|
Host_Shutdown
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-09 17:12:49 +00:00
|
|
|
FIXME: this is a callback from Sys_Quit and Sys_Error. It would be
|
|
|
|
better to run quit through here before final handoff to the sys code.
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Host_Shutdown (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
static qboolean isdown = false;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
if (isdown) {
|
2001-02-19 21:15:25 +00:00
|
|
|
printf ("recursive shutdown\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isdown = true;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
Host_WriteConfiguration ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
NET_Shutdown ();
|
2001-02-26 06:48:02 +00:00
|
|
|
if (cls.state != ca_dedicated) {
|
2001-10-03 17:25:21 +00:00
|
|
|
CDAudio_Shutdown ();
|
|
|
|
S_Shutdown ();
|
|
|
|
IN_Shutdown ();
|
2001-02-26 06:48:02 +00:00
|
|
|
VID_Shutdown ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-10-03 21:37:20 +00:00
|
|
|
Con_Shutdown ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|