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 } /* 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/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/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 a2f994b296..7462ac95af 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 )); @@ -5148,7 +5147,14 @@ qboolean SV_LoadProgs( const char *name ) static playermove_t gpMove; edict_t *e; - if( svgame.hInstance ) SV_UnloadProgs(); + 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_init.c b/engine/server/sv_init.c index ce2c7ac390..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; } @@ -1115,28 +1114,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 diff --git a/engine/server/sv_main.c b/engine/server/sv_main.c index 54430bed4e..9b30ab17b3 100644 --- a/engine/server/sv_main.c +++ b/engine/server/sv_main.c @@ -1091,7 +1091,9 @@ void SV_Shutdown( const char *finalmsg ) if( CL_IsPlaybackDemo( )) CL_Drop(); - SV_UnloadProgs (); +#if XASH_WIN32 + SV_UnloadProgs(); +#endif // XASH_WIN32 return; } @@ -1108,7 +1110,10 @@ void SV_Shutdown( const char *finalmsg ) NET_MasterShutdown(); NET_Config( false, false ); - SV_UnloadProgs (); + SV_DeactivateServer(); +#if XASH_WIN32 + SV_UnloadProgs(); +#endif // XASH_WIN32 CL_Drop(); // free current level 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) == '/' ))