]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
client: Add SV_Shutdown hook and remove all direct calls in non-server code. Lock...
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 14 May 2021 16:24:24 +0000 (16:24 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 14 May 2021 16:24:24 +0000 (16:24 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@13141 d7cf8633-e32d-0410-b094-e92efae38249

cl_demo.c
cl_input.c
cl_main.c
fs.c
host.c
host.h
netconn.c
sv_main.c

index a962785fbf79e8f8fe178b562fce1b70c0c143b5..eb4ab55e933592bbace8c10a2220e6970c9bd93d 100644 (file)
--- a/cl_demo.c
+++ b/cl_demo.c
@@ -422,10 +422,7 @@ void CL_PlayDemo(const char *demo)
        cls.demostarting = true;
 
        // disconnect from server
-       if(cls.state == ca_connected)
-               CL_Disconnect();
-       if(sv.active)
-               SV_Shutdown();
+       CL_Disconnect();
 
        // update networking ports (this is mainly just needed at startup)
        NetConn_UpdateSockets();
@@ -683,8 +680,8 @@ static void CL_Demos_f(cmd_state_t *cmd)
                return;
        if (cls.demonum == -1)
                cls.demonum = 1;
-       CL_Disconnect_f (cmd);
-       CL_NextDemo ();
+       CL_Disconnect();
+       CL_NextDemo();
 }
 
 /*
index b309f0b4453274ef8c2d73303a7dedf7102626b2..651e9d28ee56f6b4e928cde0458d76266de82786 100644 (file)
@@ -2166,9 +2166,6 @@ void CL_SendMove(void)
        {
                Con_Print("CL_SendMove: lost server connection\n");
                CL_Disconnect();
-               SV_LockThreadMutex();
-               SV_Shutdown();
-               SV_UnlockThreadMutex();
        }
 }
 
index e468e92a861074404f7d56786d76dc51019958a1..4471edd3d4e24f9e6d645e2444bf406f30e75638 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -432,6 +432,9 @@ void CL_Disconnect(void)
 
        // If we're dropped mid-connection attempt, it won't clear otherwise.
        SCR_ClearLoadingScreen(false);
+
+       if(host.hook.SV_Shutdown)
+               host.hook.SV_Shutdown();
 }
 
 /*
@@ -512,9 +515,7 @@ static void CL_Connect_f(cmd_state_t *cmd)
 
 void CL_Disconnect_f(cmd_state_t *cmd)
 {
-       CL_Disconnect ();
-       if (sv.active)
-               SV_Shutdown ();
+       CL_Disconnect();
 }
 
 
diff --git a/fs.c b/fs.c
index ff62140481ea1d773b9d80d665d7a2a8e9ef058c..f5e67b36519bb7d39cfcc472a2a681162ef166e9 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -1577,7 +1577,7 @@ qbool FS_ChangeGameDirs(int numgamedirs, char gamedirs[][MAX_QPATH], qbool compl
 
        if (cls.demoplayback)
        {
-               CL_Disconnect_f(cmd_local);
+               CL_Disconnect();
                cls.demonum = 0;
        }
 
diff --git a/host.c b/host.c
index fa3c4911894d04441ef096a3a94bc59a5d31ab11..ba8531f0ce0bb118267eb3d182a770781feaba7f 100644 (file)
--- a/host.c
+++ b/host.c
@@ -127,9 +127,8 @@ void Host_Error (const char *error, ...)
        Cvar_SetValueQuick(&csqc_progcrc, -1);
        Cvar_SetValueQuick(&csqc_progsize, -1);
 
-       SV_LockThreadMutex();
-       SV_Shutdown ();
-       SV_UnlockThreadMutex();
+       if(host.hook.SV_Shutdown)
+               host.hook.SV_Shutdown();
 
        if (cls.state == ca_dedicated)
                Sys_Error ("Host_Error: %s",hosterrorstring2);  // dedicated servers exit
@@ -374,7 +373,7 @@ static void Host_Init (void)
        host.hook.Disconnect = NULL;
        host.hook.ToggleMenu = NULL;
        host.hook.CL_Intermission = NULL;
-       host.hook.SV_CanSave = NULL;
+       host.hook.SV_Shutdown = NULL;
 
        host.state = host_init;
 
@@ -587,9 +586,8 @@ void Host_Shutdown(void)
                SV_StopThread();
 
        // shut down local server if active
-       SV_LockThreadMutex();
-       SV_Shutdown ();
-       SV_UnlockThreadMutex();
+       if(host.hook.SV_Shutdown)
+               host.hook.SV_Shutdown();
 
        // AK shutdown PRVM
        // AK hmm, no PRVM_Shutdown(); yet
diff --git a/host.h b/host.h
index c87c3649edf86715e69226558e6e0028fd877718..1d553c2509fdf3dbe0ebf8c96adc27879a245729 100644 (file)
--- a/host.h
+++ b/host.h
@@ -36,6 +36,7 @@ typedef struct host_s
                qbool (*CL_Intermission)(void); // Quake compatibility
                void (*CL_SendCvar)(struct cmd_state_s *);
                void (*SV_SendCvar)(struct cmd_state_s *);
+               void (*SV_Shutdown)(void);
        } hook;
 } host_t;
 
index 32fb1f35000229956fddc63b45550838526cc524..af1aae28eab4c3b8e15297ed96206ef3473f894d 100755 (executable)
--- a/netconn.c
+++ b/netconn.c
@@ -1527,13 +1527,7 @@ static void NetConn_ConnectionEstablished(lhnetsocket_t *mysocket, lhnetaddress_
 #ifdef CONFIG_MENU
        M_Update_Return_Reason("");
 #endif
-       // if we're connecting to a remote server, shut down any local server
-       if (LHNETADDRESS_GetAddressType(peeraddress) != LHNETADDRESSTYPE_LOOP && sv.active)
-       {
-               SV_LockThreadMutex();
-               SV_Shutdown ();
-               SV_UnlockThreadMutex();
-       }
+       // Disconnect from the current server or stop demo playback
        if(cls.state == ca_connected || cls.demoplayback)
                CL_Disconnect();
        // allocate a net connection to keep track of things
@@ -2497,9 +2491,6 @@ void NetConn_ClientFrame(void)
        {
                Con_Print("Connection timed out\n");
                CL_Disconnect();
-               SV_LockThreadMutex();
-               SV_Shutdown ();
-               SV_UnlockThreadMutex();
        }
 }
 
index 5c4c490f1243795e2452bb00babd7f0e5b84c502..dcb91a7f9147ca33912d3ab6551c0a3cad8622d3 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -686,6 +686,7 @@ void SV_Init (void)
        Cvar_RegisterVariable (&sv_writepicture_quality);
 
        SV_InitOperatorCommands();
+       host.hook.SV_Shutdown = SV_Shutdown;
 
        sv_mempool = Mem_AllocPool("server", 0, NULL);
 
@@ -2058,10 +2059,12 @@ void SV_Shutdown(void)
        prvm_prog_t *prog = SVVM_prog;
        int i;
 
-       Con_DPrintf("SV_Shutdown\n");
+       SV_LockThreadMutex();
 
        if (!sv.active)
-               return;
+               goto end;
+
+       Con_DPrintf("SV_Shutdown\n");
 
        NetConn_Heartbeat(2);
        NetConn_Heartbeat(2);
@@ -2090,6 +2093,8 @@ void SV_Shutdown(void)
 //
        memset(&sv, 0, sizeof(sv));
        memset(svs.clients, 0, svs.maxclients*sizeof(client_t));
+end:
+       SV_UnlockThreadMutex();
 }
 
 /////////////////////////////////////////////////////