From 1b92049622062956a04f1766f66f072350773acb Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Fri, 14 May 2021 16:24:24 +0000 Subject: [PATCH] client: Add SV_Shutdown hook and remove all direct calls in non-server code. Lock the server mutex within SV_Shutdown itself. Call the hook directly from CL_Disconnect. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@13141 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_demo.c | 9 +++------ cl_input.c | 3 --- cl_main.c | 7 ++++--- fs.c | 2 +- host.c | 12 +++++------- host.h | 1 + netconn.c | 11 +---------- sv_main.c | 9 +++++++-- 8 files changed, 22 insertions(+), 32 deletions(-) diff --git a/cl_demo.c b/cl_demo.c index a962785f..eb4ab55e 100644 --- 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(); } /* diff --git a/cl_input.c b/cl_input.c index b309f0b4..651e9d28 100644 --- a/cl_input.c +++ b/cl_input.c @@ -2166,9 +2166,6 @@ void CL_SendMove(void) { Con_Print("CL_SendMove: lost server connection\n"); CL_Disconnect(); - SV_LockThreadMutex(); - SV_Shutdown(); - SV_UnlockThreadMutex(); } } diff --git a/cl_main.c b/cl_main.c index e468e92a..4471edd3 100644 --- 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 ff621404..f5e67b36 100644 --- 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 fa3c4911..ba8531f0 100644 --- 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 c87c3649..1d553c25 100644 --- 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; diff --git a/netconn.c b/netconn.c index 32fb1f35..af1aae28 100755 --- 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(); } } diff --git a/sv_main.c b/sv_main.c index 5c4c490f..dcb91a7f 100644 --- 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(); } ///////////////////////////////////////////////////// -- 2.39.2