From a2c9ac5b1f6dd75f46691d4530b785ef882e6534 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 23 Sep 2023 04:07:24 +0300 Subject: [PATCH 1/6] engine: client: disable server DLL probe for GameUI, check it's existence instead --- engine/client/cl_gameui.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/engine/client/cl_gameui.c b/engine/client/cl_gameui.c index 068a47d0a7..ede3c36db2 100644 --- a/engine/client/cl_gameui.c +++ b/engine/client/cl_gameui.c @@ -982,28 +982,21 @@ pfnCheckGameDll */ int GAME_EXPORT pfnCheckGameDll( void ) { - string dllpath; - void *hInst; - -#if TARGET_OS_IPHONE - // loading server library drains too many ram - // so 512MB iPod Touch cannot even connect to - // to servers in cstrike +#if XASH_INTERNAL_GAMELIBS return true; -#endif +#else + string dllpath; if( svgame.hInstance ) return true; COM_GetCommonLibraryPath( LIBRARY_SERVER, dllpath, sizeof( dllpath )); - if(( hInst = COM_LoadLibrary( dllpath, true, false )) != NULL ) - { - COM_FreeLibrary( hInst ); // don't increase linker's reference counter + if( FS_FileExists( dllpath, false )) return true; - } - Con_Reportf( S_WARN "Could not load server library: %s\n", COM_GetLibraryError() ); + return false; +#endif } /* From d8b261370a9665ba1cf34ceef32f857dfb6e80cd Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 23 Sep 2023 04:08:35 +0300 Subject: [PATCH 2/6] engine: common: do not probe server to collect cvars for game.cfg (CHECK THIS) --- engine/common/common.h | 2 -- engine/common/con_utils.c | 8 -------- engine/server/sv_init.c | 22 ---------------------- 3 files changed, 32 deletions(-) diff --git a/engine/common/common.h b/engine/common/common.h index 0816002973..c382fbcd37 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -747,8 +747,6 @@ void SV_ShutdownGame( void ); void SV_ExecLoadLevel( void ); void SV_ExecLoadGame( void ); void SV_ExecChangeLevel( void ); -qboolean SV_InitGameProgs( void ); -void SV_FreeGameProgs( void ); void CL_WriteMessageHistory( void ); void CL_SendCmd( void ); void CL_Disconnect( void ); diff --git a/engine/common/con_utils.c b/engine/common/con_utils.c index 1be94c0aad..7a763d9e84 100644 --- a/engine/common/con_utils.c +++ b/engine/common/con_utils.c @@ -1423,15 +1423,11 @@ save serverinfo variables into server.cfg (using for dedicated server too) */ void GAME_EXPORT Host_WriteServerConfig( const char *name ) { - qboolean already_loaded; file_t *f; string newconfigfile; Q_snprintf( newconfigfile, MAX_STRING, "%s.new", name ); - // TODO: remove this mechanism, make it safer for now - already_loaded = SV_InitGameProgs(); // collect user variables - // FIXME: move this out until menu parser is done CSCR_LoadDefaultCVars( "settings.scr" ); @@ -1448,10 +1444,6 @@ void GAME_EXPORT Host_WriteServerConfig( const char *name ) Host_FinalizeConfig( f, name ); } else Con_DPrintf( S_ERROR "Couldn't write %s.\n", name ); - - // don't unload library that wasn't loaded by us - if( !already_loaded ) - SV_FreeGameProgs(); // release progs with all variables } /* diff --git a/engine/server/sv_init.c b/engine/server/sv_init.c index ce2c7ac390..87ae350e1a 100644 --- a/engine/server/sv_init.c +++ b/engine/server/sv_init.c @@ -1115,28 +1115,6 @@ int SV_GetMaxClients( void ) return svs.maxclients; } -qboolean SV_InitGameProgs( void ) -{ - string dllpath; - - if( svgame.hInstance ) return true; // already loaded - - COM_GetCommonLibraryPath( LIBRARY_SERVER, dllpath, sizeof( dllpath )); - - // just try to initialize - SV_LoadProgs( dllpath ); - - return false; -} - -void SV_FreeGameProgs( void ) -{ - if( svs.initialized ) return; // server is active - - // unload progs (free cvars and commands) - SV_UnloadProgs(); -} - /* ================ SV_ExecLoadLevel From 8fb908e3d4cd103230639f435ebc8837e76a9c54 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 23 Sep 2023 04:09:18 +0300 Subject: [PATCH 3/6] engine: server: disable SV_UnloadProgs, only call it when shutting down engine --- engine/common/host.c | 2 ++ engine/server/sv_game.c | 3 ++- engine/server/sv_main.c | 4 +--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/engine/common/host.c b/engine/common/host.c index 9aa174b71d..654a564f87 100644 --- a/engine/common/host.c +++ b/engine/common/host.c @@ -33,6 +33,7 @@ GNU General Public License for more details. #include "common.h" #include "base_cmd.h" #include "client.h" +#include "server.h" #include "netchan.h" #include "protocol.h" #include "mod_local.h" @@ -1308,6 +1309,7 @@ void EXPORT Host_Shutdown( void ) #endif SV_Shutdown( "Server shutdown\n" ); + SV_UnloadProgs(); SV_ShutdownFilter(); CL_Shutdown(); diff --git a/engine/server/sv_game.c b/engine/server/sv_game.c index a2f994b296..3b07e63fc1 100644 --- a/engine/server/sv_game.c +++ b/engine/server/sv_game.c @@ -5148,7 +5148,8 @@ qboolean SV_LoadProgs( const char *name ) static playermove_t gpMove; edict_t *e; - if( svgame.hInstance ) SV_UnloadProgs(); + if( svgame.hInstance ) + return true; // fill it in svgame.pmove = &gpMove; diff --git a/engine/server/sv_main.c b/engine/server/sv_main.c index 54430bed4e..4d012391c0 100644 --- a/engine/server/sv_main.c +++ b/engine/server/sv_main.c @@ -1090,8 +1090,6 @@ void SV_Shutdown( const char *finalmsg ) // drop the client if want to load a new map if( CL_IsPlaybackDemo( )) CL_Drop(); - - SV_UnloadProgs (); return; } @@ -1108,7 +1106,7 @@ void SV_Shutdown( const char *finalmsg ) NET_MasterShutdown(); NET_Config( false, false ); - SV_UnloadProgs (); + SV_DeactivateServer(); CL_Drop(); // free current level From 78bc177e0570f8a6aab2f93f26547dea11dd69b5 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sun, 24 Sep 2023 07:49:09 +0300 Subject: [PATCH 4/6] engine: server: remove unused host struct field --- engine/server/server.h | 1 - engine/server/sv_game.c | 1 - engine/server/sv_init.c | 3 +-- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/engine/server/server.h b/engine/server/server.h index 2077053416..7667381a03 100644 --- a/engine/server/server.h +++ b/engine/server/server.h @@ -360,7 +360,6 @@ typedef struct typedef struct { qboolean initialized; // sv_init has completed - qboolean game_library_loaded; // is game library loaded in SV_InitGame double timestart; // just for profiling int maxclients; // server max clients diff --git a/engine/server/sv_game.c b/engine/server/sv_game.c index 3b07e63fc1..aac91db0dc 100644 --- a/engine/server/sv_game.c +++ b/engine/server/sv_game.c @@ -5130,7 +5130,6 @@ void SV_UnloadProgs( void ) Mod_ResetStudioAPI (); - svs.game_library_loaded = false; COM_FreeLibrary( svgame.hInstance ); Mem_FreePool( &svgame.mempool ); memset( &svgame, 0, sizeof( svgame )); diff --git a/engine/server/sv_init.c b/engine/server/sv_init.c index 87ae350e1a..d4eebd62b0 100644 --- a/engine/server/sv_init.c +++ b/engine/server/sv_init.c @@ -706,7 +706,7 @@ qboolean SV_InitGame( void ) { string dllpath; - if( svs.game_library_loaded ) + if( svgame.hInstance ) return true; // first initialize? @@ -721,7 +721,6 @@ qboolean SV_InitGame( void ) } // client frames will be allocated in SV_ClientConnect - svs.game_library_loaded = true; return true; } From fe407fbe009955a6961712b2b6eb76bcc1f69d06 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 27 Oct 2023 08:38:20 +0300 Subject: [PATCH 5/6] public: workaround when empty string is passed to COM_ExtractFilePath (should make safe COM_ExtractFilePath) --- public/crtlib.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/public/crtlib.c b/public/crtlib.c index a556512252..6004b59b9f 100644 --- a/public/crtlib.c +++ b/public/crtlib.c @@ -642,7 +642,14 @@ COM_ExtractFilePath */ void COM_ExtractFilePath( const char *path, char *dest ) { - const char *src = path + Q_strlen( path ) - 1; + size_t len = Q_strlen( path ); + const char *src = path + len - 1; + + if( len == 0 ) + { + dest[0] = 0; + return; + } // back up until a \ or the start while( src != path && !(*(src - 1) == '\\' || *(src - 1) == '/' )) From f07eea5073c0ce6d8f285aa746f841c2d57a306b Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 28 Oct 2023 11:14:12 +0300 Subject: [PATCH 6/6] engine: server: allow server unloading for Win32 targets until we figure out the issues with MetaMod --- engine/server/sv_game.c | 6 ++++++ engine/server/sv_main.c | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/engine/server/sv_game.c b/engine/server/sv_game.c index aac91db0dc..7462ac95af 100644 --- a/engine/server/sv_game.c +++ b/engine/server/sv_game.c @@ -5148,7 +5148,13 @@ qboolean SV_LoadProgs( const char *name ) edict_t *e; if( svgame.hInstance ) + { +#if XASH_WIN32 + SV_UnloadProgs(); +#else // XASH_WIN32 return true; +#endif // XASH_WIN32 + } // fill it in svgame.pmove = &gpMove; diff --git a/engine/server/sv_main.c b/engine/server/sv_main.c index 4d012391c0..9b30ab17b3 100644 --- a/engine/server/sv_main.c +++ b/engine/server/sv_main.c @@ -1090,6 +1090,10 @@ void SV_Shutdown( const char *finalmsg ) // drop the client if want to load a new map if( CL_IsPlaybackDemo( )) CL_Drop(); + +#if XASH_WIN32 + SV_UnloadProgs(); +#endif // XASH_WIN32 return; } @@ -1107,6 +1111,9 @@ void SV_Shutdown( const char *finalmsg ) NET_Config( false, false ); SV_DeactivateServer(); +#if XASH_WIN32 + SV_UnloadProgs(); +#endif // XASH_WIN32 CL_Drop(); // free current level