コード例 #1
0
ファイル: CLuaXMLDefs.cpp プロジェクト: qaisjp/mtasa-blue
int CLuaXMLDefs::xmlNodeFindChild ( lua_State* luaVM )
{
    CXMLNode* pNode;
    SString strTagName;
    unsigned int uiIndex;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pNode );
    argStream.ReadString ( strTagName );
    argStream.ReadNumber ( uiIndex );

    if ( !argStream.HasErrors () )
    {
        CXMLNode * pFoundNode = pNode->FindSubNode ( strTagName, uiIndex );
        if ( pFoundNode )
        {
            lua_pushxmlnode ( luaVM, pFoundNode );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
コード例 #2
0
int CLuaXMLDefs::xmlNodeFindChild ( lua_State* luaVM )
{
    // xmlNode*, node name, index
    if ( lua_type ( luaVM, 1 ) != LUA_TLIGHTUSERDATA ||
         lua_type ( luaVM, 2 ) != LUA_TSTRING ||
         lua_type ( luaVM, 3 ) != LUA_TNUMBER )
    {
        m_pScriptDebugging->LogBadType ( luaVM, "xmlNodeFindChild" );

        lua_pushboolean ( luaVM, false );
        return 1;
    }
    else
    {
        CXMLNode* pNode = lua_toxmlnode ( luaVM, 1 );
        if ( pNode )
        {
            const char * szTagName = lua_tostring ( luaVM, 2 );
            unsigned int iIndex = static_cast < unsigned int > ( lua_tonumber ( luaVM, 3 ) );
            CXMLNode * pFoundNode = pNode->FindSubNode ( szTagName, iIndex );
            if ( pFoundNode )
            {
                lua_pushxmlnode ( luaVM, pFoundNode );
                return 1;
            }
        }
    }

    lua_pushboolean ( luaVM, false );
    return 1;
}
コード例 #3
0
int CLuaXMLDefs::xmlCreateChild ( lua_State* luaVM )
{
    // Node name
    if ( lua_type ( luaVM, 1 ) != LUA_TLIGHTUSERDATA ||
         lua_type ( luaVM, 2 ) != LUA_TSTRING )
    {
        m_pScriptDebugging->LogBadType ( luaVM, "xmlCreateChild" );

        lua_pushboolean ( luaVM, false );
        return 1;
    }
    else
    {
        // Get the Node
        CXMLNode* pXMLNode = lua_toxmlnode ( luaVM, 1 );
        if ( pXMLNode )
        {
            // Grab the subnode name
            const char* szSubNodeName = lua_tostring ( luaVM, 2 );
            if ( szSubNodeName )
            {
                CXMLNode* pXMLSubNode = pXMLNode->CreateSubNode ( szSubNodeName );
                if ( pXMLSubNode )
                {
                    lua_pushxmlnode ( luaVM, pXMLSubNode );
                    return 1;
                }
            }
        }
    }

    lua_pushboolean ( luaVM, false );
    return 1;
}
コード例 #4
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;
}
コード例 #5
0
int CLuaXMLDefs::xmlNodeGetChildren ( lua_State* luaVM )
{
    CXMLNode* pNode;
    unsigned int uiIndex;
        
    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pNode );
    argStream.ReadNumber ( uiIndex, 0 );

    bool bGetAllChildren = uiIndex == 0;

    if ( !argStream.HasErrors () )
    {
        CXMLNode * pFoundNode = NULL;
        if ( !bGetAllChildren )
        {
            pFoundNode = pNode->GetSubNode ( uiIndex );
            if ( pFoundNode )
            {
                lua_pushxmlnode ( luaVM, pFoundNode );
                return 1;
            }
        }
        else
        {
            lua_newtable ( luaVM );
            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->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
コード例 #6
0
ファイル: CLuaXMLDefs.cpp プロジェクト: qaisjp/mtasa-blue
int CLuaXMLDefs::xmlNodeGetParent ( lua_State* luaVM )
{
    CXMLNode* pNode = nullptr;
    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pNode );

    if ( !argStream.HasErrors () )
    {
        CXMLNode * pParent = pNode->GetParent ();
        if ( pParent )
        {
            lua_pushxmlnode ( luaVM, pParent );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
コード例 #7
0
ファイル: LuaCommon.cpp プロジェクト: AdiBoy/mtasa-blue
void lua_pushuserdata ( lua_State* luaVM, void* pData )
{
    if ( CClientEntity* pEntity = UserDataCast < CClientEntity > ( ( CClientEntity* ) NULL, pData, luaVM ) )
        return lua_pushelement ( luaVM, pEntity );
    else if ( CResource* pResource = UserDataCast < CResource > ( ( CResource* ) NULL, pData, luaVM ) )
        return lua_pushresource ( luaVM, pResource );
    else if ( CXMLNode* pNode = UserDataCast < CXMLNode > ( ( CXMLNode* ) NULL, pData, luaVM ) )
        return lua_pushxmlnode ( luaVM, pNode );
    else if ( CLuaTimer* pTimer = UserDataCast < CLuaTimer > ( ( CLuaTimer* ) NULL, pData, luaVM ) )
        return lua_pushtimer ( luaVM, pTimer );
    else if ( CLuaVector2D* pVector = UserDataCast < CLuaVector2D > ( (CLuaVector2D*) NULL, pData, luaVM ) )
        return lua_pushvector ( luaVM,* pVector );
    else if ( CLuaVector3D* pVector = UserDataCast < CLuaVector3D > ( (CLuaVector3D*) NULL, pData, luaVM ) )
        return lua_pushvector ( luaVM, *pVector );
    else if ( CLuaVector4D* pVector = UserDataCast < CLuaVector4D > ( (CLuaVector4D*) NULL, pData, luaVM ) )
        return lua_pushvector ( luaVM, *pVector );
    else if ( CLuaMatrix* pMatrix = UserDataCast < CLuaMatrix > ( (CLuaMatrix*) NULL, pData, luaVM ) )
        return lua_pushmatrix ( luaVM, *pMatrix );

    lua_pushobject ( luaVM, NULL, pData );
}
コード例 #8
0
int CLuaXMLDefs::xmlNodeGetParent ( lua_State* luaVM )
{
    // xmlNode*
    if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA )
    {
        CXMLNode* pNode = lua_toxmlnode ( luaVM, 1 );
        if ( pNode )
        {
            CXMLNode * pParent = pNode->GetParent ();
            if ( pParent )
            {
                lua_pushxmlnode ( luaVM, pParent );
                return 1;
            }
        }
    }
    else
        m_pScriptDebugging->LogBadType ( luaVM, "xmlNodeGetParent" );

    lua_pushboolean ( luaVM, false );
    return 1;
}
コード例 #9
0
ファイル: LuaCommon.cpp プロジェクト: Anubhav652/mtasa-blue
void lua_pushuserdata ( lua_State* luaVM, void* pData )
{
    if ( CElement* pEntity = UserDataCast < CElement > ( ( CElement* ) NULL, pData, NULL ) )
        return lua_pushelement ( luaVM, pEntity );
    if ( CPlayer* pEntity = UserDataCast < CPlayer > ( ( CPlayer* ) NULL, pData, NULL ) )
        return lua_pushelement ( luaVM, pEntity );
    else if ( CResource* pResource = UserDataCast < CResource > ( ( CResource* ) NULL, pData, NULL ) )
        return lua_pushresource ( luaVM, pResource );
    else if ( CXMLNode* pNode = UserDataCast < CXMLNode > ( ( CXMLNode* ) NULL, pData, NULL ) )
        return lua_pushxmlnode ( luaVM, pNode );
    else if ( CLuaTimer* pTimer = UserDataCast < CLuaTimer > ( ( CLuaTimer* ) NULL, pData, luaVM ) )
        return lua_pushtimer ( luaVM, pTimer );
    else if ( CLuaVector2D* pVector = UserDataCast < CLuaVector2D > ( (CLuaVector2D*) NULL, pData, luaVM ) )
        return lua_pushvector ( luaVM, *pVector );
    else if ( CLuaVector3D* pVector = UserDataCast < CLuaVector3D > ( (CLuaVector3D*) NULL, pData, luaVM ) )
        return lua_pushvector ( luaVM, *pVector );
    else if ( CLuaVector4D* pVector = UserDataCast < CLuaVector4D > ( (CLuaVector4D*) NULL, pData, luaVM ) )
        return lua_pushvector ( luaVM, *pVector );
    else if ( CLuaMatrix* pMatrix = UserDataCast < CLuaMatrix > ( (CLuaMatrix*) NULL, pData, luaVM ) )
        return lua_pushmatrix ( luaVM, *pMatrix );
    else if ( CAccount* pAccount = UserDataCast < CAccount > ( (CAccount*) NULL, pData, luaVM ) )
        return lua_pushaccount ( luaVM, pAccount );
    else if ( CAccessControlList* pACL = UserDataCast < CAccessControlList > ( (CAccessControlList*) NULL, pData, luaVM ) )
        return lua_pushacl ( luaVM, pACL );
    else if ( CAccessControlListGroup* pACLGroup = UserDataCast < CAccessControlListGroup > ( (CAccessControlListGroup*) NULL, pData, luaVM ) )
        return lua_pushaclgroup ( luaVM, pACLGroup );
    else if ( CBan* pBan = UserDataCast < CBan > ( (CBan*) NULL, pData, luaVM ) )
        return lua_pushban ( luaVM, pBan );
    else if ( CTextDisplay* pTextDisplay = UserDataCast < CTextDisplay > ( (CTextDisplay*) NULL, pData, luaVM ) )
        return lua_pushtextdisplay ( luaVM, pTextDisplay );
    else if ( CTextItem* pTextItem = UserDataCast < CTextItem > ( (CTextItem*) NULL, pData, luaVM ) )
        return lua_pushtextitem ( luaVM, pTextItem );
    else if ( CDbJobData* pQuery = UserDataCast < CDbJobData > ( (CDbJobData*) NULL, pData, luaVM ) )
        return lua_pushquery ( luaVM, pQuery );

    lua_pushobject ( luaVM, NULL, pData );
}
コード例 #10
0
ファイル: CLuaXMLDefs.cpp プロジェクト: qaisjp/mtasa-blue
int CLuaXMLDefs::xmlCreateChild ( lua_State* luaVM )
{
    CXMLNode* pNode = nullptr;
    SString strChildName;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pNode );
    argStream.ReadString ( strChildName );

    if ( !argStream.HasErrors () )
    {
        CXMLNode* pXMLSubNode = pNode->CreateSubNode ( strChildName );
        if ( pXMLSubNode )
        {
            lua_pushxmlnode ( luaVM, pXMLSubNode );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
コード例 #11
0
ファイル: CLuaXMLDefs.cpp プロジェクト: qaisjp/mtasa-blue
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;
}
コード例 #12
0
ファイル: CLuaXMLDefs.cpp プロジェクト: qaisjp/mtasa-blue
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;
}
コード例 #13
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;
}
コード例 #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;
}
コード例 #15
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;
}
コード例 #16
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;
}