|
|
@ -677,96 +677,6 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha |
|
|
|
if( !Sys_CheckParm( "-noch" ) ) |
|
|
|
if( !Sys_CheckParm( "-noch" ) ) |
|
|
|
Sys_SetupCrashHandler(); |
|
|
|
Sys_SetupCrashHandler(); |
|
|
|
|
|
|
|
|
|
|
|
// to be accessed later
|
|
|
|
|
|
|
|
if( ( host.daemonized = Sys_CheckParm( "-daemonize" ) ) ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
#if defined(_POSIX_VERSION) && !defined(XASH_MOBILE_PLATFORM) |
|
|
|
|
|
|
|
pid_t daemon; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
daemon = fork(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( daemon < 0 ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Host_Error( "fork() failed: %s\n", strerror( errno ) ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( daemon > 0 ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// parent
|
|
|
|
|
|
|
|
Con_Reportf( "Child pid: %i\n", daemon ); |
|
|
|
|
|
|
|
exit( 0 ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// don't be closed by parent
|
|
|
|
|
|
|
|
if( setsid() < 0 ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Host_Error( "setsid() failed: %s\n", strerror( errno ) ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// set permissions
|
|
|
|
|
|
|
|
umask( 0 ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// engine will still use stdin/stdout,
|
|
|
|
|
|
|
|
// so just redirect them to /dev/null
|
|
|
|
|
|
|
|
close( STDIN_FILENO ); |
|
|
|
|
|
|
|
close( STDOUT_FILENO ); |
|
|
|
|
|
|
|
close( STDERR_FILENO ); |
|
|
|
|
|
|
|
open("/dev/null", O_RDONLY); // becomes stdin
|
|
|
|
|
|
|
|
open("/dev/null", O_RDWR); // stdout
|
|
|
|
|
|
|
|
open("/dev/null", O_RDWR); // stderr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fallthrough
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#elif defined(XASH_MOBILE_PLATFORM) |
|
|
|
|
|
|
|
Sys_Error( "Can't run in background on mobile platforms!" ); |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
Sys_Error( "Daemonize not supported on this platform!" ); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( ( baseDir = getenv( "XASH3D_BASEDIR" ) ) ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Q_strncpy( host.rootdir, baseDir, sizeof(host.rootdir) ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
#if TARGET_OS_IOS |
|
|
|
|
|
|
|
const char *IOS_GetDocsDir(); |
|
|
|
|
|
|
|
Q_strncpy( host.rootdir, IOS_GetDocsDir(), sizeof(host.rootdir) ); |
|
|
|
|
|
|
|
#elif XASH_SDL == 2 |
|
|
|
|
|
|
|
char *szBasePath; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( !( szBasePath = SDL_GetBasePath() ) ) |
|
|
|
|
|
|
|
Sys_Error( "couldn't determine current directory: %s", SDL_GetError() ); |
|
|
|
|
|
|
|
Q_strncpy( host.rootdir, szBasePath, sizeof( host.rootdir ) ); |
|
|
|
|
|
|
|
SDL_free( szBasePath ); |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
if( !getcwd( host.rootdir, sizeof(host.rootdir) ) ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Sys_Error( "couldn't determine current directory: %s", strerror( errno ) ); |
|
|
|
|
|
|
|
host.rootdir[0] = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( host.rootdir[Q_strlen( host.rootdir ) - 1] == '/' ) |
|
|
|
|
|
|
|
host.rootdir[Q_strlen( host.rootdir ) - 1] = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get readonly root. The order is: check for arg, then env.
|
|
|
|
|
|
|
|
// if still not got it, rodir is disabled.
|
|
|
|
|
|
|
|
host.rodir[0] = 0; |
|
|
|
|
|
|
|
if( !Sys_GetParmFromCmdLine( "-rodir", host.rodir )) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
char *roDir; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(( roDir = getenv( "XASH3D_RODIR" ))) |
|
|
|
|
|
|
|
Q_strncpy( host.rodir, roDir, sizeof( host.rodir )); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( host.rodir[0] && host.rodir[Q_strlen( host.rodir ) - 1] == '/' ) |
|
|
|
|
|
|
|
host.rodir[Q_strlen( host.rodir ) - 1] = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
host.enabledll = !Sys_CheckParm( "-nodll" ); |
|
|
|
host.enabledll = !Sys_CheckParm( "-nodll" ); |
|
|
|
|
|
|
|
|
|
|
|
host.change_game = bChangeGame; |
|
|
|
host.change_game = bChangeGame; |
|
|
@ -809,30 +719,6 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#ifdef XASH_SDL |
|
|
|
|
|
|
|
#ifndef SDL_INIT_EVENTS |
|
|
|
|
|
|
|
#define SDL_INIT_EVENTS 0 |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( SDL_Init( SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS ) ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Sys_Warn( "SDL_Init failed: %s", SDL_GetError() ); |
|
|
|
|
|
|
|
host.type = HOST_DEDICATED; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if XASH_SDL == 2 |
|
|
|
|
|
|
|
SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0"); |
|
|
|
|
|
|
|
SDL_StopTextInput(); |
|
|
|
|
|
|
|
#endif // XASH_SDL == 2
|
|
|
|
|
|
|
|
#endif // XASH_SDL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( !host.rootdir[0] || SetCurrentDirectory( host.rootdir ) != 0) |
|
|
|
|
|
|
|
Con_Reportf( "%s is working directory now\n", host.rootdir ); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
Sys_Error( "Changing working directory to %s failed.\n", host.rootdir ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sys_InitLog(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// set default gamedir
|
|
|
|
// set default gamedir
|
|
|
|
if( progname[0] == '#' ) |
|
|
|
if( progname[0] == '#' ) |
|
|
|
progname++; |
|
|
|
progname++; |
|
|
@ -856,13 +742,10 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha |
|
|
|
// member console allowing
|
|
|
|
// member console allowing
|
|
|
|
host.allow_console_init = host.allow_console; |
|
|
|
host.allow_console_init = host.allow_console; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32 |
|
|
|
|
|
|
|
Wcon_CreateConsole(); // system console used by dedicated server or show fatal errors
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
// timeBeginPeriod( 1 ); // a1ba: Do we need this?
|
|
|
|
// timeBeginPeriod( 1 ); // a1ba: Do we need this?
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE: this message couldn't be passed into game console but it doesn't matter
|
|
|
|
// NOTE: this message couldn't be passed into game console but it doesn't matter
|
|
|
|
Con_Reportf( "Sys_LoadLibrary: Loading xash.dll - ok\n" ); |
|
|
|
// Con_Reportf( "Sys_LoadLibrary: Loading xash.dll - ok\n" );
|
|
|
|
|
|
|
|
|
|
|
|
// get default screen res
|
|
|
|
// get default screen res
|
|
|
|
VID_InitDefaultResolution(); |
|
|
|
VID_InitDefaultResolution(); |
|
|
@ -889,6 +772,58 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Con_Init(); // early console running to catch all the messages
|
|
|
|
Con_Init(); // early console running to catch all the messages
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Platform_Init(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( ( baseDir = getenv( "XASH3D_BASEDIR" ) ) ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Q_strncpy( host.rootdir, baseDir, sizeof(host.rootdir) ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
#if TARGET_OS_IOS |
|
|
|
|
|
|
|
const char *IOS_GetDocsDir(); |
|
|
|
|
|
|
|
Q_strncpy( host.rootdir, IOS_GetDocsDir(), sizeof(host.rootdir) ); |
|
|
|
|
|
|
|
#elif XASH_SDL == 2 |
|
|
|
|
|
|
|
char *szBasePath; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( !( szBasePath = SDL_GetBasePath() ) ) |
|
|
|
|
|
|
|
Sys_Error( "couldn't determine current directory: %s", SDL_GetError() ); |
|
|
|
|
|
|
|
Q_strncpy( host.rootdir, szBasePath, sizeof( host.rootdir ) ); |
|
|
|
|
|
|
|
SDL_free( szBasePath ); |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
if( !getcwd( host.rootdir, sizeof(host.rootdir) ) ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Sys_Error( "couldn't determine current directory: %s", strerror( errno ) ); |
|
|
|
|
|
|
|
host.rootdir[0] = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( host.rootdir[Q_strlen( host.rootdir ) - 1] == '/' ) |
|
|
|
|
|
|
|
host.rootdir[Q_strlen( host.rootdir ) - 1] = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get readonly root. The order is: check for arg, then env.
|
|
|
|
|
|
|
|
// if still not got it, rodir is disabled.
|
|
|
|
|
|
|
|
host.rodir[0] = 0; |
|
|
|
|
|
|
|
if( !Sys_GetParmFromCmdLine( "-rodir", host.rodir )) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
char *roDir; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(( roDir = getenv( "XASH3D_RODIR" ))) |
|
|
|
|
|
|
|
Q_strncpy( host.rodir, roDir, sizeof( host.rodir )); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( host.rodir[0] && host.rodir[Q_strlen( host.rodir ) - 1] == '/' ) |
|
|
|
|
|
|
|
host.rodir[Q_strlen( host.rodir ) - 1] = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( !host.rootdir[0] || SetCurrentDirectory( host.rootdir ) != 0) |
|
|
|
|
|
|
|
Con_Reportf( "%s is working directory now\n", host.rootdir ); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
Sys_Error( "Changing working directory to %s failed.\n", host.rootdir ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sys_InitLog(); |
|
|
|
|
|
|
|
|
|
|
|
Cmd_AddCommand( "exec", Host_Exec_f, "execute a script file" ); |
|
|
|
Cmd_AddCommand( "exec", Host_Exec_f, "execute a script file" ); |
|
|
|
Cmd_AddCommand( "memlist", Host_MemStats_f, "prints memory pool information" ); |
|
|
|
Cmd_AddCommand( "memlist", Host_MemStats_f, "prints memory pool information" ); |
|
|
|
|
|
|
|
|
|
|
@ -1064,9 +999,7 @@ void EXPORT Host_Shutdown( void ) |
|
|
|
NET_Shutdown(); |
|
|
|
NET_Shutdown(); |
|
|
|
HTTP_Shutdown(); |
|
|
|
HTTP_Shutdown(); |
|
|
|
Host_FreeCommon(); |
|
|
|
Host_FreeCommon(); |
|
|
|
#ifdef _WIN32 |
|
|
|
Platform_Shutdown(); |
|
|
|
Wcon_DestroyConsole(); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// must be last, console uses this
|
|
|
|
// must be last, console uses this
|
|
|
|
Mem_FreePool( &host.mempool ); |
|
|
|
Mem_FreePool( &host.mempool ); |
|
|
|