command: move kill and pause commands server side

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
This commit is contained in:
Kevin Shanahan 2013-03-24 18:26:07 +10:30
parent 7a1e32fdcf
commit a429465604
3 changed files with 53 additions and 63 deletions

View File

@ -855,4 +855,6 @@ CL_Init(void)
Cmd_AddCommand("notarget", NULL);
Cmd_AddCommand("ping", NULL);
Cmd_AddCommand("give", NULL);
Cmd_AddCommand("kill", NULL);
Cmd_AddCommand("pause", NULL);
}

View File

@ -625,63 +625,6 @@ Host_Tell_f(void)
host_client = save;
}
/*
==================
Host_Kill_f
==================
*/
static void
Host_Kill_f(void)
{
if (cmd_source == src_command) {
Cmd_ForwardToServer();
return;
}
if (sv_player->v.health <= 0) {
SV_ClientPrintf("Can't suicide -- allready 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
==================
*/
static 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_GetString(sv_player->v.netname));
} else {
SV_BroadcastPrintf("%s unpaused the game\n",
PR_GetString(sv_player->v.netname));
}
// send notification to all clients
MSG_WriteByte(&sv.reliable_datagram, svc_setpause);
MSG_WriteByte(&sv.reliable_datagram, sv.paused);
}
}
//===========================================================================
@ -1161,8 +1104,6 @@ Host_InitCommands(void)
Cmd_AddCommand("say", Host_Say_f);
Cmd_AddCommand("say_team", Host_Say_Team_f);
Cmd_AddCommand("tell", Host_Tell_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);

View File

@ -782,6 +782,55 @@ SV_Give_f(client_t *client)
}
}
/*
==================
SV_Kill_f
==================
*/
static void
SV_Kill_f(client_t *client)
{
edict_t *player = client->edict;
if (player->v.health <= 0) {
SV_ClientPrintf("Can't suicide -- allready dead!\n");
return;
}
pr_global_struct->time = sv.time;
pr_global_struct->self = EDICT_TO_PROG(player);
PR_ExecuteProgram(pr_global_struct->ClientKill);
}
/*
==================
Host_Pause_f
==================
*/
static void
SV_Pause_f(client_t *client)
{
edict_t *player;
if (!pausable.value) {
SV_ClientPrintf("Pause not allowed.\n");
return;
}
player = client->edict;
sv.paused ^= 1;
if (sv.paused)
SV_BroadcastPrintf("%s paused the game\n",
PR_GetString(player->v.netname));
else
SV_BroadcastPrintf("%s unpaused the game\n",
PR_GetString(player->v.netname));
// send notification to all clients
MSG_WriteByte(&sv.reliable_datagram, svc_setpause);
MSG_WriteByte(&sv.reliable_datagram, sv.paused);
}
/* ------------------------------------------------------------------------ */
typedef struct {
@ -799,6 +848,8 @@ static client_command_t client_commands[] = {
{ "notarget", SV_Notarget_f },
{ "give", SV_Give_f },
{ "ping", SV_Ping_f },
{ "kill", SV_Kill_f },
{ "pause", SV_Pause_f },
{ NULL, NULL },
};
@ -883,10 +934,6 @@ SV_ReadClientMessage(client_t *client)
ret = 1;
else if (strncasecmp(message, "tell", 4) == 0)
ret = 1;
else if (strncasecmp(message, "kill", 4) == 0)
ret = 1;
else if (strncasecmp(message, "pause", 5) == 0)
ret = 1;
else if (strncasecmp(message, "spawn", 5) == 0)
ret = 1;
else if (strncasecmp(message, "begin", 5) == 0)