From b97c3abf02ec5e30cba555bbbe03928d2e6cdd93 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Tue, 1 Oct 2024 15:33:12 +0100 Subject: [PATCH 01/19] add new serverlist rule values mtaserver.conf --- Server/mods/deathmatch/editor.conf | 43 +++++++++++++------ Server/mods/deathmatch/local.conf | 43 +++++++++++++------ Server/mods/deathmatch/mtaserver.conf | 35 ++++++++++----- .../mods/deathmatch/mtaserver.conf.template | 29 ++++++++++--- 4 files changed, 105 insertions(+), 45 deletions(-) diff --git a/Server/mods/deathmatch/editor.conf b/Server/mods/deathmatch/editor.conf index f72486a6cb2..aa15946bb92 100644 --- a/Server/mods/deathmatch/editor.conf +++ b/Server/mods/deathmatch/editor.conf @@ -3,14 +3,29 @@ Map Editor Server - + + + + + + + + + + + + + + + - + 22010 - + 1 - + 22011 - + @@ -51,7 +66,7 @@ e.g. 88.11.22.33,101.2.3.4 --> - none @@ -173,17 +188,17 @@ - + editor_acl.xml - logs/editor_scripts.log - + logs/editor_scripts.log + 0 - + 0 @@ -197,12 +212,12 @@ 0 - + 1 - + @@ -268,7 +283,7 @@ parameter(s). Optional parameter. --> - + @@ -278,5 +293,5 @@ - + diff --git a/Server/mods/deathmatch/local.conf b/Server/mods/deathmatch/local.conf index ec3defd37d2..78d36b61ff0 100644 --- a/Server/mods/deathmatch/local.conf +++ b/Server/mods/deathmatch/local.conf @@ -3,7 +3,22 @@ Default MTA Server - + + + + + + + + + + + + + + + 22010 - + 32 - + 22011 - + @@ -51,7 +66,7 @@ e.g. 88.11.22.33,101.2.3.4 --> - none @@ -173,17 +188,17 @@ - + acl.xml - logs/local_scripts.log - + logs/local_scripts.log + 0 - + 0 @@ -197,12 +212,12 @@ 0 - + 1 - + @@ -268,7 +283,7 @@ parameter(s). Optional parameter. --> - + @@ -289,8 +304,8 @@ - + - + diff --git a/Server/mods/deathmatch/mtaserver.conf b/Server/mods/deathmatch/mtaserver.conf index 19fe4a05d83..76acba95277 100644 --- a/Server/mods/deathmatch/mtaserver.conf +++ b/Server/mods/deathmatch/mtaserver.conf @@ -3,7 +3,22 @@ Default MTA Server - + + + + + + + + + + + + + + + 22003 - + 32 - + 22005 - + @@ -177,7 +192,7 @@ - + acl.xml @@ -201,12 +216,12 @@ 0 - + 1 - + @@ -279,7 +294,7 @@ parameter(s). Optional parameter. --> - + @@ -302,9 +317,9 @@ - + - + diff --git a/Server/mods/deathmatch/mtaserver.conf.template b/Server/mods/deathmatch/mtaserver.conf.template index faf1c71a6d2..fb31333c7a6 100644 --- a/Server/mods/deathmatch/mtaserver.conf.template +++ b/Server/mods/deathmatch/mtaserver.conf.template @@ -4,7 +4,22 @@ Default MTA Server - + + + + + + + + + + + + + + + 22003 - + 32 - + 22005 - + @@ -178,7 +193,7 @@ - + acl.xml @@ -202,12 +217,12 @@ 0 - + 1 - + From bf12328cddd54016a4c7ba20e64f0431c3852159 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Thu, 3 Oct 2024 10:22:07 +0100 Subject: [PATCH 02/19] Fix empty lines etc --- Server/mods/deathmatch/editor.conf | 55 +++++++++++-------- Server/mods/deathmatch/local.conf | 55 +++++++++++-------- Server/mods/deathmatch/mtaserver.conf | 47 +++++++++------- .../mods/deathmatch/mtaserver.conf.template | 41 ++++++++------ 4 files changed, 117 insertions(+), 81 deletions(-) diff --git a/Server/mods/deathmatch/editor.conf b/Server/mods/deathmatch/editor.conf index aa15946bb92..2a91669c334 100644 --- a/Server/mods/deathmatch/editor.conf +++ b/Server/mods/deathmatch/editor.conf @@ -4,28 +4,37 @@ and on Game-Monitor. It is a required parameter. --> Map Editor Server - - + + + - + + + - + + - - - - + + + + + + + + + - + 22010 - + 1 - + 22011 - + @@ -66,7 +75,7 @@ e.g. 88.11.22.33,101.2.3.4 --> - none @@ -188,17 +197,17 @@ - + editor_acl.xml - logs/editor_scripts.log - + logs/editor_scripts.log + 0 - + 0 @@ -212,12 +221,12 @@ 0 - + 1 - + @@ -283,7 +292,7 @@ parameter(s). Optional parameter. --> - + @@ -293,5 +302,5 @@ - - + + \ No newline at end of file diff --git a/Server/mods/deathmatch/local.conf b/Server/mods/deathmatch/local.conf index 78d36b61ff0..454a482b4ae 100644 --- a/Server/mods/deathmatch/local.conf +++ b/Server/mods/deathmatch/local.conf @@ -4,21 +4,30 @@ and on Game-Monitor. It is a required parameter. --> Default MTA Server - - + + + - + + + - + + - - - - + + + + + + + + + 22010 - + 32 - + 22011 - + @@ -66,7 +75,7 @@ e.g. 88.11.22.33,101.2.3.4 --> - none @@ -188,17 +197,17 @@ - + acl.xml - logs/local_scripts.log - + logs/local_scripts.log + 0 - + 0 @@ -212,12 +221,12 @@ 0 - + 1 - + @@ -283,7 +292,7 @@ parameter(s). Optional parameter. --> - + @@ -304,8 +313,8 @@ - + - - + + \ No newline at end of file diff --git a/Server/mods/deathmatch/mtaserver.conf b/Server/mods/deathmatch/mtaserver.conf index 76acba95277..0d07558b1a6 100644 --- a/Server/mods/deathmatch/mtaserver.conf +++ b/Server/mods/deathmatch/mtaserver.conf @@ -4,20 +4,29 @@ and on Game-Monitor. It is a required parameter. --> Default MTA Server - - + + + - + + + - + + - - - - + + + + + + + + + 22003 - + 32 - + 22005 - + @@ -192,7 +201,7 @@ - + acl.xml @@ -216,12 +225,12 @@ 0 - + 1 - + @@ -294,7 +303,7 @@ parameter(s). Optional parameter. --> - + @@ -317,9 +326,9 @@ - + + - - + \ No newline at end of file diff --git a/Server/mods/deathmatch/mtaserver.conf.template b/Server/mods/deathmatch/mtaserver.conf.template index fb31333c7a6..5048b9398b8 100644 --- a/Server/mods/deathmatch/mtaserver.conf.template +++ b/Server/mods/deathmatch/mtaserver.conf.template @@ -5,21 +5,30 @@ and on Game-Monitor. It is a required parameter. --> Default MTA Server - - + + + - + + + - + + - - - - + + + + + + + + + 22003 - + 32 - + 22005 - + @@ -193,7 +202,7 @@ - + acl.xml @@ -217,12 +226,12 @@ 0 - + 1 - + @@ -290,4 +299,4 @@ Max events per interval range: 1 to 1000. Default: 100 --> 1000 100 - + \ No newline at end of file From ed0d19ab3c6476162f990dde19be4e2d5e1109e1 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Thu, 3 Oct 2024 10:24:33 +0100 Subject: [PATCH 03/19] Fix newline at end of line --- Server/mods/deathmatch/editor.conf | 4 ++-- Server/mods/deathmatch/local.conf | 4 ++-- Server/mods/deathmatch/mtaserver.conf | 4 ++-- Server/mods/deathmatch/mtaserver.conf.template | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Server/mods/deathmatch/editor.conf b/Server/mods/deathmatch/editor.conf index 2a91669c334..8b72a7d3244 100644 --- a/Server/mods/deathmatch/editor.conf +++ b/Server/mods/deathmatch/editor.conf @@ -13,7 +13,7 @@ - + @@ -303,4 +303,4 @@ - \ No newline at end of file + diff --git a/Server/mods/deathmatch/local.conf b/Server/mods/deathmatch/local.conf index 454a482b4ae..58fb4859cba 100644 --- a/Server/mods/deathmatch/local.conf +++ b/Server/mods/deathmatch/local.conf @@ -13,7 +13,7 @@ - + @@ -317,4 +317,4 @@ - \ No newline at end of file + diff --git a/Server/mods/deathmatch/mtaserver.conf b/Server/mods/deathmatch/mtaserver.conf index 0d07558b1a6..ff1863315b4 100644 --- a/Server/mods/deathmatch/mtaserver.conf +++ b/Server/mods/deathmatch/mtaserver.conf @@ -13,7 +13,7 @@ - + @@ -331,4 +331,4 @@ - \ No newline at end of file + diff --git a/Server/mods/deathmatch/mtaserver.conf.template b/Server/mods/deathmatch/mtaserver.conf.template index 5048b9398b8..06d120248ba 100644 --- a/Server/mods/deathmatch/mtaserver.conf.template +++ b/Server/mods/deathmatch/mtaserver.conf.template @@ -14,7 +14,7 @@ - + @@ -299,4 +299,4 @@ Max events per interval range: 1 to 1000. Default: 100 --> 1000 100 - \ No newline at end of file + From c29110a74f8efe025463de0d3eb2904dfc804815 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Thu, 3 Oct 2024 13:48:12 +0100 Subject: [PATCH 04/19] 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 58989394ec2..e035cfeeb49 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 a535aa0ab62..e5773aa3074 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 b52733229a4..9c83aec82ab 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; From 5cbe04d40537229883aeee75a3da3f05f78850b9 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Thu, 3 Oct 2024 16:52:33 +0100 Subject: [PATCH 05/19] Improve code thnx to review by tederis --- Server/mods/deathmatch/logic/CMainConfig.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Server/mods/deathmatch/logic/CMainConfig.cpp b/Server/mods/deathmatch/logic/CMainConfig.cpp index e5773aa3074..559657fed47 100644 --- a/Server/mods/deathmatch/logic/CMainConfig.cpp +++ b/Server/mods/deathmatch/logic/CMainConfig.cpp @@ -135,7 +135,7 @@ bool CMainConfig::Load() // Grab rules CXMLNode* pNode = nullptr; - unsigned int uiCurrentIndex = 0; + std::size_t uiCurrentIndex = 0; do { // Grab the current script node @@ -144,17 +144,15 @@ bool CMainConfig::Load() { // Grab its "name" attribute CXMLAttribute* pAttribute = pNode->GetAttributes().Find("name"); - SString strName = pAttribute ? pAttribute->GetValue() : ""; + SString strName = pAttribute ? pAttribute->GetValue() : SString{}; // Grab its "value" attribute pAttribute = pNode->GetAttributes().Find("value"); - SString strValue = pAttribute ? pAttribute->GetValue() : ""; + SString strValue = pAttribute ? pAttribute->GetValue() : SString{}; // Ignore if name or value are empty - if (strName != "" && strValue != "") { - // Store the key value pair - m_RulesForASEMap[strName] = strValue; - } + if (!strName.empty() && !strValue.empty()) + m_RulesForASEMap[std::move(strName)] = std::move(strValue); } } while (pNode); From e4b797fb5333340024a62c2c66c9791004cf51c4 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Thu, 3 Oct 2024 16:56:01 +0100 Subject: [PATCH 06/19] add const noexcept GetRulesForASE --- Server/mods/deathmatch/logic/CMainConfig.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/mods/deathmatch/logic/CMainConfig.h b/Server/mods/deathmatch/logic/CMainConfig.h index 9c83aec82ab..29bc0483cde 100644 --- a/Server/mods/deathmatch/logic/CMainConfig.h +++ b/Server/mods/deathmatch/logic/CMainConfig.h @@ -87,7 +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; }; + const std::map& GetRulesForASE() const noexcept { 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; } From 32c56a25ba112112e0f89d631c023aa3740548d5 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Thu, 3 Oct 2024 18:50:02 +0100 Subject: [PATCH 07/19] Refactor --- Server/mods/deathmatch/logic/CGame.cpp | 4 ++-- Server/mods/deathmatch/logic/CMainConfig.cpp | 24 +++++++------------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/Server/mods/deathmatch/logic/CGame.cpp b/Server/mods/deathmatch/logic/CGame.cpp index e035cfeeb49..e271d1dbce3 100644 --- a/Server/mods/deathmatch/logic/CGame.cpp +++ b/Server/mods/deathmatch/logic/CGame.cpp @@ -968,8 +968,8 @@ bool CGame::Start(int iArgumentCount, char* szArguments[]) // Set the Rules loaded from config std::map rulesMap = m_pMainConfig->GetRulesForASE(); - for (const auto& rule : rulesMap) - m_pASE->SetRuleValue(rule.first, rule.second); + for (const auto& [key, value] : rulesMap) + m_pASE->SetRuleValue(key, value); } ApplyAseSetting(); diff --git a/Server/mods/deathmatch/logic/CMainConfig.cpp b/Server/mods/deathmatch/logic/CMainConfig.cpp index 559657fed47..19589fd7a5d 100644 --- a/Server/mods/deathmatch/logic/CMainConfig.cpp +++ b/Server/mods/deathmatch/logic/CMainConfig.cpp @@ -136,25 +136,17 @@ bool CMainConfig::Load() // Grab rules CXMLNode* pNode = nullptr; std::size_t uiCurrentIndex = 0; - do + while (pNode = m_pRootNode->FindSubNode("rule", uiCurrentIndex++)) { - // 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() : SString{}; + CXMLAttribute* pAttribute = pNode->GetAttributes().Find("name"); + SString strName = pAttribute ? pAttribute->GetValue() : SString{}; - // Grab its "value" attribute - pAttribute = pNode->GetAttributes().Find("value"); - SString strValue = pAttribute ? pAttribute->GetValue() : SString{}; + pAttribute = pNode->GetAttributes().Find("value"); + SString strValue = pAttribute ? pAttribute->GetValue() : SString{}; - // Ignore if name or value are empty - if (!strName.empty() && !strValue.empty()) - m_RulesForASEMap[std::move(strName)] = std::move(strValue); - } - } while (pNode); + if (!strName.empty() && !strValue.empty()) + m_RulesForASEMap[std::move(strName)] = std::move(strValue); + } // Grab the forced server ip(s) GetString(m_pRootNode, "serverip", m_strServerIP); From f8b08f5bbdabfd3e3373d5b2ca8077a650dfb022 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Thu, 3 Oct 2024 23:06:01 +0100 Subject: [PATCH 08/19] Refactor hungarian notation --- Server/mods/deathmatch/logic/CMainConfig.cpp | 32 ++++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Server/mods/deathmatch/logic/CMainConfig.cpp b/Server/mods/deathmatch/logic/CMainConfig.cpp index 19589fd7a5d..f7db6c93581 100644 --- a/Server/mods/deathmatch/logic/CMainConfig.cpp +++ b/Server/mods/deathmatch/logic/CMainConfig.cpp @@ -134,18 +134,18 @@ bool CMainConfig::Load() } // Grab rules - CXMLNode* pNode = nullptr; - std::size_t uiCurrentIndex = 0; - while (pNode = m_pRootNode->FindSubNode("rule", uiCurrentIndex++)) + CXMLNode* currentNode = nullptr; + std::size_t currentIndex = 0; + while (currentNode = m_pRootNode->FindSubNode("rule", currentIndex++)) { - CXMLAttribute* pAttribute = pNode->GetAttributes().Find("name"); - SString strName = pAttribute ? pAttribute->GetValue() : SString{}; + CXMLAttribute* attribute = currentNode->GetAttributes().Find("name"); + SString ruleName = attribute ? attribute->GetValue() : SString{}; - pAttribute = pNode->GetAttributes().Find("value"); - SString strValue = pAttribute ? pAttribute->GetValue() : SString{}; + attribute = currentNode->GetAttributes().Find("value"); + SString ruleValue = attribute ? attribute->GetValue() : SString{}; - if (!strName.empty() && !strValue.empty()) - m_RulesForASEMap[std::move(strName)] = std::move(strValue); + if (!ruleName.empty() && !ruleValue.empty()) + m_RulesForASEMap[std::move(ruleName)] = std::move(ruleValue); } // Grab the forced server ip(s) @@ -247,21 +247,21 @@ bool CMainConfig::Load() GetInteger(m_pRootNode, "verifyclientsettings", m_iEnableClientChecks); // Handle the nodes - pNode = nullptr; - uiCurrentIndex = 0; + currentNode = nullptr; + currentIndex = 0; do { // Grab the current script node - pNode = m_pRootNode->FindSubNode("client_file", uiCurrentIndex++); - if (pNode) + currentNode = m_pRootNode->FindSubNode("client_file", currentIndex++); + if (currentNode) { // Grab its "name" attribute - CXMLAttribute* pAttribute = pNode->GetAttributes().Find("name"); + CXMLAttribute* pAttribute = currentNode->GetAttributes().Find("name"); SString strName = pAttribute ? pAttribute->GetValue() : ""; strName = strName.Replace("\\", "/").ToLower(); // Grab its "verify" attribute - pAttribute = pNode->GetAttributes().Find("verify"); + pAttribute = currentNode->GetAttributes().Find("verify"); SString strVerify = pAttribute ? pAttribute->GetValue() : ""; bool bVerify = strVerify == "true" || strVerify == "yes" || strVerify == "1"; @@ -283,7 +283,7 @@ bool CMainConfig::Load() if (!bFound) CLogger::ErrorPrintf("Unknown client_file '%s'\n", *strName); } - } while (pNode); + } while (currentNode); // allow_gta3_img_mods SString strImgMods; From 4cb8995a354148cc219fe61bc689c30bbe4d0544 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Thu, 3 Oct 2024 23:09:03 +0100 Subject: [PATCH 09/19] Fix redundant check ASE --- Server/mods/deathmatch/logic/CGame.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Server/mods/deathmatch/logic/CGame.cpp b/Server/mods/deathmatch/logic/CGame.cpp index e271d1dbce3..4be94173e6f 100644 --- a/Server/mods/deathmatch/logic/CGame.cpp +++ b/Server/mods/deathmatch/logic/CGame.cpp @@ -960,17 +960,15 @@ bool CGame::Start(int iArgumentCount, char* szArguments[]) } } - // If ASE is enabled + // Init ASE m_pASE = new ASE(m_pMainConfig, m_pPlayerManager, static_cast(usServerPort), strServerIPList); - 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& [key, value] : rulesMap) - m_pASE->SetRuleValue(key, value); - } + if (m_pMainConfig->GetSerialVerificationEnabled()) + m_pASE->SetRuleValue("SerialVerification", "yes"); + + // Set the Rules loaded from config + std::map rulesMap = m_pMainConfig->GetRulesForASE(); + for (const auto& [key, value] : rulesMap) + m_pASE->SetRuleValue(key, value); ApplyAseSetting(); m_pMasterServerAnnouncer = new CMasterServerAnnouncer(); From a938d624ed18d33acbb297563efe22f76c4725cb Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Fri, 4 Oct 2024 12:41:41 +0100 Subject: [PATCH 10/19] Refactor grab client_file part --- Server/mods/deathmatch/logic/CMainConfig.cpp | 54 +++++++++----------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/Server/mods/deathmatch/logic/CMainConfig.cpp b/Server/mods/deathmatch/logic/CMainConfig.cpp index f7db6c93581..94d3b8901e2 100644 --- a/Server/mods/deathmatch/logic/CMainConfig.cpp +++ b/Server/mods/deathmatch/logic/CMainConfig.cpp @@ -249,41 +249,35 @@ bool CMainConfig::Load() // Handle the nodes currentNode = nullptr; currentIndex = 0; - do + while (currentNode = m_pRootNode->FindSubNode("client_file", currentIndex++)) { - // Grab the current script node - currentNode = m_pRootNode->FindSubNode("client_file", currentIndex++); - if (currentNode) + // Grab its "name" attribute + CXMLAttribute* attribute = currentNode->GetAttributes().Find("name"); + SString name = attribute ? attribute->GetValue() : SString{}; + name = name.Replace("\\", "/").ToLower(); + + // Grab its "verify" attribute + attribute = currentNode->GetAttributes().Find("verify"); + SString verify = attribute ? attribute->GetValue() : SString{}; + bool shouldVerify = verify == "true" || verify == "yes" || verify == "1"; + + // Find bitnumber + bool found = false; + for (uint i = 0; i < NUMELMS(gtaDataFiles); i++) { - // Grab its "name" attribute - CXMLAttribute* pAttribute = currentNode->GetAttributes().Find("name"); - SString strName = pAttribute ? pAttribute->GetValue() : ""; - strName = strName.Replace("\\", "/").ToLower(); - - // Grab its "verify" attribute - pAttribute = currentNode->GetAttributes().Find("verify"); - SString strVerify = pAttribute ? pAttribute->GetValue() : ""; - bool bVerify = strVerify == "true" || strVerify == "yes" || strVerify == "1"; - - // Find bitnumber - bool bFound = false; - for (uint i = 0; i < NUMELMS(gtaDataFiles); i++) + if (name == gtaDataFiles[i].szRealFilename) { - if (strName == gtaDataFiles[i].szRealFilename) - { - if (bVerify) - m_iEnableClientChecks |= 1 << gtaDataFiles[i].iBitNumber; - else - m_iEnableClientChecks &= ~(1 << gtaDataFiles[i].iBitNumber); - bFound = true; - break; - } + if (shouldVerify) + m_iEnableClientChecks |= 1 << gtaDataFiles[i].iBitNumber; + else + m_iEnableClientChecks &= ~(1 << gtaDataFiles[i].iBitNumber); + found = true; + break; } - - if (!bFound) - CLogger::ErrorPrintf("Unknown client_file '%s'\n", *strName); } - } while (currentNode); + if (!found) + CLogger::ErrorPrintf("Unknown client_file '%s'\n", *name); + } // allow_gta3_img_mods SString strImgMods; From be21fa158fd17e6ebd557d58dd168ebf29a696c8 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Sat, 5 Oct 2024 13:20:26 +0100 Subject: [PATCH 11/19] Refactor CMainConfig::AddMissingSettings() and edit .conf comments --- Server/mods/deathmatch/editor.conf | 6 +- Server/mods/deathmatch/local.conf | 6 +- Server/mods/deathmatch/logic/CMainConfig.cpp | 95 ++++++++++++++----- Server/mods/deathmatch/mtaserver.conf | 6 +- .../mods/deathmatch/mtaserver.conf.template | 6 +- 5 files changed, 77 insertions(+), 42 deletions(-) diff --git a/Server/mods/deathmatch/editor.conf b/Server/mods/deathmatch/editor.conf index 8b72a7d3244..c4455bcd4f9 100644 --- a/Server/mods/deathmatch/editor.conf +++ b/Server/mods/deathmatch/editor.conf @@ -4,10 +4,8 @@ and on Game-Monitor. It is a required parameter. --> Map Editor Server - - - + diff --git a/Server/mods/deathmatch/local.conf b/Server/mods/deathmatch/local.conf index 58fb4859cba..74189976789 100644 --- a/Server/mods/deathmatch/local.conf +++ b/Server/mods/deathmatch/local.conf @@ -4,10 +4,8 @@ and on Game-Monitor. It is a required parameter. --> Default MTA Server - - - + diff --git a/Server/mods/deathmatch/logic/CMainConfig.cpp b/Server/mods/deathmatch/logic/CMainConfig.cpp index 94d3b8901e2..0560b8ce14f 100644 --- a/Server/mods/deathmatch/logic/CMainConfig.cpp +++ b/Server/mods/deathmatch/logic/CMainConfig.cpp @@ -263,7 +263,7 @@ bool CMainConfig::Load() // Find bitnumber bool found = false; - for (uint i = 0; i < NUMELMS(gtaDataFiles); i++) + for (std::uint8_t i = 0; i < NUMELMS(gtaDataFiles); i++) { if (name == gtaDataFiles[i].szRealFilename) { @@ -856,44 +856,87 @@ bool CMainConfig::AddMissingSettings() if (!g_pGame->IsUsingMtaServerConf()) return false; - SString strTemplateFilename = PathJoin(g_pServerInterface->GetServerModPath(), "mtaserver.conf.template"); + const SString& templateFileName = PathJoin(g_pServerInterface->GetServerModPath(), "mtaserver.conf.template"); - if (!FileExists(strTemplateFilename)) + if (!FileExists(templateFileName)) return false; - CXMLFile* pFileTemplate = g_pServerInterface->GetXML()->CreateXML(strTemplateFilename); - CXMLNode* pRootNodeTemplate = pFileTemplate && pFileTemplate->Parse() ? pFileTemplate->GetRootNode() : nullptr; - if (!pRootNodeTemplate) + CXMLFile* templateFile = g_pServerInterface->GetXML()->CreateXML(templateFileName); + CXMLNode* templateRootNode = templateFile && templateFile->Parse() ? templateFile->GetRootNode() : nullptr; + if (!templateRootNode) { - CLogger::ErrorPrintf("Can't parse '%s'\n", *strTemplateFilename); + CLogger::ErrorPrintf("Can't parse '%s'\n", *templateFileName); return false; } // Check that each item in the template also exists in the server config - bool bChanged = false; - CXMLNode* pPrevNode = nullptr; - for (auto it = pRootNodeTemplate->ChildrenBegin(); it != pRootNodeTemplate->ChildrenEnd(); ++it) - { - CXMLNode* pNodeTemplate = *it; - SString strNodeName = pNodeTemplate->GetTagName(); - CXMLNode* pNode = m_pRootNode->FindSubNode(strNodeName); - if (!pNode) + bool hasConfigChanged = false; + CXMLNode* previousNode = nullptr; + for (auto it = templateRootNode->ChildrenBegin(); it != templateRootNode->ChildrenEnd(); ++it) + { + CXMLNode* templateNode = *it; + SString templateNodeTagName = templateNode->GetTagName(); + + // Find node with exact same attributes + CXMLAttributes& templateAttributes = templateNode->GetAttributes(); + CXMLNode* foundNode = nullptr; + for (auto it2 = m_pRootNode->ChildrenBegin(); it2 != m_pRootNode->ChildrenEnd(); ++it2) { - CLogger::LogPrintf("Adding missing '%s' to mtaserver.conf\n", *strNodeName); - SString strNodeValue = pNodeTemplate->GetTagContent(); - SString strNodeComment = pNodeTemplate->GetCommentText(); - pNode = m_pRootNode->CreateSubNode(strNodeName, pPrevNode); - pNode->SetTagContent(strNodeValue); - pNode->SetCommentText(strNodeComment, true); - bChanged = true; + CXMLNode* tempNode = *it2; + if (tempNode->GetTagName() == templateNodeTagName) + { + bool bAttributesMatch = true; + CXMLAttributes& attributes = tempNode->GetAttributes(); + for (auto it3 = templateAttributes.ListBegin(); it3 != templateAttributes.ListEnd(); ++it3) + { + CXMLAttribute* templateAttribute = *it3; + const SString& strKey = templateAttribute->GetName(); + const SString& strValue = templateAttribute->GetValue(); + CXMLAttribute* foundAttribute = attributes.Find(strKey); + if (!foundAttribute || foundAttribute->GetValue() != strValue) + { + bAttributesMatch = false; + break; + } + } + if (bAttributesMatch) + { + foundNode = tempNode; + break; + } + } + } + // Create missing node if not found + if (!foundNode) + { + CLogger::LogPrintf("Adding missing '%s' to mtaserver.conf\n", *templateNodeTagName); + SString value = templateNode->GetTagContent(); + SString commentText = templateNode->GetCommentText(); + foundNode = m_pRootNode->CreateSubNode(templateNodeTagName, previousNode); + foundNode->SetTagContent(value); + foundNode->SetCommentText(commentText, true); + + // Copy attributes from template node + CXMLAttributes& templateAttributes = templateNode->GetAttributes(); + for (auto it = templateAttributes.ListBegin(); it != templateAttributes.ListEnd(); ++it) + { + CXMLAttribute* templateAttribute = *it; + const SString& attributeName = templateAttribute->GetName(); + const SString& attributeValue = templateAttribute->GetValue(); + + CXMLAttribute* newAttribute = foundNode->GetAttributes().Create(attributeName); + if (newAttribute) + newAttribute->SetValue(attributeValue); + } + hasConfigChanged = true; } - pPrevNode = pNode; + previousNode = foundNode; } // Clean up - g_pServerInterface->GetXML()->DeleteXML(pFileTemplate); - FileDelete(strTemplateFilename); - return bChanged; + g_pServerInterface->GetXML()->DeleteXML(templateFile); + FileDelete(templateFileName); + return hasConfigChanged; } bool CMainConfig::IsValidPassword(const char* szPassword) diff --git a/Server/mods/deathmatch/mtaserver.conf b/Server/mods/deathmatch/mtaserver.conf index ff1863315b4..0b7df4c7017 100644 --- a/Server/mods/deathmatch/mtaserver.conf +++ b/Server/mods/deathmatch/mtaserver.conf @@ -4,10 +4,8 @@ and on Game-Monitor. It is a required parameter. --> Default MTA Server - - - + diff --git a/Server/mods/deathmatch/mtaserver.conf.template b/Server/mods/deathmatch/mtaserver.conf.template index 06d120248ba..cacc98a029f 100644 --- a/Server/mods/deathmatch/mtaserver.conf.template +++ b/Server/mods/deathmatch/mtaserver.conf.template @@ -5,10 +5,8 @@ and on Game-Monitor. It is a required parameter. --> Default MTA Server - - - + From d191085b3e5b81eb29befec1e818004271b4881f Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Sat, 5 Oct 2024 13:34:05 +0100 Subject: [PATCH 12/19] early continue --- Server/mods/deathmatch/logic/CMainConfig.cpp | 38 +++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/Server/mods/deathmatch/logic/CMainConfig.cpp b/Server/mods/deathmatch/logic/CMainConfig.cpp index 0560b8ce14f..65c6deafb30 100644 --- a/Server/mods/deathmatch/logic/CMainConfig.cpp +++ b/Server/mods/deathmatch/logic/CMainConfig.cpp @@ -883,28 +883,32 @@ bool CMainConfig::AddMissingSettings() for (auto it2 = m_pRootNode->ChildrenBegin(); it2 != m_pRootNode->ChildrenEnd(); ++it2) { CXMLNode* tempNode = *it2; - if (tempNode->GetTagName() == templateNodeTagName) + if (tempNode->GetTagName() != templateNodeTagName) { - bool bAttributesMatch = true; - CXMLAttributes& attributes = tempNode->GetAttributes(); - for (auto it3 = templateAttributes.ListBegin(); it3 != templateAttributes.ListEnd(); ++it3) - { - CXMLAttribute* templateAttribute = *it3; - const SString& strKey = templateAttribute->GetName(); - const SString& strValue = templateAttribute->GetValue(); - CXMLAttribute* foundAttribute = attributes.Find(strKey); - if (!foundAttribute || foundAttribute->GetValue() != strValue) - { - bAttributesMatch = false; - break; - } - } - if (bAttributesMatch) + continue; + } + CXMLAttributes& attributes = tempNode->GetAttributes(); + bool attributesMatch = true; + + for (auto it3 = templateAttributes.ListBegin(); it3 != templateAttributes.ListEnd(); ++it3) + { + CXMLAttribute* templateAttribute = *it3; + const SString& strKey = templateAttribute->GetName(); + const SString& strValue = templateAttribute->GetValue(); + + CXMLAttribute* foundAttribute = attributes.Find(strKey); + if (!foundAttribute || foundAttribute->GetValue() != strValue) { - foundNode = tempNode; + attributesMatch = false; break; } } + + if (attributesMatch) + { + foundNode = tempNode; + break; + } } // Create missing node if not found if (!foundNode) From 2e39c066af32d38c52f8794da4a7e5304290b9df Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Tue, 8 Oct 2024 21:41:33 +0100 Subject: [PATCH 13/19] fix --- Server/mods/deathmatch/logic/CMainConfig.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/mods/deathmatch/logic/CMainConfig.cpp b/Server/mods/deathmatch/logic/CMainConfig.cpp index 65c6deafb30..a15568f172e 100644 --- a/Server/mods/deathmatch/logic/CMainConfig.cpp +++ b/Server/mods/deathmatch/logic/CMainConfig.cpp @@ -856,7 +856,7 @@ bool CMainConfig::AddMissingSettings() if (!g_pGame->IsUsingMtaServerConf()) return false; - const SString& templateFileName = PathJoin(g_pServerInterface->GetServerModPath(), "mtaserver.conf.template"); + const SString templateFileName = PathJoin(g_pServerInterface->GetServerModPath(), "mtaserver.conf.template"); if (!FileExists(templateFileName)) return false; From 75d3ccb3e1c5cd24b1272ceba68ed0c620c3fa31 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Tue, 8 Oct 2024 21:41:47 +0100 Subject: [PATCH 14/19] refactor --- Server/mods/deathmatch/logic/CMainConfig.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server/mods/deathmatch/logic/CMainConfig.cpp b/Server/mods/deathmatch/logic/CMainConfig.cpp index a15568f172e..1d66eedc29d 100644 --- a/Server/mods/deathmatch/logic/CMainConfig.cpp +++ b/Server/mods/deathmatch/logic/CMainConfig.cpp @@ -263,7 +263,7 @@ bool CMainConfig::Load() // Find bitnumber bool found = false; - for (std::uint8_t i = 0; i < NUMELMS(gtaDataFiles); i++) + for (std::size_t i = 0; i < std::size(gtaDataFiles); i++) { if (name == gtaDataFiles[i].szRealFilename) { From 75cc9332ff1f10cee3dd100109abd38a0c4f5435 Mon Sep 17 00:00:00 2001 From: Fernando Rocha <34967844+Fernando-A-Rocha@users.noreply.github.com> Date: Thu, 2 Jan 2025 02:14:09 +0000 Subject: [PATCH 15/19] Reviews-1 Co-authored-by: Marek Kulik --- Server/mods/deathmatch/logic/CGame.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Server/mods/deathmatch/logic/CGame.cpp b/Server/mods/deathmatch/logic/CGame.cpp index eefbf18bba0..fe8d5397fe7 100644 --- a/Server/mods/deathmatch/logic/CGame.cpp +++ b/Server/mods/deathmatch/logic/CGame.cpp @@ -985,8 +985,7 @@ bool CGame::Start(int iArgumentCount, char* szArguments[]) m_pASE->SetRuleValue("SerialVerification", "yes"); // Set the Rules loaded from config - std::map rulesMap = m_pMainConfig->GetRulesForASE(); - for (const auto& [key, value] : rulesMap) + for (const auto& [key, value] : m_pMainConfig->GetRulesForASE()) m_pASE->SetRuleValue(key, value); ApplyAseSetting(); From e6b69c79e934ab079516f5c121869e9f08d492cb Mon Sep 17 00:00:00 2001 From: Fernando Rocha <34967844+Fernando-A-Rocha@users.noreply.github.com> Date: Thu, 2 Jan 2025 02:14:38 +0000 Subject: [PATCH 16/19] Reviews-2 Co-authored-by: Marek Kulik --- Server/mods/deathmatch/local.conf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Server/mods/deathmatch/local.conf b/Server/mods/deathmatch/local.conf index 458fbebdf08..93b1304c9db 100644 --- a/Server/mods/deathmatch/local.conf +++ b/Server/mods/deathmatch/local.conf @@ -18,13 +18,13 @@ - + - + - + - + - + - + - + - + - + - + - + - +