Index: darkplaces/cl_demo.c
diff -u darkplaces/cl_demo.c:1.23 darkplaces/cl_demo.c:1.24
--- darkplaces/cl_demo.c:1.23	Wed Mar 10 01:17:56 2004
+++ darkplaces/cl_demo.c	Mon Apr  5 02:20:23 2004
@@ -319,6 +319,7 @@
 
 	// disconnect from server
 	CL_Disconnect ();
+	Host_ShutdownServer (false);
 
 	// update networking ports (this is mainly just needed at startup)
 	NetConn_ClientFrame();
Index: darkplaces/cl_input.c
diff -u darkplaces/cl_input.c:1.29 darkplaces/cl_input.c:1.30
--- darkplaces/cl_input.c:1.29	Tue Mar  9 22:28:01 2004
+++ darkplaces/cl_input.c	Mon Apr  5 02:20:23 2004
@@ -465,6 +465,7 @@
 	{
 		Con_Print("CL_SendMove: lost server connection\n");
 		CL_Disconnect();
+		Host_ShutdownServer(false);
 	}
 }
 
Index: darkplaces/cl_main.c
diff -u darkplaces/cl_main.c:1.118 darkplaces/cl_main.c:1.119
--- darkplaces/cl_main.c:1.118	Wed Mar 17 01:48:04 2004
+++ darkplaces/cl_main.c	Mon Apr  5 02:20:23 2004
@@ -159,6 +159,8 @@
 	if (cls.state == ca_dedicated)
 		return;
 
+	Con_DPrintf("CL_Disconnect\n");
+
 // stop sounds (especially looping!)
 	S_StopAllSounds (true);
 
@@ -184,13 +186,6 @@
 		SZ_Clear(&cls.message);
 		NetConn_Close(cls.netcon);
 		cls.netcon = NULL;
-		// if running a local server, shut it down
-		if (sv.active)
-		{
-			// prevent this code from executing again during Host_ShutdownServer
-			cls.state = ca_disconnected;
-			Host_ShutdownServer(false);
-		}
 	}
 	cls.state = ca_disconnected;
 
Index: darkplaces/host.c
diff -u darkplaces/host.c:1.101 darkplaces/host.c:1.102
--- darkplaces/host.c:1.101	Wed Mar 10 01:17:56 2004
+++ darkplaces/host.c	Mon Apr  5 02:20:23 2004
@@ -111,8 +111,7 @@
 	va_end (argptr);
 	Con_DPrintf("Host_EndGame: %s\n",string);
 
-	if (sv.active)
-		Host_ShutdownServer (false);
+	Host_ShutdownServer (false);
 
 	if (cls.state == ca_dedicated)
 		Sys_Error ("Host_EndGame: %s\n",string);	// dedicated servers exit
@@ -168,8 +167,7 @@
 
 	PRVM_ProcessError();
 
-	if (sv.active)
-		Host_ShutdownServer (false);
+	Host_ShutdownServer (false);
 
 	if (cls.state == ca_dedicated)
 		Sys_Error ("Host_Error: %s\n",hosterrorstring2);	// dedicated servers exit
@@ -507,14 +505,11 @@
 	if (!sv.active)
 		return;
 
+	Con_DPrintf("Host_ShutdownServer\n");
+
 	// print out where the crash happened, if it was caused by QC
 	PR_Crash();
 
-	sv.active = false;
-
-// stop all client sounds immediately
-	CL_Disconnect();
-
 	NetConn_Heartbeat(2);
 	NetConn_Heartbeat(2);
 
@@ -533,6 +528,8 @@
 
 	NetConn_CloseServerPorts();
 
+	sv.active = false;
+
 //
 // clear structures
 //
Index: darkplaces/host_cmd.c
diff -u darkplaces/host_cmd.c:1.63 darkplaces/host_cmd.c:1.64
--- darkplaces/host_cmd.c:1.63	Tue Mar  9 22:28:01 2004
+++ darkplaces/host_cmd.c	Mon Apr  5 02:20:23 2004
@@ -1673,6 +1673,7 @@
 	if (!cls.demoplayback)
 		return;
 	CL_Disconnect ();
+	Host_ShutdownServer (false);
 }
 
 static void MaxPlayers_f(void)
Index: darkplaces/netconn.c
diff -u darkplaces/netconn.c:1.27 darkplaces/netconn.c:1.28
--- darkplaces/netconn.c:1.27	Fri Apr  2 02:12:10 2004
+++ darkplaces/netconn.c	Mon Apr  5 02:20:23 2004
@@ -986,6 +986,7 @@
 	{
 		Con_Print("Connection timed out\n");
 		CL_Disconnect();
+		Host_ShutdownServer (false);
 	}
 	for (conn = netconn_list;conn;conn = conn->next)
 		NetConn_ReSendMessage(conn);