📄 host_cmd.c
字号:
cl->edict->v.flags = (int)cl->edict->v.flags & ~(FL_GODMODE|FL_NOTARGET);
cl->edict->v.movetype = MOVETYPE_WALK;
noclip_anglehack = false;
}
else
cl->privileged = true;
}
if (Cmd_Argc () != 2)
return;
for (j=0, cl = svs.clients ; j<svs.maxclients ; j++, cl++)
{
if (!cl->active)
continue;
if (Q_strcasecmp(cl->name, Cmd_Argv(1)) == 0)
{
if (cl->privileged)
{
cl->privileged = false;
cl->edict->v.flags = (int)cl->edict->v.flags & ~(FL_GODMODE|FL_NOTARGET);
cl->edict->v.movetype = MOVETYPE_WALK;
noclip_anglehack = false;
}
else
cl->privileged = true;
break;
}
}
}
#endif
void Host_Say(qboolean teamonly)
{
client_t *client;
client_t *save;
int j;
char *p;
unsigned char text[64];
qboolean fromServer = false;
if (cmd_source == src_command)
{
if (cls.state == ca_dedicated)
{
fromServer = true;
teamonly = false;
}
else
{
Cmd_ForwardToServer ();
return;
}
}
if (Cmd_Argc () < 2)
return;
save = host_client;
p = Cmd_Args();
// remove quotes if present
if (*p == '"')
{
p++;
p[strlen(p)-1] = 0;
}
// turn on color set 1
if (!fromServer)
sprintf (text, "%c%s: ", 1, save->name);
else
sprintf (text, "%c<%s> ", 1, hostname->string);
j = sizeof(text) - 2 - strlen(text); // -2 for /n and null terminator
if (strlen(p) > j)
p[j] = 0;
strcat (text, p);
strcat (text, "\n");
for (j = 0, client = svs.clients; j < svs.maxclients; j++, client++)
{
if (!client || !client->active || !client->spawned)
continue;
if (teamplay->value && teamonly && client->edict->v.team != save->edict->v.team)
continue;
host_client = client;
SV_ClientPrintf("%s", text);
}
host_client = save;
Sys_Printf("%s", &text[1]);
}
void Host_Say_f(void)
{
Host_Say(false);
}
void Host_Say_Team_f(void)
{
Host_Say(true);
}
void Host_Tell_f(void)
{
// 2001-09-09 Tell command accepts player number by Maddes start
char *who;
char *message = NULL;
qboolean byNumber = false;
// 2001-09-09 Tell command accepts player number by Maddes end
client_t *client;
client_t *save;
int j;
// 2001-09-09 Tell command accepts player number by Maddes start
/*
char *p;
char text[64];
*/
// 2001-09-09 Tell command accepts player number by Maddes end
if (cmd_source == src_command)
{
Cmd_ForwardToServer ();
return;
}
// 2001-09-09 Tell command accepts player number by Maddes start
if (Cmd_Argc () < 3)
{
SV_ClientPrintf ("Syntax: tell <playername|# playernumber> <message>\n");
return;
}
if (strcmp(Cmd_Argv(1), "#") == 0) // user stated a player number
{
if (Cmd_Argc() < 4)
{
SV_ClientPrintf ("Syntax: tell # <playernumber> <message>\n");
return;
}
j = Q_atof(Cmd_Argv(2)) - 1;
if (j < 0 || j >= svs.maxclients)
return;
client = &svs.clients[j];
if (!client->active || !client->spawned)
return;
byNumber = true;
}
else
{
// 2001-09-09 Tell command accepts player number by Maddes end
if (Cmd_Argc () < 3)
return;
// 2001-09-09 Tell command accepts player number by Maddes start
/*
strcpy(text, host_client->name);
strcat(text, ": ");
p = Cmd_Args();
// remove quotes if present
if (*p == '"')
{
p++;
p[strlen(p)-1] = 0;
}
// check length & truncate if necessary
j = sizeof(text) - 2 - strlen(text); // -2 for /n and null terminator
if (strlen(p) > j)
p[j] = 0;
strcat (text, p);
strcat (text, "\n");
save = host_client;
*/
// 2001-09-09 Tell command accepts player number by Maddes end
for (j = 0, client = svs.clients; j < svs.maxclients; j++, client++)
{
if (!client->active || !client->spawned)
continue;
if (Q_strcasecmp(client->name, Cmd_Argv(1)))
continue;
// 2001-09-09 Tell command accepts player number by Maddes start
/*
host_client = client;
SV_ClientPrintf("%s", text);
*/
// 2001-09-09 Tell command accepts player number by Maddes end
break;
}
// 2001-09-09 Tell command accepts player number by Maddes start
}
if (j >= svs.maxclients)
{
return;
}
// can't tell yourself!
if (host_client == client)
return;
who = host_client->name;
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++;
save = host_client;
host_client = client;
SV_ClientPrintf ("%s: %s\n", who, message);
// 2001-09-09 Tell command accepts player number by Maddes end
host_client = save;
}
/*
==================
Host_Color_f
==================
*/
void Host_Color_f(void)
{
int top, bottom;
int playercolor;
if (Cmd_Argc() == 1)
{
Con_Printf ("\"color\" is \"%i %i\"\n", ((int)cl_color->value) >> 4, ((int)cl_color->value) & 0x0f);
Con_Printf ("color <0-13> [0-13]\n");
return;
}
if (Cmd_Argc() == 2)
top = bottom = atoi(Cmd_Argv(1));
else
{
top = atoi(Cmd_Argv(1));
bottom = atoi(Cmd_Argv(2));
}
top &= 15;
if (top > 13)
top = 13;
bottom &= 15;
if (bottom > 13)
bottom = 13;
playercolor = top*16 + bottom;
if (cmd_source == src_command)
{
Cvar_SetValue (cl_color, playercolor);
if (cls.state == ca_connected)
Cmd_ForwardToServer ();
return;
}
host_client->colors = playercolor;
host_client->edict->v.team = bottom + 1;
// send notification to all clients
MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
}
/*
==================
Host_Kill_f
==================
*/
void Host_Kill_f (void)
{
if (cmd_source == src_command)
{
Cmd_ForwardToServer ();
return;
}
// 2001-09-09 Kill command does not work for zombie players fix by Maddes start
// if (sv_player->v.health <= 0)
if ((sv_player->v.health <= 0) && (sv_player->v.deadflag != DEAD_NO))
// 2001-09-09 Kill command does not work for zombie players fix by Maddes end
{
SV_ClientPrintf ("Can't suicide -- already dead!\n");
return;
}
pr_global_struct->time = sv.time;
pr_global_struct->self = EDICT_TO_PROG(sv_player);
PR_ExecuteProgram (pr_global_struct->ClientKill);
}
/*
==================
Host_Pause_f
==================
*/
void Host_Pause_f (void)
{
if (cmd_source == src_command)
{
Cmd_ForwardToServer ();
return;
}
if (!pausable->value)
SV_ClientPrintf ("Pause not allowed.\n");
else
{
sv.paused ^= 1;
if (sv.paused)
{
SV_BroadcastPrintf ("%s paused the game\n", pr_strings + sv_player->v.netname);
}
else
{
SV_BroadcastPrintf ("%s unpaused the game\n",pr_strings + sv_player->v.netname);
}
// send notification to all clients
MSG_WriteByte (&sv.reliable_datagram, svc_setpause);
MSG_WriteByte (&sv.reliable_datagram, sv.paused);
}
}
//===========================================================================
/*
==================
Host_PreSpawn_f
==================
*/
void Host_PreSpawn_f (void)
{
if (cmd_source == src_command)
{
Con_Printf ("prespawn is not valid from the console\n");
return;
}
if (host_client->spawned)
{
Con_Printf ("prespawn not valid -- already spawned\n");
return;
}
// 2000-04-30 NVS HANDSHAKE SRV<->CL by Maddes start
// check client against required version
if (NVS_RejectClient())
{
return;
}
// 2000-04-30 NVS HANDSHAKE SRV<->CL by Maddes end
SZ_Write (&host_client->message, sv.signon.data, sv.signon.cursize);
MSG_WriteByte (&host_client->message, svc_signonnum);
MSG_WriteByte (&host_client->message, 2);
host_client->sendsignon = true;
}
/*
==================
Host_Spawn_f
==================
*/
void Host_Spawn_f (void)
{
int i;
client_t *client;
edict_t *ent;
eval_t *val; // 2000-04-30 NVS HANDSHAKE QC<->CL by Maddes
if (cmd_source == src_command)
{
Con_Printf ("spawn is not valid from the console\n");
return;
}
if (host_client->spawned)
{
Con_Printf ("Spawn not valid -- already spawned\n");
return;
}
// run the entrance script
if (sv.loadgame)
{ // loaded games are fully inited already
// if this is the last client to be connected, unpause
sv.paused = false;
}
else
{
// set up the edict
ent = host_client->edict;
memset (&ent->v, 0, progs->entityfields * 4);
ent->v.colormap = NUM_FOR_EDICT(ent);
ent->v.team = (host_client->colors & 15) + 1;
ent->v.netname = host_client->name - pr_strings;
// copy spawn parms out of the client_t
for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
(&pr_global_struct->parm1)[i] = host_client->spawn_parms[i];
// call the spawn function
// 2000-04-30 NVS HANDSHAKE QC<->CL by Maddes start
// let the QuakeC code know the NVS version of the client
if (pr_field_nvs_svc)
{
// 2001-11-15 Better GetEdictFieldValue performance by LordHavoc/Maddes start
// val = GetEdictFieldValue(ent, "nvs_svc");
val = GETEDICTFIELDVALUE(ent, pr_field_nvs_svc);
// 2001-11-15 Better GetEdictFieldValue performance by LordHavoc/Maddes end
if (val)
{
val->_float = host_client->nvs_csvc;
}
}
// 2000-04-30 NVS HANDSHAKE QC<->CL by Maddes end
pr_global_struct->time = sv.time;
pr_global_struct->self = EDICT_TO_PROG(sv_player);
PR_ExecuteProgram (pr_global_struct->ClientConnect);
if ((Sys_FloatTime() - host_client->netconnection->connecttime) <= sv.time)
Sys_Printf ("%s entered the game\n", host_client->name);
PR_ExecuteProgram (pr_global_struct->PutClientInServer);
}
// send all current names, colors, and frag counts
SZ_Clear (&host_client->message);
// send time of update
MSG_WriteByte (&host_client->message, svc_time);
MSG_WriteFloat (&host_client->message, sv.time);
for (i=0, client = svs.clients ; i<svs.maxclients ; i++, client++)
{
MSG_WriteByte (&host_client->message, svc_updatename);
MSG_WriteByte (&host_client->message, i);
MSG_WriteString (&host_client->message, client->name);
MSG_WriteByte (&host_client->message, svc_updatefrags);
MSG_WriteByte (&host_client->message, i);
MSG_WriteShort (&host_client->message, client->old_frags);
MSG_WriteByte (&host_client->message, svc_updatecolors);
MSG_WriteByte (&host_client->message, i);
MSG_WriteByte (&host_client->message, client->colors);
}
// send all current light styles
for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
{
MSG_WriteByte (&host_client->message, svc_lightstyle);
MSG_WriteByte (&host_client->message, (char)i);
MSG_WriteString (&host_client->message, sv.lightstyles[i]);
}
//
// send some stats
//
MSG_WriteByte (&host_client->message, svc_updatestat);
MSG_WriteByte (&host_client->message, STAT_TOTALSECRETS);
MSG_WriteLong (&host_client->message, pr_global_struct->total_secrets);
MSG_WriteByte (&host_client->message, svc_updatestat);
MSG_WriteByte (&host_client->message, STAT_TOTALMONSTERS);
MSG_WriteLong (&host_client->message, pr_global_struct->total_monsters);
MSG_WriteByte (&host_client->message, svc_updatestat);
MSG_WriteByte (&host_client->message, STAT_SECRETS);
MSG_WriteLong (&host_client->message, pr_global_struct->found_secrets);
MSG_WriteByte (&host_client->message, svc_updatestat);
MSG_WriteByte (&host_client->message, STAT_MONSTERS);
MSG_WriteLong (&host_client->message, pr_global_struct->killed_monsters);
//
// send a fixangle
// Never send a roll angle, because savegames can catch the server
// in a state where it is expecting the client to correct the angle
// and it won't happen if the game was just loaded, so you wind up
// with a permanent head tilt
ent = EDICT_NUM( 1 + (host_client - svs.clients) );
// 2000-05-02 NVS SVC_setangle by Maddes start
// MSG_WriteByte (&host_client->message, svc_setangle);
NVS_InitSVCMsg(MSG_ONE, svc_setangle, 0, host_client);
NVS_WriteByte (MSG_ONE, svc_setangle, NULL);
// 2000-05-02 NVS SVC_setangle by Maddes end
for (i=0 ; i < 2 ; i++)
// 2000-05-02 NVS SVC_setangle by Maddes start
// MSG_WriteAngle (&host_client->message, ent->v.angles[i] );
{
NVS_WriteAngle (MSG_ONE, ent->v.angles[i], NULL);
}
// MSG_WriteAngle (&host_client->message, 0 );
NVS_WriteAngle (MSG_ONE, 0, NULL);
if (nvs_current_ssvc->value >= 0.50)
{
for (i=0 ; i < 2 ; i++)
{
NVS_WriteFloat (MSG_ONE, ent->v.angles[i], NULL);
}
NVS_WriteFloat (MSG_ONE, 0, NULL);
}
// 2000-05-02 NVS SVC_setangle by Maddes end
SV_WriteClientdataToMessage (sv_player, &host_client->message);
MSG_WriteByte (&host_client->message, svc_signonnum);
MSG_WriteByte (&host_client->message, 3);
host_client->sendsignon = true;
}
/*
==================
Host_Begin_f
==================
*/
void Host_Begin_f (void)
{
if (cmd_source == src_command)
{
Con_Printf ("begin is not valid from the console\n");
return;
}
host_client->spawned = true;
}
//===========================================================================
/*
==================
Host_Kick_f
Kicks a user off of the server
==================
*/
void Host_Kick_f (void)
{
char *who;
char *message = NULL;
client_t *save;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -