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

📄 host_cmd.c

📁 quake1 dos源代码最新版本
💻 C
📖 第 1 页 / 共 4 页
字号:
	int			i;
	qboolean	byNumber = false;

	if (cmd_source == src_command)
	{
		if (!sv.active)
		{
			Cmd_ForwardToServer ();
			return;
		}
	}
	else if (pr_global_struct->deathmatch && !host_client->privileged)
		return;

	save = host_client;

	if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
	{
		i = Q_atof(Cmd_Argv(2)) - 1;
		if (i < 0 || i >= svs.maxclients)
			return;
		if (!svs.clients[i].active)
			return;
		host_client = &svs.clients[i];
		byNumber = true;
	}
	else
	{
		for (i = 0, host_client = svs.clients; i < svs.maxclients; i++, host_client++)
		{
			if (!host_client->active)
				continue;
			if (Q_strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
				break;
		}
	}

	if (i < svs.maxclients)
	{
		if (cmd_source == src_command)
		{	// 1999-12-24 explicit brackets by Maddes
			if (cls.state == ca_dedicated)
				who = "Console";
			else
				who = cl_name->string;
		}	// 1999-12-24 explicit brackets by Maddes
		else
			who = save->name;

		// can't kick yourself!
		if (host_client == save)
			return;

		if (Cmd_Argc() > 2)
		{
			message = COM_Parse(Cmd_Args());
			if (byNumber)
			{
				message++;							// skip the #
				while (*message == ' ')				// skip white space
					message++;
				message += strlen(Cmd_Argv(2));	// skip the number
			}
			while (*message && *message == ' ')
				message++;
		}
		if (message)
			SV_ClientPrintf ("Kicked by %s: %s\n", who, message);
		else
			SV_ClientPrintf ("Kicked by %s\n", who);
		SV_DropClient (false);
	}

	host_client = save;
}

/*
===============================================================================

DEBUGGING TOOLS

===============================================================================
*/

/*
==================
Host_Give_f
==================
*/
void Host_Give_f (void)
{
	char	*t;
// 2000-07-30 DJGPP compiler warning fix by Norberto Alfredo Bensa  start
//	int	v, w;
	int	v;
// 2000-07-30 DJGPP compiler warning fix by Norberto Alfredo Bensa  end
	eval_t	*val;

	if (cmd_source == src_command)
	{
		Cmd_ForwardToServer ();
		return;
	}

	if (pr_global_struct->deathmatch && !host_client->privileged)
		return;

	t = Cmd_Argv(1);
	v = atoi (Cmd_Argv(2));

	switch (t[0])
	{
	case '0':
	case '1':
	case '2':
	case '3':
	case '4':
	case '5':
	case '6':
	case '7':
	case '8':
	case '9':
		// MED 01/04/97 added hipnotic give stuff
		if (hipnotic)
		{
			if (t[0] == '6')
			{
				if (t[1] == 'a')
					sv_player->v.items = (int)sv_player->v.items | HIT_PROXIMITY_GUN;
				else
					sv_player->v.items = (int)sv_player->v.items | IT_GRENADE_LAUNCHER;
			}
			else if (t[0] == '9')
				sv_player->v.items = (int)sv_player->v.items | HIT_LASER_CANNON;
			else if (t[0] == '0')
				sv_player->v.items = (int)sv_player->v.items | HIT_MJOLNIR;
			else if (t[0] >= '2')
				sv_player->v.items = (int)sv_player->v.items | (IT_SHOTGUN << (t[0] - '2'));
		}
		else
		{
			if (t[0] >= '2')
				sv_player->v.items = (int)sv_player->v.items | (IT_SHOTGUN << (t[0] - '2'));
		}
		break;

	case 's':
		if (rogue)
		{
// 2001-11-15 Better GetEdictFieldValue performance by LordHavoc/Maddes  start
//			val = GetEdictFieldValue(sv_player, "ammo_shells1");
			val = GETEDICTFIELDVALUE(sv_player, pr_field_ammo_shells1);
// 2001-11-15 Better GetEdictFieldValue performance by LordHavoc/Maddes  end
			if (val)
				val->_float = v;
		}

		sv_player->v.ammo_shells = v;
		break;
	case 'n':
		if (rogue)
		{
// 2001-11-15 Better GetEdictFieldValue performance by LordHavoc/Maddes  start
//			val = GetEdictFieldValue(sv_player, "ammo_nails1");
			val = GETEDICTFIELDVALUE(sv_player, pr_field_ammo_nails1);
// 2001-11-15 Better GetEdictFieldValue performance by LordHavoc/Maddes  end
			if (val)
			{
				val->_float = v;
				if (sv_player->v.weapon <= IT_LIGHTNING)
					sv_player->v.ammo_nails = v;
			}
		}
		else
		{
			sv_player->v.ammo_nails = v;
		}
		break;
	case 'l':
		if (rogue)
		{
// 2001-11-15 Better GetEdictFieldValue performance by LordHavoc/Maddes  start
//			val = GetEdictFieldValue(sv_player, "ammo_lava_nails");
			val = GETEDICTFIELDVALUE(sv_player, pr_field_ammo_lava_nails);
// 2001-11-15 Better GetEdictFieldValue performance by LordHavoc/Maddes  end
			if (val)
			{
				val->_float = v;
				if (sv_player->v.weapon > IT_LIGHTNING)
					sv_player->v.ammo_nails = v;
			}
		}
		break;
	case 'r':
		if (rogue)
		{
// 2001-11-15 Better GetEdictFieldValue performance by LordHavoc/Maddes  start
//			val = GetEdictFieldValue(sv_player, "ammo_rockets1");
			val = GETEDICTFIELDVALUE(sv_player, pr_field_ammo_rockets1);
// 2001-11-15 Better GetEdictFieldValue performance by LordHavoc/Maddes  end
			if (val)
			{
				val->_float = v;
				if (sv_player->v.weapon <= IT_LIGHTNING)
					sv_player->v.ammo_rockets = v;
			}
		}
		else
		{
			sv_player->v.ammo_rockets = v;
		}
		break;
	case 'm':
		if (rogue)
		{
// 2001-11-15 Better GetEdictFieldValue performance by LordHavoc/Maddes  start
//			val = GetEdictFieldValue(sv_player, "ammo_multi_rockets");
			val = GETEDICTFIELDVALUE(sv_player, pr_field_ammo_multi_rockets);
// 2001-11-15 Better GetEdictFieldValue performance by LordHavoc/Maddes  end
			if (val)
			{
				val->_float = v;
				if (sv_player->v.weapon > IT_LIGHTNING)
					sv_player->v.ammo_rockets = v;
			}
		}
		break;
	case 'h':
		sv_player->v.health = v;
		break;
	case 'c':
		if (rogue)
		{
// 2001-11-15 Better GetEdictFieldValue performance by LordHavoc/Maddes  start
//			val = GetEdictFieldValue(sv_player, "ammo_cells1");
			val = GETEDICTFIELDVALUE(sv_player, pr_field_ammo_cells1);
// 2001-11-15 Better GetEdictFieldValue performance by LordHavoc/Maddes  end
			if (val)
			{
				val->_float = v;
				if (sv_player->v.weapon <= IT_LIGHTNING)
					sv_player->v.ammo_cells = v;
			}
		}
		else
		{
			sv_player->v.ammo_cells = v;
		}
		break;
	case 'p':
		if (rogue)
		{
// 2001-11-15 Better GetEdictFieldValue performance by LordHavoc/Maddes  start
//			val = GetEdictFieldValue(sv_player, "ammo_plasma");
			val = GETEDICTFIELDVALUE(sv_player, pr_field_ammo_plasma);
// 2001-11-15 Better GetEdictFieldValue performance by LordHavoc/Maddes  end
			if (val)
			{
				val->_float = v;
				if (sv_player->v.weapon > IT_LIGHTNING)
					sv_player->v.ammo_cells = v;
			}
		}
		break;
	}
}

edict_t	*FindViewthing (void)
{
	int		i;
	edict_t	*e;

	for (i=0 ; i<sv.num_edicts ; i++)
	{
		e = EDICT_NUM(i);
		if ( !strcmp (pr_strings + e->v.classname, "viewthing") )
			return e;
	}
	Con_Printf ("No viewthing on map\n");
	return NULL;
}

/*
==================
Host_Viewmodel_f
==================
*/
void Host_Viewmodel_f (void)
{
	edict_t	*e;
	model_t	*m;

	e = FindViewthing ();
	if (!e)
		return;

	m = Mod_ForName (Cmd_Argv(1), false);
	if (!m)
	{
		Con_Printf ("Can't load %s\n", Cmd_Argv(1));
		return;
	}

	e->v.frame = 0;
	cl.model_precache[(int)e->v.modelindex] = m;
}

/*
==================
Host_Viewframe_f
==================
*/
void Host_Viewframe_f (void)
{
	edict_t	*e;
	int		f;
	model_t	*m;

	e = FindViewthing ();
	if (!e)
		return;
	m = cl.model_precache[(int)e->v.modelindex];

	f = atoi(Cmd_Argv(1));
	if (f >= m->numframes)
		f = m->numframes-1;

	e->v.frame = f;
}


void PrintFrameName (model_t *m, int frame)
{
	aliashdr_t 			*hdr;
	maliasframedesc_t	*pframedesc;

	hdr = (aliashdr_t *)Mod_Extradata (m);
	if (!hdr)
		return;
	pframedesc = &hdr->frames[frame];

	Con_Printf ("frame %i: %s\n", frame, pframedesc->name);
}

/*
==================
Host_Viewnext_f
==================
*/
void Host_Viewnext_f (void)
{
	edict_t	*e;
	model_t	*m;

	e = FindViewthing ();
	if (!e)
		return;
	m = cl.model_precache[(int)e->v.modelindex];

	e->v.frame = e->v.frame + 1;
	if (e->v.frame >= m->numframes)
		e->v.frame = m->numframes - 1;

	PrintFrameName (m, e->v.frame);
}

/*
==================
Host_Viewprev_f
==================
*/
void Host_Viewprev_f (void)
{
	edict_t	*e;
	model_t	*m;

	e = FindViewthing ();
	if (!e)
		return;

	m = cl.model_precache[(int)e->v.modelindex];

	e->v.frame = e->v.frame - 1;
	if (e->v.frame < 0)
		e->v.frame = 0;

	PrintFrameName (m, e->v.frame);
}

/*
===============================================================================

DEMO LOOP CONTROL

===============================================================================
*/


/*
==================
Host_Startdemos_f
==================
*/
void Host_Startdemos_f (void)
{
	int		i, c;

	if (cls.state == ca_dedicated)
	{
		if (!sv.active)
			Cbuf_AddText ("map start\n");
		return;
	}

	c = Cmd_Argc() - 1;
	if (c > MAX_DEMOS)
	{
		Con_Printf ("Max %i demos in demoloop\n", MAX_DEMOS);
		c = MAX_DEMOS;
	}
	Con_Printf ("%i demo(s) in loop\n", c);

	for (i=1 ; i<c+1 ; i++)
		strncpy (cls.demos[i-1], Cmd_Argv(i), sizeof(cls.demos[0])-1);

	if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
	{
		cls.demonum = 0;
		CL_NextDemo ();
	}
	else
		cls.demonum = -1;
}


/*
==================
Host_Demos_f

Return to looping demos
==================
*/
void Host_Demos_f (void)
{
	if (cls.state == ca_dedicated)
		return;
	if (cls.demonum == -1)
		cls.demonum = 1;
	CL_Disconnect_f ();
	CL_NextDemo ();
}

/*
==================
Host_Stopdemo_f

Return to looping demos
==================
*/
void Host_Stopdemo_f (void)
{
	if (cls.state == ca_dedicated)
		return;
	if (!cls.demoplayback)
		return;
	CL_StopPlayback ();
	CL_Disconnect ();
}

// 2001-09-20 Configurable limits by Maddes  start
/*
==================
Host_Limit_Request_f
==================
*/
void Host_Limit_Request_f (void)
{
	if (cmd_source == src_command)	// this a client remote only command
	{
		Con_Printf ("%s is not valid from the console\n", Cmd_Argv(0));
		return;
	}

	if (host_client->spawned)
	{
		SV_ClientPrintf ("%s not valid -- already spawned\n", Cmd_Argv(0));
		return;
	}

// 2001-12-24 Keeping full backwards compatibility by Maddes  start
	if (sv_compatibility->value)	// do not reply, like the original Quake executable
	{
		return;
	}
// 2001-12-24 Keeping full backwards compatibility by Maddes  end

// 2001-09-20 Configurable entity limits by Maddes  start
	if (nvs_current_ssvc->value >= 0.00)	// HACK!!! Using version 0.00 for lowest version the
											// client must now when sending this command on connect
	{
		NVS_InitSVCMsg(MSG_ONE, svc_limit, LIM_ENTITIES, host_client);
		NVS_WriteByte (MSG_ONE, svc_limit, NULL);
		NVS_WriteByte (MSG_ONE, LIM_ENTITIES, NULL);
		NVS_WriteShort (MSG_ONE, sv.max_edicts, NULL);
		NVS_WriteShort (MSG_ONE, sv_entities_static->value, NULL);
		NVS_WriteShort (MSG_ONE, sv_entities_temp->value, NULL);
	}
// 2001-09-20 Configurable entity limits by Maddes  end
}
// 2001-09-20 Configurable limits by Maddes  end

//=============================================================================

/*
==================
Host_InitCommands
==================
*/
void Host_InitCommands (void)
{
	Cmd_AddCommand ("status", Host_Status_f);
	Cmd_AddCommand ("quit", Host_Quit_f);
	Cmd_AddCommand ("god", Host_God_f);
	Cmd_AddCommand ("notarget", Host_Notarget_f);
	Cmd_AddCommand ("fly", Host_Fly_f);
	Cmd_AddCommand ("map", Host_Map_f);
	Cmd_AddCommand ("restart", Host_Restart_f);
	Cmd_AddCommand ("changelevel", Host_Changelevel_f);
#ifdef QUAKE2
	Cmd_AddCommand ("changelevel2", Host_Changelevel2_f);
#endif
	Cmd_AddCommand ("connect", Host_Connect_f);
	Cmd_AddCommand ("reconnect", Host_Reconnect_f);
	Cmd_AddCommand ("name", Host_Name_f);
	Cmd_AddCommand ("noclip", Host_Noclip_f);
	Cmd_AddCommand ("version", Host_Version_f);
#ifdef IDGODS
	Cmd_AddCommand ("please", Host_Please_f);
#endif
	Cmd_AddCommand ("say", Host_Say_f);
	Cmd_AddCommand ("say_team", Host_Say_Team_f);
	Cmd_AddCommand ("tell", Host_Tell_f);
	Cmd_AddCommand ("color", Host_Color_f);
	Cmd_AddCommand ("kill", Host_Kill_f);
	Cmd_AddCommand ("pause", Host_Pause_f);
	Cmd_AddCommand ("spawn", Host_Spawn_f);
	Cmd_AddCommand ("begin", Host_Begin_f);
	Cmd_AddCommand ("prespawn", Host_PreSpawn_f);
	Cmd_AddCommand ("kick", Host_Kick_f);
	Cmd_AddCommand ("ping", Host_Ping_f);
	Cmd_AddCommand ("load", Host_Loadgame_f);
	Cmd_AddCommand ("save", Host_Savegame_f);
	Cmd_AddCommand ("give", Host_Give_f);

	Cmd_AddCommand ("startdemos", Host_Startdemos_f);
	Cmd_AddCommand ("demos", Host_Demos_f);
	Cmd_AddCommand ("stopdemo", Host_Stopdemo_f);

	Cmd_AddCommand ("viewmodel", Host_Viewmodel_f);
	Cmd_AddCommand ("viewframe", Host_Viewframe_f);
	Cmd_AddCommand ("viewnext", Host_Viewnext_f);
	Cmd_AddCommand ("viewprev", Host_Viewprev_f);

	Cmd_AddCommand ("mcache", Mod_Print);

	Cmd_AddCommand ("qcexec", Host_QC_Exec_f);	// 2000-01-09 QCExec by FrikaC/Maddes

	Cmd_AddCommand ("limit_request", Host_Limit_Request_f);	// 2001-09-20 Configurable limits by Maddes
}

⌨️ 快捷键说明

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