예제 #1
0
bool CLocalServer::Save ( void )
{
    if ( m_pConfig && m_pConfig->GetRootNode() )
    {
        StoreConfigValue ( "servername", ( m_pEditName->GetText().length() > 0 ) ? m_pEditName->GetText().c_str() : "MTA Local Server" );
        StoreConfigValue ( "maxplayers", ( atoi ( m_pEditPlayers->GetText().c_str() ) ) ? m_pEditPlayers->GetText().c_str() : "32" );
        StoreConfigValue ( "donotbroadcastlan", ( m_pBroadcastLan->IsActive () ) ? "0" : "1" );
        StoreConfigValue ( "ase", ( m_pBroadcastInternet->IsActive () ) ? "1" : "0" );
        StoreConfigValue ( "password", m_pEditPass->GetText().c_str() );

        // Remove old resources from the config
        CXMLNode* pRoot = m_pConfig->GetRootNode();
        list < CXMLNode* > ::const_iterator iter = pRoot->ChildrenBegin ();
        for ( ; iter != pRoot->ChildrenEnd (); iter++ )
        {
            CXMLNode* pNode = reinterpret_cast < CXMLNode* > ( *iter );
            if ( pNode->GetTagName().compare ( "resource" ) == 0 )
            {
                pRoot->DeleteSubNode ( pNode );
                iter = pRoot->ChildrenBegin ();
            }
        }

        // Add new resources to the config
        for ( int i = 0; i < m_pResourcesCur->GetRowCount(); i++ )
        {
            CXMLNode* pResourceNode = pRoot->CreateSubNode ( "resource" );
            pResourceNode->GetAttributes().Create ( "src" )->SetValue ( m_pResourcesCur->GetItemText ( i, 1 ) );
            pResourceNode->GetAttributes().Create ( "startup" )->SetValue ( "1" );
            pResourceNode->GetAttributes().Create ( "protected" )->SetValue ( "0" );
        }
        m_pConfig->Write ();
    }
    return true;
}
예제 #2
0
void CWebCore::LoadListsFromXML ( bool bWhitelist, bool bBlacklist, bool bCustomLists )
{
    if ( !m_pXmlConfig )
        return;

    CXMLNode* pRootNode = m_pXmlConfig->GetRootNode ();
    if ( !pRootNode )
        return;

    if ( bWhitelist )
    {
        CXMLNode* pWhiteSubNode = pRootNode->FindSubNode ( "globalwhitelist" );
        if ( pWhiteSubNode )
        {
            for ( std::list<CXMLNode*>::iterator iter = pWhiteSubNode->ChildrenBegin (); iter != pWhiteSubNode->ChildrenEnd (); ++iter )
            {
                AddAllowedPage ( (*iter)->GetTagContent (), eWebFilterType::WEBFILTER_DYNAMIC );
            }
        }
    }
    
    if ( bBlacklist )
    {
        CXMLNode* pBlackSubNode = pRootNode->FindSubNode ( "globalblacklist" );
        if ( pBlackSubNode )
        {
            for ( std::list<CXMLNode*>::iterator iter = pBlackSubNode->ChildrenBegin (); iter != pBlackSubNode->ChildrenEnd (); ++iter )
            {
                AddBlockedPage ( (*iter)->GetTagContent (), eWebFilterType::WEBFILTER_DYNAMIC );
            }
        }
    }

    if ( bCustomLists )
    {
        CXMLNode* pBlackSubNode = pRootNode->FindSubNode ( "customblacklist" );
        if ( pBlackSubNode )
        {
            for ( std::list<CXMLNode*>::iterator iter = pBlackSubNode->ChildrenBegin (); iter != pBlackSubNode->ChildrenEnd (); ++iter )
            {
                AddBlockedPage ( (*iter)->GetTagContent (), eWebFilterType::WEBFILTER_USER );
            }
        }
        CXMLNode* pWhiteSubNode = pRootNode->FindSubNode ( "customwhitelist" );
        if ( pWhiteSubNode )
        {
            for ( std::list<CXMLNode*>::iterator iter = pWhiteSubNode->ChildrenBegin (); iter != pWhiteSubNode->ChildrenEnd (); ++iter )
            {
                AddAllowedPage ( (*iter)->GetTagContent (), eWebFilterType::WEBFILTER_USER );
            }
        }
    }
}
예제 #3
0
int CLuaXMLDefs::xmlNodeGetChildren ( lua_State* luaVM )
{
    // xmlNode*, [index]
    if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA )
    {
        CXMLNode* pNode = lua_toxmlnode ( luaVM, 1 );
        if ( pNode )
        {
            unsigned int uiIndex = 0;
            bool bGetAllChildren = true;
            int iArgument2 = lua_type ( luaVM, 2 );
            if ( iArgument2 == LUA_TNUMBER || iArgument2 == LUA_TSTRING )
            {
                uiIndex = static_cast < unsigned int > ( lua_tonumber ( luaVM, 2 ) );
                bGetAllChildren = false;
            }
            CXMLNode * pFoundNode = NULL;
            if ( !bGetAllChildren )
            {
                pFoundNode = pNode->GetSubNode ( uiIndex );
                if ( pFoundNode )
                {
                    lua_pushxmlnode ( luaVM, pFoundNode );
                    return 1;
                }
            }
            else
            {
                lua_newtable ( luaVM );
                uiIndex = 0;
                list < CXMLNode * > ::iterator iter = pNode->ChildrenBegin ();
                for ( ; iter != pNode->ChildrenEnd () ; iter++ )
                {
                    lua_pushnumber ( luaVM, ++uiIndex );
                    lua_pushxmlnode ( luaVM, *iter );
                    lua_settable ( luaVM, -3 );
                }
                return 1;
            }
        }
    }
    else
        m_pScriptDebugging->LogBadType ( luaVM, "xmlNodeGetChildren" );

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::XMLNodeGetChildren ( lua_State* luaVM )
{
    // xmlNode*, [index]
    CXMLNode* pNode = NULL;
    unsigned int uiIndex = 0;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pNode );
    argStream.ReadNumber ( uiIndex, -1 );

    if ( !argStream.HasErrors ( ) )
    {
        if ( pNode )
        {
            bool bGetAllChildren = uiIndex == -1;

            CXMLNode * pFoundNode = NULL;
            if ( !bGetAllChildren )
            {
                pFoundNode = pNode->GetSubNode ( uiIndex );
                if ( pFoundNode )
                {
                    lua_pushxmlnode ( luaVM, pFoundNode );
                    return 1;
                }
            }
            else
            {
                lua_newtable ( luaVM );
                uiIndex = 0;
                list < CXMLNode * > ::iterator iter = pNode->ChildrenBegin ();
                for ( ; iter != pNode->ChildrenEnd () ; iter++ )
                {                
                    lua_pushnumber ( luaVM, ++uiIndex );
                    lua_pushxmlnode ( luaVM, ( CXMLNode * ) ( *iter ) );
                    lua_settable ( luaVM, -3 );
                }
                return 1;
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
예제 #5
0
bool CResourceMapItem::LoadSubNodes ( CXMLNode& Node, CElement* pParent, vector < CElement* >* pAdded, bool bIsDuringStart )
{
    // Iterate the nodes
    CXMLNode* pNode = NULL;
    list < CXMLNode * > ::iterator iter = Node.ChildrenBegin ();
    for ( ; iter != Node.ChildrenEnd () ; iter++ )
    {
        // Grab the node
        pNode = *iter;
        if ( pNode )
        {
            // Handle it (if it can't be handled, just ignore it and continue to the next)
            HandleNode ( *pNode, pParent, pAdded, bIsDuringStart, NULL );
        }
    }

    // Success
    return true;
}
예제 #6
0
bool CLocalServer::Load ( void )
{
    // Get server module root
    SString strServerPath = CalcMTASAPath( PathJoin ( "server", "mods", "deathmatch" ) );

    m_pConfig = g_pCore->GetXML ()->CreateXML ( PathJoin ( strServerPath, m_strConfig ) );
    if ( m_pConfig && m_pConfig->Parse() )
    {
        CXMLNode* pRoot = m_pConfig->GetRootNode();
        CXMLNode* pServerName = pRoot->FindSubNode ( "servername", 0 );
        if ( pServerName ) m_pEditName->SetText ( pServerName->GetTagContent().c_str() );
        CXMLNode* pServerPass = pRoot->FindSubNode ( "password", 0 );
        if ( pServerPass ) m_pEditPass->SetText ( pServerPass->GetTagContent().c_str() );
        CXMLNode* pServerPlayers = pRoot->FindSubNode ( "maxplayers", 0 );
        if ( pServerPlayers ) m_pEditPlayers->SetText ( pServerPlayers->GetTagContent().c_str() );

        // Read the startup resources
        list < CXMLNode* > ::const_iterator iter = pRoot->ChildrenBegin ();
        for ( ; iter != pRoot->ChildrenEnd (); iter++ )
        {
            CXMLNode* pNode = reinterpret_cast < CXMLNode* > ( *iter );
            if ( pNode->GetTagName ().compare ( "resource" ) == 0 )
            {
                CXMLAttribute* src = pNode->GetAttributes().Find ( "src" );
                if ( src && src->GetValue()[1] )
                {
                    m_pResourcesCur->SetItemText ( m_pResourcesCur->AddRow (), m_hResourcesCur, src->GetValue().c_str() );
                }
            }
        }
    }

    // Get list of resource names
    std::vector < SString > resourceNameList;
    GetResourceNameList ( resourceNameList, strServerPath );

    // Put resource names into the GUI
    for ( std::vector < SString >::iterator iter = resourceNameList.begin () ; iter != resourceNameList.end () ; ++iter )
        HandleResource ( *iter );

    return true;
}
예제 #7
0
int CLuaXMLDefs::xmlNodeGetChildren ( lua_State* luaVM )
{
    CXMLNode* pNode;
    unsigned int uiIndex;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pNode );
    argStream.ReadNumber ( uiIndex, -1 );

    if ( !argStream.HasErrors () )
    {
        bool bGetAllChildren = uiIndex == -1;
        if ( !bGetAllChildren )
        {
            CXMLNode* pFoundNode = pNode->GetSubNode ( uiIndex );
            if ( pFoundNode )
            {
                lua_pushxmlnode ( luaVM, pFoundNode );
                return 1;
            }
        }
        else
        {
            lua_newtable ( luaVM );
            uiIndex = 0;
            for (auto iter = pNode->ChildrenBegin (); iter != pNode->ChildrenEnd (); ++iter )
            {
                lua_pushnumber ( luaVM, ++uiIndex );
                lua_pushxmlnode ( luaVM, *iter );
                lua_settable ( luaVM, -3 );
            }
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
예제 #8
0
bool CLocalServer::Load ( void )
{
    // Get server module root
    SString strServerPath = g_pCore->GetInstallRoot ();
    strServerPath += "/server/mods/deathmatch";

    SString strConfigPath ( "%s/%s", strServerPath.c_str (), m_strConfig.c_str () );
    m_pConfig = g_pCore->GetXML ()->CreateXML ( strConfigPath );
    if ( m_pConfig && m_pConfig->Parse() )
    {
        CXMLNode* pRoot = m_pConfig->GetRootNode();
        CXMLNode* pServerName = pRoot->FindSubNode ( "servername", 0 );
        if ( pServerName ) m_pEditName->SetText ( pServerName->GetTagContent().c_str() );
        CXMLNode* pServerPass = pRoot->FindSubNode ( "password", 0 );
        if ( pServerPass ) m_pEditPass->SetText ( pServerPass->GetTagContent().c_str() );
        CXMLNode* pServerPlayers = pRoot->FindSubNode ( "maxplayers", 0 );
        if ( pServerPlayers ) m_pEditPlayers->SetText ( pServerPlayers->GetTagContent().c_str() );

        // Read the startup resources
        list < CXMLNode* > ::const_iterator iter = pRoot->ChildrenBegin ();
        for ( ; iter != pRoot->ChildrenEnd (); iter++ )
        {
            CXMLNode* pNode = reinterpret_cast < CXMLNode* > ( *iter );
            if ( pNode->GetTagName ().compare ( "resource" ) == 0 )
            {
                CXMLAttribute* src = pNode->GetAttributes().Find ( "src" );
                if ( src && src->GetValue()[1] )
                {
                    m_pResourcesCur->SetItemText ( m_pResourcesCur->AddRow (), m_hResourcesCur, src->GetValue().c_str() );
                }
            }
        }
    }
    //

    SString strResourceDirectoryPath ( "%s/resources/*", strServerPath.c_str () );

    unsigned int uiCount = 0;

    #ifdef WIN32

        // Find all .map files in the maps folder
        WIN32_FIND_DATA FindData;
        HANDLE hFind = FindFirstFile ( strResourceDirectoryPath, &FindData );
        if ( hFind != INVALID_HANDLE_VALUE )
        {
            // Remove the extension and store the time
            FindData.cFileName [ strlen ( FindData.cFileName ) - 4 ] = 0;
            // Add each file
            do
            {
                if ( strcmp ( FindData.cFileName, ".." ) != 0 && strcmp ( FindData.cFileName, "." ) != 0 )
                {
                    char * extn = NULL;
                    if ( ( FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) != FILE_ATTRIBUTE_DIRECTORY )
                    {
                        extn = &FindData.cFileName [ strlen ( FindData.cFileName ) - 3 ];
                        FindData.cFileName [ strlen ( FindData.cFileName ) - 4 ] = 0;
                    }

                    if ( extn == NULL || strcmp ( extn, "zip" ) == 0 )
                    {
                        // Add the resource
                        HandleResource ( FindData.cFileName );

                        // Increment the counter
                        uiCount++;
                    }
                }
            } while ( FindNextFile ( hFind, &FindData ) );

            // Close the search
            FindClose ( hFind );
        }
    #else
        DIR *Dir;
		struct dirent *DirEntry;
		time_t llHighestTime = 0;
		char szPath[MAX_PATH] = {0};

		if ( ( Dir = opendir ( strResourceDirectoryPath ) ) )
		{
			while ( ( DirEntry = readdir ( Dir ) ) != NULL )
			{
                // Skip . and .. entry
                if ( strcmp ( DirEntry->d_name, "." ) != 0 && 
                     strcmp ( DirEntry->d_name, ".." ) != 0 )
                {
				    struct stat Info;
				    bool bDir = false;

				    // Get the path
				    if ( strlen(szBuffer) + strlen(DirEntry->d_name) < MAX_PATH )
                    {
					    strcpy ( szPath, szBuffer );
					    unsigned long ulPathLength = strlen ( szPath );

					    if ( szPath [ ulPathLength-1 ] != '/') strcat ( szPath, "/" );

					    strcat ( szPath, DirEntry->d_name );

					    // Determine the file stats
					    if ( lstat ( szPath, &Info ) != -1 )
						    bDir = S_ISDIR ( Info.st_mode );
					    else
						    CLogger::ErrorPrintf ( "Unable to stat %s\n", szPath );

				        // Chop off the extension if it's not a dir
				        char * extn = NULL;
				        if ( !bDir )
                        {
					        extn = &(DirEntry->d_name [ strlen ( DirEntry->d_name ) - 3 ]);
					        DirEntry->d_name [ strlen ( DirEntry->d_name ) - 4 ] = 0;
				        }
                        if ( extn == NULL || strcmp ( extn, "zip" ) == 0 )
                        {
                            // Add the resource
                            HandleResource ( DirEntry->d_name );

                            // Increment the counter
                            uiCount++;
                        }

				    }
                }


			}

			// Close the directory handle
			closedir ( Dir );
		}
    #endif
    return true;
}