From bea6cb189cb6d95a1e99321231ddc42ee214337c Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Fri, 9 Feb 2024 16:53:14 +1000 Subject: [PATCH] changelevel: start a map even if none is running Implements https://gitlab.com/xonotic/darkplaces/-/issues/408 Although the original implementation of this convenience 688396cea66f09e7ce20d3e3b077261dd1d3db7e labeled it as a hack, it was robust, simple and worked fine in div0-stable, so removing it in cb11bdeed238603b11d8dac4908cfdbabe298079 was a regression. Also removes some redundant string copying. Signed-off-by: bones_was_here --- sv_ccmds.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/sv_ccmds.c b/sv_ccmds.c index 2b2a0c96..138b2c09 100644 --- a/sv_ccmds.c +++ b/sv_ccmds.c @@ -49,8 +49,6 @@ command from the console. Active clients are kicked off. */ static void SV_Map_f(cmd_state_t *cmd) { - char level[MAX_QPATH]; - if (Cmd_Argc(cmd) != 2) { Con_Print("map : start a new game (kicks off all players)\n"); @@ -78,8 +76,7 @@ static void SV_Map_f(cmd_state_t *cmd) host.hook.ToggleMenu(); svs.serverflags = 0; // haven't completed an episode yet - dp_strlcpy(level, Cmd_Argv(cmd, 1), sizeof(level)); - SV_SpawnServer(level); + SV_SpawnServer(Cmd_Argv(cmd, 1)); if(sv.active && host.hook.ConnectLocal != NULL) host.hook.ConnectLocal(); @@ -94,8 +91,6 @@ Goes to a new map, taking all clients along */ static void SV_Changelevel_f(cmd_state_t *cmd) { - char level[MAX_QPATH]; - if (Cmd_Argc(cmd) != 2) { Con_Print("changelevel : continue game on a new level\n"); @@ -104,7 +99,7 @@ static void SV_Changelevel_f(cmd_state_t *cmd) if (!sv.active) { - Con_Printf("You must be running a server to changelevel. Use 'map %s' instead\n", Cmd_Argv(cmd, 1)); + SV_Map_f(cmd); return; } @@ -112,8 +107,7 @@ static void SV_Changelevel_f(cmd_state_t *cmd) host.hook.ToggleMenu(); SV_SaveSpawnparms (); - dp_strlcpy(level, Cmd_Argv(cmd, 1), sizeof(level)); - SV_SpawnServer(level); + SV_SpawnServer(Cmd_Argv(cmd, 1)); if(sv.active && host.hook.ConnectLocal != NULL) host.hook.ConnectLocal(); @@ -128,8 +122,6 @@ Restarts the current server for a dead player */ static void SV_Restart_f(cmd_state_t *cmd) { - char mapname[MAX_QPATH]; - if (Cmd_Argc(cmd) != 1) { Con_Print("restart : restart current level\n"); @@ -144,8 +136,7 @@ static void SV_Restart_f(cmd_state_t *cmd) if(host.hook.ToggleMenu) host.hook.ToggleMenu(); - dp_strlcpy(mapname, sv.worldbasename, sizeof(mapname)); - SV_SpawnServer(mapname); + SV_SpawnServer(sv.worldbasename); if(sv.active && host.hook.ConnectLocal != NULL) host.hook.ConnectLocal(); @@ -1613,7 +1604,7 @@ void SV_InitOperatorCommands(void) Cmd_AddCommand(CF_SERVER | CF_SERVER_FROM_CLIENT, "status", SV_Status_f, "print server status information"); Cmd_AddCommand(CF_SHARED, "map", SV_Map_f, "kick everyone off the server and start a new level"); Cmd_AddCommand(CF_SHARED, "restart", SV_Restart_f, "restart current level"); - Cmd_AddCommand(CF_SHARED, "changelevel", SV_Changelevel_f, "change to another level, bringing along all connected clients"); + Cmd_AddCommand(CF_SHARED, "changelevel", SV_Changelevel_f, "change to another level, bringing along all connected clients (or start a new level if none is loaded)"); Cmd_AddCommand(CF_SHARED | CF_SERVER_FROM_CLIENT, "say", SV_Say_f, "send a chat message to everyone on the server"); Cmd_AddCommand(CF_SERVER_FROM_CLIENT, "say_team", SV_Say_Team_f, "send a chat message to your team on the server"); Cmd_AddCommand(CF_SHARED | CF_SERVER_FROM_CLIENT, "tell", SV_Tell_f, "send a chat message to only one person on the server"); -- 2.39.2