Example #1
0
bool CMainConfig::LoadExtended ( void )
{
    std::string strBuffer;
    int iTemp = 0, iResult = 0;

    // minclientversion - Minimum client version or kick
    GetString ( m_pRootNode, "minclientversion", m_strMinClientVersion );
    if ( m_strMinClientVersion != "" && !IsValidVersionString ( m_strMinClientVersion ) )
    {
        CLogger::LogPrint ( "WARNING: Invalid value specified in \"minclientversion\"\n" );
        m_strMinClientVersion = "";
    }

    // recommendedclientversion - Minimum client version or spam
    GetString ( m_pRootNode, "recommendedclientversion", m_strRecommendedClientVersion );
    if ( m_strRecommendedClientVersion != "" && !IsValidVersionString ( m_strRecommendedClientVersion ) )
    {
        CLogger::LogPrint ( "WARNING: Invalid value specified in \"recommendedclientversion\"\n" );
        m_strRecommendedClientVersion = "";
    }

    // Grab the script debuglog
    if ( GetString ( m_pRootNode, "scriptdebuglogfile", strBuffer, 1, 255 ) == IS_SUCCESS )
    {
        m_strScriptDebugLogFile = g_pServerInterface->GetModManager ()->GetAbsolutePath ( strBuffer.c_str () );
        m_bScriptDebugLogEnabled = true;
    }
    else
    {
        m_bScriptDebugLogEnabled = false;
    }

    // Grab the script debuglog level
    iResult = GetInteger ( m_pRootNode, "scriptdebugloglevel", iTemp, 0, 3 );
    if ( iResult == IS_SUCCESS )
    {
        m_uiScriptDebugLogLevel = iTemp;
    }
    else
    {
        if ( iResult == INVALID_VALUE )
        {
            CLogger::LogPrint ( "WARNING: Invalid value specified in \"scriptdebugloglevel\" tag; defaulting to 0\n" );
        }

        m_uiScriptDebugLogLevel = 0;
    }

    iResult = GetInteger ( m_pRootNode, "htmldebuglevel", iTemp, 0, 3 );
    if ( iResult == IS_SUCCESS )
    {
        g_pGame->GetScriptDebugging()->SetHTMLLogLevel ( iTemp );
    }
    else
    {
        if ( iResult == INVALID_VALUE )
        {
            CLogger::LogPrint ( "WARNING: Invalid value specified in \"htmldebuglevel\" tag; defaulting to 0\n" );
        }

        g_pGame->GetScriptDebugging()->SetHTMLLogLevel ( 0 );
    }

    // Handle the <module> nodes
    CXMLNode* pNode = NULL;
    unsigned int uiCurrentIndex = 0;
    do
    {
        pNode = m_pRootNode->FindSubNode ( "module", uiCurrentIndex++ );
        if ( pNode )
        {
            CXMLAttribute* pAttribute = pNode->GetAttributes ().Find ( "src" );
            if ( pAttribute )
            {
                std::string strBuffer = pAttribute->GetValue ();
                SString strFilename ( "%s/modules/%s", g_pServerInterface->GetModManager ()->GetModPath (), strBuffer.c_str () );

                if ( IsValidFilePath ( strBuffer.c_str () ) )
                {
                    m_pLuaManager->GetLuaModuleManager ()->_LoadModule ( strBuffer.c_str (), strFilename, false );
                }
            }
        }
    }
    while ( pNode );
    
    // Handle the <resource> nodes
    pNode = NULL;
    uiCurrentIndex = 0;
    bool bFoundDefault = false;

    CLogger::SetMinLogLevel ( LOGLEVEL_MEDIUM );
    CLogger::LogPrint ( "Starting resources..." );
    CLogger::ProgressDotsBegin ();

    do
    {
        if ( g_pServerInterface->IsRequestingExit () )
            return false;

        // Grab the current script node
        pNode = m_pRootNode->FindSubNode ( "resource", uiCurrentIndex++ );
        if ( pNode )
        {
            // Grab its "src" attribute
            CXMLAttribute* pAttribute = pNode->GetAttributes ().Find ( "src" );
            if ( pAttribute )
            {
                // Grab the text in it and convert iwt to a path inside "scripts"
                std::string strBuffer = pAttribute->GetValue ();

                CResource * loadedResource = g_pGame->GetResourceManager ()->GetResource ( strBuffer.c_str () );
                if ( !loadedResource )
                {
                    CLogger::ErrorPrintf ( "Couldn't find resource %s. Check it exists.\n", strBuffer.c_str () );
                }
                else
                {
                    loadedResource->SetPersistent ( true );

                    pAttribute = pNode->GetAttributes ().Find ( "startup" );
                    if ( pAttribute )
                    {
                        std::string strStartup = pAttribute->GetValue ();
                        if ( strStartup.compare ( "true" ) == 0 ||
                             strStartup.compare ( "yes" ) == 0 ||
                             strStartup.compare ( "1" ) == 0 )
                        {
                            if ( loadedResource->Start( NULL, true ) )
                            {
                                CLogger::ProgressDotsUpdate ();
                            }
                            else
                            {
                                CLogger::ErrorPrintf ( "Unable to start resource %s; %s\n", strBuffer.c_str (), loadedResource->GetFailureReason ().c_str () );
                            }
                        }
                    }

                    pAttribute = pNode->GetAttributes ().Find ( "protected" );
                    if ( pAttribute )
                    {
                        std::string strProtected = pAttribute->GetValue ();
                        if ( strProtected.compare ( "true" ) == 0 ||
                             strProtected.compare ( "yes" ) == 0 ||
                             strProtected.compare ( "1" ) == 0 )
                            loadedResource->SetProtected ( true );
                    }

                    // Default resource
                    pAttribute = pNode->GetAttributes ().Find ( "default" );
                    if ( pAttribute )
                    {
                        if ( !bFoundDefault )
                        {
                            std::string strDefault = pAttribute->GetValue ();
                            if ( strDefault.compare ( "true" ) == 0 ||
                                strDefault.compare ( "yes" ) == 0 ||
                                strDefault.compare ( "1" ) == 0 )
                            {
                                std::string strName = loadedResource->GetName ();
                                if ( !strName.empty () )
                                {
                                    g_pGame->GetHTTPD ()->SetDefaultResource ( strName.c_str () );
                                }

                                bFoundDefault = true;
                            }
                        }
                        else
                        {
                            CLogger::ErrorPrintf ( "More than one default resource specified!\n" );
                        }
                    }
                }
            }
        }
    }
    while ( pNode );

    CLogger::ProgressDotsEnd ();
    CLogger::SetMinLogLevel ( LOGLEVEL_LOW );

    // Register the commands
    RegisterCommand ( "start", CConsoleCommands::StartResource, false );
    RegisterCommand ( "stop", CConsoleCommands::StopResource, false );
    RegisterCommand ( "stopall", CConsoleCommands::StopAllResources, false );
    RegisterCommand ( "restart", CConsoleCommands::RestartResource, false );
    RegisterCommand ( "refresh", CConsoleCommands::RefreshResources, false );
    RegisterCommand ( "refreshall", CConsoleCommands::RefreshAllResources, false );
    RegisterCommand ( "list", CConsoleCommands::ListResources, false );
    RegisterCommand ( "info", CConsoleCommands::ResourceInfo, false );
    RegisterCommand ( "upgrade", CConsoleCommands::UpgradeResources, false );
    RegisterCommand ( "check", CConsoleCommands::CheckResources, false );

    RegisterCommand ( "say", CConsoleCommands::Say, false );
    RegisterCommand ( "teamsay", CConsoleCommands::TeamSay, false );
    //RegisterCommand ( "asay", CConsoleCommands::ASay, false );    // Not working
    RegisterCommand ( "msg", CConsoleCommands::Msg, false );
    //RegisterCommand ( "amsg", CConsoleCommands::AMsg, false );    // Not working
    RegisterCommand ( "me", CConsoleCommands::Me, false );
    RegisterCommand ( "nick", CConsoleCommands::Nick, false );

    RegisterCommand ( "login", CConsoleCommands::LogIn, false );
    RegisterCommand ( "logout", CConsoleCommands::LogOut, false );
    RegisterCommand ( "chgmypass", CConsoleCommands::ChgMyPass, false );

    RegisterCommand ( "addaccount", CConsoleCommands::AddAccount, false );
    RegisterCommand ( "delaccount", CConsoleCommands::DelAccount, false );
    RegisterCommand ( "chgpass", CConsoleCommands::ChgPass, false );
    RegisterCommand ( "shutdown", CConsoleCommands::Shutdown, false );

    RegisterCommand ( "aexec", CConsoleCommands::AExec, false );

    RegisterCommand ( "whois", CConsoleCommands::WhoIs, false );
    RegisterCommand ( "whowas", CConsoleCommands::WhoWas, false );

    RegisterCommand ( "debugscript", CConsoleCommands::DebugScript, false );

    //RegisterCommand ( "sudo", CConsoleCommands::Sudo, false );    // Not working

    RegisterCommand ( "help", CConsoleCommands::Help, false );

    RegisterCommand ( "loadmodule", CConsoleCommands::LoadModule, false );
    //RegisterCommand ( "unloadmodule", CConsoleCommands::UnloadModule, false );
    //RegisterCommand ( "reloadmodule", CConsoleCommands::ReloadModule, false );

    RegisterCommand ( "ver", CConsoleCommands::Ver, false );
    RegisterCommand ( "sver", CConsoleCommands::Ver, false );
    RegisterCommand ( "ase", CConsoleCommands::Ase, false );
    RegisterCommand ( "openports", CConsoleCommands::OpenPortsTest, false );

    RegisterCommand ( "debugdb", CConsoleCommands::SetDbLogLevel, false );

    RegisterCommand ( "reloadbans", CConsoleCommands::ReloadBans, false );

    RegisterCommand ( "aclrequest", CConsoleCommands::AclRequest, false );
    RegisterCommand ( "debugjoinflood", CConsoleCommands::DebugJoinFlood, false );
#if defined(MTA_DEBUG) || defined(MTA_BETA)
    RegisterCommand ( "sfakelag", CConsoleCommands::FakeLag, false );
#endif
    return true;
}
Example #2
0
bool CMainConfig::LoadExtended ( void )
{
    std::string strBuffer;
    int iTemp = 0, iResult = 0;

	// Grab the script debuglog
    if ( GetString ( m_pRootNode, "scriptdebuglogfile", strBuffer, 255, 1 ) == IS_SUCCESS )
    {
        m_strScriptDebugLogFile = g_pServerInterface->GetModManager ()->GetAbsolutePath ( strBuffer.c_str () );
        m_bScriptDebugLogEnabled = true;
    }
    else
    {
        m_bScriptDebugLogEnabled = false;
    }

    // Grab the script debuglog level
    iResult = GetInteger ( m_pRootNode, "scriptdebugloglevel", iTemp, 0, 3 );
    if ( iResult == IS_SUCCESS )
    {
        m_uiScriptDebugLogLevel = iTemp;
    }
    else
    {
        if ( iResult == INVALID_VALUE )
        {
            CLogger::LogPrint ( "WARNING: Invalid value specified in \"scriptdebugloglevel\" tag; defaulting to 0\n" );
        }

        m_uiScriptDebugLogLevel = 0;
    }

    iResult = GetInteger ( m_pRootNode, "htmldebuglevel", iTemp, 0, 3 );
    if ( iResult == IS_SUCCESS )
    {
        g_pGame->GetScriptDebugging()->SetHTMLLogLevel ( iTemp );
    }
    else
    {
        if ( iResult == INVALID_VALUE )
        {
            CLogger::LogPrint ( "WARNING: Invalid value specified in \"htmldebuglevel\" tag; defaulting to 0\n" );
        }

        g_pGame->GetScriptDebugging()->SetHTMLLogLevel ( 0 );
    }

	// Handle the <module> nodes
    CXMLNode* pNode = NULL;
    unsigned int uiCurrentIndex = 0;
    do
    {
        pNode = m_pRootNode->FindSubNode ( "module", uiCurrentIndex++ );
        if ( pNode )
        {
            CXMLAttribute* pAttribute = pNode->GetAttributes ().Find ( "src" );
            if ( pAttribute )
            {
                std::string strBuffer = pAttribute->GetValue ();
                SString strFilename ( "%s/modules/%s", g_pServerInterface->GetModManager ()->GetModPath (), strBuffer.c_str () );

                if ( IsValidFilePath ( strBuffer.c_str () ) )
                {
                    m_pLuaManager->GetLuaModuleManager ()->_LoadModule ( strBuffer.c_str (), strFilename, false );
                }
            }
        }
    }
	while ( pNode );
    
    // Handle the <resource> nodes
    pNode = NULL;
    uiCurrentIndex = 0;
    bool bFoundDefault = false;
    bool bFirst = true;
    bool bNoProgress = false;

    do
    {
        // Grab the current script node
        pNode = m_pRootNode->FindSubNode ( "resource", uiCurrentIndex++ );
        if ( pNode )
        {
            // Grab its "src" attribute
            CXMLAttribute* pAttribute = pNode->GetAttributes ().Find ( "src" );
            if ( pAttribute )
            {
                // Grab the text in it and convert iwt to a path inside "scripts"
                std::string strBuffer = pAttribute->GetValue ();

                CResource * loadedResource = g_pGame->GetResourceManager ()->GetResource ( strBuffer.c_str () );
                if ( !loadedResource )
                {
                    CLogger::LogPrintNoStamp ( "\n" );
                    CLogger::ErrorPrintf ( "Couldn't find resource %s. Check it exists.\n", strBuffer.c_str () );
                    bNoProgress = true;
                }
                else
                {
                    loadedResource->SetPersistent ( true );

                    pAttribute = pNode->GetAttributes ().Find ( "startup" );
                    if ( pAttribute )
                    {
                        std::string strStartup = pAttribute->GetValue ();
                        if ( strStartup.compare ( "true" ) == 0 ||
                             strStartup.compare ( "yes" ) == 0 ||
                             strStartup.compare ( "1" ) == 0 )
                        {
                            CLogger::SetOutputEnabled ( false );
                            if ( loadedResource->Start( NULL, true ) )
                            {
                                CLogger::SetOutputEnabled ( true );
                                if ( !bNoProgress )
                                {
                                    if ( bFirst )
                                        CLogger::LogPrint ( "Starting resources..." );
                                    else
                                        CLogger::LogPrintNoStamp ( "." );

                                    bFirst = false;
                                }
                            }
                            else
                            {
                                CLogger::SetOutputEnabled ( true );
                                CLogger::LogPrintNoStamp ( "\n" );
                                CLogger::ErrorPrintf ( "Unable to start resource %s; %s\n", strBuffer.c_str (), loadedResource->GetFailureReason ().c_str () );
                                bNoProgress = true;
                            }
                        }
                    }

					pAttribute = pNode->GetAttributes ().Find ( "protected" );
                    if ( pAttribute )
                    {
                        std::string strProtected = pAttribute->GetValue ();
                        if ( strProtected.compare ( "true" ) == 0 ||
                             strProtected.compare ( "yes" ) == 0 ||
                             strProtected.compare ( "1" ) == 0 )
                            loadedResource->SetProtected ( true );
                    }

                    // Default resource
                    pAttribute = pNode->GetAttributes ().Find ( "default" );
                    if ( pAttribute )
                    {
                        if ( !bFoundDefault )
                        {
                            std::string strProtected = pAttribute->GetValue ();
                            if ( strProtected.compare ( "true" ) == 0 ||
                                strProtected.compare ( "yes" ) == 0 ||
                                strProtected.compare ( "1" ) == 0 )
                            {
                                std::string strName = loadedResource->GetName ();
                                if ( !strName.empty () )
                                {
                                    g_pGame->GetHTTPD ()->SetDefaultResource ( strName.c_str () );
                                }

                                bFoundDefault = true;
                            }
                        }
                        else
                        {
                            CLogger::LogPrintNoStamp ( "\n" );
                            CLogger::ErrorPrintf ( "More than one default resource specified!\n" );
                            bNoProgress = true;
                        }
                    }
                }
            }
        }
    }
    while ( pNode );

    if ( !bNoProgress ) CLogger::LogPrintNoStamp ( "\n" );

    // Register the commands
    RegisterCommand ( "update", CConsoleCommands::Update, false );
    RegisterCommand ( "start", CConsoleCommands::StartResource, false );
    RegisterCommand ( "stop", CConsoleCommands::StopResource, false );
	RegisterCommand ( "stopall", CConsoleCommands::StopAllResources, false );
    RegisterCommand ( "restart", CConsoleCommands::RestartResource, false );
    RegisterCommand ( "refresh", CConsoleCommands::RefreshResources, false );
    RegisterCommand ( "refreshall", CConsoleCommands::RefreshAllResources, false );
    RegisterCommand ( "list", CConsoleCommands::ListResources, false );
    RegisterCommand ( "info", CConsoleCommands::ResourceInfo, false );
    RegisterCommand ( "install", CConsoleCommands::InstallResource, false );
    RegisterCommand ( "upgrade", CConsoleCommands::UpgradeResources, false );

    RegisterCommand ( "say", CConsoleCommands::Say, false );
    RegisterCommand ( "teamsay", CConsoleCommands::TeamSay, false );
    RegisterCommand ( "asay", CConsoleCommands::ASay, false );
    RegisterCommand ( "msg", CConsoleCommands::Msg, false );
    RegisterCommand ( "amsg", CConsoleCommands::AMsg, false );
    RegisterCommand ( "me", CConsoleCommands::Me, false );
    RegisterCommand ( "nick", CConsoleCommands::Nick, false );

    RegisterCommand ( "login", CConsoleCommands::LogIn, false );
    RegisterCommand ( "logout", CConsoleCommands::LogOut, false );
    RegisterCommand ( "chgmypass", CConsoleCommands::ChgMyPass, false );

    RegisterCommand ( "addaccount", CConsoleCommands::AddAccount, false );
    RegisterCommand ( "delaccount", CConsoleCommands::DelAccount, false );
    RegisterCommand ( "chgpass", CConsoleCommands::ChgPass, false );
    RegisterCommand ( "shutdown", CConsoleCommands::Shutdown, false );

    RegisterCommand ( "aexec", CConsoleCommands::AExec, false );

    RegisterCommand ( "whois", CConsoleCommands::WhoIs, false );
    RegisterCommand ( "whowas", CConsoleCommands::WhoWas, false );

    RegisterCommand ( "debugscript", CConsoleCommands::DebugScript, false );

	RegisterCommand ( "sudo", CConsoleCommands::Sudo, false );

    RegisterCommand ( "help", CConsoleCommands::Help, false );

	RegisterCommand ( "loadmodule", CConsoleCommands::LoadModule, false );
	//RegisterCommand ( "unloadmodule", CConsoleCommands::UnloadModule, false );
	//RegisterCommand ( "reloadmodule", CConsoleCommands::ReloadModule, false );

    RegisterCommand ( "ver", CConsoleCommands::Ver, false );
    RegisterCommand ( "sver", CConsoleCommands::Ver, false );

	return true;
}