Exemple #1
0
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{

	char lpFilename[MAX_OSPATH];
    char sys_cmdline[MAX_STRING_CHARS];
	char *lastSep;
	DWORD copylen;
	
	if(lpCmdLine != NULL)
		Q_strncpyz( sys_cmdline, lpCmdLine, sizeof( sys_cmdline ) );
	else
		sys_cmdline[0] = '\0';
		
	g_wv.hInstance = hInstance;

	copylen = GetModuleFileName(NULL, lpFilename, sizeof(lpFilename));
	if(copylen >= (sizeof(lpFilename) -1))
	{
		Sys_SetExeFile( "" );
		Sys_SetBinaryPath( "" );
		MessageBoxA(NULL, "Path is too long. The whole path to location of this .exe file must not exceed 254 characters", CLIENT_WINDOW_TITLE " Error", MB_OK | MB_ICONERROR);
		return 1;
	}else{
		Sys_SetExeFile( lpFilename );
		lastSep = strrchr(lpFilename, '\\');
		
		if(lastSep != NULL)
		{
			*lastSep = '\0';
			if(strlen(lastSep +1) > MAX_QPATH)
			{
				MessageBoxA(NULL, ".EXE filename exceeds " "64" " characters.", CLIENT_WINDOW_TITLE " Error", MB_OK | MB_ICONERROR);
				return 1;
			}
			Sys_SetBinaryPath( lpFilename );
		}else{
			MessageBoxA(NULL, "GetModuleFileName() returned an unexpected filepath.", CLIENT_WINDOW_TITLE " Error", MB_OK | MB_ICONERROR);
			return 1;	
		}
	}
	
    return Sys_Main(sys_cmdline);
}
Exemple #2
0
int main(int argc, char* argv[])
{

    int i;

    uid_t uid = getuid();
    if( uid == 0 || uid != geteuid() ) { // warn user that he/she's operating as a privliged user
        Com_Printf( "********************************************************\n" );    
        Com_Printf( "***** RUNNING SERVER AS A ROOT IS GENERALLY UNSAFE *****\n" );
        Com_Printf( "********************************************************\n\n" );  
    }
    // go back to real user for config loads
    seteuid( uid );


    char commandLine[MAX_STRING_CHARS];

    commandLine[0] = 0;

    // Concatenate the command line for passing to Com_Init
    for( i = 1; i < argc; i++ )
    {
        const qboolean containsSpaces = strchr(argv[i], ' ') != NULL;
        if (containsSpaces)
            Q_strcat( commandLine, sizeof( commandLine ), "\"" );

        Q_strcat( commandLine, sizeof( commandLine ), argv[ i ] );

        if (containsSpaces)
            Q_strcat( commandLine, sizeof( commandLine ), "\"" );

        Q_strcat( commandLine, sizeof( commandLine ), " " );
    }

    Sys_SetExeFile( argv[ 0 ] );
    /* This function modifies argv[ 0 ] :S */
    Sys_SetBinaryPath( Sys_Dirname( argv[ 0 ] ) );

    return Sys_Main(commandLine);
}