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
|
|
|
|
|
2010-11-29 10:50:59 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include "unistd.h"
|
|
|
|
#endif
|
|
|
|
|
2002-07-31 05:19:03 +00:00
|
|
|
#include "QF/cbuf.h"
|
2001-04-10 21:45:42 +00:00
|
|
|
#include "QF/cdaudio.h"
|
2011-12-22 06:44:28 +00:00
|
|
|
#include "QF/draw.h"
|
|
|
|
#include "QF/idparse.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"
|
2012-01-05 10:19:37 +00:00
|
|
|
#include "QF/image.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"
|
2012-01-05 10:19:37 +00:00
|
|
|
#include "QF/png.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"
|
2012-01-05 10:19:37 +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
|
|
|
|
2012-02-13 12:58:34 +00:00
|
|
|
#include "QF/plugin/console.h"
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "QF/plugin/vid_render.h"
|
2012-02-13 12:58:34 +00:00
|
|
|
|
2002-04-11 18:42:55 +00:00
|
|
|
#include "buildnum.h"
|
2001-08-29 02:12:57 +00:00
|
|
|
#include "compat.h"
|
2020-06-21 14:15:17 +00:00
|
|
|
|
|
|
|
#include "nq/include/chase.h"
|
|
|
|
#include "nq/include/host.h"
|
|
|
|
#include "nq/include/server.h"
|
|
|
|
#include "nq/include/sv_progs.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
|
|
|
|
};
|
|
|
|
|
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;
|
2021-07-29 02:12:37 +00:00
|
|
|
size_t host_hunklevel;
|
2013-01-16 04:18:54 +00:00
|
|
|
int host_in_game;
|
2021-07-26 06:43:57 +00:00
|
|
|
size_t 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-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;
|
2010-08-24 00:53:54 +00:00
|
|
|
cvar_t *max_edicts;
|
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;
|
2010-11-29 10:50:59 +00:00
|
|
|
cvar_t *cl_usleep;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2010-11-29 10:50:59 +00:00
|
|
|
static int cl_usleep_cache;
|
|
|
|
|
|
|
|
static void
|
|
|
|
cl_usleep_f (cvar_t *var)
|
|
|
|
{
|
|
|
|
cl_usleep_cache = var->int_val;
|
|
|
|
}
|
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);
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_dev, "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;
|
|
|
|
|
2011-12-09 09:41:52 +00:00
|
|
|
cl.loading = false;
|
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
|
|
|
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_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 =
|
2021-07-28 06:01:45 +00:00
|
|
|
Hunk_AllocName (0, 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");
|
2010-08-24 00:53:54 +00:00
|
|
|
max_edicts = Cvar_Get ("max_edicts", "1024", CVAR_NONE, NULL,
|
|
|
|
"maximum server edicts");
|
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");
|
2010-12-16 02:34:39 +00:00
|
|
|
cl_usleep = Cvar_Get ("cl_usleep", "1", CVAR_ARCHIVE, cl_usleep_f,
|
2010-11-29 10:50:59 +00:00
|
|
|
"Turn this on to save cpu when fps limited. "
|
|
|
|
"May affect frame rate adversely depending on "
|
|
|
|
"local machine/os conditions");
|
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
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_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
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_net, "dropping client\n");
|
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
|
|
|
|
2010-01-13 06:42:26 +00:00
|
|
|
This happens only 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
|
|
|
{
|
2005-06-08 06:35:48 +00:00
|
|
|
byte message[4];
|
2001-02-26 06:48:02 +00:00
|
|
|
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
|
2012-05-23 12:38:25 +00:00
|
|
|
if (cls.state >= ca_connected)
|
2001-02-19 21:15:25 +00:00
|
|
|
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);
|
2010-11-21 05:27:43 +00:00
|
|
|
count = NET_SendToAll (&buf, 5.0);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (count)
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf
|
2001-02-26 06:48:02 +00:00
|
|
|
("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
|
|
|
{
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_dev, "Clearing memory\n");
|
2019-07-08 03:46:22 +00:00
|
|
|
CL_ClearMemory ();
|
2001-02-19 21:15:25 +00:00
|
|
|
Mod_ClearAll ();
|
|
|
|
if (host_hunklevel)
|
2021-07-28 06:01:45 +00:00
|
|
|
Hunk_FreeToLowMark (0, host_hunklevel);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
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
|
|
|
*/
|
2010-11-29 10:50:59 +00:00
|
|
|
static float
|
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);
|
|
|
|
|
2021-02-03 09:24:15 +00:00
|
|
|
if (!cls.demoplayback && (timedifference > 0))
|
2010-11-29 10:50:59 +00:00
|
|
|
return timedifference; // framerate is too high
|
2002-05-07 04:32:28 +00:00
|
|
|
|
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
|
2021-02-03 09:24:15 +00:00
|
|
|
host_frametime = bound (0.000, host_frametime, 0.1);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2010-11-29 10:50:59 +00:00
|
|
|
return 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Host_ServerFrame (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2011-12-22 04:42:39 +00:00
|
|
|
*sv_globals.frametime = sv_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
|
2013-01-16 04:18:54 +00:00
|
|
|
if (!sv.paused && (svs.maxclients > 1 || host_in_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
|
2012-05-23 12:38:25 +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
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
r_data->inhibit_viewmodel = (chase_active->int_val
|
|
|
|
|| (cl.stats[STAT_ITEMS] & IT_INVISIBILITY)
|
|
|
|
|| cl.stats[STAT_HEALTH] <= 0);
|
|
|
|
r_data->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
|
2012-05-23 12:38:25 +00:00
|
|
|
if (cls.state == ca_active) {
|
2012-02-13 04:44:29 +00:00
|
|
|
mleaf_t *l;
|
|
|
|
byte *asl = 0;
|
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
l = Mod_PointInLeaf (r_data->origin, cl.worldmodel);
|
2012-02-13 04:44:29 +00:00
|
|
|
if (l)
|
|
|
|
asl = l->ambient_sound_level;
|
2012-02-14 08:28:09 +00:00
|
|
|
S_Update (r_data->origin, r_data->vpn, r_data->vright, r_data->vup,
|
|
|
|
asl);
|
|
|
|
r_funcs->R_DecayLights (host_frametime);
|
2001-02-26 06:48:02 +00:00
|
|
|
} else
|
2012-02-13 04:44:29 +00:00
|
|
|
S_Update (vec3_origin, vec3_origin, vec3_origin, vec3_origin, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
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;
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_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;
|
2010-11-29 10:50:59 +00:00
|
|
|
float sleeptime;
|
2004-01-27 06:02:41 +00:00
|
|
|
|
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
|
|
|
|
|
2012-01-05 10:19:37 +00:00
|
|
|
if (cls.demo_capture)
|
|
|
|
time = 1.0 / 30; //FIXME fixed 30fps atm
|
|
|
|
|
2003-08-16 05:29:02 +00:00
|
|
|
// decide the simulation time
|
2010-11-29 10:50:59 +00:00
|
|
|
if ((sleeptime = Host_FilterTime (time)) != 0) {
|
|
|
|
// don't run too fast, or packet will flood outs
|
|
|
|
#ifdef HAVE_USLEEP
|
|
|
|
if (cl_usleep_cache && sleeptime > 0.002) // minimum sleep time
|
|
|
|
usleep ((unsigned long) (sleeptime * 1000000 / 2));
|
|
|
|
#endif
|
2012-05-21 23:23:22 +00:00
|
|
|
return;
|
2010-11-29 10:50:59 +00:00
|
|
|
}
|
2003-08-16 05:29:02 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2012-01-05 10:19:37 +00:00
|
|
|
if (cls.demo_capture) {
|
2012-02-14 08:28:09 +00:00
|
|
|
tex_t *tex = r_funcs->SCR_CaptureBGR ();
|
2021-01-31 07:01:20 +00:00
|
|
|
WritePNGqfs (va (0, "%s/qfmv%06d.png", qfs_gamedir->dir.shots,
|
2012-01-05 10:19:37 +00:00
|
|
|
cls.demo_capture++),
|
|
|
|
tex->data, tex->width, tex->height);
|
|
|
|
free (tex);
|
|
|
|
}
|
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_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
|
|
|
}
|
|
|
|
|
2021-12-13 00:13:39 +00:00
|
|
|
static memhunk_t *
|
2011-12-22 06:44:28 +00:00
|
|
|
Host_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");
|
2021-07-26 06:43:57 +00:00
|
|
|
size_t mem_size;
|
2002-02-19 20:47:45 +00:00
|
|
|
void *mem_base;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (standard_quake)
|
|
|
|
minimum_memory = MINIMUM_MEMORY;
|
|
|
|
else
|
|
|
|
minimum_memory = MINIMUM_MEMORY_LEVELPAK;
|
|
|
|
|
2010-12-16 02:34:39 +00:00
|
|
|
host_mem_size = Cvar_Get ("host_mem_size", "40", CVAR_NONE, NULL,
|
2002-02-19 20:47:45 +00:00
|
|
|
"Amount of memory (in MB) to allocate for the "
|
2010-08-19 06:01:43 +00:00
|
|
|
PACKAGE_NAME " heap");
|
2002-02-19 20:47:45 +00:00
|
|
|
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);
|
|
|
|
|
2021-07-26 06:43:57 +00:00
|
|
|
mem_size = ((size_t) 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
|
|
|
|
2021-02-03 04:19:19 +00:00
|
|
|
mem_base = Sys_Alloc (mem_size);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-02-19 20:47:45 +00:00
|
|
|
if (!mem_base)
|
2021-07-26 06:43:57 +00:00
|
|
|
Sys_Error ("Can't allocate %zd", mem_size);
|
2002-02-19 20:47:45 +00:00
|
|
|
|
|
|
|
Sys_PageIn (mem_base, mem_size);
|
2021-12-13 00:13:39 +00:00
|
|
|
memhunk_t *hunk = Memory_Init (mem_base, mem_size);
|
2012-02-01 12:52:47 +00:00
|
|
|
|
|
|
|
Sys_Printf ("%4.1f megabyte heap\n", host_mem_size->value);
|
2021-12-13 00:13:39 +00:00
|
|
|
return hunk;
|
2002-02-19 20:47:45 +00:00
|
|
|
}
|
2021-11-18 06:27:44 +00:00
|
|
|
|
2013-01-16 04:18:54 +00:00
|
|
|
static void
|
2021-11-18 06:27:44 +00:00
|
|
|
Host_ExecConfig (cbuf_t *cbuf, int skip_quakerc)
|
2013-01-16 04:18:54 +00:00
|
|
|
{
|
2021-11-18 06:27:44 +00:00
|
|
|
// quakeforge.cfg overrides quake.rc as it contains quakeforge-specific
|
|
|
|
// commands. If it doesn't exist, then this is the first time quakeforge
|
|
|
|
// has been used in this installation, thus any existing legacy config
|
|
|
|
// should be used to set up defaults on the assumption that the user has
|
|
|
|
// things set up to work with another (hopefully compatible) client
|
|
|
|
if (CL_ReadConfiguration ("quakeforge.cfg")) {
|
|
|
|
Cmd_Exec_File (cbuf, fs_usercfg->string, 0);
|
|
|
|
Cmd_StuffCmds (cbuf);
|
|
|
|
COM_Check_quakerc ("startdemos", cbuf);
|
|
|
|
} else {
|
|
|
|
if (!skip_quakerc) {
|
|
|
|
Cbuf_InsertText (cbuf, "exec quake.rc\n");
|
|
|
|
}
|
|
|
|
Cmd_Exec_File (cbuf, fs_usercfg->string, 0);
|
|
|
|
// Reparse the command line for + commands.
|
|
|
|
// (sets still done, but it doesn't matter)
|
|
|
|
// (Note, no non-base commands exist yet)
|
|
|
|
if (skip_quakerc || !COM_Check_quakerc ("stuffcmds", 0)) {
|
|
|
|
Cmd_StuffCmds (cbuf);
|
|
|
|
}
|
|
|
|
}
|
2013-01-16 04:18:54 +00:00
|
|
|
}
|
2021-11-18 06:27:44 +00:00
|
|
|
|
2002-02-19 20:47:45 +00:00
|
|
|
void
|
|
|
|
Host_Init (void)
|
|
|
|
{
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_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;
|
|
|
|
|
2002-08-20 23:04:57 +00:00
|
|
|
Sys_Init ();
|
2011-12-22 06:44:28 +00:00
|
|
|
GIB_Init (true);
|
2021-07-05 07:26:07 +00:00
|
|
|
GIB_Key_Init ();
|
2021-04-12 13:09:09 +00:00
|
|
|
COM_ParseConfig (host_cbuf);
|
2011-12-22 06:44:28 +00:00
|
|
|
|
2021-12-13 00:13:39 +00:00
|
|
|
memhunk_t *hunk = Host_Init_Memory ();
|
2002-01-17 04:29:41 +00:00
|
|
|
|
2002-01-17 04:11:36 +00:00
|
|
|
PI_Init ();
|
|
|
|
|
2021-12-13 00:13:39 +00:00
|
|
|
Game_Init (hunk);
|
2011-12-22 06:44:28 +00:00
|
|
|
|
2012-02-01 12:52:47 +00:00
|
|
|
if (!isDedicated)
|
|
|
|
CL_InitCvars ();
|
|
|
|
|
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");
|
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 ();
|
|
|
|
|
2002-01-17 04:11:36 +00:00
|
|
|
Mod_Init ();
|
2002-04-11 18:42:55 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
SV_Init ();
|
|
|
|
|
2011-12-22 06:44:28 +00:00
|
|
|
if (cls.state != ca_dedicated)
|
|
|
|
CL_Init (host_cbuf);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-02-26 09:45:50 +00:00
|
|
|
if (con_module) {
|
|
|
|
con_module->data->console->realtime = &con_realtime;
|
|
|
|
con_module->data->console->frametime = &con_frametime;
|
|
|
|
con_module->data->console->quit = Host_Quit_f;
|
|
|
|
con_module->data->console->cbuf = host_cbuf;
|
|
|
|
}
|
|
|
|
|
2002-10-11 03:40:41 +00:00
|
|
|
CL_UpdateScreen (cl.time);
|
|
|
|
CL_UpdateScreen (cl.time);
|
|
|
|
|
2021-11-18 06:27:44 +00:00
|
|
|
Host_ExecConfig (host_cbuf, isDedicated || !cl_quakerc->int_val);
|
2001-05-17 07:53:22 +00:00
|
|
|
|
2021-07-28 06:01:45 +00:00
|
|
|
Hunk_AllocName (0, 0, "-HOST_HUNKLEVEL-");
|
|
|
|
host_hunklevel = Hunk_LowMark (0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2010-08-19 06:01:43 +00:00
|
|
|
Sys_Printf ("\nVersion %s (build %04d)\n\n", PACKAGE_VERSION,
|
2002-04-11 18:42:55 +00:00
|
|
|
build_number ());
|
|
|
|
|
2010-08-19 06:01:43 +00:00
|
|
|
Sys_Printf ("\x80\x81\x81\x82 %s initialized \x80\x81\x81\x82\n",
|
|
|
|
PACKAGE_NAME);
|
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
|
2020-03-21 13:24:11 +00:00
|
|
|
Host_Shutdown (void *data)
|
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;
|
|
|
|
}
|