From 733cf20a1038593d68acf3c461eb27936377476a Mon Sep 17 00:00:00 2001
From: JugadorXEI <eugeniom9@gmail.com>
Date: Fri, 28 May 2021 16:32:21 +0200
Subject: [PATCH] Set GS_LEVEL after level load, set GS_WAITINGFORPLAYERS
 during level transition if GS_LEVEL is current GS

---
 src/d_main.c |  2 +-
 src/g_game.c | 22 ++++++++++++++--------
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/d_main.c b/src/d_main.c
index 2c02565dc..d570ae356 100644
--- a/src/d_main.c
+++ b/src/d_main.c
@@ -1597,9 +1597,9 @@ void D_SRB2Main(void)
 	{
 		pagename = "TITLESKY";
 		levelstarttic = gametic;
-		G_SetGamestate(GS_LEVEL);
 		if (!P_SetupLevel(false))
 			I_Quit(); // fail so reset game stuff
+		G_SetGamestate(GS_LEVEL);
 	}
 
 #ifdef HAVE_DISCORDRPC
diff --git a/src/g_game.c b/src/g_game.c
index c6cb31b08..c6c6d63ff 100644
--- a/src/g_game.c
+++ b/src/g_game.c
@@ -1733,14 +1733,12 @@ void G_DoLoadLevel(boolean resetplayer)
 		Y_EndIntermission();
 	if (gamestate == GS_VOTING)
 		Y_EndVote();
-
-	G_SetGamestate(GS_LEVEL);
-
-	for (i = 0; i < MAXPLAYERS; i++)
-	{
-		if (resetplayer || (playeringame[i] && players[i].playerstate == PST_DEAD))
-			players[i].playerstate = PST_REBORN;
-	}
+	// Don't allow people to download a partial/corrupted
+	// save while the server's loading the map/during the wipe.
+	// (this addresses "map" command usage, which means
+	// transitions/different gamestates would be skipped.)
+	if (gamestate == GS_LEVEL)
+		gamestate = GS_WAITINGPLAYERS;
 
 	// Setup the level.
 	if (!P_SetupLevel(false))
@@ -1750,6 +1748,14 @@ void G_DoLoadLevel(boolean resetplayer)
 		return;
 	}
 
+	G_SetGamestate(GS_LEVEL);
+
+	for (i = 0; i < MAXPLAYERS; i++)
+	{
+		if (resetplayer || (playeringame[i] && players[i].playerstate == PST_DEAD))
+			players[i].playerstate = PST_REBORN;
+	}
+
 	if (!resetplayer)
 		P_FindEmerald();
 
-- 
GitLab