From c29110a74f8efe025463de0d3eb2904dfc804815 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Thu, 3 Oct 2024 13:48:12 +0100 Subject: [PATCH] Load rules from mtaserver.conf --- Server/mods/deathmatch/logic/CGame.cpp | 12 ++++++-- Server/mods/deathmatch/logic/CMainConfig.cpp | 29 ++++++++++++++++++-- Server/mods/deathmatch/logic/CMainConfig.h | 2 ++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/Server/mods/deathmatch/logic/CGame.cpp b/Server/mods/deathmatch/logic/CGame.cpp index 58989394ec..e035cfeeb4 100644 --- a/Server/mods/deathmatch/logic/CGame.cpp +++ b/Server/mods/deathmatch/logic/CGame.cpp @@ -962,8 +962,16 @@ bool CGame::Start(int iArgumentCount, char* szArguments[]) // If ASE is enabled m_pASE = new ASE(m_pMainConfig, m_pPlayerManager, static_cast(usServerPort), strServerIPList); - if (m_pMainConfig->GetSerialVerificationEnabled()) - m_pASE->SetRuleValue("SerialVerification", "yes"); + if (m_pASE) { + if (m_pMainConfig->GetSerialVerificationEnabled()) + m_pASE->SetRuleValue("SerialVerification", "yes"); + + // Set the Rules loaded from config + std::map rulesMap = m_pMainConfig->GetRulesForASE(); + for (const auto& rule : rulesMap) + m_pASE->SetRuleValue(rule.first, rule.second); + } + ApplyAseSetting(); m_pMasterServerAnnouncer = new CMasterServerAnnouncer(); m_pMasterServerAnnouncer->Pulse(); diff --git a/Server/mods/deathmatch/logic/CMainConfig.cpp b/Server/mods/deathmatch/logic/CMainConfig.cpp index a535aa0ab6..e5773aa307 100644 --- a/Server/mods/deathmatch/logic/CMainConfig.cpp +++ b/Server/mods/deathmatch/logic/CMainConfig.cpp @@ -133,6 +133,31 @@ bool CMainConfig::Load() return false; } + // Grab rules + CXMLNode* pNode = nullptr; + unsigned int uiCurrentIndex = 0; + do + { + // Grab the current script node + pNode = m_pRootNode->FindSubNode("rule", uiCurrentIndex++); + if (pNode) + { + // Grab its "name" attribute + CXMLAttribute* pAttribute = pNode->GetAttributes().Find("name"); + SString strName = pAttribute ? pAttribute->GetValue() : ""; + + // Grab its "value" attribute + pAttribute = pNode->GetAttributes().Find("value"); + SString strValue = pAttribute ? pAttribute->GetValue() : ""; + + // Ignore if name or value are empty + if (strName != "" && strValue != "") { + // Store the key value pair + m_RulesForASEMap[strName] = strValue; + } + } + } while (pNode); + // Grab the forced server ip(s) GetString(m_pRootNode, "serverip", m_strServerIP); m_strServerIP = SString(m_strServerIP).Replace(" ", ""); @@ -232,8 +257,8 @@ bool CMainConfig::Load() GetInteger(m_pRootNode, "verifyclientsettings", m_iEnableClientChecks); // Handle the nodes - CXMLNode* pNode = NULL; - unsigned int uiCurrentIndex = 0; + pNode = nullptr; + uiCurrentIndex = 0; do { // Grab the current script node diff --git a/Server/mods/deathmatch/logic/CMainConfig.h b/Server/mods/deathmatch/logic/CMainConfig.h index b52733229a..9c83aec82a 100644 --- a/Server/mods/deathmatch/logic/CMainConfig.h +++ b/Server/mods/deathmatch/logic/CMainConfig.h @@ -87,6 +87,7 @@ class CMainConfig : public CXMLConfig unsigned int GetScriptDebugLogLevel() { return m_uiScriptDebugLogLevel; }; const std::string& GetAccessControlListFile() { return m_strAccessControlListFile; }; bool GetSerialVerificationEnabled() { return m_bVerifySerials; }; + std::map GetRulesForASE() { return m_RulesForASEMap; }; bool IsDisableAC(const char* szTagAC) { return MapContains(m_DisableComboACMap, szTagAC); }; bool IsEnableDiagnostic(const char* szTag) { return MapContains(m_EnableDiagnosticMap, szTag); }; CMtaVersion GetMinClientVersion() { return m_strMinClientVersion; } @@ -190,6 +191,7 @@ class CMainConfig : public CXMLConfig unsigned short m_usFPSLimit; int m_bDontBroadcastLan; std::set m_DisableComboACMap; + std::map m_RulesForASEMap; std::set m_EnableDiagnosticMap; std::vector m_AuthSerialGroupList; bool m_bAuthSerialHttpEnabled;