shithub: qk1

Download patch

ref: d308fcf8a67f13bf34be3ed9862d3386de49c21d
parent: ac7e6ac77f7eaa31be48c79a18b28f41e6ee9c22
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Fri Dec 29 14:45:28 EST 2023

demo: instead of failing on EOF when running a demo with no other demos queued, disconnect properly

--- a/cl_main.c
+++ b/cl_main.c
@@ -112,10 +112,9 @@
 	SCR_BringDownConsole ();
 
 	// if running a local server, shut it down
-	if (cls.demoplayback)
-		abortdemo ();
-	else if (cls.state == ca_connected)
-	{
+	if(cls.demoplayback)
+		abortdemo();
+	else if (cls.state == ca_connected){
 		if (cls.demorecording)
 			stopdemo();
 
@@ -219,29 +218,28 @@
 Called to play the next demo in the demo loop
 =====================
 */
-void CL_NextDemo (void)
+bool
+CL_NextDemo (void)
 {
-	char	str[1024];
+	char str[1024];
 
-	if (cls.demonum == -1)
-		return;		// don't play demos
+	if(cls.demonum < 0)
+		return false; // don't play demos
 
-	SCR_BeginLoadingPlaque ();
-
-	if (!cls.demos[cls.demonum][0] || cls.demonum == MAX_DEMOS)
-	{
+	if(!cls.demos[cls.demonum][0] || cls.demonum == MAX_DEMOS){
 		cls.demonum = 0;
-		if (!cls.demos[cls.demonum][0])
-		{
-			Con_Printf ("No demos listed with startdemos\n");
+		if(!cls.demos[cls.demonum][0]){
+			Con_Printf("No demos listed with startdemos\n");
 			cls.demonum = -1;
-			return;
+			return false;
 		}
 	}
 
-	sprint (str,"playdemo %s\n", cls.demos[cls.demonum]);
-	Cbuf_InsertText (str);
+	SCR_BeginLoadingPlaque();
+	sprint(str, "playdemo %s\n", cls.demos[cls.demonum]);
+	Cbuf_InsertText(str);
 	cls.demonum++;
+	return true;
 }
 
 /*
--- a/client.h
+++ b/client.h
@@ -262,7 +262,7 @@
 
 void CL_Disconnect (void);
 void CL_Disconnect_f (void);
-void CL_NextDemo (void);
+bool CL_NextDemo (void);
 
 #define			MAX_VISEDICTS	65536
 extern	int				cl_numvisedicts;
--- a/host.c
+++ b/host.c
@@ -69,9 +69,7 @@
 		Host_ShutdownServer(false);
 	if(cls.state == ca_dedicated)
 		fatal("Host_EndGame: %s\n", s);	// dedicated servers exit
-	if(cls.demonum != -1)
-		CL_NextDemo();
-	else
+	if(!CL_NextDemo())
 		CL_Disconnect();
 
 	longjmp(host_abortserver, 1);