Example #1
0
int main(int argc, char** argv)
{
	if(!udtSameVersion())
	{
		PrintError("Compiled with header for version %s, but linked against version %s", UDT_VERSION_STRING, udtGetVersionString());
		return 1;
	}

	if(argc < 2)
	{
		PrintHelp();
		return 2;
	}

	if(!IsValidFilePath(argv[1]))
	{
		PrintHelp();
		return 3;
	}

	udtInitLibrary();
	udtSetCrashHandler(&CrashCallback);

	PlayerPrinter printer;
	if(printer.Init())
	{
		printer.ProcessDemoFile(argv[1]);
	}

	udtShutDownLibrary();

	return 0;
}
Example #2
0
gfcontext_t *BuildContextFromRequestString(char *request)
{
	char *delimiter = " ";
	char *saveptr;

	printf("Parsing request string [%s]\n", request);

	gfcontext_t *context = malloc(sizeof(gfcontext_t));
	context->Scheme = ParseScheme(strtok_r(request, delimiter, &saveptr));
	context->Method = ParseMethod(strtok_r(NULL, delimiter, &saveptr));
	context->FilePath = strtok_r(NULL, delimiter, &saveptr);
	context->Status = GF_OK;

	if(context->Scheme == NO_SCHEME)
	{
		printf("Parsed scheme [%d] is not a known scheme.", context->Scheme);
		context->Status = GF_ERROR;
		return context;
	}

	if(context->Method == NO_METHOD)
	{
		printf("Parsed method [%d] is not a known method.", context->Method);
		context->Status = GF_ERROR;
		return context;
	}

	if(!IsValidFilePath(context->FilePath))
	{
		printf("Parsed file path [%s] is not a known path.", context->FilePath);
		context->Status = GF_ERROR;
		return context;
	}

    printf("Context.Scheme: %d\n", context->Scheme);
    printf("Context.Method: %d\n", context->Method);
    printf("Context.FilePath: %s\n", context->FilePath);
	return context;
}
Example #3
0
int CLuaDatabaseDefs::DbConnect ( lua_State* luaVM )
{
    //  element dbConnect ( string type, string host, string username, string password, string options )
    SString strType; SString strHost; SString strUsername; SString strPassword; SString strOptions;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( strType );
    argStream.ReadString ( strHost );
    argStream.ReadString ( strUsername, "" );
    argStream.ReadString ( strPassword, "" );
    argStream.ReadString ( strOptions, "" );

    if ( !argStream.HasErrors () )
    {
        CResource* pThisResource = m_pLuaManager->GetVirtualMachineResource ( luaVM );
        if ( pThisResource )
        {
            // If type is sqlite, and has a host, try to resolve path
            if ( strType == "sqlite" && !strHost.empty () )
            {
                // If path starts with :/ then use global database directory
                if ( strHost.BeginsWith ( ":/" ) )
                {
                    strHost = strHost.SubStr ( 1 );
                    if ( !IsValidFilePath ( strHost ) )
                    {
                        argStream.SetCustomError( SString( "host path %s not valid", *strHost ) );
                    }
                    else
                    {
                        strHost = PathJoin ( g_pGame->GetConfig ()->GetGlobalDatabasesPath (), strHost );
                    }
                }
                else
                {
                    std::string strAbsPath;

                    // Parse path
                    CResource* pPathResource = pThisResource;
                    if ( CResourceManager::ParseResourcePathInput ( strHost, pPathResource, &strAbsPath ) )
                    {
                        strHost = strAbsPath;
                        CheckCanModifyOtherResource( argStream, pThisResource, pPathResource );
                    }
                    else
                    {
                        argStream.SetCustomError( SString( "host path %s not found", *strHost ) );
                    }
                }
            }

            if ( !argStream.HasErrors() )
            {
                if ( strType == "mysql" )
                    pThisResource->SetUsingDbConnectMysql( true );

                // Add logging options
                bool bLoggingEnabled;
                SString strLogTag;
                SString strQueueName;
                // Set default values if required
                GetOption < CDbOptionsMap > ( strOptions, "log", bLoggingEnabled, 1 );
                GetOption < CDbOptionsMap > ( strOptions, "tag", strLogTag, "script" );
                GetOption < CDbOptionsMap > ( strOptions, "queue", strQueueName, (strType == "mysql") ? strHost : DB_SQLITE_QUEUE_NAME_DEFAULT );
                SetOption < CDbOptionsMap > ( strOptions, "log", bLoggingEnabled );
                SetOption < CDbOptionsMap > ( strOptions, "tag", strLogTag );
                SetOption < CDbOptionsMap > ( strOptions, "queue", strQueueName );
                // Do connect
                SConnectionHandle connection = g_pGame->GetDatabaseManager ()->Connect ( strType, strHost, strUsername, strPassword, strOptions );
                if ( connection == INVALID_DB_HANDLE )
                {
                    argStream.SetCustomError( g_pGame->GetDatabaseManager()->GetLastErrorMessage() );
                }
                else
                {
                    // Use an element to wrap the connection for auto disconnected when the resource stops
                    // Don't set a parent because the element should not be accessible from other resources
                    CDatabaseConnectionElement* pElement = new CDatabaseConnectionElement ( NULL, connection );
                    CElementGroup * pGroup = pThisResource->GetElementGroup ();
                    if ( pGroup )
                    {
                        pGroup->Add ( pElement );
                    }

                    lua_pushelement ( luaVM, pElement );
                    return 1;
                }
            }
        }
    }

    if ( argStream.HasErrors() )
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}