⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 host.c

📁 quake1 dos源代码最新版本
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
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 the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/
// host.c -- coordinates spawning and killing of local servers

#include "quakedef.h"
#include "r_local.h"

/*

A server can always be started, even if the system started out as a client
to a remote system.

A client can NOT be started if the system started as a dedicated server.

Memory is cleared / released when a server or client begins, not when they end.

*/

// 2001-10-20 TIMESCALE extension by Tomaz/Maddes  start
double	host_cpu_frametime;
double	host_org_frametime;

cvar_t	*host_timescale;
// 2001-10-20 TIMESCALE extension by Tomaz/Maddes  end

quakeparms_t host_parms;

qboolean	host_initialized;		// true if into command execution

double		host_frametime;
double		host_time;
double		realtime;				// without any filtering or bounding
double		oldrealtime;			// last frame run
int			host_framecount;

int			host_hunklevel;

int			minimum_memory;

client_t	*host_client;			// current client

jmp_buf 	host_abortserver;

byte		*host_basepal;
byte		*host_colormap;

cvar_t	*host_framerate;	// set for slow motion
cvar_t	*host_speeds;		// set for running times

cvar_t	*sys_ticrate;
cvar_t	*serverprofile;

cvar_t	*fraglimit;
cvar_t	*timelimit;
cvar_t	*teamplay;

cvar_t	*samelevel;
cvar_t	*noexit;

cvar_t	*developer;

cvar_t	*skill;					// 0 - 3
cvar_t	*deathmatch;			// 0, 1, or 2
cvar_t	*coop;					// 0 or 1

cvar_t	*pausable;

cvar_t	*temp1;

cvar_t	*contact;		// 2000-01-31 Contact cvar by Maddes

cvar_t	*max_fps;		// 2001-12-16 MAX_FPS cvar by MrG

int		fps_count;	// 2001-11-31 FPS display by QuakeForge/Muff  end

/*
================
Host_EndGame
================
*/
void Host_EndGame (char *message, ...)
{
	va_list		argptr;
	char		string[1024];

	va_start (argptr,message);
	vsprintf (string,message,argptr);
	va_end (argptr);
	Con_DPrintf ("Host_EndGame: %s\n",string);

	if (sv.active)
		Host_ShutdownServer (false);

	if (cls.state == ca_dedicated)
		Sys_Error ("Host_EndGame: %s\n",string);	// dedicated servers exit

	if (cls.demonum != -1)
		CL_NextDemo ();
	else
		CL_Disconnect ();

	longjmp (host_abortserver, 1);
}

/*
================
Host_Error

This shuts down both the client and server
================
*/
void Host_Error (char *error, ...)
{
	va_list		argptr;
	char		string[1024];
	static	qboolean inerror = false;

	if (inerror)
		Sys_Error ("Host_Error: recursively entered");
	inerror = true;

	SCR_EndLoadingPlaque ();		// reenable screen updates

	va_start (argptr,error);
	vsprintf (string,error,argptr);
	va_end (argptr);
	Con_Printf ("Host_Error: %s\n",string);

	if (sv.active)
		Host_ShutdownServer (false);

	if (cls.state == ca_dedicated)
		Sys_Error ("Host_Error: %s",string);	// dedicated servers exit

	CL_Disconnect ();
	cls.demonum = -1;

	inerror = false;

	longjmp (host_abortserver, 1);
}

/*
================
Host_FindMaxClients
================
*/
void	Host_FindMaxClients (void)
{
	int		i;

	svs.maxclients = 1;
	svs.maxclientslimit = MAX_SCOREBOARD;	// 2000-01-11 Set default maximum clients to 16 instead of 4 by Maddes

	i = COM_CheckParm ("-dedicated");
	if (i)
	{
		cls.state = ca_dedicated;
		if (i != (com_argc - 1))
		{
			svs.maxclients = Q_atoi (com_argv[i+1]);
		}
		else
			svs.maxclients = 8;
	}
	else
		cls.state = ca_disconnected;

	i = COM_CheckParm ("-listen");
	if (i)
	{
		if (cls.state == ca_dedicated)
			Sys_Error ("Only one of -dedicated or -listen can be specified");
		if (i != (com_argc - 1))
			svs.maxclients = Q_atoi (com_argv[i+1]);
		else
			svs.maxclients = 8;
	}
	if (svs.maxclients < 1)
		svs.maxclients = 8;
// 2000-01-11 Set default maximum clients to 16 instead of 4 by Maddes  start
/*
	else if (svs.maxclients > MAX_SCOREBOARD)
		svs.maxclients = MAX_SCOREBOARD;

	svs.maxclientslimit = svs.maxclients;
*/
// 2000-01-11 Set default maximum clients to 16 instead of 4 by Maddes  end
	if (svs.maxclientslimit < 4)
		svs.maxclientslimit = 4;

// 2000-01-11 Set default maximum clients to 16 instead of 4 by Maddes  start
	if (svs.maxclientslimit > MAX_SCOREBOARD)
		svs.maxclientslimit = MAX_SCOREBOARD;

	if (svs.maxclients > svs.maxclientslimit)
		svs.maxclients = svs.maxclientslimit;
// 2000-01-11 Set default maximum clients to 16 instead of 4 by Maddes  end
	svs.clients = Hunk_AllocName (svs.maxclientslimit*sizeof(client_t), "clients");

	if (svs.maxclients > 1)
		Cvar_Set (deathmatch, "1");
	else
		Cvar_Set (deathmatch, "0");
}

// 1999-09-06 deathmatch/coop not at the same time fix by Maddes  start
void Callback_Deathmatch (cvar_t *var)
{
	if (var->value)
	{
		Cvar_Set (coop, "0");
	}
}

void Callback_Coop (cvar_t *var)
{
	if (var->value)
	{
		Cvar_Set (deathmatch, "0");
	}
}
// 1999-09-06 deathmatch/coop not at the same time fix by Maddes  end

// 2001-09-18 New cvar system by Maddes (Init)  start
/*
=======================
Host_InitLocal_Cvars
======================
*/
void Host_InitLocal_Cvars (void)
{
// 2001-10-20 TIMESCALE extension by Tomaz/Maddes  start
	host_timescale = Cvar_Get ("host_timescale", "1", CVAR_NONE);
	Cvar_SetRangecheck (host_timescale, Cvar_RangecheckFloat, 0.0, 10.0);
	Cvar_Set(host_timescale, host_timescale->string);	// do rangecheck
// 2001-10-20 TIMESCALE extension by Tomaz/Maddes  end

	host_framerate = Cvar_Get ("host_framerate", "0", CVAR_ORIGINAL);
	host_speeds = Cvar_Get ("host_speeds", "0", CVAR_ORIGINAL);

	sys_ticrate = Cvar_Get ("sys_ticrate", "0.05", CVAR_ORIGINAL);
	serverprofile = Cvar_Get ("serverprofile", "0", CVAR_ORIGINAL);

	fraglimit = Cvar_Get ("fraglimit", "0", CVAR_NOTIFY|CVAR_SERVERINFO|CVAR_ORIGINAL);
	timelimit = Cvar_Get ("timelimit", "0", CVAR_NOTIFY|CVAR_SERVERINFO|CVAR_ORIGINAL);
	teamplay = Cvar_Get ("teamplay", "0", CVAR_NOTIFY|CVAR_SERVERINFO|CVAR_ORIGINAL);

 	samelevel = Cvar_Get ("samelevel", "0", CVAR_ORIGINAL);
	noexit = Cvar_Get ("noexit", "0", CVAR_NOTIFY|CVAR_SERVERINFO|CVAR_ORIGINAL);
	skill = Cvar_Get ("skill", "1", CVAR_ORIGINAL);

#ifdef QUAKE2
	developer = Cvar_Get ("developer", "1", CVAR_ORIGINAL);	// should be 0 for release!
#else
	developer = Cvar_Get ("developer", "0", CVAR_ORIGINAL);
#endif

	deathmatch = Cvar_Get ("deathmatch", "0", CVAR_ORIGINAL);
	Cvar_SetCallback (deathmatch, Callback_Deathmatch);	// 1999-09-06 deathmatch/coop not at the same time fix by Maddes

	coop = Cvar_Get ("coop", "0", CVAR_ORIGINAL);
	Cvar_SetCallback (coop, Callback_Coop);	// 1999-09-06 deathmatch/coop not at the same time fix by Maddes

	pausable = Cvar_Get ("pausable", "1", CVAR_ORIGINAL);

	temp1 = Cvar_Get ("temp1", "0", CVAR_ORIGINAL);

	contact = Cvar_Get ("contact", "", CVAR_ARCHIVE);	// 2000-01-31 Contact cvar by Maddes

// 2001-12-16 MAX_FPS cvar by MrG  start
	max_fps = Cvar_Get ("max_fps", "72", CVAR_ARCHIVE);
	Cvar_SetRangecheck (max_fps, Cvar_RangecheckInt, 10, 200);
	Cvar_Set(max_fps, max_fps->string);	// do rangecheck
// 2001-12-16 MAX_FPS cvar by MrG  end
}
// 2001-09-18 New cvar system by Maddes (Init)  end

/*
=======================
Host_InitLocal
======================
*/
void Host_InitLocal (void)
{
	Host_InitCommands ();

// 2001-09-18 New cvar system by Maddes (Init)  start
/*
// 2001-10-20 TIMESCALE extension by Tomaz/Maddes  start
	host_timescale = Cvar_Get ("host_timescale", "1", CVAR_NONE);
	Cvar_SetRangecheck (host_timescale, Cvar_RangecheckFloat, 0.0, 10.0);
	Cvar_Set(host_timescale, host_timescale->string);	// do rangecheck
// 2001-10-20 TIMESCALE extension by Tomaz/Maddes  end

	host_framerate = Cvar_Get ("host_framerate", "0", CVAR_ORIGINAL);
	host_speeds = Cvar_Get ("host_speeds", "0", CVAR_ORIGINAL);

	sys_ticrate = Cvar_Get ("sys_ticrate", "0.05", CVAR_ORIGINAL);
	serverprofile = Cvar_Get ("serverprofile", "0", CVAR_ORIGINAL);

	fraglimit = Cvar_Get ("fraglimit", "0", CVAR_NOTIFY|CVAR_SERVERINFO|CVAR_ORIGINAL);
	timelimit = Cvar_Get ("timelimit", "0", CVAR_NOTIFY|CVAR_SERVERINFO|CVAR_ORIGINAL);
	teamplay = Cvar_Get ("teamplay", "0", CVAR_NOTIFY|CVAR_SERVERINFO|CVAR_ORIGINAL);

 	samelevel = Cvar_Get ("samelevel", "0", CVAR_ORIGINAL);
	noexit = Cvar_Get ("noexit", "0", CVAR_NOTIFY|CVAR_SERVERINFO|CVAR_ORIGINAL);
	skill = Cvar_Get ("skill", "1", CVAR_ORIGINAL);

#ifdef QUAKE2
	developer = Cvar_Get ("developer", "1", CVAR_ORIGINAL);	// should be 0 for release!
#else
	developer = Cvar_Get ("developer", "0", CVAR_ORIGINAL);
#endif

	deathmatch = Cvar_Get ("deathmatch", "0", CVAR_ORIGINAL);
	Cvar_SetCallback (deathmatch, Callback_Deathmatch);	// 1999-09-06 deathmatch/coop not at the same time fix by Maddes

	coop = Cvar_Get ("coop", "0", CVAR_ORIGINAL);
	Cvar_SetCallback (coop, Callback_Coop);	// 1999-09-06 deathmatch/coop not at the same time fix by Maddes

	pausable = Cvar_Get ("pausable", "1", CVAR_ORIGINAL);

	temp1 = Cvar_Get ("temp1", "0", CVAR_ORIGINAL);

	contact = Cvar_Get ("contact", "", CVAR_ARCHIVE);	// 2000-01-31 Contact cvar by Maddes
*/
// 2001-09-18 New cvar system by Maddes (Init)  end

	Host_FindMaxClients ();

	host_time = 1.0;		// so a think at time 0 won't get called
}


/*
===============
Host_WriteConfiguration

Writes key bindings and archived cvars to config.cfg
===============
*/
void Host_WriteConfiguration (void)
{
	FILE	*f;

// dedicated servers initialize the host but don't parse and set the
// config.cfg cvars
//	if (host_initialized & !isDedicated)
	if (host_initialized && !isDedicated)	// 1999-12-24 logical correction by Maddes
	{
		f = fopen (va("%s/config.cfg",com_gamedir), "w");
		if (!f)
		{
			Con_Printf ("Couldn't write config.cfg.\n");
			return;
		}

		Key_WriteBindings (f);
		Cvar_WriteVariables (f, false);	// 2001-09-18 New cvar system by Maddes

		fclose (f);

// 2001-09-18 New cvar system by Maddes  start
		f = fopen (va("%s/config.rc",com_gamedir), "w");
		if (!f)
		{
			Con_Printf ("Couldn't write config.rc.\n");
			return;
		}

		Cvar_WriteVariables (f, true);	// 2001-09-18 New cvar system by Maddes

		fclose (f);
// 2001-09-18 New cvar system by Maddes  end
	}
}


/*
=================
SV_ClientPrintf

Sends text across to be displayed
FIXME: make this just a stuffed echo?
=================
*/
void SV_ClientPrintf (char *fmt, ...)
{
	va_list		argptr;
	char		string[1024];

	va_start (argptr,fmt);
	vsprintf (string, fmt,argptr);
	va_end (argptr);

	MSG_WriteByte (&host_client->message, svc_print);
	MSG_WriteString (&host_client->message, string);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -