本文整理汇总了C++中CXMLNode::GetAttributes方法的典型用法代码示例。如果您正苦于以下问题:C++ CXMLNode::GetAttributes方法的具体用法?C++ CXMLNode::GetAttributes怎么用?C++ CXMLNode::GetAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CXMLNode
的用法示例。
在下文中一共展示了CXMLNode::GetAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Save
bool CLocalServer::Save ( void )
{
if ( m_pConfig && m_pConfig->GetRootNode() )
{
StoreConfigValue ( "servername", ( m_pEditName->GetText().length() > 0 ) ? m_pEditName->GetText().c_str() : "MTA Local Server" );
StoreConfigValue ( "maxplayers", ( atoi ( m_pEditPlayers->GetText().c_str() ) ) ? m_pEditPlayers->GetText().c_str() : "32" );
StoreConfigValue ( "donotbroadcastlan", ( m_pBroadcastLan->IsActive () ) ? "0" : "1" );
StoreConfigValue ( "ase", ( m_pBroadcastInternet->IsActive () ) ? "1" : "0" );
StoreConfigValue ( "password", m_pEditPass->GetText().c_str() );
// Remove old resources from the config
CXMLNode* pRoot = m_pConfig->GetRootNode();
list < CXMLNode* > ::const_iterator iter = pRoot->ChildrenBegin ();
for ( ; iter != pRoot->ChildrenEnd (); iter++ )
{
CXMLNode* pNode = reinterpret_cast < CXMLNode* > ( *iter );
if ( pNode->GetTagName().compare ( "resource" ) == 0 )
{
pRoot->DeleteSubNode ( pNode );
iter = pRoot->ChildrenBegin ();
}
}
// Add new resources to the config
for ( int i = 0; i < m_pResourcesCur->GetRowCount(); i++ )
{
CXMLNode* pResourceNode = pRoot->CreateSubNode ( "resource" );
pResourceNode->GetAttributes().Create ( "src" )->SetValue ( m_pResourcesCur->GetItemText ( i, 1 ) );
pResourceNode->GetAttributes().Create ( "startup" )->SetValue ( "1" );
pResourceNode->GetAttributes().Create ( "protected" )->SetValue ( "0" );
}
m_pConfig->Write ();
}
return true;
}
示例2: SaveServerList
bool CServerBrowser::SaveServerList ( CXMLNode* pNode, std::string strTagName, CServerList *pList )
{
if ( !pNode )
return false;
// Start by clearing out all previous nodes
pNode->DeleteAllSubNodes ();
// Iterate through the list, adding any items to our node
CServerListIterator i, i_b = pList->IteratorBegin (), i_e = pList->IteratorEnd ();
int j = 0;
int k = pList->GetServerCount ();
if ( k > 0 )
{
for ( CServerListIterator i = i_b; i != i_e; i++ )
{
CServerListItem * pServer = *i;
// Add the item to the node
CXMLNode * pSubNode = pNode->CreateSubNode ( strTagName.c_str () );
if ( pSubNode )
{
CXMLAttribute* pHostAttribute = pSubNode->GetAttributes ().Create ( "host" );
pHostAttribute->SetValue ( pServer->strHost.c_str () );
CXMLAttribute* pPortAttribute = pSubNode->GetAttributes ().Create ( "port" );
pPortAttribute->SetValue ( pServer->usGamePort );
}
j++;
}
}
return true;
}
示例3: XMLNodeGetAttributes
int CLuaFunctionDefs::XMLNodeGetAttributes ( lua_State* luaVM )
{
// pNode, Attribute Name, [Buffer Size]
CXMLNode* pNode = NULL;
CScriptArgReader argStream ( luaVM );
argStream.ReadUserData ( pNode );
if ( !argStream.HasErrors ( ) )
{
if ( pNode )
{
lua_newtable ( luaVM );
unsigned int uiIndex = 0;
list < CXMLAttribute * > ::iterator iter = pNode->GetAttributes ().ListBegin ();
for ( ; iter != pNode->GetAttributes ().ListEnd () ; iter++ )
{
lua_pushstring ( luaVM, ( *iter )->GetName ().c_str () );
lua_pushstring ( luaVM, ( *iter )->GetValue ().c_str () );
lua_settable ( luaVM, -3 );
}
return 1;
}
else
m_pScriptDebugging->LogBadType ( luaVM );
}
else
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );
lua_pushboolean ( luaVM, false );
return 1;
}
示例4: SetServerPassword
void CServerBrowser::SetServerPassword ( std::string strHost, std::string strPassword )
{
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" );
pPassword->SetValue(strPassword.c_str());
return;
}
}
}
}
// Otherwise create the node from scratch
CXMLNode* pNode = pServerPasswords->CreateSubNode( "server" );
CXMLAttribute* pHostAttribute = pNode->GetAttributes().Create ( "host" );
pHostAttribute->SetValue(strHost.c_str());
CXMLAttribute* pPasswordAttribute = pNode->GetAttributes().Create ( "password" );
pPasswordAttribute->SetValue(strPassword.c_str());
}
示例5: xmlNodeGetAttributes
int CLuaXMLDefs::xmlNodeGetAttributes ( lua_State* luaVM )
{
CXMLNode* pNode;
CScriptArgReader argStream ( luaVM );
argStream.ReadUserData ( pNode );
if ( !argStream.HasErrors () )
{
lua_newtable ( luaVM );
list < class CXMLAttribute * > ::iterator iter = pNode->GetAttributes().ListBegin();
for ( ; iter != pNode->GetAttributes().ListEnd() ; ++iter )
{
lua_pushstring ( luaVM, ( *iter )->GetName().c_str () );
lua_pushstring ( luaVM, ( *iter )->GetValue().c_str () );
lua_settable ( luaVM, -3 );
}
return 1;
}
else
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );
lua_pushboolean ( luaVM, false );
return 1;
}
示例6: WriteToXMLNode
void CAccessControlListGroup::WriteToXMLNode ( CXMLNode* pNode )
{
assert ( pNode );
// Create the subnode for this
CXMLNode* pSubNode = pNode->CreateSubNode ( "group" );
assert ( pSubNode );
// Create attribute for the name and set it
CXMLAttribute* pAttribute = pSubNode->GetAttributes ().Create ( "name" );
pAttribute->SetValue ( m_strGroupName );
// Write the ACL's this group use
ACLsList::iterator iterACL = m_ACLs.begin ();
for ( ; iterACL != m_ACLs.end (); iterACL++ )
{
CAccessControlList* pACL = *iterACL;
// Create the subnode for this object and write the name attribute we generated
CXMLNode* pObjectNode = pSubNode->CreateSubNode ( "acl" );
pAttribute = pObjectNode->GetAttributes ().Create ( "name" );
pAttribute->SetValue ( pACL->GetName () );
}
// Write every object
ObjectList::iterator iter = m_Objects.begin ();
for ( ; iter != m_Objects.end (); iter++ )
{
CAccessControlListGroupObject* pObject = *iter;
// Find out the object type string
char szObjectType [255];
switch ( pObject->GetObjectType () )
{
case CAccessControlListGroupObject::OBJECT_TYPE_RESOURCE:
strcpy ( szObjectType, "resource" );
break;
case CAccessControlListGroupObject::OBJECT_TYPE_USER:
strcpy ( szObjectType, "user" );
break;
default:
strcpy ( szObjectType, "error" );
break;
}
// Append a dot append the name of the node
strcat ( szObjectType, "." );
strncat ( szObjectType, pObject->GetObjectName (), NUMELMS( szObjectType ) - 1 );
// Create the subnode for this object and write the name attribute we generated
CXMLNode* pObjectNode = pSubNode->CreateSubNode ( "object" );
pAttribute = pObjectNode->GetAttributes ().Create ( "name" );
pAttribute->SetValue ( szObjectType );
}
}
示例7: XMLNodeSetAttribute
int CLuaFunctionDefs::XMLNodeSetAttribute ( lua_State* luaVM )
{
// pNode, Attribute Name, Value
CXMLNode* pNode = NULL;
SString strAttributeName = "";
SString strAttributeValue = "";
CScriptArgReader argStream ( luaVM );
argStream.ReadUserData ( pNode );
argStream.ReadString ( strAttributeName );
argStream.ReadString ( strAttributeValue, "" );
if ( !argStream.HasErrors ( ) )
{
if ( pNode )
{
// Are we going to set it to a value?
if ( argStream.NextCouldBeString( -1 ) )
{
// Write the node
CXMLAttribute* pAttribute = pNode->GetAttributes ().Create ( strAttributeName );
if ( pAttribute )
{
pAttribute->SetValue ( strAttributeValue );
lua_pushboolean ( luaVM, true );
return 1;
}
}
else
{
// Delete the attribute if it exists
CXMLAttribute* pAttribute = pNode->GetAttributes ().Find ( strAttributeName );
if ( pAttribute )
{
delete pAttribute;
lua_pushboolean ( luaVM, true );
return 1;
}
}
}
}
else
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );
lua_pushboolean ( luaVM, false );
return 1;
}
示例8: LoadServerList
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;
}
示例9: GetSettingTable
//////////////////////////////////////////////////////////////////////
//
// 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: StaticSaveServerIdMap
///////////////////////////////////////////////////////////////
//
// 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;
}
示例11: xmlNodeGetAttribute
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;
}
示例12: LoadServerIdMap
///////////////////////////////////////////////////////////////
//
// 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;
}
示例13:
// Creates a new setting and adds it to the destination node
CXMLNode *CSettings::CreateSetting(CXMLNode *pDst, const char *szName, const char *szContent)
{
// Create the node
CXMLNode * pNode = pDst->CreateSubNode("setting");
CXMLAttributes *pAttributes = &(pNode->GetAttributes());
// Add the attributes with the corresponding values
pAttributes->Create("name")->SetValue(szName);
pAttributes->Create("value")->SetValue(szContent);
return pNode;
}
示例14: CheckMetaSourceForIssues
///////////////////////////////////////////////////////////////
//
// CResourceChecker::CheckMetaSourceForIssues
//
//
//
///////////////////////////////////////////////////////////////
void CResourceChecker::CheckMetaSourceForIssues ( CXMLNode* pRootNode, const string& strFileName, const string& strResourceName, ECheckerModeType checkerMode, bool* pbOutHasChanged )
{
// Check min_mta_version is correct
if ( m_strReqClientVersion > m_strMinClientReqFromMetaXml || m_strReqServerVersion > m_strMinServerReqFromMetaXml )
{
// It's not right. What to do?
if ( checkerMode == ECheckerMode::WARNINGS )
{
SString strTemp = "<min_mta_version> section in the meta.xml is incorrect or missing (expected at least ";
if ( m_strReqClientVersion > m_strMinClientReqFromMetaXml )
strTemp += SString ( "client %s because of '%s')", *m_strReqClientVersion, *m_strReqClientReason );
else
if ( m_strReqServerVersion > m_strMinServerReqFromMetaXml )
strTemp += SString ( "server %s because of '%s')", *m_strReqServerVersion, *m_strReqServerReason );
CLogger::LogPrint ( SString ( "WARNING: %s %s\n", strResourceName.c_str (), *strTemp ) );
}
else
if ( checkerMode == ECheckerMode::UPGRADE )
{
// Create min_mta_version node if required
CXMLNode* pNodeMinMtaVersion = pRootNode->FindSubNode("min_mta_version", 0);
if ( !pNodeMinMtaVersion )
pNodeMinMtaVersion = pRootNode->CreateSubNode ( "min_mta_version" );
CXMLAttributes& attributes = pNodeMinMtaVersion->GetAttributes ();
attributes.Delete ( "server" );
attributes.Delete ( "client" );
attributes.Delete ( "both" );
if ( !m_strReqServerVersion.empty () )
{
CXMLAttribute* pAttr = attributes.Create ( "server" );
pAttr->SetValue ( m_strReqServerVersion );
}
if ( !m_strReqClientVersion.empty () )
{
CXMLAttribute* pAttr = attributes.Create ( "client" );
pAttr->SetValue ( m_strReqClientVersion );
}
if ( pbOutHasChanged )
*pbOutHasChanged = true;
}
}
}
示例15: Load
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;
}