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 ); } }
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; }
int CLuaFunctionDefs::XMLCreateChild ( lua_State* luaVM ) { // Node name CXMLNode* pNode = NULL; SString strChild = ""; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pNode ); argStream.ReadString ( strChild ); if ( !argStream.HasErrors ( ) ) { if ( pNode ) { CXMLNode* pXMLSubNode = pNode->CreateSubNode ( strChild ); if ( pXMLSubNode ) { lua_pushxmlnode ( luaVM, pXMLSubNode ); return 1; } } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
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()); }
/////////////////////////////////////////////////////////////// // // 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; }
void CWebCore::WriteCustomList ( const SString& strListName, const std::vector<SString>& customList, bool bReset ) { if ( !m_pXmlConfig || !MakeSureXMLNodesExist () ) return; CXMLNode* pRootNode = m_pXmlConfig->GetRootNode (); if ( !pRootNode ) return; CXMLNode* pCustomListNode = pRootNode->FindSubNode ( strListName ); if ( !pCustomListNode ) return; pCustomListNode->DeleteAllSubNodes(); for ( std::vector<SString>::const_iterator iter = customList.begin (); iter != customList.end (); ++iter ) { CXMLNode* pNode = pCustomListNode->CreateSubNode ( "url" ); if ( pNode ) pNode->SetTagContent ( *iter ); } // Write custom blacklist and reload from XML m_pXmlConfig->Write (); if ( bReset ) ResetFilter ( false ); }
_MEMBER_FUNCTION_IMPL(xml, createNode) { // Get the XML instance pointer CXML * pXML = sq_getinstance< CXML* >( pVM ); // Is the xml instance valid? if( pXML ) { // Get the XML node pointer CXMLNode * pNode = sq_getpointer< CXMLNode* >( pVM, 2 ); // Is the node valid? if( pNode ) { // Get the node name const char * szName; sq_getstring( pVM, 3, &szName ); // Create the node CXMLNode * pNewNode = pNode->CreateSubNode( szName ); // Did the new node create? if( pNewNode ) { // Push the new node instance sq_pushpointer< CXMLNode* >( pVM, pNewNode ); return 1; } } } sq_pushbool( pVM, false ); return 1; }
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; }
void CLocalServer::StoreConfigValue ( const char* szNode, const char* szValue ) { CXMLNode* pRoot = m_pConfig->GetRootNode(); CXMLNode* pNode = pRoot->FindSubNode ( szNode, 0 ); if ( pNode ) { pNode->SetTagContent ( szValue ); } else { pNode = pRoot->CreateSubNode ( szNode ); pNode->SetTagContent ( szValue ); } }
bool CWebCore::StaticFetchBlacklistProgress ( double dDownloadNow, double dDownloadTotal, char* pCompletedData, size_t completedLength, void *pObj, bool bComplete, int iError ) { if ( !bComplete ) return false; CWebCore* pWebCore = static_cast < CWebCore* > ( pObj ); if ( !pWebCore->m_pXmlConfig ) return false; if ( !pWebCore->MakeSureXMLNodesExist () ) return false; CXMLNode* pRootNode = pWebCore->m_pXmlConfig->GetRootNode (); std::vector<SString> blacklist; SString strData = pCompletedData; strData.Split ( ";", blacklist ); CXMLNode* pListNode = pRootNode->FindSubNode ( "globalblacklist" ); if ( !pListNode ) return false; pListNode->DeleteAllSubNodes (); for ( std::vector<SString>::const_iterator iter = blacklist.begin (); iter != blacklist.end (); ++iter ) { CXMLNode* pNode = pListNode->CreateSubNode ( "url" ); pNode->SetTagContent ( *iter ); } // Set blacklist revision CXMLNode* pNode = pRootNode->FindSubNode ( "blacklistrev" ); if ( !pNode ) return false; pNode->SetTagContent ( pWebCore->m_iBlacklistRevision ); // Write changes to the XML file pWebCore->m_pXmlConfig->Write (); pWebCore->LoadListsFromXML ( false, true, false ); #ifdef MTA_DEBUG OutputDebugLine ( "Updated browser blacklist!" ); #endif return true; }
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; } }
void CWebCore::StaticFetchWhitelistFinished ( char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode ) { if ( !bSuccess ) return; CWebCore* pWebCore = static_cast < CWebCore* > ( pObj ); if ( !pWebCore->m_pXmlConfig ) return; if ( !pWebCore->MakeSureXMLNodesExist () ) return; CXMLNode* pRootNode = pWebCore->m_pXmlConfig->GetRootNode (); std::vector<SString> whitelist; SString strData = pCompletedData; strData.Split ( ";", whitelist ); CXMLNode* pListNode = pRootNode->FindSubNode ( "globalwhitelist" ); if ( !pListNode ) return; pListNode->DeleteAllSubNodes (); for ( std::vector<SString>::const_iterator iter = whitelist.begin (); iter != whitelist.end (); ++iter ) { CXMLNode* pNode = pListNode->CreateSubNode ( "url" ); pNode->SetTagContent ( *iter ); } // Set whitelist revision CXMLNode* pNode = pRootNode->FindSubNode ( "whitelistrev" ); if ( !pNode ) return; pNode->SetTagContent ( pWebCore->m_iWhitelistRevision ); // Write changes to the XML file pWebCore->m_pXmlConfig->Write (); pWebCore->LoadListsFromXML ( true, false, false ); #ifdef MTA_DEBUG OutputDebugLine ( "Updated whitelist!" ); #endif }
bool CClientVariables::Load ( void ) { // Get the root node CXMLNode *pRoot = CCore::GetSingleton ().GetConfig (); if ( !pRoot ) return false; m_iRevision++; // Load the cvars m_pStorage = pRoot->FindSubNode ( CONFIG_NODE_CVARS ); if ( !m_pStorage ) { // Non-existant, create a new node m_pStorage = pRoot->CreateSubNode ( CONFIG_NODE_CVARS ); } // Verify that at least all the defaults are in LoadDefaults (); return true; }
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; }
/////////////////////////////////////////////////////////////// // // CJoystickManager::SaveToXML // // Save axes mapping for the current joypad. // /////////////////////////////////////////////////////////////// bool CJoystickManager::SaveToXML ( void ) { if ( !IsJoypadValid () ) return false; m_SettingsRevision++; CXMLNode* pMainNode = GetConfigNode ( true ); // Add the current settings if ( pMainNode ) { // Clear our current bind nodes pMainNode->DeleteAllSubNodes (); { // Create a new 'info' node CXMLNode* pNode = pMainNode->CreateSubNode ( "info" ); // If it was created if ( pNode ) { CXMLAttributes* pAttributes = &pNode->GetAttributes (); CXMLAttribute* pA = NULL; pA = pAttributes->Create ( "deadzone" ); pA->SetValue ( m_DevInfo.iDeadZone ); pA = pAttributes->Create ( "saturation" ); pA->SetValue ( m_DevInfo.iSaturation ); pA = pAttributes->Create ( "product_name" ); pA->SetValue ( m_DevInfo.strProductName.c_str () ); } } // Iterate the binds adding them to the XML tree for ( int i = 0 ; i < NUMELMS(m_currentMapping) ; i++ ) { const SMappingLine& line = m_currentMapping[i]; // Create the new 'axis' node CXMLNode* pNode = pMainNode->CreateSubNode ( "axis" ); // If it was created if ( pNode ) { CXMLAttributes* pAttributes = &pNode->GetAttributes (); CXMLAttribute* pA = NULL; pA = pAttributes->Create ( "source_index" ); pA->SetValue ( line.SourceAxisIndex ); pA = pAttributes->Create ( "source_dir" ); pA->SetValue ( line.SourceAxisDir ); pA = pAttributes->Create ( "output_index" ); pA->SetValue ( line.OutputAxisIndex ); pA = pAttributes->Create ( "output_dir" ); pA->SetValue ( line.OutputAxisDir ); pA = pAttributes->Create ( "enabled" ); pA->SetValue ( line.bEnabled ); pA = pAttributes->Create ( "max_value" ); pA->SetValue ( line.MaxValue ); } } return true; } return false; }
bool CWebCore::MakeSureXMLNodesExist () { // Check xml file if ( !m_pXmlConfig ) { SString browserDataPath = CalcMTASAPath ( MTA_BROWSERDATA_PATH ); bool exists = FileExists ( browserDataPath ); m_pXmlConfig = g_pCore->GetXML ()->CreateXML ( browserDataPath ); if ( !m_pXmlConfig || ( exists && !m_pXmlConfig->Parse () ) ) return false; } CXMLNode* pRootNode = m_pXmlConfig->GetRootNode (); if ( !pRootNode ) { pRootNode = m_pXmlConfig->CreateRootNode ( "browserdata" ); if ( !pRootNode ) return false; } if ( !pRootNode->FindSubNode ( "lastupdate" ) ) { CXMLNode* pNode = pRootNode->CreateSubNode ( "lastupdate" ); if ( !pNode ) return false; pNode->SetTagContent ( 0 ); } if ( !pRootNode->FindSubNode ( "whitelistrev" ) ) { if ( !pRootNode->CreateSubNode ( "whitelistrev" ) ) return false; } if ( !pRootNode->FindSubNode ( "blacklistrev" ) ) { if ( !pRootNode->CreateSubNode ( "blacklistrev" ) ) return false; } if ( !pRootNode->FindSubNode ( "globalwhitelist" ) ) { if ( !pRootNode->CreateSubNode ( "globalwhitelist" ) ) return false; } if ( !pRootNode->FindSubNode ( "globalblacklist" ) ) { if ( !pRootNode->CreateSubNode ( "globalblacklist" ) ) return false; } if ( !pRootNode->FindSubNode ( "customblacklist" ) ) { if ( !pRootNode->CreateSubNode ( "customblacklist" ) ) return false; } if ( !pRootNode->FindSubNode ( "customwhitelist" ) ) { if ( !pRootNode->CreateSubNode ( "customwhitelist" ) ) return false; } return true; }
/////////////////////////////////////////////////////////////// // // CJoystickManager::GetConfigNode // // Get the main node for load/saving data for the current joypad. // /////////////////////////////////////////////////////////////// CXMLNode* CJoystickManager::GetConfigNode ( bool bCreateIfRequired ) { // Get the root node CXMLNode *pRoot = CCore::GetSingleton ().GetConfig (); if ( !pRoot ) return NULL; // Get the top joypad config node CXMLNode* pSectionNode = pRoot->FindSubNode ( CONFIG_NODE_JOYPAD ); if ( !pSectionNode ) { if ( !bCreateIfRequired ) return NULL; // Non-existant, create a new node pSectionNode = pRoot->CreateSubNode ( CONFIG_NODE_JOYPAD ); } // Get the node for this joystick's GUID CXMLNode* pItemNode = NULL; // Find existing node for( int i=0; true; i++ ) { CXMLNode* pNode = pSectionNode->FindSubNode ( "product", i ); if ( !pNode ) break; CXMLAttributes* pAttributes = &pNode->GetAttributes (); if ( CXMLAttribute* pA = pAttributes->Find ( "guid" ) ) { string value = pA->GetValue (); if ( value == m_DevInfo.strGuid ) { pItemNode = pNode; break; } } } if ( !pItemNode ) { if ( !bCreateIfRequired ) return NULL; // Non-existant, create a new node pItemNode = pSectionNode->CreateSubNode ( "product" ); if ( pItemNode ) { CXMLAttributes* pAttributes = &pItemNode->GetAttributes (); CXMLAttribute* pA = NULL; pA = pAttributes->Create ( "guid" ); pA->SetValue ( m_DevInfo.strGuid.c_str () ); } } return pItemNode; }