예제 #1
0
BOOL CAnalogProfilePage::LoadXML()
{
	CString strValue;
	CXMLAttribute* pAttri = NULL;
	
	for ( POSITION pos = m_pXML->GetElementIterator() ; pos ; )
	{
		CXMLElement* pMap = m_pXML->GetNextElement( pos );
		if ( ! pMap->IsNamed( _T("Map") ) ) continue;
		
		if ( pAttri = pMap->GetAttribute( _T("ID") ) )
		{
			int nItem = m_wndList.InsertItem( LVIF_IMAGE|LVIF_PARAM,
				m_wndList.GetItemCount(), NULL, 0, 0, 28, (LPARAM)pMap );
			
			strValue = pAttri->GetValue();
			m_wndList.SetItemText( nItem, 1, pAttri->GetValue() );
			
			if ( pAttri = pMap->GetAttribute( _T("LinkId") ) )
			{
				m_wndList.SetItemText( nItem, 0, pAttri->GetValue() );
			}
			
			if ( pAttri = pMap->GetAttribute( _T("LocalId") ) )
			{
				m_wndList.SetItemText( nItem, 2, pAttri->GetValue() );
			}
		}
	}

	return TRUE;
}
예제 #2
0
void CElement::ReadCustomData ( CLuaMain* pLuaMain, CEvents* pEvents )
{
    assert ( pLuaMain );
    assert ( pEvents );

    // Got an XML node?
    if ( m_pXMLNode )
    {
        // Iterate the attributes of our XML node
        CXMLAttributes* pAttributes = &(m_pXMLNode->GetAttributes ());
        unsigned int uiAttributeCount = pAttributes->Count ();
        for ( unsigned int uiIndex = 0; uiIndex < uiAttributeCount; uiIndex++ )
        {
            // Grab the node (we can assume it exists here)
            CXMLAttribute* pAttribute = pAttributes->Get ( uiIndex );

            // Make a lua argument from it and set the content
            CLuaArguments args;
            if ( !args.ReadFromJSONString ( pAttribute->GetValue ().c_str() ) )
                args.PushString ( pAttribute->GetValue ().c_str () );

            // Don't trigger onElementDataChanged event
            SetCustomData ( pAttribute->GetName ().c_str (), *args[0], pLuaMain, g_pGame->GetConfig ()->GetSyncMapElementData (), NULL, false );
        }
    }
}
예제 #3
0
bool CServerBrowser::LoadServerList ( CXMLNode* pNode, std::string strTagName, CServerList *pList )
{
    CXMLNode* pSubNode = NULL;
    in_addr Address;
    int iPort;

    if ( !pNode )
        return false;

    // Loop through all subnodes looking for relevant nodes
    unsigned int uiCount = pNode->GetSubNodeCount ();
    for ( unsigned int i = 0; i < uiCount; i++ )
    {
        pSubNode = pNode->GetSubNode ( i );
        if ( pSubNode && pSubNode->GetTagName ().compare ( strTagName ) == 0 )
        {
            // This node is relevant, so get the attributes we need and add it to the list
            CXMLAttribute* pHostAttribute = pSubNode->GetAttributes ().Find ( "host" );
            CXMLAttribute* pPortAttribute = pSubNode->GetAttributes ().Find ( "port" );
            if ( pHostAttribute && pPortAttribute ) {
                if ( CServerListItem::Parse ( pHostAttribute->GetValue ().c_str (), Address ) )
                {
                    iPort = atoi ( pPortAttribute->GetValue ().c_str () ) + SERVER_LIST_QUERY_PORT_OFFSET;
                    if ( iPort > 0 )
                        pList->Add ( CServerListItem ( Address, iPort ) );
                }
            }
        }
    }
    pList->SetUpdated ( true );
    return true;
}
예제 #4
0
BOOL CPlayProfilePage::LoadXML()
{
	CString strValue;
	CXMLAttribute* pAttri = NULL;
	
	for ( POSITION pos = m_pXML->GetElementIterator() ; pos ; )
	{
		CXMLElement* pMap = m_pXML->GetNextElement( pos );
		if ( ! pMap->IsNamed( _T("Map") ) ) continue;
		
		if ( pAttri = pMap->GetAttribute( _T("ID") ) )
		{
			strValue = pAttri->GetValue();
			int nItem = m_wndList.InsertItem(
				LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM,
				m_wndList.GetItemCount(), strValue, 0, 0,
				CoolInterface.ImageForID(ID_REPORT_MUSIC), (LPARAM)pMap );
			
			if ( pAttri = pMap->GetAttribute( _T("Play") ) )
			{
				m_wndList.SetItemText( nItem, 1, pAttri->GetValue() );
			}
		}
	}

	return TRUE;
}
예제 #5
0
BOOL CUserMeetingDlg::CreateMenuGroup(CXMLElement* pXML, HMENU hParent)
{
	UINT nMenuId = MIN_GROUP;
	
	for ( POSITION pos = pXML->GetElementIterator() ; pos ; )
	{
		CXMLElement* pSync = pXML->GetNextElement( pos );
		if ( ! pSync->IsNamed( "SyncOrder" ) ) continue;
		
		static LPCTSTR pszGroup[] = { _T("xgroupname"), _T("xgroupnum") };
		
		CXMLAttribute* pAttri = pSync->GetAttribute( pszGroup[0] );
		if ( ! pAttri || pAttri->GetValue().IsEmpty() ) pAttri = pSync->GetAttribute( pszGroup[1] );
		
		if ( pAttri && m_wndGroup.FindStringExact( -1, pAttri->GetValue() ) != m_wndGroup.GetCurSel() ) continue;
		
		HMENU hMenu = FindMenuGroup( hParent, pAttri->GetValue() );	if ( ! hMenu )
		{
			hMenu = CreatePopupMenu();
			AppendMenu( hParent, MF_STRING|MF_POPUP, (UINT)hMenu, pAttri->GetValue() );
		}
		
		CString strText = pSync->GetAttributeValue( _T("xname") );
		if ( ! strText.IsEmpty() ) strText += '\t';
		
		strText += pSync->GetAttributeValue( _T("xphone") );
		AppendMenu( hMenu, MF_STRING, nMenuId++, strText );
		
		if ( nMenuId > MAX_GROUP ) break;
	}
	
	return TRUE;
}
예제 #6
0
void CGroupingDlg::OnSelChangeGroup()
{
	m_wndList.DeleteAllItems();
	CWaitCursor pCursor;
	
	int nItem = m_wndGroup.GetCurSel();
	if ( nItem < 0 ) return;
	
	CXMLElement* pXML = (CXMLElement*)m_wndGroup.GetItemDataPtr( nItem );
	ASSERT( pXML != NULL );
	
	for ( POSITION posNext = pXML->GetElementIterator(); posNext; )
	{
		CXMLElement* pSync = pXML->GetNextElement( posNext );
		if ( ! pSync->IsNamed( "SyncOrder" ) ) continue;
		
		static LPCTSTR pszGroup[] = { _T("xgroupname"), _T("xgroupnum") };
		
		CXMLAttribute* pAttri = pSync->GetAttribute( pszGroup[0] );
		if ( ! pAttri || pAttri->GetValue().IsEmpty() ) pAttri = pSync->GetAttribute( pszGroup[1] );
		
		if ( pAttri && m_wndGroup.FindStringExact( -1, pAttri->GetValue() ) != nItem ) continue;
		
		static LPCTSTR pszSuffix[] = { _T("xphone"), _T("xname"), NULL };
		
		int nItem = m_wndList.InsertItem( LVIF_TEXT|LVIF_PARAM,
				m_wndList.GetItemCount(), NULL, 0, 0, 0, (LPARAM)pSync );
		
		for ( int i = 0; pszSuffix[i] != NULL; i ++ )
		{
			CXMLAttribute* pAttri = pSync->GetAttribute( pszSuffix[i] );
			if ( pAttri ) m_wndList.SetItemText( nItem, i, pAttri->GetValue() );
		}
	}
}
예제 #7
0
BOOL CGroupingDlg::OnSyncDataViewResp(CXMLElement* pXML)
{
	CWaitCursor pCursor;
	
	m_wndGroup.ResetContent();
	m_pXML->Delete(); m_pXML = pXML;
	
	for ( POSITION posNext = pXML->GetElementIterator(); posNext; )
	{
		CXMLElement* pSync = pXML->GetNextElement( posNext );
		if ( ! pSync->IsNamed( "SyncOrder" ) ) continue;
		
		static LPCTSTR pszGroup[] = { _T("xgroupname"), _T("xgroupnum") };
		
		CXMLAttribute* pAttri = pSync->GetAttribute( pszGroup[0] );
		if ( ! pAttri || pAttri->GetValue().IsEmpty() ) pAttri = pSync->GetAttribute( pszGroup[1] );
		
		if ( pAttri && m_wndGroup.FindStringExact( -1, pAttri->GetValue() ) == CB_ERR )
		m_wndGroup.SetItemDataPtr( m_wndGroup.AddString( pAttri->GetValue() ), pXML );
	}
	
	m_wndGroup.SetCurSel( 0 );
	SendMessage(WM_COMMAND, MAKELONG(m_wndGroup.GetDlgCtrlID(),CBN_SELCHANGE), (LPARAM)m_hWnd);
	
	return TRUE;
}
예제 #8
0
BOOL CNetworkMonitorBox::ProcessXML(POSITION posNext)
{
	CXMLElement* pXML = Profiles.FindProcess( NULL, posNext );
	if ( pXML == NULL ) return FALSE;
	
	CSingleLock pLock( &Network.m_pSection, TRUE );
	
	CString strValue = pXML->GetAttributeValue( "Host" );
	
	if ( CChannel* pChannel = Network.FindChannel( strValue ) )
	{
		if ( pChannel->m_hSocket == INVALID_SOCKET && pChannel->TimeOut( 60 * 1000 ) ) 
		{
			CXMLAttribute* pAttri = pXML->GetAttribute( "Retry" );
			if ( ! pAttri ) pAttri = pXML->AddAttribute( "Retry" );
			
			if ( _ttoi( pAttri->GetValue() ) >= 2 )
			{
				AlarmToShortMessage( (LPCTSTR)strValue );
				strValue = pXML->GetAttributeValue( _T("Path") );
				RestartMachine( (LPCTSTR)strValue );
				
				pXML->DeleteAttribute( "Retry" );
			}
			else
			{
				strValue.Format( "%i", _ttoi( pAttri->GetValue() ) + 1 );
				pAttri->SetValue( (LPCTSTR)strValue );
				
				pChannel->LinkRestart();
				pChannel->m_tConnected	= GetTickCount();
			}
		}
		else
		if ( pChannel->IsConnected() )
		{
			pXML->DeleteAttribute( "Retry" );
		}
	}
	else
	{
		CChannel* pChannel = new CSentryChannel( pXML );
		Network.SetChannel( pChannel );
		
		pChannel->LinkRestart();
	}
	
	if ( posNext ) return ProcessXML( posNext );
	return TRUE;
}
예제 #9
0
//////////////////////////////////////////////////////////////////////
//
// Fetch multiple values for a named setting from the server config
//
//  <module src="module_test.dll" />
//  <resource src="admin" startup="1" protected="0" />
//
//////////////////////////////////////////////////////////////////////
bool CMainConfig::GetSettingTable ( const SString& strName, const char** szAttribNames, uint uiNumAttribNames, CLuaArguments* outTable )
{
    uint uiXMLIndex = 0;
    uint uiLuaIndex = 1;
    CXMLNode* pNode = NULL;
    do
    {
        // Grab the current script node
        pNode = m_pRootNode->FindSubNode ( strName, uiXMLIndex++ );
        if ( pNode )
        {
            CLuaArguments resultLine;
            CXMLAttributes& attributes = pNode->GetAttributes();
            for ( uint i = 0 ; i < attributes.Count() ; i++ )
            {
                CXMLAttribute* pAttribute = attributes.Get( i );
                resultLine.PushString( pAttribute->GetName() );
                resultLine.PushString( pAttribute->GetValue() );
            }

            if ( resultLine.Count() != 0 )
            {
                outTable->PushNumber( uiLuaIndex++ );
                outTable->PushTable( &resultLine );
            }
        }
    }
    while( pNode );

    return outTable->Count() != 0;
}
예제 #10
0
std::string CServerBrowser::GetServerPassword ( std::string strHost )
{
    CXMLNode* pConfig = CCore::GetSingletonPtr ()->GetConfig ();
    CXMLNode* pServerPasswords = pConfig->FindSubNode ( CONFIG_NODE_SERVER_SAVED );
    if ( !pServerPasswords )
    {
        pServerPasswords = pConfig ->CreateSubNode ( CONFIG_NODE_SERVER_SAVED );
    }
    //Check if the server password already exists
    for ( unsigned int i = 0 ; i < pServerPasswords->GetSubNodeCount() ; i++ )
    {    
        CXMLAttributes* pAttributes = &(pServerPasswords->GetSubNode(i)->GetAttributes());
        if ( pAttributes->Find( "host" ) )
        {
            if ( CXMLAttribute* pHost = pAttributes->Find ( "host" ) )
            {
                std::string strXMLHost = pHost->GetValue();
                if ( strXMLHost == strHost )
                {
                    CXMLAttribute* pPassword = pAttributes->Create( "password" );
                    std::string strPassword = pPassword->GetValue();
                    return strPassword;
                }
            }
        }
        
    }
    return "";
}
예제 #11
0
void CXMLElement::AddRecursiveWords(CString& strWords) const
{
	for ( POSITION pos = GetAttributeIterator() ; pos ; )
	{
		CXMLAttribute* pAttribute = GetNextAttribute( pos );
		CString strText = pAttribute->GetName();

		if ( strText.Find( ':' ) >= 0 ) continue;
		if ( strText.CompareNoCase( _T("SHA1") ) == 0 ) continue;	// NOTE: PeerProject/Shareaza Specific

		if ( ! strWords.IsEmpty() ) strWords += ' ';
		strWords += pAttribute->GetValue();
	}

	for ( POSITION pos = GetElementIterator() ; pos ; )
	{
		GetNextElement( pos )->AddRecursiveWords( strWords );
	}

	if ( ! m_sValue.IsEmpty() )
	{
		if ( ! strWords.IsEmpty() )
			strWords += ' ';
		strWords += m_sValue;
	}
}
예제 #12
0
Bool CMaterialResource::Init()
{
	CXMLDocument document;
	document.Load( m_FilePath.c_str() );

	CXMLNode rootNode = document.GetRootNode();

	//Read out textures
	CXMLNode childNode = rootNode.GetChildNode( "Texture2D" );

	while ( childNode.IsEmpty() == false )
	{
		CXMLAttribute attribute = childNode.GetAttribute( "Hash" );
		const Uint hash = (Uint)strtoul( attribute.GetValue(), NULL, 0 );
		AddDependentHash( hash );
		childNode = childNode.GetNextSibling();
	}

	if ( m_DependenciesLeft == 0 )
	{
		return true;
	}

	return false;
}
예제 #13
0
int CLuaXMLDefs::xmlNodeGetAttribute ( lua_State* luaVM )
{
    CXMLNode* pNode = nullptr;
    SString strAttributeName = "";
    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pNode );
    argStream.ReadString ( strAttributeName );

    if ( !argStream.HasErrors () )
    {
        // Find the attribute with that name
        CXMLAttribute * pAttribute = pNode->GetAttributes ().Find ( strAttributeName );
        if ( pAttribute )
        {
            // Read the attribute and return the string
            lua_pushstring ( luaVM, pAttribute->GetValue ().c_str () );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
예제 #14
0
BOOL CProfiles::IsDenied(IN_ADDR* pAddress)
{
	CSingleLock pLock( &m_pSection, TRUE );
	
	if ( ! m_pXMLSecure ) return FALSE;
	
	CString strValue;
	BOOL bFound = FALSE;
	CXMLAttribute* pAttri = NULL;
	
	for ( POSITION pos = m_pXMLSecure->GetElementIterator() ; pos ; )
	{
		CXMLElement* pMap = m_pXMLSecure->GetNextElement( pos );
		if ( ! pMap->IsNamed( _T("Map") ) ) continue;
		
		if ( pAttri = pMap->GetAttribute( _T("Host") ) )
		{
			strValue = pAttri->GetValue();
			if ( strValue.CompareNoCase( _T("任意") ) == 0
			  || inet_addr((LPCTSTR)strValue) == *(DWORD*)pAddress )
			{
				bFound = TRUE; break;
			}
		}
	}
	
	// 拒绝条件: 拒绝 && bFound ==> TRUE
	//         : !拒绝 && !Found ==> TRUE
	// 受理方法: 异或 = 0 ==> TRUE, 否则 FALSE
	CString xAction = m_pXMLSecure->GetAttributeValue( _T("Action") );
	if ( xAction.CompareNoCase( _T("拒绝") ) ^ bFound  ) return FALSE;
	
	return TRUE;
}
예제 #15
0
CXMLElement* CProfiles::FindProcess(LPCTSTR xJobId, POSITION& posNext, CXMLElement** ppActionXML)
{
    CSingleLock pLock( &m_pSection, TRUE );
    if ( ! m_pXMLMonitor ) return NULL;

    CXMLElement* pAction = NULL;
    if ( ! ppActionXML ) ppActionXML = &pAction;

    *ppActionXML = m_pXMLMonitor->GetElementByName( _T("ShortMessage") );

    if ( CXMLElement* pXML = m_pXMLMonitor->GetElementByName( _T("Process") ) )
    {
        if ( ! posNext ) posNext = pXML->GetElementIterator();
        if ( ! posNext ) return NULL;

        CXMLElement* pMap = pXML->GetNextElement( posNext );
        if ( ! pMap->IsNamed( _T("Map") ) ) return posNext ? FindProcess( xJobId, posNext ) : NULL;

        if ( ! xJobId || ! _tcscmp(xJobId, _T("ÈÎÒâ")) ) return pMap;

        CXMLAttribute* pAttri = pMap->GetAttribute( "Host" );
        if ( pAttri && pAttri->GetValue() == xJobId ) return pMap;

        return posNext ? FindProcess( xJobId, posNext, ppActionXML ) : NULL;
    }

    return NULL;
}
예제 #16
0
void CLightNode::Load( const Core::CXMLNode& a_Node )
{
	CSceneNode::Load( a_Node );
	//Color
	CVector3 color;
	CXMLAttribute attribute = a_Node.GetAttribute( "ColorR" );	color.X = (float)atof( attribute.GetValue( "0.0f" ) );
				  attribute = a_Node.GetAttribute( "ColorG" );	color.Y = (float)atof( attribute.GetValue( "0.0f" ) );
				  attribute = a_Node.GetAttribute( "ColorB" );	color.Z = (float)atof( attribute.GetValue( "0.0f" ) );

	//Light properties
	float outerAngle, innerAngle, constAtten, linearAtten, quadAtten;
	attribute = a_Node.GetAttribute( "OuterAngle" );  outerAngle = (float)atof( attribute.GetValue( "0.0f" ) );	
	attribute = a_Node.GetAttribute( "InnerAngle" );  innerAngle = (float)atof( attribute.GetValue( "0.0f" ) );

	attribute = a_Node.GetAttribute( "ConstantAttentuation" );  constAtten = (float)atof( attribute.GetValue( "0.0f" ) );
	attribute = a_Node.GetAttribute( "LinearAttentuation" );  linearAtten = (float)atof( attribute.GetValue( "0.0f" ) );
	attribute = a_Node.GetAttribute( "QuadraticAttentuation" );  quadAtten = (float)atof( attribute.GetValue( "0.0f" ) );

	const char* lightTypeString;
	int lightType;
	attribute = a_Node.GetAttribute( "Type" ); lightTypeString = attribute.GetValue();
	
	if ( strcmp( lightTypeString, "Point" ) == 0 )
	{
		lightType = CLight::LightTypePoint;
	}
	else if ( strcmp( lightTypeString, "Spot" ) == 0 )
	{
		lightType = CLight::LightTypeSpot;
	}
	else if ( strcmp( lightTypeString, "Directional" ) == 0 )
	{
		lightType = CLight::LightTypeDirectional;
	}
	else
	{
		CLog::GetInstance()->OutMessage( "Incorrect light type: %s", CLog::MESSAGETYPE_ERROR, lightTypeString );
	}

	std::string shadowContext;
	attribute = a_Node.GetAttribute( "ShadowContext" );
	shadowContext += attribute.GetValue( "" );
	
	m_Light = new CLight( m_Position, m_Rotation, (CLight::LightType)lightType, color, constAtten, linearAtten, quadAtten, innerAngle, outerAngle, shadowContext );
}
예제 #17
0
파일: XML.cpp 프로젝트: GetEnvy/Envy
BOOL CXMLElement::Merge(const CXMLElement* pInput, BOOL bOverwrite)
{
	if ( ! this || ! pInput ) return FALSE;
	if ( this == pInput ) return TRUE;

	TRACE( "Merging   XML: %s\n", (LPCSTR)CT2A( ToString( FALSE, FALSE ) ) );
	TRACE( "      and XML: %s\n", (LPCSTR)CT2A( pInput->ToString( FALSE, FALSE ) ) );

	if ( m_sName.CompareNoCase( pInput->m_sName ) != 0 )
	{
		TRACE( "Failed to merge XML due different schemes \"%s\" and \"%s\".\n", (LPCSTR)CT2A( m_sName ), (LPCSTR)CT2A( pInput->m_sName ) );
		return FALSE;
	}

	BOOL bChanged = FALSE;

	for ( POSITION pos = pInput->GetElementIterator(); pos; )
	{
		const CXMLElement* pElement = pInput->GetNextElement( pos );
		CXMLElement* pTarget = GetElementByName( pElement->m_sName );

		if ( pTarget == NULL )
		{
			AddElement( pElement->Clone() );
			bChanged = TRUE;
		}
		else if ( pTarget->Merge( pElement, bOverwrite ) )
		{
			bChanged = TRUE;
		}
	}

	for ( POSITION pos = pInput->GetAttributeIterator(); pos; )
	{
		CXMLAttribute* pAttribute = pInput->GetNextAttribute( pos );
		CXMLAttribute* pTarget = GetAttribute( pAttribute->m_sName );

		if ( pTarget == NULL )
		{
			AddAttribute( pAttribute->Clone() );
			bChanged = TRUE;
		}
		else if ( bOverwrite && ! pTarget->Equals( pAttribute ) )
		{
			pTarget->SetValue( pAttribute->GetValue() );
			bChanged = TRUE;
		}
	}

	if ( bChanged )
		TRACE( "resulting XML: %s\n", (LPCSTR)CT2A( ToString( FALSE, FALSE ) ) );
	else
		TRACE( "resulting XML unchanged.\n" );

	return bChanged;
}
예제 #18
0
std::string CBanManager::SafeGetValue ( CXMLNode* pNode, const char* szKey )
{
    CXMLAttribute* pAttribute = pNode->GetAttributes ().Find ( szKey );

    if ( pAttribute )
    {
        return pAttribute->GetValue ();
    }
    return std::string();
}
예제 #19
0
void CModelNode::Load( const Core::CXMLNode& a_Node )
{
	CSceneNode::Load( a_Node );
	CXMLAttribute attribute = a_Node.GetAttribute( "Reference" );
	const Char* referencePath = attribute.GetValue( "UNKOWN" );	
	if ( strcmp( referencePath, "UNKOWN" ) == 0 )
	{
		CLog::GetInstance()->OutMessage( "Model node with no reference set in XML file\n", CLog::MESSAGETYPE_WARNING );
	}
}
예제 #20
0
void CHisReport::Register(int nInk)
{
    DWORD nValue;
    CString strValue;
    CXMLAttribute* pAttri;

    CXMLElement* pXML = FindToday( TRUE );

    pAttri = pXML->GetAttribute( "Total" );
    if ( ! pAttri ) pAttri = pXML->AddAttribute( "Total" );

    strValue = pAttri->GetValue();
    nValue = _ttol( strValue );
    strValue.Format( _T("%lu"), nValue + nInk );
    pAttri->SetValue( strValue );

    pAttri = m_pXML->GetAttribute( "Total" );
    if ( ! pAttri ) pAttri = m_pXML->AddAttribute( "Total" );

    strValue = pAttri->GetValue();
    nValue = _ttol( strValue );
    strValue.Format( _T("%lu"), nValue + nInk );
    pAttri->SetValue( strValue );
}
예제 #21
0
void CGroupingDlg::FormatUpdate(CXMLElement* pXML, CString& str)
{
	for ( POSITION pos = pXML->GetAttributeIterator() ; pos ; )
	{
		CXMLAttribute* pAttri = pXML->GetNextAttribute( pos );
		
		if ( ! str.IsEmpty() ) str += _T(", ");
		
		BOOL bNumber = IsNumField( pAttri->GetName() );
		
		str += pAttri->GetName(); str += '=';
		if ( ! bNumber ) str += '\'';
		str += pAttri->GetValue();
		if ( ! bNumber ) str += '\'';
	}
}
예제 #22
0
int CLuaXMLDefs::xmlNodeGetAttribute ( lua_State* luaVM )
{
    // pNode, Attribute Name, [Buffer Size]
    int iThirdVariableType = lua_type ( luaVM, 3 );
    if ( lua_type ( luaVM, 1 ) != LUA_TLIGHTUSERDATA ||
        !( iThirdVariableType == LUA_TNONE || iThirdVariableType == LUA_TNUMBER ) ||
        lua_type ( luaVM, 2 ) != LUA_TSTRING )
    {
        m_pScriptDebugging->LogBadType ( luaVM, "xmlNodeGetAttribute" );

        lua_pushboolean ( luaVM, false );
        return 1;
    }
    else
    {
        // Grab the XML node
        CXMLNode* pNode = lua_toxmlnode ( luaVM, 1 );
        if ( pNode )
        {
            // Find the attribute with that name
            const char * szAttributeName = lua_tostring ( luaVM, 2 );
            CXMLAttribute * pAttribute = pNode->GetAttributes().Find ( szAttributeName );
            if ( pAttribute )
            {
                // Limit reading to that many characters
                unsigned int iBufferSize = 255;
                if ( iThirdVariableType == LUA_TNUMBER )
                {
                    iBufferSize = static_cast < unsigned int > ( lua_tonumber ( luaVM, 3 ) );
                    if ( iBufferSize > 1024 )
                        iBufferSize = 255;
                }

                // Read the attribute and return the string
                lua_pushstring ( luaVM, pAttribute->GetValue ().c_str () );
                return 1;
            }
        }
    }

    lua_pushboolean ( luaVM, false );
    return 1;
}
예제 #23
0
bool CLocalServer::Load ( void )
{
    // Get server module root
    SString strServerPath = CalcMTASAPath( PathJoin ( "server", "mods", "deathmatch" ) );

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

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

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

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

    return true;
}
예제 #24
0
void CGroupingDlg::FormatMapping(CXMLElement* pXML, CString& str)
{
	static LPCTSTR pszNum[] = { _T("xgroupnum"), _T("xgrouprow") };
	static LPCTSTR pszExclude[] = { _T("xgroupname"), NULL };
	
	for ( POSITION pos = pXML->GetAttributeIterator() ; pos ; )
	{
		CXMLAttribute* pAttri = pXML->GetNextAttribute( pos );
		
		if ( IsNotField( pAttri->GetName() ) ) continue;
		
		if ( ! str.IsEmpty() ) str += _T(" and ");
		BOOL bNumber = IsNumField( pAttri->GetName() );
		
		str += pAttri->GetName(); str += '=';
		if ( ! bNumber ) str += '\'';
		str += pAttri->GetValue();
		if ( ! bNumber ) str += '\'';
	}
}
예제 #25
0
CRelatedSearch::CRelatedSearch(CMatchFile* pFile)
{
	if ( pFile != NULL )
	{
		m_bSHA1		= pFile->m_bSHA1;
		m_pSHA1		= pFile->m_pSHA1;
		m_bTiger	= pFile->m_bTiger;
		m_pTiger	= pFile->m_pTiger;
		m_bED2K		= pFile->m_bED2K;
		m_pED2K		= pFile->m_pED2K;
		m_sName		= pFile->m_pBest->m_sName;

		m_pSchema	= SchemaCache.Get( pFile->m_pBest->m_sSchemaURI );
		m_pXML		= NULL;
		m_bXML		= FALSE;

		if ( m_pSchema != NULL )
		{
			m_pXML = new CXMLElement( NULL, m_pSchema->m_sSingular );
			m_bXML = TRUE;

			for ( CQueryHit* pHit = pFile->m_pHits ; pHit ; pHit = pHit->m_pNext )
			{
				if ( pHit->m_pXML != NULL )
				{
					for ( POSITION pos = pHit->m_pXML->GetAttributeIterator() ; pos ; )
					{
						CXMLAttribute* pAttribute = pHit->m_pXML->GetNextAttribute( pos );
						m_pXML->AddAttribute( pAttribute->GetName(), pAttribute->GetValue() );
					}
				}
			}
		}
	}
	else
	{
		m_bSHA1 = m_bTiger = m_bED2K = m_bXML = FALSE;
		m_pSchema = NULL;
		m_pXML = NULL;
	}
}
예제 #26
0
파일: main.cpp 프로젝트: astromaker/sandbox
void	DumpXMLElement( const CXMLElement * pElement )
{
	if( pElement != NULL )
	{
		::wprintf( L"Element Name: %s\n", pElement->GetName() );
		::wprintf( L"Text: %s\n", pElement->GetText() );

		CXMLElement::ATTR_CONST_ITER pos = pElement->GetAttrBegin();
		CXMLElement::ATTR_CONST_ITER end = pElement->GetAttrEnd();

		for( ; pos != end; ++pos )
		{
			CXMLAttribute * pAttr = *pos;
			if( pAttr != NULL )
			{
				::wprintf( L"<%s = %s>\n", pAttr->GetName(), pAttr->GetValue() );
			}
		}

		::wprintf( L"\n" );
	}
}
예제 #27
0
BOOL CRulerSettingsPage::LoadXML()
{
	CString strValue;
	CXMLElement* pXML = NULL;
	CXMLAttribute* pAttri = NULL;
	
	if ( pXML = m_pXML->GetElementByName( _T("BlackList") ) )
	{
		for ( POSITION pos = pXML->GetElementIterator() ; pos ; )
		{
			CXMLElement* pMap = pXML->GetNextElement( pos );
			if ( ! pMap->IsNamed( _T("Map") ) ) continue;

			if ( pAttri = pMap->GetAttribute( _T("ID") ) )
			{
				strValue = pAttri->GetValue();
				m_wndExtList.AddString( strValue );
			}
		}
	}

	return TRUE;
}
예제 #28
0
void CCameraSceneNode::Load( const CXMLNode& a_XMLNode )
{
	LoadCommonValues( a_XMLNode );
	LoadChildren( a_XMLNode );

	// Do own stuff
	m_Camera = new CCamera();

	float FOV, screenHeight, screenWidth, aspectRatio, nearPlaneDist, farPlaneDist;

	CXMLAttribute attribute = a_XMLNode.GetAttribute( "Active" );
	m_Active = (bool)atoi( attribute.GetValue( "0" ) );
	attribute = a_XMLNode.GetAttribute( "FOV" );
	FOV = (float)atof( attribute.GetValue( "60" ) );
	attribute = a_XMLNode.GetAttribute( "ScrHeight" );
	screenHeight = (float)atof( attribute.GetValue( "3" ) );
	attribute = a_XMLNode.GetAttribute( "ScrWidth" );
	screenWidth = (float)atof( attribute.GetValue( "4" ) );
	attribute = a_XMLNode.GetAttribute( "Near" );
	nearPlaneDist = (float)atof( attribute.GetValue( "0.1" ) );
	attribute = a_XMLNode.GetAttribute( "Far" );
	farPlaneDist = (float)atof( attribute.GetValue( "100.0" ) );

	aspectRatio = screenWidth / screenHeight;

	printf( "Loaded camera %s, FOV %.1f, Aspect %.4f, Near %.5f, Far %.3f, Active %i\n", m_Name.c_str(), FOV, aspectRatio, nearPlaneDist, farPlaneDist, m_Active );

	glm::mat4 perspectiveMatrix = glm::perspective( FOV, aspectRatio, nearPlaneDist, farPlaneDist );
	perspectiveMatrix[1].y *= -1.0f;
	m_Camera->SetProjectionMatrix( perspectiveMatrix );
	m_Camera->SetTransformationMatrix( m_WorldMatrix );
	m_Camera->SetPosition( m_Position );
	m_Camera->SetRotation( m_Rotation );
	m_Camera->SetFarPlaneDistance( farPlaneDist );
	m_Camera->SetNearPlaneDistance( nearPlaneDist );
}
bool CAccessControlListManager::Load ( void )
{
    // Eventually destroy the previously loaded xml
    if ( m_pXML )
    {
        delete m_pXML;
    }

    // Load the XML
    m_pXML = g_pServerInterface->GetXML ()->CreateXML ( GetFileName ().c_str () );
    if ( !m_pXML )
    {
        CLogger::ErrorPrintf ( "Error loading Access Control List file\n" );
        return false;
    }

    // Parse it
    if ( !m_pXML->Parse () )
    {
        CLogger::ErrorPrintf ( "Error parsing Access Control List file\n" );
        return false;
    }

    // Grab the XML root node
    m_pRootNode = m_pXML->GetRootNode ();
    if ( !m_pRootNode )
    {
        CLogger::ErrorPrintf ( "Missing root node ('ACL')\n" );
        return false;
    }

    // Clear previous ACL stuff
    ClearACLs ();
    ClearGroups ();

    // load the acl's
    CXMLNode* pSubNode = NULL;
    unsigned int uiSubNodesCount = m_pRootNode->GetSubNodeCount ();
    for ( unsigned int i = 0 ; i < uiSubNodesCount ; i++ )
    {
        pSubNode = m_pRootNode->GetSubNode ( i );
        if ( !pSubNode ) continue;

        if ( pSubNode->GetTagName ().compare ( "acl" ) == 0 )
        {
            CXMLAttribute* pAttribute = pSubNode->GetAttributes ().Find ( "name" );
            if ( pAttribute )
            {
                CAccessControlList* pACL = AddACL ( pAttribute->GetValue ().c_str () );

                CXMLNode* pSubSubNode = NULL;
                unsigned int uiSubSubNodesCount = pSubNode->GetSubNodeCount ();
                for ( unsigned int j = 0 ; j < uiSubSubNodesCount ; j++ )
                {
                    // If this subnode doesn't exist, return to the for loop and continue it
                    pSubSubNode = pSubNode->GetSubNode ( j );
                    if ( !pSubSubNode ) continue;

                    // Check that this subsub node is named "right"
                    if ( pSubSubNode->GetTagName ().compare ( "right" ) == 0 )
                    {
                        // Grab the name and the access attributes
                        CXMLAttribute* pNameAttribute = pSubSubNode->GetAttributes ().Find ( "name" );
                        CXMLAttribute* pAccessAttribute = pSubSubNode->GetAttributes ().Find ( "access" );
                        if ( pNameAttribute && pAccessAttribute )
                        {
                            // See if the access attribute is true or false
                            bool bAccess = false;
                            std::string strAccess = pAccessAttribute->GetValue ();

                            if ( stricmp ( strAccess.c_str (), "true" ) == 0 ||
                                 stricmp ( strAccess.c_str (), "yes" ) == 0 ||
                                 strcmp ( strAccess.c_str (), "1" ) == 0 )
                            {
                                bAccess = true;
                            }

                            // Grab the name of the 'right' name
                            const char *szRightName = pNameAttribute->GetValue ().c_str ();

                            // Create the rights control list
                            CAccessControlListRight* pRight = NULL;
                            if ( StringBeginsWith ( szRightName, "command." ) )
                            {
                                pRight = pACL->AddRight ( &szRightName[8], CAccessControlListRight::RIGHT_TYPE_COMMAND, bAccess );
                            }
                            else if ( StringBeginsWith ( szRightName, "function." ) )
                            {
                                pRight = pACL->AddRight ( &szRightName[9], CAccessControlListRight::RIGHT_TYPE_FUNCTION, bAccess );
                            }
                            else if ( StringBeginsWith ( szRightName, "resource." ) )
                            {
                                pRight = pACL->AddRight ( &szRightName[9], CAccessControlListRight::RIGHT_TYPE_RESOURCE, bAccess );
                            }
                            else if ( StringBeginsWith ( szRightName, "general." ) )
                            {
                                pRight = pACL->AddRight ( &szRightName[8], CAccessControlListRight::RIGHT_TYPE_GENERAL, bAccess );
                            }
                            else continue;

                            // Set all the extra attributes
                            for ( uint i = 0 ; i < pSubSubNode->GetAttributes ().Count () ; i++ )
                            {
                                CXMLAttribute* pAttribute = pSubSubNode->GetAttributes ().Get ( i );
                                pRight->SetAttributeValue ( pAttribute->GetName (), pAttribute->GetValue () );
                            }
                        }
                    }
                }
            }
        }
    }

    // Load the groups
    pSubNode = NULL;
    uiSubNodesCount = m_pRootNode->GetSubNodeCount ();
    for ( unsigned int i = 0 ; i < uiSubNodesCount ; i++ )
    {
        pSubNode = m_pRootNode->GetSubNode ( i );
        if ( !pSubNode ) continue;

        if ( pSubNode->GetTagName ().compare ( "group" ) == 0 )
        {
            CXMLAttribute* pAttribute = pSubNode->GetAttributes ().Find ( "name" );
            if ( pAttribute )
            {
                CAccessControlListGroup* pGroup = AddGroup ( pAttribute->GetValue ().c_str () );

                CXMLNode* pSubSubNode = NULL;
                unsigned int uiSubSubNodesCount = pSubNode->GetSubNodeCount ();
                for ( unsigned int j = 0 ; j < uiSubSubNodesCount ; j++ )
                {
                    pSubSubNode = pSubNode->GetSubNode ( j );
                    if ( !pSubSubNode ) continue;

                    if ( pSubSubNode->GetTagName ().compare ( "object" ) == 0 )
                    {
                        CXMLAttribute* pSubAttribute = pSubSubNode->GetAttributes ().Find ( "name" );
                        if ( pSubAttribute )
                        {
                            const char *szAccountName = pSubAttribute->GetValue ().c_str ();

                            if ( StringBeginsWith ( szAccountName, "user." ) )
                            {
                                pGroup->AddObject ( &szAccountName[5], CAccessControlListGroupObject::OBJECT_TYPE_USER );
                            }
                            else if ( StringBeginsWith ( szAccountName, "resource." ) )
                            {
                                pGroup->AddObject ( &szAccountName[9], CAccessControlListGroupObject::OBJECT_TYPE_RESOURCE );
                            }
                        }
                    }
                    else if ( pSubSubNode->GetTagName ().compare ( "acl" ) == 0 )
                    {
                        CXMLAttribute* pSubAttribute = pSubSubNode->GetAttributes ().Find ( "name" );
                        if ( pSubAttribute )
                        {
                            CAccessControlList* pACL = GetACL ( pSubAttribute->GetValue ().c_str () );
                            if ( pACL )
                            {
                                pGroup->AddACL ( pACL );
                            }
                        }
                    }
                }
            }
        }
    }

    m_bNeedsSave = false;
    return true;
}
예제 #30
0
int CLuaFunctionDefs::Get ( lua_State* luaVM )
{
    CResource* pResource = m_pLuaManager->GetVirtualMachine ( luaVM )->GetResource ();
    SString strSetting;
    CLuaArguments Args;

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

    if ( !argStream.HasErrors () )
    {
        unsigned int uiIndex = 0;
        bool bDeleteNode;

        // Extract attribute name if setting to be gotten has three parts i.e. resname.settingname.attributename
        SString strAttribute = "value";
        vector < SString > Result;
        strSetting.Split ( ".", Result );
        if ( Result.size () == 3 && Result[2].length () )
        {
            strAttribute = Result[2];
        }

        // Get the setting
        CXMLNode *pSubNode, *pNode = g_pGame->GetSettings ()->Get ( pResource->GetName ().c_str (), strSetting.c_str (), bDeleteNode );

        // Only proceed if we have a valid node
        if ( pNode ) {
            // Argument count
            unsigned int uiArgCount = 1;

            // See if we need to return a table with single or multiple entries
            if ( pNode->GetSubNodeCount () == 0 ) {
                // See if required attribute exists
                CXMLAttribute *pAttribute = pNode->GetAttributes ().Find ( strAttribute.c_str () );
                if ( !pAttribute )
                {
                    if ( bDeleteNode )
                        delete pNode;
                    lua_pushboolean ( luaVM, false );
                    return 1;
                }
                // We only have a single entry for a specific setting, so output a string
                const std::string& strDataValue = pAttribute->GetValue ();
                if ( !Args.ReadFromJSONString ( strDataValue.c_str () ) ) {
                    // No valid JSON? Parse as plain text
                    Args.PushString ( strDataValue );
                }

                Args.PushArguments ( luaVM );
                uiArgCount = Args.Count ();

                /* Don't output a table because although it is more consistent with the multiple values output below,
                ** due to lua's implementation of associative arrays (assuming we use the "setting-name", "value" key-value pairs)
                ** it would require the scripter to walk through an array that only has a single entry which is a Bad Thing, performance wise.
                **
                PUSH_SETTING ( pNode );
                Args.PushAsTable ( luaVM );
                **/
            }
            else {
                // We need to return multiply entries, so push all subnodes
                while ( ( pSubNode = pNode->FindSubNode ( "setting", uiIndex++ ) ) )
                {
                    CXMLAttributes& attributes = pSubNode->GetAttributes ();
                    Args.PushString ( attributes.Find ( "name" )->GetValue () );
                    const std::string& strDataValue = attributes.Find ( "value" )->GetValue ();
                    if ( !Args.ReadFromJSONString ( strDataValue.c_str () ) )
                    {
                        Args.PushString ( strDataValue );
                    }
                }
                // Push a table and return
                Args.PushAsTable ( luaVM );
            }

            // Check if we have to delete the node
            if ( bDeleteNode )
                delete pNode;

            return uiArgCount;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}