Пример #1
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;
}
Пример #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::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;
}
int CLuaFunctionDefs::XMLCreateFile ( lua_State* luaVM )
{
//  xmlnode xmlCreateFile ( string filePath, string rootNodeName )
    SString filePath; SString rootNodeName;

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

    // Safety check: Don't allow the rootNodeName "private" incase user forget to declare a node name
    if ( rootNodeName == EnumToString ( ACCESS_PRIVATE ) )
    {
        argStream.SetCustomError( "Expected string at argument 2, got access-type" );
    }

    if ( !argStream.HasErrors () )
    {
        CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine(luaVM);
        if ( pLuaMain )
        {
            CResource* pResource = pLuaMain->GetResource();
            SString strFile;
            if ( CResourceManager::ParseResourcePathInput( filePath, pResource, strFile ) )
            {
                // Make sure the directory exists
                MakeSureDirExists ( strFile.c_str () );

                // Create the XML
                CXMLFile * xmlFile = pLuaMain->CreateXML ( strFile.c_str () );
                if ( xmlFile )
                {
                    // Create its root node
                    CXMLNode* pRootNode = xmlFile->CreateRootNode ( rootNodeName );
                    if ( pRootNode )
                    {
                        lua_pushxmlnode ( luaVM, pRootNode );
                        return 1;
                    }

                    // Delete the XML again
                    pLuaMain->DestroyXML ( xmlFile );
                }
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Пример #5
0
void TestReadExternalReference(void)
{
	CXMLFile	cXMLFile;
	CChars		szDoc;
	int			iLine;
	char		szExpected[] = "<InputDevices>\n\
  This is text &lt; and doom stuff\n\
  <RootInSecond>\n\
    Hello\n\
  </RootInSecond>\n\
  Sweet &gt; other stuff\n\
  <ThirdsRoot>\n\
    World\n\
  </ThirdsRoot>\n\
</InputDevices>\n";
	CMarkupTag*	pcTag;
	CMarkupTag*	pcSecondTag;
	CMarkupTag*	pcThirdTag;
	CChars		szText;

	cXMLFile.Init();
	cXMLFile.Read("First.xml", ".");

	szDoc.Init(16);
	iLine = cXMLFile.mcMarkup.mpcDoc->ToString(&szDoc);
	AssertInt(10, iLine);
	AssertString(szExpected, szDoc.Text());
	szDoc.Kill();

	pcTag = cXMLFile.mcMarkup.mpcDoc->GetRootTag();
	pcSecondTag = pcTag->GetTag("RootInSecond");
	AssertNotNull(pcSecondTag);
	szText.Init();
	pcSecondTag->GetText(&szText);
	szText.StripWhiteSpace(TRUE);
	AssertString("Hello", szText.Text());
	szText.Kill();

	pcTag = cXMLFile.mcMarkup.mpcDoc->GetRootTag();
	pcThirdTag = pcTag->GetTag("ThirdsRoot");
	AssertNotNull(pcThirdTag);
	szText.Init();
	pcThirdTag->GetText(&szText);
	szText.StripWhiteSpace(TRUE);
	AssertString("World", szText.Text());
	szText.Kill();

	cXMLFile.Kill();
}
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;
}
Пример #7
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;
            }
        }
    }
}
Пример #8
0
void CBanManager::SaveBanList ( void )
{
    // Create the XML file
    CXMLFile* pFile = g_pServerInterface->GetXML ()->CreateXML ( m_strPath );
    if ( pFile )
    {
		// create the root node again as you are outputting all the bans again not just new ones
		CXMLNode* pRootNode = pFile->CreateRootNode ( "banlist" );	

        // Check it was created
        if ( pRootNode )
        {
            // Iterate the ban list adding it to the XML tree
            CXMLNode* pNode;
            list < CBan* >::const_iterator iter = m_BanManager.begin ();
            for ( ; iter != m_BanManager.end (); iter++ )
            {
                pNode = pRootNode->CreateSubNode ( "ban" );

                if ( pNode )
                {
                    SafeSetValue ( pNode, "nick", (*iter)->GetNick() );
                    SafeSetValue ( pNode, "ip", (*iter)->GetIP() );
                    SafeSetValue ( pNode, "serial", (*iter)->GetSerial() );
                    SafeSetValue ( pNode, "account", (*iter)->GetAccount() );
                    SafeSetValue ( pNode, "banner", (*iter)->GetBanner() );
                    SafeSetValue ( pNode, "reason", (*iter)->GetReason() );
                    SafeSetValue ( pNode, "time", ( unsigned int )(*iter)->GetTimeOfBan() );
                    if ( (*iter)->GetTimeOfUnban() > 0 )
                    {
                        SafeSetValue ( pNode, "unban", ( unsigned int )(*iter)->GetTimeOfUnban() );
                    }
                }
            }

            // Write the XML file
            pFile->Write ();
        }

        // Delete the file pointer
        delete pFile;
    }
}
Пример #9
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;
}
Пример #10
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;
                }
            }
        }
    }
}
Пример #11
0
void TestRepeatedExternalTags(void)
{
	CXMLFile		cXMLFile;
	CChars			szDoc;
	int				iLine;
	char			szExpected[] = "<Root>\n\
  <ExtTag>\n\
    <SubTag>Look at me!  I&apos;m going to be an elite pilot.</SubTag>\n\
    <SubTag>Also *very* messed up.</SubTag>\n\
  </ExtTag>\n\
  <ExtTag>\n\
    <SubTag>Look at me!  I&apos;m going to be an elite pilot.</SubTag>\n\
    <SubTag>Also *very* messed up.</SubTag>\n\
  </ExtTag>\n\
  <ExtTag>\n\
    <SubTag>Look at me!  I&apos;m going to be an elite pilot.</SubTag>\n\
    <SubTag>Also *very* messed up.</SubTag>\n\
  </ExtTag>\n\
  <ExtTag>\n\
    <SubTag>Look at me!  I&apos;m going to be an elite pilot.</SubTag>\n\
    <SubTag>Also *very* messed up.</SubTag>\n\
  </ExtTag>\n\
</Root>\n";
	CMarkupTag*		pcRoot;
	int				iCount;
	CMarkupTag*		pcExtTag;
	CMarkupTag*		pcSubTag1;
	CMarkupTag*		pcSubTag2;
	CMarkupTag*		pcSubTag3;
	CChars			szText;
	STagIterator	sIter;

	cXMLFile.Init();
	cXMLFile.Read("File.xml", ".");

	szDoc.Init(16);
	iLine = cXMLFile.mcMarkup.mpcDoc->ToString(&szDoc);
	AssertInt(18, iLine);
	AssertString(szExpected, szDoc.Text());
	szDoc.Kill();

	pcRoot = cXMLFile.mcMarkup.mpcDoc->GetRootTag();

	iCount = 0;
	pcExtTag = pcRoot->GetTag("ExtTag", &sIter);
	while (pcExtTag)
	{
		iCount++;

		if (iCount > 4)
		{
			//This is to take care of the case where GetNextTag always get's the first tag.
			break;
		}

		pcSubTag1 = pcExtTag->GetTag("SubTag", 0);
		pcSubTag2 = pcExtTag->GetTag("SubTag", 1);
		pcSubTag3 = pcExtTag->GetTag("SubTag", 2);

		szText.Init();
		pcSubTag1->GetText(&szText);
		AssertString("Look at me!  I'm going to be an elite pilot.", szText.Text());
		szText.Kill();		
		
		szText.Init();
		pcSubTag2->GetText(&szText);
		AssertString("Also *very* messed up.", szText.Text());
		szText.Kill();

		AssertNull(pcSubTag3);

		pcExtTag = pcRoot->GetNextTag(&sIter);
	}

	AssertInt(4, iCount);
	cXMLFile.Kill();
}
Пример #12
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);
    }
}
Пример #13
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;
}
Пример #14
0
int CLuaXMLDefs::xmlCreateFile ( lua_State* luaVM )
{
    if ( lua_type ( luaVM, 3 ) == LUA_TLIGHTUSERDATA )
        m_pScriptDebugging->LogCustom ( luaVM, "xmlCreateFile 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 ) ||
             ( lua_type ( luaVM, 2 ) != LUA_TSTRING ) )
        {
            m_pScriptDebugging->LogBadType ( luaVM, "xmlCreateFile" );

            lua_pushboolean ( luaVM, false );
            return 1;
        }
        else
        {
            std::string strFile = lua_tostring ( luaVM, 1 );
            std::string strPath;

            if ( CResourceManager::ParseResourcePathInput ( strFile, pResource, &strPath, NULL ) )
            {
                // We have access to modify this resource?
                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 () );

                    // Grab the root
                    const char* szRootName = lua_tostring ( luaVM, 2 );

                    // Create the XML file
                    CXMLFile * xmlFile = pLUA->CreateXML ( strPath.c_str () );
                    if ( xmlFile )
                    {
                        // Create its root node
                        CXMLNode* pRootNode = xmlFile->CreateRootNode ( szRootName );
                        if ( pRootNode )
                        {
                            lua_pushxmlnode ( luaVM, pRootNode );
                            return 1;
                        }

                        // Delete it again
                        pLUA->DestroyXML ( xmlFile );
                    }
                }
            }
        }
    }

    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaFunctionDefs::XMLCopyFile ( lua_State* luaVM )
{
//  xmlnode xmlCopyFile ( xmlnode nodeToCopy, string newFilePath )
    CXMLNode* pSourceNode; SString newFilePath;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pSourceNode );
    argStream.ReadString ( newFilePath );

    if ( !argStream.HasErrors () )
    {
        // Grab the virtual machine for this luastate
        CLuaMain* pLUA = m_pLuaManager->GetVirtualMachine ( luaVM );
        if ( pLUA )
        {
            CResource* pResource = pLUA->GetResource();
            SString strFilename;
            if ( CResourceManager::ParseResourcePathInput( newFilePath, pResource, strFilename ) )
            {
                if ( pSourceNode )
                {
                    // Grab the roots tag name
                    std::string strRootTagName;
                    strRootTagName = pSourceNode->GetTagName ();

                    // Grab our lua VM
                    CLuaMain* pLUA = m_pLuaManager->GetVirtualMachine ( luaVM );

                    // Create the new XML file and its root node
                    CXMLFile* pNewXML = pLUA->CreateXML ( strFilename );
                    if ( pNewXML )
                    {
                        // Create root for new XML
                        CXMLNode* pNewRoot = pNewXML->CreateRootNode ( strRootTagName );
                        if ( pNewRoot )
                        {
                            // Copy over the attributes from the root
                            int iAttributeCount = pSourceNode->GetAttributes ().Count ();
                            int i = 0;
                            CXMLAttribute* pAttribute;
                            for ( ; i < iAttributeCount; i++ )
                            {
                                pAttribute = pSourceNode->GetAttributes ().Get ( i );
                                if ( pAttribute )
                                    pNewRoot->GetAttributes ().Create ( *pAttribute );
                            }

                            // Copy the stuff from the given source node to the destination root
                            if ( pSourceNode->CopyChildrenInto ( pNewRoot, true ) )
                            {
                                lua_pushxmlnode ( luaVM, pNewRoot );
                                return 1;
                            }
                        }

                        // Delete the XML again
                        pLUA->DestroyXML ( pNewXML );
                    }
                }
            }
            else
                CLogger::ErrorPrintf ( "Unable to copy xml file; bad filepath" );
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );

    // Error
    lua_pushboolean ( luaVM, false );
    return 1;
}
Пример #16
0
BOOL CTileMapXML::Import(CTileWorld* pcTileWorld)
{
	CXMLFile		cXMLFile;
	CMarkup*		pcMarkup;
	BOOL			bResult;
	CMarkupTag*		pcTagBrushSources;
	CMarkupTag*		pcTagObjectSources;
	CMarkupTag*		pcTagMaps;
	CChars			szFileName;
	CChars			szDirectory;
	CFileUtil		cFileUtil;

	mpcWorld = pcTileWorld;
	mpcWorld->Init();

	szFileName.Init();
	szDirectory.Init();
	cFileUtil.SplitPath(mszMapName.Text(), &szFileName, &szDirectory);

	cXMLFile.Init();
	bResult = cXMLFile.Read(szFileName.Text(), szDirectory.Text());
	szFileName.Kill();
	szDirectory.Kill();
	if (!bResult)
	{
		cXMLFile.Kill();
		gcLogger.Error2(szFileName.Text(), " not found or could not be parsed.", NULL);
		return FALSE;
	}
	pcMarkup = &cXMLFile.mcMarkup;

	if (pcMarkup->GetRootTag() == NULL)
	{
		pcMarkup->Kill();
		gcLogger.Error("XML root tag not found");
		return FALSE;
	}

	pcTagBrushSources = CMarkupTextParser::GetTag(pcMarkup->GetRootTag(), "BrushSources");
	if (!pcTagBrushSources)
	{
		pcMarkup->Kill();
		return FALSE;
	}

	pcTagObjectSources = CMarkupTextParser::GetTag(pcMarkup->GetRootTag(), "ObjectClasses");
	if (!pcTagObjectSources)
	{
		pcMarkup->Kill();
		return FALSE;
	}

	pcTagMaps = CMarkupTextParser::GetTag(pcMarkup->GetRootTag(), "Maps");
	if (!pcTagMaps)
	{
		pcMarkup->Kill();
		return FALSE;
	}

	bResult = ImportBrushSources(pcTagBrushSources);
	if (!bResult)
	{
		pcMarkup->Kill();
		return FALSE;
	}

	bResult = ImportObjectSources(pcTagObjectSources);
	if (!bResult)
	{
		pcMarkup->Kill();
		return FALSE;
	}

	bResult = ImportMaps(pcTagMaps);
	if (!bResult)
	{
		pcMarkup->Kill();
		return FALSE;
	}

	pcMarkup->Kill();
	return bResult;
}
Пример #17
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 )
    {
        SString strFile;
        
        CScriptArgReader argStream ( luaVM );
        argStream.ReadString ( strFile );

        if ( !argStream.HasErrors () )
        {
            SString strPath;
            CResource* pThisResource = pLUA->GetResource ();
            CResource* pOtherResource = pThisResource;
            
            // Resolve other resource from name
            if ( CResourceManager::ParseResourcePathInput ( strFile, pOtherResource, &strPath, NULL ) )
            {
                // 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 ) )
                {

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

                    // 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
                    argStream.SetCustomError( SString( "ModifyOtherObjects in ACL denied resource '%s' to access '%s'", pThisResource->GetName ().c_str (), pOtherResource->GetName ().c_str () ), "Access denied" );
            }
        }

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

    lua_pushboolean ( luaVM, false );
    return 1;
}
Пример #18
0
int CLuaXMLDefs::xmlCopyFile ( lua_State* luaVM )
{
#ifndef MTA_CLIENT
    if ( lua_type ( luaVM, 3 ) == LUA_TLIGHTUSERDATA )
        m_pScriptDebugging->LogCustom ( luaVM, "xmlCopyFile may be using an outdated syntax. Please check and update." );
#endif // !MTA_CLIENT

    // Grab our resource
    CLuaMain* pLUA = m_pLuaManager->GetVirtualMachine ( luaVM );
    if ( pLUA )
    {
        SString strFile;
        CXMLNode* pSourceNode;

        CScriptArgReader argStream ( luaVM );
        argStream.ReadUserData ( pSourceNode );
        argStream.ReadString ( strFile );

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

            // Resolve other resource from name
            if ( CResourceManager::ParseResourcePathInput ( strFile, pOtherResource, &strPath, NULL ) )
            {
#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
                {
                    if ( pSourceNode ) {

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

                        // Grab the roots tag name
                        std::string strRootTagName;
                        strRootTagName = pSourceNode->GetTagName ();

                        // Create the new XML file and its root node
                        CXMLFile* pNewXML = pLUA->CreateXML ( strPath.c_str () );
                        if ( pNewXML )
                        {
                            // Grab the root of the new XML
                            CXMLNode* pNewRoot = pNewXML->CreateRootNode ( strRootTagName );
                            if ( pNewRoot )
                            {
                                // Copy over the attributes from the root
                                int iAttributeCount = pSourceNode->GetAttributes ().Count ();
                                int i = 0;
                                CXMLAttribute* pAttribute;
                                for ( ; i < iAttributeCount; i++ )
                                {
                                    pAttribute = pSourceNode->GetAttributes ().Get ( i );
                                    if ( pAttribute )
                                        pNewRoot->GetAttributes ().Create ( *pAttribute );
                                }

                                // Copy the stuff from the given source node to the destination root
                                if ( pSourceNode->CopyChildrenInto ( pNewRoot, true ) )
                                {
                                    lua_pushxmlnode ( luaVM, pNewRoot );
                                    return 1;
                                }
                            }

                            // Delete the XML again
                            pLUA->DestroyXML ( pNewXML );
                        }
                    }
                    else
                        argStream.SetCustomError ( SString ( "Unable to copy XML file %s", strFile.c_str () ), "Bad filepath" );
                }
#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
            }
        }

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

    // Error
    lua_pushboolean ( luaVM, false );
    return 1;
}
Пример #19
0
int CLuaXMLDefs::xmlCreateFile ( lua_State* luaVM )
{
#ifndef MTA_CLIENT
    if ( lua_type ( luaVM, 3 ) == LUA_TLIGHTUSERDATA )
        m_pScriptDebugging->LogCustom ( luaVM, "xmlCreateFile 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 strInputPath, strRootNodeName;

        CScriptArgReader argStream ( luaVM );
        argStream.ReadString ( strInputPath );
        argStream.ReadString ( strRootNodeName );

        if ( !argStream.HasErrors () )
        {
            SString strPath;
            CResource* pThisResource = pLuaMain->GetResource ();
            CResource* pOtherResource = pThisResource; // clientside, this variable will always be pThisResource

            // Resolve other resource from name
            if ( CResourceManager::ParseResourcePathInput ( strInputPath, pOtherResource, &strPath, nullptr ) )
            {
#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 file
                    CXMLFile * xmlFile = pLuaMain->CreateXML ( strPath );
                    if ( xmlFile )
                    {
                        // Create its root node
                        CXMLNode* pRootNode = xmlFile->CreateRootNode ( strRootNodeName );
                        if ( pRootNode )
                        {
                            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;
}
Пример #20
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;
}
Пример #21
0
//////////////////////////////////////////////////////////////////////////
//简要描述 : 设置扩展属性配置文件
//输入参数 :
//返 回 值 :
//
//
//修改日志 :
//////////////////////////////////////////////////////////////////////////
STDMETHODIMP CDwgWriter::put_XDataXMLConfigFile(BSTR sXMLFile)
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    if (sXMLFile == NULL) return S_OK;

    CString sXml = sXMLFile;
    if (sXml.IsEmpty()) return S_OK;

    m_XDataCfgs.RemoveAll();

    try
    {
        CXMLFile xmlfile;
        xmlfile.load(sXml);
        MSXML2::IXMLDOMNodePtr pNode;
        MSXML2::IXMLDOMNodePtr pExtAttrNode = NULL;
        xmlfile.GetNode("LAYERS", pNode);
        if (pNode == NULL)
        {
            //AfxMessageBox("XML配置文件不正确,请检查。");
            m_dwgWriter.WriteLog("XML配置文件不正确,请检查。");
            return S_FALSE;
        }
        pNode = pNode->GetfirstChild();
        if (pNode == NULL)
        {
            //AfxMessageBox("XML配置文件不正确,请检查。");
            m_dwgWriter.WriteLog("XML配置文件不正确,请检查。");
            return S_FALSE;
        }
        CComBSTR bsNodeName;
        CComBSTR bsExtAttrs;
        CString sLayerName;
        CString sRegAppName;
        CString sExtAttrs;
        while (pNode != NULL)
        {
            //得到图层名
            pNode->get_nodeName(&bsNodeName);
            sLayerName = bsNodeName;

            //去掉前面的_前缀,解决数字开头的节点问题
            CString sSign = "";
            sSign = sLayerName.Mid(0, 1);
            if (sSign.CompareNoCase("_") == 0)
            {
                sLayerName = sLayerName.Mid(1);
            }

            XDataAttrLists* pExtAttrs = new XDataAttrLists();
            //得到图层下的注册应用名
            if (pNode->hasChildNodes())
            {
                pExtAttrNode = pNode->GetfirstChild();
                while (pExtAttrNode != NULL)
                {
                    pExtAttrNode->get_nodeName(&bsNodeName);
                    sRegAppName = bsNodeName;

                    //去掉前面的_前缀,解决数字开头的节点问题
                    sSign = sRegAppName.Mid(0, 1);
                    if (sSign.CompareNoCase("_") == 0)
                    {
                        sRegAppName = sRegAppName.Mid(1);
                    }

                    pExtAttrNode->get_text(&bsExtAttrs);
                    sExtAttrs = bsExtAttrs;
                    CStringList* pAttrLst = new CStringList();
                    //解析注册应用名下的属性字段名称
                    CString sAttr;
                    int iPos  = sExtAttrs.Find(',');
                    while (iPos > 0)
                    {
                        sAttr = sExtAttrs.Mid(0, iPos);
                        sExtAttrs = sExtAttrs.Mid(iPos + 1);
                        if (!sAttr.IsEmpty())
                        {
                            pAttrLst->AddTail(sAttr);
                        }
                        iPos  = sExtAttrs.Find(',');
                    }
                    if (iPos == -1)
                    {
                        if (!sExtAttrs.IsEmpty())
                        {
                            pAttrLst->AddTail(sExtAttrs);
                        }
                    }
                    pExtAttrs->SetAt(sRegAppName, pAttrLst);
                    //得到下一个注册应用名的配置
                    pExtAttrNode = pExtAttrNode->GetnextSibling();
                }
            }

            m_XDataCfgs.SetAt(sLayerName, pExtAttrs);
            //得到下一个图层的扩展属性的配置
            pNode = pNode->GetnextSibling();
        }
    }
    catch (...)
    {
		m_dwgWriter.WriteLog("解析XML文件出错,请检查。");
        return S_FALSE;
    }

    return S_OK;
}
Пример #22
0
int CLuaXMLDefs::xmlCopyFile ( lua_State* luaVM )
{
    if ( lua_type ( luaVM, 3 ) == LUA_TLIGHTUSERDATA )
        m_pScriptDebugging->LogCustom ( luaVM, "xmlCopyFile 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;

        // Verify the argument types passed
        if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA  &&
            lua_type ( luaVM, 2 ) == LUA_TSTRING )
        {
            // Grab the filename passed
            std::string strFile = lua_tostring ( luaVM, 2 );
            std::string strPath;
            if ( CResourceManager::ParseResourcePathInput ( strFile, pResource, &strPath, NULL ) )
            {
                // We have access to modify this resource?
                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 () );

                    // Grab the source node
                    CXMLNode* pSourceNode = lua_toxmlnode ( luaVM, 1 );
                    if ( pSourceNode )
                    {
                        // Grab the roots tag name
                        std::string strRootTagName;
                        strRootTagName = pSourceNode->GetTagName ();

                        // Create the new XML file and its root node
                        CXMLFile* pNewXML = pLUA->CreateXML ( strPath.c_str () );
                        if ( pNewXML )
                        {
                            // Grab the root of the new XML
                            CXMLNode* pNewRoot = pNewXML->CreateRootNode ( strRootTagName );
                            if ( pNewRoot )
                            {
                                // Copy over the attributes from the root
                                int iAttributeCount = pSourceNode->GetAttributes ().Count ();
                                int i = 0;
                                CXMLAttribute* pAttribute;
                                for ( ; i < iAttributeCount; i++ )
                                {
                                    pAttribute = pSourceNode->GetAttributes ().Get ( i );
                                    if ( pAttribute )
                                        pNewRoot->GetAttributes ().Create ( *pAttribute );
                                }

                                // Copy the stuff from the given source node to the destination root
                                if ( pSourceNode->CopyChildrenInto ( pNewRoot, true ) )
                                {
                                    lua_pushxmlnode ( luaVM, pNewRoot );
                                    return 1;
                                }
                            }

                            // Delete the XML again
                            pLUA->DestroyXML ( pNewXML );
                        }
                    }
                    else
                        CLogger::ErrorPrintf ( "Unable to copy xml file; bad filepath" );
                }
                else
                    m_pScriptDebugging->LogError ( luaVM,"xmlCopyFile failed; ModifyOtherObjects in ACL denied resource %s to access %s", pThisResource->GetName ().c_str (), pResource->GetName ().c_str () );
            }
        }
        else
            m_pScriptDebugging->LogBadType ( luaVM, "xmlCopyFile" );
    }

    // Error
    lua_pushboolean ( luaVM, false );
    return 1;
}