NetworkSystem: fix bug when checking for pending map change

We need to check if it has a string before calling Playlists_Parse(), because if it has it will be emptied so the check afterwards won't work.
This commit is contained in:
Kawe Mazidjatari 2024-12-05 23:38:53 +01:00
parent 8490344d93
commit 551840e6a3

View File

@ -30,6 +30,8 @@ static void HostManager_HandleCommandInternal(const char* const map, const char*
Msg(eDLL_T::ENGINE, "Starting server with name: \"%s\" map: \"%s\" mode: \"%s\"\n", Msg(eDLL_T::ENGINE, "Starting server with name: \"%s\" map: \"%s\" mode: \"%s\"\n",
hostname->GetString(), map, mode); hostname->GetString(), map, mode);
bool hasPendingMap = *g_pPlaylistMapToLoad != '\0';
// NOTE: when the provided playlist is the same as the one we're currently // NOTE: when the provided playlist is the same as the one we're currently
// on, and there's already a pending map load request, the game will run // on, and there's already a pending map load request, the game will run
// "map <mapName>" in Playlists_Parse, where the map name is dictated by // "map <mapName>" in Playlists_Parse, where the map name is dictated by
@ -37,13 +39,16 @@ static void HostManager_HandleCommandInternal(const char* const map, const char*
// requested map here as to prevent Playlists_Parse from running the map // requested map here as to prevent Playlists_Parse from running the map
// command on it, as we are going to run the changelevel command anyways. // command on it, as we are going to run the changelevel command anyways.
// Not doing this will result in running both map and changelevel commands. // Not doing this will result in running both map and changelevel commands.
if (changeLevel) if (changeLevel && hasPendingMap)
{
*g_pPlaylistMapToLoad = '\0'; *g_pPlaylistMapToLoad = '\0';
hasPendingMap = false;
}
const bool samePlaylist = v_Playlists_Parse(mode); const bool samePlaylist = v_Playlists_Parse(mode);
char commandBuf[512]; char commandBuf[512];
if (!samePlaylist || !*g_pPlaylistMapToLoad) if (!samePlaylist || !hasPendingMap)
{ {
snprintf(commandBuf, sizeof(commandBuf), "%s %s\n", changeLevel ? "changelevel" : "map", map); snprintf(commandBuf, sizeof(commandBuf), "%s %s\n", changeLevel ? "changelevel" : "map", map);
Cbuf_AddText(Cbuf_GetCurrentPlayer(), commandBuf, cmd_source_t::kCommandSrcCode); Cbuf_AddText(Cbuf_GetCurrentPlayer(), commandBuf, cmd_source_t::kCommandSrcCode);