📄 sv_ccmds.c
字号:
// we must restore these for clients to transfer over correctly
for (i=0,cl=svs.clients ; i<maxclients->value; i++,cl++)
cl->edict->inuse = savedInuse[i];
free (savedInuse);
}
}
// start up the next map
SV_Map (false, Cmd_Argv(1), false );
// archive server state
strncpy (svs.mapcmd, Cmd_Argv(1), sizeof(svs.mapcmd)-1);
// copy off the level to the autosave slot
if (!dedicated->value)
{
SV_WriteServerFile (true);
SV_CopySaveGame ("current", "save0");
}
}
/*
==================
SV_Map_f
Goes directly to a given map without any savegame archiving.
For development work
==================
*/
void SV_Map_f (void)
{
char *map;
char expanded[MAX_QPATH];
// if not a pcx, demo, or cinematic, check to make sure the level exists
map = Cmd_Argv(1);
if (!strstr (map, "."))
{
Com_sprintf (expanded, sizeof(expanded), "maps/%s.bsp", map);
if (FS_LoadFile (expanded, NULL) == -1)
{
Com_Printf ("Can't find %s\n", expanded);
return;
}
}
sv.state = ss_dead; // don't save current level when changing
SV_WipeSavegame("current");
SV_GameMap_f ();
}
/*
=====================================================================
SAVEGAMES
=====================================================================
*/
/*
==============
SV_Loadgame_f
==============
*/
void SV_Loadgame_f (void)
{
char name[MAX_OSPATH];
FILE *f;
char *dir;
if (Cmd_Argc() != 2)
{
Com_Printf ("USAGE: loadgame <directory>\n");
return;
}
Com_Printf ("Loading game...\n");
dir = Cmd_Argv(1);
if (strstr (dir, "..") || strstr (dir, "/") || strstr (dir, "\\") )
{
Com_Printf ("Bad savedir.\n");
}
// make sure the server.ssv file exists
Com_sprintf (name, sizeof(name), "%s/save/%s/server.ssv", FS_Gamedir(), Cmd_Argv(1));
f = fopen (name, "rb");
if (!f)
{
Com_Printf ("No such savegame: %s\n", name);
return;
}
fclose (f);
SV_CopySaveGame (Cmd_Argv(1), "current");
SV_ReadServerFile ();
// go to the map
sv.state = ss_dead; // don't save current level when changing
SV_Map (false, svs.mapcmd, true);
}
/*
==============
SV_Savegame_f
==============
*/
void SV_Savegame_f (void)
{
char *dir;
if (sv.state != ss_game)
{
Com_Printf ("You must be in a game to save.\n");
return;
}
if (Cmd_Argc() != 2)
{
Com_Printf ("USAGE: savegame <directory>\n");
return;
}
if (Cvar_VariableValue("deathmatch"))
{
Com_Printf ("Can't savegame in a deathmatch\n");
return;
}
if (!strcmp (Cmd_Argv(1), "current"))
{
Com_Printf ("Can't save to 'current'\n");
return;
}
if (maxclients->value == 1 && svs.clients[0].edict->client->ps.stats[STAT_HEALTH] <= 0)
{
Com_Printf ("\nCan't savegame while dead!\n");
return;
}
dir = Cmd_Argv(1);
if (strstr (dir, "..") || strstr (dir, "/") || strstr (dir, "\\") )
{
Com_Printf ("Bad savedir.\n");
}
Com_Printf ("Saving game...\n");
// archive current level, including all client edicts.
// when the level is reloaded, they will be shells awaiting
// a connecting client
SV_WriteLevelFile ();
// save server state
SV_WriteServerFile (false);
// copy it off
SV_CopySaveGame ("current", dir);
Com_Printf ("Done.\n");
}
//===============================================================
/*
==================
SV_Kick_f
Kick a user off of the server
==================
*/
void SV_Kick_f (void)
{
if (!svs.initialized)
{
Com_Printf ("No server running.\n");
return;
}
if (Cmd_Argc() != 2)
{
Com_Printf ("Usage: kick <userid>\n");
return;
}
if (!SV_SetPlayer ())
return;
SV_BroadcastPrintf (PRINT_HIGH, "%s was kicked\n", sv_client->name);
// print directly, because the dropped client won't get the
// SV_BroadcastPrintf message
SV_ClientPrintf (sv_client, PRINT_HIGH, "You were kicked from the game\n");
SV_DropClient (sv_client);
sv_client->lastmessage = svs.realtime; // min case there is a funny zombie
}
/*
================
SV_Status_f
================
*/
void SV_Status_f (void)
{
int i, j, l;
client_t *cl;
char *s;
int ping;
if (!svs.clients)
{
Com_Printf ("No server running.\n");
return;
}
Com_Printf ("map : %s\n", sv.name);
Com_Printf ("num score ping name lastmsg address qport \n");
Com_Printf ("--- ----- ---- --------------- ------- --------------------- ------\n");
for (i=0,cl=svs.clients ; i<maxclients->value; i++,cl++)
{
if (!cl->state)
continue;
Com_Printf ("%3i ", i);
Com_Printf ("%5i ", cl->edict->client->ps.stats[STAT_FRAGS]);
if (cl->state == cs_connected)
Com_Printf ("CNCT ");
else if (cl->state == cs_zombie)
Com_Printf ("ZMBI ");
else
{
ping = cl->ping < 9999 ? cl->ping : 9999;
Com_Printf ("%4i ", ping);
}
Com_Printf ("%s", cl->name);
l = 16 - strlen(cl->name);
for (j=0 ; j<l ; j++)
Com_Printf (" ");
Com_Printf ("%7i ", svs.realtime - cl->lastmessage );
s = NET_AdrToString ( cl->netchan.remote_address);
Com_Printf ("%s", s);
l = 22 - strlen(s);
for (j=0 ; j<l ; j++)
Com_Printf (" ");
Com_Printf ("%5i", cl->netchan.qport);
Com_Printf ("\n");
}
Com_Printf ("\n");
}
/*
==================
SV_ConSay_f
==================
*/
void SV_ConSay_f(void)
{
client_t *client;
int j;
char *p;
char text[1024];
if (Cmd_Argc () < 2)
return;
strcpy (text, "console: ");
p = Cmd_Args();
if (*p == '"')
{
p++;
p[strlen(p)-1] = 0;
}
strcat(text, p);
for (j = 0, client = svs.clients; j < maxclients->value; j++, client++)
{
if (client->state != cs_spawned)
continue;
SV_ClientPrintf(client, PRINT_CHAT, "%s\n", text);
}
}
/*
==================
SV_Heartbeat_f
==================
*/
void SV_Heartbeat_f (void)
{
svs.last_heartbeat = -9999999;
}
/*
===========
SV_Serverinfo_f
Examine or change the serverinfo string
===========
*/
void SV_Serverinfo_f (void)
{
Com_Printf ("Server info settings:\n");
Info_Print (Cvar_Serverinfo());
}
/*
===========
SV_DumpUser_f
Examine all a users info strings
===========
*/
void SV_DumpUser_f (void)
{
if (Cmd_Argc() != 2)
{
Com_Printf ("Usage: info <userid>\n");
return;
}
if (!SV_SetPlayer ())
return;
Com_Printf ("userinfo\n");
Com_Printf ("--------\n");
Info_Print (sv_client->userinfo);
}
/*
==============
SV_ServerRecord_f
Begins server demo recording. Every entity and every message will be
recorded, but no playerinfo will be stored. Primarily for demo merging.
==============
*/
void SV_ServerRecord_f (void)
{
char name[MAX_OSPATH];
char buf_data[32768];
sizebuf_t buf;
int len;
int i;
if (Cmd_Argc() != 2)
{
Com_Printf ("serverrecord <demoname>\n");
return;
}
if (svs.demofile)
{
Com_Printf ("Already recording.\n");
return;
}
if (sv.state != ss_game)
{
Com_Printf ("You must be in a level to record.\n");
return;
}
//
// open the demo file
//
Com_sprintf (name, sizeof(name), "%s/demos/%s.dm2", FS_Gamedir(), Cmd_Argv(1));
Com_Printf ("recording to %s.\n", name);
FS_CreatePath (name);
svs.demofile = fopen (name, "wb");
if (!svs.demofile)
{
Com_Printf ("ERROR: couldn't open.\n");
return;
}
// setup a buffer to catch all multicasts
SZ_Init (&svs.demo_multicast, svs.demo_multicast_buf, sizeof(svs.demo_multicast_buf));
//
// write a single giant fake message with all the startup info
//
SZ_Init (&buf, buf_data, sizeof(buf_data));
//
// serverdata needs to go over for all types of servers
// to make sure the protocol is right, and to set the gamedir
//
// send the serverdata
MSG_WriteByte (&buf, svc_serverdata);
MSG_WriteLong (&buf, PROTOCOL_VERSION);
MSG_WriteLong (&buf, svs.spawncount);
// 2 means server demo
MSG_WriteByte (&buf, 2); // demos are always attract loops
MSG_WriteString (&buf, Cvar_VariableString ("gamedir"));
MSG_WriteShort (&buf, -1);
// send full levelname
MSG_WriteString (&buf, sv.configstrings[CS_NAME]);
for (i=0 ; i<MAX_CONFIGSTRINGS ; i++)
if (sv.configstrings[i][0])
{
MSG_WriteByte (&buf, svc_configstring);
MSG_WriteShort (&buf, i);
MSG_WriteString (&buf, sv.configstrings[i]);
}
// write it to the demo file
Com_DPrintf ("signon message length: %i\n", buf.cursize);
len = LittleLong (buf.cursize);
fwrite (&len, 4, 1, svs.demofile);
fwrite (buf.data, buf.cursize, 1, svs.demofile);
// the rest of the demo file will be individual frames
}
/*
==============
SV_ServerStop_f
Ends server demo recording
==============
*/
void SV_ServerStop_f (void)
{
if (!svs.demofile)
{
Com_Printf ("Not doing a serverrecord.\n");
return;
}
fclose (svs.demofile);
svs.demofile = NULL;
Com_Printf ("Recording completed.\n");
}
/*
===============
SV_KillServer_f
Kick everyone off, possibly in preparation for a new game
===============
*/
void SV_KillServer_f (void)
{
if (!svs.initialized)
return;
SV_Shutdown ("Server was killed.\n", false);
NET_Config ( false ); // close network sockets
}
/*
===============
SV_ServerCommand_f
Let the game dll handle a command
===============
*/
void SV_ServerCommand_f (void)
{
if (!ge)
{
Com_Printf ("No game loaded.\n");
return;
}
ge->ServerCommand();
}
//===========================================================
/*
==================
SV_InitOperatorCommands
==================
*/
void SV_InitOperatorCommands (void)
{
Cmd_AddCommand ("heartbeat", SV_Heartbeat_f);
Cmd_AddCommand ("kick", SV_Kick_f);
Cmd_AddCommand ("status", SV_Status_f);
Cmd_AddCommand ("serverinfo", SV_Serverinfo_f);
Cmd_AddCommand ("dumpuser", SV_DumpUser_f);
Cmd_AddCommand ("map", SV_Map_f);
Cmd_AddCommand ("demomap", SV_DemoMap_f);
Cmd_AddCommand ("gamemap", SV_GameMap_f);
Cmd_AddCommand ("setmaster", SV_SetMaster_f);
if ( dedicated->value )
Cmd_AddCommand ("say", SV_ConSay_f);
Cmd_AddCommand ("serverrecord", SV_ServerRecord_f);
Cmd_AddCommand ("serverstop", SV_ServerStop_f);
Cmd_AddCommand ("save", SV_Savegame_f);
Cmd_AddCommand ("load", SV_Loadgame_f);
Cmd_AddCommand ("killserver", SV_KillServer_f);
Cmd_AddCommand ("sv", SV_ServerCommand_f);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -