Пример #1
0
///////////////////////////////////////////////////////////////
//
// CServerIdManagerImpl::StaticSaveServerIdMap
//
//
//
///////////////////////////////////////////////////////////////
void CServerIdManagerImpl::StaticSaveServerIdMap ( void )
{
    CXMLFile* pConfigFile = g_pCore->GetXML ()->CreateXML ( PathJoin ( g_pClientGame->GetFileCacheRoot(), MTA_SERVERID_LOOKUP_XML ) );
    if ( !pConfigFile )
        return;
    pConfigFile->Reset ();

    CXMLNode* pRoot = pConfigFile->GetRootNode ();
    if ( !pRoot )
        pRoot = pConfigFile->CreateRootNode ( "root" );

    // Transfer each item from m_ServerIdMap into the file
    for ( std::map < CServerIdKey, CServerIdInfo >::iterator it = ms_ServerIdMap.begin () ; it != ms_ServerIdMap.end () ; ++it )
    {
        const SString& strId = it->first.strId;
        const SString& strDir = it->second.strDir;

        CXMLNode* pSubNode = pRoot->CreateSubNode ( "id" );
        pSubNode->SetTagContent ( strId );
        pSubNode->GetAttributes().Create ( "dir" )->SetValue ( strDir );
    }

    pConfigFile->Write ();
    delete pConfigFile;
}
Пример #2
0
bool CLuaMain::SaveXML(CXMLNode* pRootNode)
{
    list<CXMLFile*>::iterator iter;
    for (iter = m_XMLFiles.begin(); iter != m_XMLFiles.end(); iter++)
    {
        CXMLFile* file = (*iter);
        if (file)
        {
            if (file->GetRootNode() == pRootNode)
            {
                return file->Write();
            }
        }
    }
    if (m_pResource)
    {
        list<CResourceConfigItem*>::iterator iter = m_pResource->ConfigIterBegin();
        for (; iter != m_pResource->ConfigIterEnd(); iter++)
        {
            CResourceConfigItem* pConfigItem = *iter;
            if (pConfigItem->GetRoot() == pRootNode)
            {
                CXMLFile* pFile = pConfigItem->GetFile();
                if (pFile)
                {
                    return pFile->Write();
                }
                return false;
            }
        }
    }
    return false;
}
Пример #3
0
///////////////////////////////////////////////////////////////
//
// CServerIdManagerImpl::LoadServerIdMap
//
// Load server id data from xml file
//
///////////////////////////////////////////////////////////////
bool CServerIdManagerImpl::LoadServerIdMap ( void )
{
    // Load config XML file
    CXMLFile* pConfigFile = g_pCore->GetXML ()->CreateXML ( PathJoin ( g_pClientGame->GetFileCacheRoot(), MTA_SERVERID_LOOKUP_XML ) );
    if ( !pConfigFile )
        return false;
    pConfigFile->Parse ();

    CXMLNode* pRoot = pConfigFile->GetRootNode ();
    if ( !pRoot )
        pRoot = pConfigFile->CreateRootNode ( "root" );

    m_ServerIdMap.clear ();

    // Read each node
    for ( uint i = 0 ; i < pRoot->GetSubNodeCount () ; i++ )
    {
        CXMLNode* pSubNode = pRoot->GetSubNode ( i );

        CServerIdKey key;
        CServerIdInfo info;
        key.strId = pSubNode->GetTagContent ();
        if ( CXMLAttribute* pAttribute = pSubNode->GetAttributes().Find ( "dir" ) )
            info.strDir = pAttribute->GetValue ();

        if ( !info.strDir.empty () )
            MapSet ( m_ServerIdMap, key, info );
    }

    // Maybe one day remove unwanted directories

    delete pConfigFile;
    return true;
}
int CLuaFunctionDefs::XMLLoadFile ( lua_State* luaVM )
{
//  xmlnode xmlLoadFile ( string filePath )
    SString filePath;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadString ( filePath );

    if ( !argStream.HasErrors () )
    {
        CLuaMain * luaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( luaMain )
        {
            CResource* pResource = luaMain->GetResource();
            SString strFilename;
            if ( CResourceManager::ParseResourcePathInput( filePath, pResource, strFilename ) )
            {
                // Create the XML
                CXMLFile * xmlFile = luaMain->CreateXML ( strFilename );
                if ( xmlFile )
                {
                    // Parse it
                    if ( xmlFile->Parse() )
                    {
                        // Create the root node if it doesn't exist
                        CXMLNode* pRootNode = xmlFile->GetRootNode ();
                        if ( !pRootNode )
                            pRootNode = xmlFile->CreateRootNode ( "root" );

                        // Got a root node?
                        if ( pRootNode )
                        {
                            lua_pushxmlnode ( luaVM, pRootNode );
                            return 1;
                        }
                    }

                    // Destroy the XML
                    luaMain->DestroyXML ( xmlFile );
                }   
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Пример #5
0
void CLuaMain::DestroyXML(CXMLNode* pRootNode)
{
    list<CXMLFile*>::iterator iter;
    for (iter = m_XMLFiles.begin(); iter != m_XMLFiles.end(); iter++)
    {
        CXMLFile* file = (*iter);
        if (file)
        {
            if (file->GetRootNode() == pRootNode)
            {
                delete file;
                m_XMLFiles.erase(iter);
                break;
            }
        }
    }
}
Пример #6
0
///////////////////////////////////////////////////////////////
//
// CResourceChecker::CheckMetaFileForIssues
//
//
//
///////////////////////////////////////////////////////////////
void CResourceChecker::CheckMetaFileForIssues ( const string& strPath, const string& strFileName, const string& strResourceName )
{
    // Load the meta file
    CXMLFile* metaFile = g_pServerInterface->GetXML ()->CreateXML ( strPath.c_str() );
    if ( !metaFile )
        return;

    CXMLNode* pRootNode = metaFile->Parse () ? metaFile->GetRootNode () : NULL;
    if ( !pRootNode )
    {
        delete metaFile;
        return;
    }

    // Ouput warnings...
    if ( m_bUpgradeScripts == false )
    {
        CheckMetaSourceForIssues ( pRootNode, strFileName, strResourceName, ECheckerMode::WARNINGS );
    }
    else
    // ..or do an upgrade
    if ( m_bUpgradeScripts == true )
    {
        bool bHasChanged = false;
        CheckMetaSourceForIssues ( pRootNode, strFileName, strResourceName, ECheckerMode::UPGRADE, &bHasChanged );

        // Has contents changed?
        if ( bHasChanged )
        {
            // Rename original to xml.old
            if( !RenameBackupFile( strPath, ".old" ) )
                return;

            // Save new content
            metaFile->Write ();
            CLogger::LogPrintf ( "Upgrading %s:%s ...........done\n", strResourceName.c_str (), strFileName.c_str () );

            m_upgradedFullPathList.push_back( strPath );
        }
    }

    delete metaFile;
}
Пример #7
0
void CLuaMain::SaveXML ( CXMLNode * pRootNode )
{
    list<CXMLFile *>::iterator iter;
    for ( iter = m_XMLFiles.begin(); iter != m_XMLFiles.end(); ++iter )
    {
        CXMLFile * file = (*iter);
        if ( file )
        {
            if ( file->GetRootNode() == pRootNode )
            {
                file->Write();
                break;
            }
        }
    }
    if ( m_pResource )
    {
        list < CResourceFile* > ::iterator iter = m_pResource->IterBegin ();
        for ( ; iter != m_pResource->IterEnd () ; ++iter )
        {
            CResourceFile* pResourceFile = *iter;
            if ( pResourceFile->GetType () == CResourceFile::RESOURCE_FILE_TYPE_CONFIG )
            {
                CResourceConfigItem* pConfigItem = static_cast < CResourceConfigItem* > ( pResourceFile );
                if ( pConfigItem->GetRoot () == pRootNode )
                {
                    CXMLFile* pFile = pConfigItem->GetFile ();
                    if ( pFile )
                    {
                        pFile->Write ();
                    }
                    break;
                }
            }
        }
    }
}
Пример #8
0
int CLuaXMLDefs::xmlLoadFile ( lua_State* luaVM )
{
#ifndef MTA_CLIENT
    if ( lua_type ( luaVM, 2 ) == LUA_TLIGHTUSERDATA )
        m_pScriptDebugging->LogCustom ( luaVM, "xmlLoadFile may be using an outdated syntax. Please check and update." );
#endif // !MTA_CLIENT

    // Grab our resource
    CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
    if ( pLuaMain )
    {
        SString strFileInput;

        CScriptArgReader argStream ( luaVM );
        argStream.ReadString ( strFileInput );

        if ( !argStream.HasErrors () )
        {
            SString strPath;
            CResource* pThisResource = pLuaMain->GetResource ();
            CResource* pOtherResource = pThisResource;

            // Resolve other resource from name
            if ( CResourceManager::ParseResourcePathInput ( strFileInput, pOtherResource, &strPath ) )
            {
                // SS only
#ifndef MTA_CLIENT
                // We have access to modify other resource?
                if ( pOtherResource == pThisResource ||
                    m_pACLManager->CanObjectUseRight ( pThisResource->GetName ().c_str (),
                        CAccessControlListGroupObject::OBJECT_TYPE_RESOURCE,
                        "ModifyOtherObjects",
                        CAccessControlListRight::RIGHT_TYPE_GENERAL,
                        false ) )
#endif // !MTA_CLIENT
                {

                    // Make sure the dir exists so we can successfully make the file
                    MakeSureDirExists ( strPath );

                    // Create the XML
                    CXMLFile* xmlFile = pLuaMain->CreateXML ( strPath.c_str () );
                    if ( xmlFile )
                    {
                        // Try to parse it
                        if ( xmlFile->Parse () )
                        {
                            // Grab the root node. If it didn't exist, create one
                            CXMLNode * pRootNode = xmlFile->GetRootNode ();
                            if ( !pRootNode )
                                pRootNode = xmlFile->CreateRootNode ( "root" );

                            // Could we create one?
                            if ( pRootNode )
                            {
                                // Return the root node
                                lua_pushxmlnode ( luaVM, pRootNode );
                                return 1;
                            }
                        }

                        // Destroy it if we failed
                        pLuaMain->DestroyXML ( xmlFile );
                    }
                }
#ifndef MTA_CLIENT
                else
                    argStream.SetCustomError ( SString ( "ModifyOtherObjects in ACL denied resource '%s' to access '%s'", pThisResource->GetName ().c_str (), pOtherResource->GetName ().c_str () ), "Access denied" );
#endif // !MTA_CLIENT
            }
        }

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

    lua_pushboolean ( luaVM, false );
    return 1;
}
Пример #9
0
////////////////////////////////////////////////////
//
//  CNewsBrowser::InitNewsItemList
//
//
//
////////////////////////////////////////////////////
void CNewsBrowser::InitNewsItemList(void)
{
    m_NewsitemList.clear();

    // Find all sub-directories in 'news' directory
    SString              strAllNewsDir = PathJoin(GetMTADataPath(), "news");
    std::vector<SString> directoryList = FindFiles(strAllNewsDir + "\\*", false, true);
    std::sort(directoryList.begin(), directoryList.end());

    // Get news settings
    SString strOldestPost;
    uint    uiMaxHistoryLength;
    GetVersionUpdater()->GetNewsSettings(strOldestPost, uiMaxHistoryLength);

    // Process each sub-directory
    for (uint i = 0; i < directoryList.size(); i++)
    {
        SString strItemDir = directoryList[directoryList.size() - 1 - i];
        if (strItemDir < strOldestPost)
            continue;            // Post too old
        if (m_NewsitemList.size() >= uiMaxHistoryLength)
            continue;            // Post count too high

        SNewsItem newsItem;
        newsItem.strContentFullDir = PathJoin(strAllNewsDir, strItemDir);

        // Get filenames from XML file
        CXMLFile* pFile = g_pCore->GetXML()->CreateXML(PathJoin(newsItem.strContentFullDir, "files.xml"));
        if (pFile)
        {
            pFile->Parse();
            CXMLNode* pRoot = pFile->GetRootNode();

            if (pRoot)
            {
                // Headline text
                CXMLNode* pHeadline = pRoot->FindSubNode("headline", 0);
                if (pHeadline)
                    newsItem.strHeadline = pHeadline->GetTagContent();

                // Date text
                CXMLNode* pDate = pRoot->FindSubNode("date", 0);
                if (pDate)
                    newsItem.strDate = pDate->GetTagContent();
                else
                    newsItem.strHeadline.Split(" - ", &newsItem.strHeadline, &newsItem.strDate, true);

                // Layout filename
                CXMLNode* pLayout = pRoot->FindSubNode("layout", 0);
                if (pLayout)
                    newsItem.strLayoutFilename = pLayout->GetTagContent();

                // Imageset filenames
                CXMLNode* pImages = pRoot->FindSubNode("imagesetlist", 0);
                if (pImages)
                    for (uint i = 0; i < pImages->GetSubNodeCount(); i++)
                        newsItem.imagesetFilenameList.push_back(pImages->GetSubNode(i)->GetTagContent());
            }

            delete pFile;
        }

        // Add to news item list if valid
        if (!newsItem.strHeadline.empty() && !newsItem.strLayoutFilename.empty())
            m_NewsitemList.push_back(newsItem);
    }
}
Пример #10
0
bool CBanManager::LoadBanList ( void )
{
    // Create the XML
    CXMLFile* pFile = g_pServerInterface->GetXML ()->CreateXML ( m_strPath );
    if ( !pFile )
    {
        return false;
    }

    // Parse it
    if ( !pFile->Parse () )
    {
        delete pFile;
        CLogger::ErrorPrintf ( "Error parsing banlist\n" );
        return false;
    }

    // Grab the XML root node
    CXMLNode* pRootNode = pFile->GetRootNode ();
    if ( !pRootNode )
    {
        pRootNode = pFile->CreateRootNode ( "banlist" );
    }

    // Is the rootnode's name <banlist>?
    if ( pRootNode->GetTagName ().compare ( "banlist" ) != 0 )
    {
        CLogger::ErrorPrintf ( "Wrong root node ('banlist')\n" );
        return false;
    }

    // Iterate the nodes
    CXMLNode* pNode = NULL;
    unsigned int uiCount = pRootNode->GetSubNodeCount ();

    for ( unsigned int i = 0; i < uiCount; i++ )
    {
        // Grab the node
        pNode = pRootNode->GetSubNode ( i );

        if ( pNode )
        {
            if ( pNode->GetTagName ().compare ( "ban" ) == 0 )
            {
                std::string strIP = SafeGetValue ( pNode, "ip" ),
                            strSerial = SafeGetValue ( pNode, "serial" ),
                            strAccount = SafeGetValue ( pNode, "account" );
                if ( !strIP.empty() || !strSerial.empty() || !strAccount.empty() )
                {
                    CBan* pBan = AddBan ();
                    if ( IsValidIP ( strIP.c_str() ) )
                    {
                        pBan->SetIP ( strIP );
                        g_pNetServer->AddBan ( strIP.c_str() );
                    }
                    pBan->SetAccount ( strAccount );
                    pBan->SetSerial ( strSerial );
                    pBan->SetBanner ( SafeGetValue ( pNode, "banner" ) );
                    pBan->SetNick ( SafeGetValue ( pNode, "nick" ) );
                    pBan->SetReason ( SafeGetValue ( pNode, "reason" ) );

                    std::string strTime = SafeGetValue ( pNode, "time" );
                    if ( !strTime.empty() ) pBan->SetTimeOfBan ( ( time_t ) atoi ( strTime.c_str() ) );

                    strTime = SafeGetValue ( pNode, "unban" );
                    if ( !strTime.empty() ) pBan->SetTimeOfUnban ( ( time_t ) atoi ( strTime.c_str() ) );
                }
            }
        }
    }

    delete pFile;
    return true;
}
Пример #11
0
int CLuaXMLDefs::xmlLoadFile ( lua_State* luaVM )
{
     if ( lua_type ( luaVM, 2 ) == LUA_TLIGHTUSERDATA )
        m_pScriptDebugging->LogCustom ( luaVM, "xmlLoadFile may be using an outdated syntax. Please check and update." );

    // Grab our resource
    CLuaMain* pLUA = m_pLuaManager->GetVirtualMachine ( luaVM );
    if ( pLUA )
    {
        CResource* pThisResource = pLUA->GetResource ();
        CResource* pResource = pThisResource;
        
        // Filename
        if ( lua_type ( luaVM, 1 ) != LUA_TSTRING )
        {
            m_pScriptDebugging->LogBadType ( luaVM, "xmlLoadFile" );

            lua_pushboolean ( luaVM, false );
            return 1;
        }
        // Grab the filename passed
        std::string strFile = lua_tostring ( luaVM, 1 );
        std::string strPath;


        if ( CResourceManager::ParseResourcePathInput ( strFile, pResource, &strPath, NULL ) )
        {
            if ( pResource == pThisResource ||
                m_pACLManager->CanObjectUseRight ( pThisResource->GetName ().c_str (),
                                                CAccessControlListGroupObject::OBJECT_TYPE_RESOURCE,
                                                "ModifyOtherObjects",
                                                CAccessControlListRight::RIGHT_TYPE_GENERAL,
                                                false ) )
            {
                // Make sure the dir exists so we can successfully make the file
                MakeSureDirExists ( strPath.c_str () );

                // Create the XML
                CXMLFile* xmlFile = pLUA->CreateXML ( strPath.c_str () );
                if ( xmlFile )
                {
                    // Try to parse it
                    if ( xmlFile->Parse () )
                    {
                        // Grab the root node. If it didn't exist, create one
                        CXMLNode * pRootNode = xmlFile->GetRootNode ();
                        if ( !pRootNode )
                            pRootNode = xmlFile->CreateRootNode ( "root" );

                        // Could we create one?
                        if ( pRootNode )
                        {
                            // Return the root node
                            lua_pushxmlnode ( luaVM, pRootNode );
                            return 1;
                        }
                    }

                    // Destroy it if we failed
                    pLUA->DestroyXML ( xmlFile );
                }
            }
            else
                m_pScriptDebugging->LogError ( luaVM, "xmlLoadFile failed; ModifyOtherObjects in ACL denied resource %s to access %s", pThisResource->GetName ().c_str (), pResource->GetName ().c_str () );
        }
    }

    lua_pushboolean ( luaVM, false );
    return 1;
}