Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable server unload #1430

Merged
merged 6 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions engine/client/cl_gameui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/*
Expand Down
2 changes: 0 additions & 2 deletions engine/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
8 changes: 0 additions & 8 deletions engine/common/con_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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" );

Expand All @@ -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
}

/*
Expand Down
2 changes: 2 additions & 0 deletions engine/common/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1308,6 +1309,7 @@ void EXPORT Host_Shutdown( void )
#endif

SV_Shutdown( "Server shutdown\n" );
SV_UnloadProgs();
SV_ShutdownFilter();
CL_Shutdown();

Expand Down
1 change: 0 additions & 1 deletion engine/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions engine/server/sv_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ));
Expand All @@ -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;
Expand Down
25 changes: 1 addition & 24 deletions engine/server/sv_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ qboolean SV_InitGame( void )
{
string dllpath;

if( svs.game_library_loaded )
if( svgame.hInstance )
return true;

// first initialize?
Expand All @@ -721,7 +721,6 @@ qboolean SV_InitGame( void )
}

// client frames will be allocated in SV_ClientConnect
svs.game_library_loaded = true;
return true;
}

Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions engine/server/sv_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion public/crtlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) == '/' ))
Expand Down
Loading