From 525f43d046a6851d463e602a0c59649072d0a505 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Thu, 14 Nov 2024 23:40:55 +0000 Subject: [PATCH 01/11] remove mtaserver.conf.template --- Server/mods/deathmatch/logic/CMainConfig.cpp | 57 ---- Server/mods/deathmatch/logic/CMainConfig.h | 1 - .../mods/deathmatch/mtaserver.conf.template | 288 ------------------ utils/buildactions/install_data.lua | 9 +- 4 files changed, 1 insertion(+), 354 deletions(-) delete mode 100644 Server/mods/deathmatch/mtaserver.conf.template diff --git a/Server/mods/deathmatch/logic/CMainConfig.cpp b/Server/mods/deathmatch/logic/CMainConfig.cpp index bece65e885f..f19a642f57f 100644 --- a/Server/mods/deathmatch/logic/CMainConfig.cpp +++ b/Server/mods/deathmatch/logic/CMainConfig.cpp @@ -22,8 +22,6 @@ #include "CHTTPD.h" #include "CStaticFunctionDefinitions.h" -#define MTA_SERVER_CONF_TEMPLATE "mtaserver.conf.template" - extern CGame* g_pGame; CBandwidthSettings* g_pBandwidthSettings = new CBandwidthSettings(); @@ -116,11 +114,6 @@ bool CMainConfig::Load() return false; } - if (AddMissingSettings()) - { - Save(); - } - // Name int iResult = GetString(m_pRootNode, "servername", m_strServerName, 1, 96); if (iResult == DOESNT_EXIST) @@ -843,56 +836,6 @@ bool CMainConfig::Save() return false; } -// -// Compare against default config and add missing nodes. -// Returns true if nodes were added. -// -bool CMainConfig::AddMissingSettings() -{ - // Only mtaserver.conf is currently supported - if (!g_pGame->IsUsingMtaServerConf()) - return false; - - SString strTemplateFilename = PathJoin(g_pServerInterface->GetServerModPath(), "mtaserver.conf.template"); - - if (!FileExists(strTemplateFilename)) - return false; - - CXMLFile* pFileTemplate = g_pServerInterface->GetXML()->CreateXML(strTemplateFilename); - CXMLNode* pRootNodeTemplate = pFileTemplate && pFileTemplate->Parse() ? pFileTemplate->GetRootNode() : nullptr; - if (!pRootNodeTemplate) - { - CLogger::ErrorPrintf("Can't parse '%s'\n", *strTemplateFilename); - 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) - { - 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; - } - pPrevNode = pNode; - } - - // Clean up - g_pServerInterface->GetXML()->DeleteXML(pFileTemplate); - FileDelete(strTemplateFilename); - return bChanged; -} - bool CMainConfig::IsValidPassword(const char* szPassword) { if (!szPassword) diff --git a/Server/mods/deathmatch/logic/CMainConfig.h b/Server/mods/deathmatch/logic/CMainConfig.h index 9758ae2dbfd..6d4da5e987c 100644 --- a/Server/mods/deathmatch/logic/CMainConfig.h +++ b/Server/mods/deathmatch/logic/CMainConfig.h @@ -152,7 +152,6 @@ class CMainConfig : public CXMLConfig private: void RegisterCommand(const char* szName, FCommandHandler* pFunction, bool bRestricted, const char* szConsoleHelpText); bool GetSettingTable(const SString& strName, const char** szAttribNames, uint uiNumAttribNames, CLuaArguments* outTable); - bool AddMissingSettings(); CConsole* m_pConsole; CXMLNode* m_pRootNode; diff --git a/Server/mods/deathmatch/mtaserver.conf.template b/Server/mods/deathmatch/mtaserver.conf.template deleted file mode 100644 index 88288cc9d64..00000000000 --- a/Server/mods/deathmatch/mtaserver.conf.template +++ /dev/null @@ -1,288 +0,0 @@ - - - - Default MTA Server - - - - - - auto - - - 22003 - - - 32 - - - 22005 - - - - - - 5 - - - 20 - - - - - - none - - - - - - - - - - - - - - - - 1 - - - - - - 1 - - - 0 - - - - - - medium - - - - 100 - - 1500 - - 500 - - 400 - - 2000 - - 400 - - 100 - - 100 - - - 1 - - - 30 - - - 0 - - - 150 - - - 0 - - - server-id.keys - - - logs/server.log - - - logs/server_auth.log - - - logs/db.log - - - - - - acl.xml - - - logs/scripts.log - - - 0 - - - 0 - - - 1 - - - 60 - - - 0 - - - 1 - - - 4 - - - - - - backups - - - 3 - - - 10 - - - 1 - - - 1 - - - Admin - - - 1 - - - 127.0.0.1 - - - 1 - - - 0 - - - 1000 - 100 - - - 1 - diff --git a/utils/buildactions/install_data.lua b/utils/buildactions/install_data.lua index 930ecf35197..e2c40ec9a12 100644 --- a/utils/buildactions/install_data.lua +++ b/utils/buildactions/install_data.lua @@ -49,13 +49,6 @@ newaction { return end - local success, message = os.copydir("Server/mods/deathmatch", BIN_DIR.."/server/mods/deathmatch", "mtaserver.conf.template", false, true) - if not success then - errormsg("ERROR: Couldn't copy server config files", "\n"..message) - os.exit(1) - return - end - local success, message = os.copydir("Server/mods/deathmatch", BIN_DIR.."/server/mods/deathmatch", "*.xml", false, true) if not success then errormsg("ERROR: Couldn't copy server xml files", "\n"..message) @@ -76,7 +69,7 @@ newaction { success = success and http.download_print_errors(NET_PATH_X64_WIN, BIN_DIR.."/server/x64/net.dll") success = success and http.download_print_errors(NET_PATH_ARM64_WIN, BIN_DIR.."/server/arm64/net.dll") success = success and http.download_print_errors(NETC_PATH_WIN, BIN_DIR.."/MTA/netc.dll") - + -- A download failed if not success then os.exit(1) From 899dd5280def8f1cb987f2ebdf6cfa1c3142072e Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Thu, 14 Nov 2024 23:47:26 +0000 Subject: [PATCH 02/11] . --- utils/buildactions/compose_files.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/utils/buildactions/compose_files.lua b/utils/buildactions/compose_files.lua index 0adaf2cfc1a..e94d9d91536 100644 --- a/utils/buildactions/compose_files.lua +++ b/utils/buildactions/compose_files.lua @@ -11,10 +11,10 @@ local WINDOWS = os.host() == "windows" newaction { trigger = "compose_files", description = "Composes files that are required for building the installer", - + execute = function() os.mkdir(OUTPUT_DIR) - + -- Copy data files if WINDOWS then os.copydir(DATA_DIR.."/MTA", OUTPUT_DIR.."/MTA") @@ -25,9 +25,8 @@ newaction { -- Copy configs os.copydir("Server/mods/deathmatch", OUTPUT_DIR.."/server/mods/deathmatch", "*.conf") - os.copydir("Server/mods/deathmatch", OUTPUT_DIR.."/server/mods/deathmatch", "mtaserver.conf.template") os.copydir("Server/mods/deathmatch", OUTPUT_DIR.."/server/mods/deathmatch", "*.xml") - + -- Copy compiled binaries if WINDOWS then os.copydir(BIN_DIR, OUTPUT_DIR, "**.exe") From f0195c7dc5d4c5ef08004b84aedb5de09fdf2c13 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Fri, 15 Nov 2024 11:31:14 +0000 Subject: [PATCH 03/11] dont remove the template --- Server/mods/deathmatch/logic/CMainConfig.cpp | 58 ++++++++++++++++++++ Server/mods/deathmatch/logic/CMainConfig.h | 1 + utils/buildactions/compose_files.lua | 7 ++- utils/buildactions/install_data.lua | 8 ++- 4 files changed, 70 insertions(+), 4 deletions(-) diff --git a/Server/mods/deathmatch/logic/CMainConfig.cpp b/Server/mods/deathmatch/logic/CMainConfig.cpp index f19a642f57f..c8ca6eef4b5 100644 --- a/Server/mods/deathmatch/logic/CMainConfig.cpp +++ b/Server/mods/deathmatch/logic/CMainConfig.cpp @@ -22,6 +22,8 @@ #include "CHTTPD.h" #include "CStaticFunctionDefinitions.h" +#define MTA_SERVER_CONF_TEMPLATE "mtaserver.conf.template" + extern CGame* g_pGame; CBandwidthSettings* g_pBandwidthSettings = new CBandwidthSettings(); @@ -114,6 +116,11 @@ bool CMainConfig::Load() return false; } + if (AddMissingSettings()) + { + Save(); + } + // Name int iResult = GetString(m_pRootNode, "servername", m_strServerName, 1, 96); if (iResult == DOESNT_EXIST) @@ -836,6 +843,57 @@ bool CMainConfig::Save() return false; } +// +// Compare against default config and add missing nodes. +// Returns true if nodes were added. +// +bool CMainConfig::AddMissingSettings() +{ + // Only mtaserver.conf is currently supported + if (!g_pGame->IsUsingMtaServerConf()) + return false; + + SString templateFileName = PathJoin(g_pServerInterface->GetServerModPath(), MTA_SERVER_CONF_TEMPLATE); + if (!FileExists(templateFileName)) + return false; + + CXMLFile* templateFile = g_pServerInterface->GetXML()->CreateXML(templateFileName); + CXMLNode* templateRootNode = templateFile && templateFile->Parse() ? templateFile->GetRootNode() : nullptr; + if (!templateRootNode) + { + CLogger::ErrorPrintf("Can't parse '%s'\n", *templateFileName); + return false; + } + + // Check that each item in the template also exists in the server config + bool configChanged = false; + CXMLNode* previousNode = nullptr; + for (auto it = templateRootNode->ChildrenBegin(); it != templateRootNode->ChildrenEnd(); ++it) + { + CXMLNode* templateNode = *it; + SString templateNodeName = templateNode->GetTagName(); + + // Skip certain optional nodes + if (templateNodeName == "resource" || templateNodeName == "module") + continue; + + CXMLNode* foundNode = m_pRootNode->FindSubNode(templateNodeName); + if (!foundNode) + { + SString templateNodeValue = templateNode->GetTagContent(); + SString templateNodeComment = templateNode->GetCommentText(); + foundNode = m_pRootNode->CreateSubNode(templateNodeName, previousNode); + foundNode->SetTagContent(templateNodeValue); + foundNode->SetCommentText(templateNodeComment, true); + CLogger::LogPrintf("[%s] Added missing '%s' setting to mtaserver.conf\n", MTA_SERVER_CONF_TEMPLATE, *templateNodeName); + configChanged = true; + } + previousNode = foundNode; + } + g_pServerInterface->GetXML()->DeleteXML(templateFile); + return configChanged; +} + bool CMainConfig::IsValidPassword(const char* szPassword) { if (!szPassword) diff --git a/Server/mods/deathmatch/logic/CMainConfig.h b/Server/mods/deathmatch/logic/CMainConfig.h index 6d4da5e987c..9758ae2dbfd 100644 --- a/Server/mods/deathmatch/logic/CMainConfig.h +++ b/Server/mods/deathmatch/logic/CMainConfig.h @@ -152,6 +152,7 @@ class CMainConfig : public CXMLConfig private: void RegisterCommand(const char* szName, FCommandHandler* pFunction, bool bRestricted, const char* szConsoleHelpText); bool GetSettingTable(const SString& strName, const char** szAttribNames, uint uiNumAttribNames, CLuaArguments* outTable); + bool AddMissingSettings(); CConsole* m_pConsole; CXMLNode* m_pRootNode; diff --git a/utils/buildactions/compose_files.lua b/utils/buildactions/compose_files.lua index e94d9d91536..0adaf2cfc1a 100644 --- a/utils/buildactions/compose_files.lua +++ b/utils/buildactions/compose_files.lua @@ -11,10 +11,10 @@ local WINDOWS = os.host() == "windows" newaction { trigger = "compose_files", description = "Composes files that are required for building the installer", - + execute = function() os.mkdir(OUTPUT_DIR) - + -- Copy data files if WINDOWS then os.copydir(DATA_DIR.."/MTA", OUTPUT_DIR.."/MTA") @@ -25,8 +25,9 @@ newaction { -- Copy configs os.copydir("Server/mods/deathmatch", OUTPUT_DIR.."/server/mods/deathmatch", "*.conf") + os.copydir("Server/mods/deathmatch", OUTPUT_DIR.."/server/mods/deathmatch", "mtaserver.conf.template") os.copydir("Server/mods/deathmatch", OUTPUT_DIR.."/server/mods/deathmatch", "*.xml") - + -- Copy compiled binaries if WINDOWS then os.copydir(BIN_DIR, OUTPUT_DIR, "**.exe") diff --git a/utils/buildactions/install_data.lua b/utils/buildactions/install_data.lua index e2c40ec9a12..135ef02ad2c 100644 --- a/utils/buildactions/install_data.lua +++ b/utils/buildactions/install_data.lua @@ -49,6 +49,12 @@ newaction { return end + if not os.copyfile(BIN_DIR.."/server/mods/deathmatch/mtaserver.conf", BIN_DIR.."/server/mods/deathmatch/mtaserver.conf.template") then + errormsg("ERROR: Could not copy mtaserver.conf to mtaserver.conf.template") + os.exit(1) + return + end + local success, message = os.copydir("Server/mods/deathmatch", BIN_DIR.."/server/mods/deathmatch", "*.xml", false, true) if not success then errormsg("ERROR: Couldn't copy server xml files", "\n"..message) @@ -69,7 +75,7 @@ newaction { success = success and http.download_print_errors(NET_PATH_X64_WIN, BIN_DIR.."/server/x64/net.dll") success = success and http.download_print_errors(NET_PATH_ARM64_WIN, BIN_DIR.."/server/arm64/net.dll") success = success and http.download_print_errors(NETC_PATH_WIN, BIN_DIR.."/MTA/netc.dll") - + -- A download failed if not success then os.exit(1) From d3bb1ea3d2707798fe9fe84176a17038d68228c3 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Fri, 15 Nov 2024 11:44:58 +0000 Subject: [PATCH 04/11] include mtaserver.conf.template in installer --- Shared/installer/nightly.nsi | 1 + 1 file changed, 1 insertion(+) diff --git a/Shared/installer/nightly.nsi b/Shared/installer/nightly.nsi index d270a0d7194..3393386ba30 100644 --- a/Shared/installer/nightly.nsi +++ b/Shared/installer/nightly.nsi @@ -858,6 +858,7 @@ SectionGroup /e "$(INST_SEC_SERVER)" SECGSERVER File "${SERVER_FILES_ROOT}\mods\deathmatch\libcrypto-3.dll" File "${SERVER_FILES_ROOT}\mods\deathmatch\libssl-3.dll" !endif + File "${SERVER_FILES_ROOT}\mods\deathmatch\mtaserver.conf.template" ;Only overwrite the following files if previous versions were bugged and explicitly need replacing !insertmacro FileIfMD5 "${SERVER_FILES_ROOT}\mods\deathmatch\editor_acl.xml" "711185d8f4ebb355542053ce408b82b3" From 2796ea05d2712dbd4a02e6e448cfed9e7419bef9 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Fri, 15 Nov 2024 11:51:10 +0000 Subject: [PATCH 05/11] compose_files --- utils/buildactions/compose_files.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/buildactions/compose_files.lua b/utils/buildactions/compose_files.lua index 0adaf2cfc1a..4cc2bfae178 100644 --- a/utils/buildactions/compose_files.lua +++ b/utils/buildactions/compose_files.lua @@ -25,7 +25,7 @@ newaction { -- Copy configs os.copydir("Server/mods/deathmatch", OUTPUT_DIR.."/server/mods/deathmatch", "*.conf") - os.copydir("Server/mods/deathmatch", OUTPUT_DIR.."/server/mods/deathmatch", "mtaserver.conf.template") + os.copyfile(OUTPUT_DIR.."/server/mods/deathmatch/mtaserver.conf", OUTPUT_DIR.."/server/mods/deathmatch/mtaserver.conf.template") os.copydir("Server/mods/deathmatch", OUTPUT_DIR.."/server/mods/deathmatch", "*.xml") -- Copy compiled binaries From 8d3da297536e248594e32a395f3d5740b79f0cf9 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Mon, 18 Nov 2024 15:08:02 +0000 Subject: [PATCH 06/11] more refactoring --- Server/mods/deathmatch/logic/CMainConfig.cpp | 38 ++++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/Server/mods/deathmatch/logic/CMainConfig.cpp b/Server/mods/deathmatch/logic/CMainConfig.cpp index c8ca6eef4b5..f09dd5958dc 100644 --- a/Server/mods/deathmatch/logic/CMainConfig.cpp +++ b/Server/mods/deathmatch/logic/CMainConfig.cpp @@ -22,7 +22,7 @@ #include "CHTTPD.h" #include "CStaticFunctionDefinitions.h" -#define MTA_SERVER_CONF_TEMPLATE "mtaserver.conf.template" +#define SETTINGS_TEMPLATE_PATH "mtaserver.conf.template" extern CGame* g_pGame; @@ -853,44 +853,52 @@ bool CMainConfig::AddMissingSettings() if (!g_pGame->IsUsingMtaServerConf()) return false; - SString templateFileName = PathJoin(g_pServerInterface->GetServerModPath(), MTA_SERVER_CONF_TEMPLATE); + const std::string templateFileName = PathJoin(g_pServerInterface->GetServerModPath(), SETTINGS_TEMPLATE_PATH); if (!FileExists(templateFileName)) return false; - CXMLFile* templateFile = g_pServerInterface->GetXML()->CreateXML(templateFileName); - CXMLNode* templateRootNode = templateFile && templateFile->Parse() ? templateFile->GetRootNode() : nullptr; + std::unique_ptr templateFile(g_pServerInterface->GetXML()->CreateXML(templateFileName.c_str())); + if (!templateFile || !templateFile->Parse()) + { + CLogger::ErrorPrintf("Failed to parse template file: '%s'\n", templateFileName.c_str()); + return false; + } + + CXMLNode* templateRootNode = templateFile->GetRootNode(); if (!templateRootNode) { - CLogger::ErrorPrintf("Can't parse '%s'\n", *templateFileName); + CLogger::ErrorPrintf("Template file '%s' has no root node\n", templateFileName.c_str()); return false; } // Check that each item in the template also exists in the server config - bool configChanged = false; + bool configChanged = false; CXMLNode* previousNode = nullptr; + for (auto it = templateRootNode->ChildrenBegin(); it != templateRootNode->ChildrenEnd(); ++it) { CXMLNode* templateNode = *it; - SString templateNodeName = templateNode->GetTagName(); + const std::string& templateNodeName = templateNode->GetTagName(); // Skip certain optional nodes if (templateNodeName == "resource" || templateNodeName == "module") continue; - CXMLNode* foundNode = m_pRootNode->FindSubNode(templateNodeName); + CXMLNode* foundNode = m_pRootNode->FindSubNode(templateNodeName.c_str()); if (!foundNode) { - SString templateNodeValue = templateNode->GetTagContent(); - SString templateNodeComment = templateNode->GetCommentText(); - foundNode = m_pRootNode->CreateSubNode(templateNodeName, previousNode); - foundNode->SetTagContent(templateNodeValue); - foundNode->SetCommentText(templateNodeComment, true); - CLogger::LogPrintf("[%s] Added missing '%s' setting to mtaserver.conf\n", MTA_SERVER_CONF_TEMPLATE, *templateNodeName); + const std::string templateNodeValue = templateNode->GetTagContent(); + const std::string templateNodeComment = templateNode->GetCommentText(); + + foundNode = m_pRootNode->CreateSubNode(templateNodeName.c_str(), previousNode); + foundNode->SetTagContent(templateNodeValue.c_str()); + foundNode->SetCommentText(templateNodeComment.c_str(), true); + + CLogger::LogPrintf("Added missing '%s' setting to mtaserver.conf\n", &templateNodeName); configChanged = true; } previousNode = foundNode; } - g_pServerInterface->GetXML()->DeleteXML(templateFile); return configChanged; } From d3d57403403661388bfd7acc5669840c3f625db0 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Fri, 22 Nov 2024 11:07:15 +0000 Subject: [PATCH 07/11] mtaserver.conf.template add header comment --- utils/buildactions/compose_files.lua | 8 ++++---- utils/buildactions/install_data.lua | 4 ++-- utils/buildactions/utils.lua | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/utils/buildactions/compose_files.lua b/utils/buildactions/compose_files.lua index 4cc2bfae178..42bb664902f 100644 --- a/utils/buildactions/compose_files.lua +++ b/utils/buildactions/compose_files.lua @@ -11,10 +11,10 @@ local WINDOWS = os.host() == "windows" newaction { trigger = "compose_files", description = "Composes files that are required for building the installer", - + execute = function() os.mkdir(OUTPUT_DIR) - + -- Copy data files if WINDOWS then os.copydir(DATA_DIR.."/MTA", OUTPUT_DIR.."/MTA") @@ -25,9 +25,9 @@ newaction { -- Copy configs os.copydir("Server/mods/deathmatch", OUTPUT_DIR.."/server/mods/deathmatch", "*.conf") - os.copyfile(OUTPUT_DIR.."/server/mods/deathmatch/mtaserver.conf", OUTPUT_DIR.."/server/mods/deathmatch/mtaserver.conf.template") + os.makeconfigtemplate(OUTPUT_DIR.."/server/mods/deathmatch/mtaserver.conf", OUTPUT_DIR.."/server/mods/deathmatch/mtaserver.conf.template") os.copydir("Server/mods/deathmatch", OUTPUT_DIR.."/server/mods/deathmatch", "*.xml") - + -- Copy compiled binaries if WINDOWS then os.copydir(BIN_DIR, OUTPUT_DIR, "**.exe") diff --git a/utils/buildactions/install_data.lua b/utils/buildactions/install_data.lua index 135ef02ad2c..e05bc74fa07 100644 --- a/utils/buildactions/install_data.lua +++ b/utils/buildactions/install_data.lua @@ -49,7 +49,7 @@ newaction { return end - if not os.copyfile(BIN_DIR.."/server/mods/deathmatch/mtaserver.conf", BIN_DIR.."/server/mods/deathmatch/mtaserver.conf.template") then + if not os.makeconfigtemplate(BIN_DIR.."/server/mods/deathmatch/mtaserver.conf", BIN_DIR.."/server/mods/deathmatch/mtaserver.conf.template") then errormsg("ERROR: Could not copy mtaserver.conf to mtaserver.conf.template") os.exit(1) return @@ -75,7 +75,7 @@ newaction { success = success and http.download_print_errors(NET_PATH_X64_WIN, BIN_DIR.."/server/x64/net.dll") success = success and http.download_print_errors(NET_PATH_ARM64_WIN, BIN_DIR.."/server/arm64/net.dll") success = success and http.download_print_errors(NETC_PATH_WIN, BIN_DIR.."/MTA/netc.dll") - + -- A download failed if not success then os.exit(1) diff --git a/utils/buildactions/utils.lua b/utils/buildactions/utils.lua index 42899f4769b..97fd3deddb1 100644 --- a/utils/buildactions/utils.lua +++ b/utils/buildactions/utils.lua @@ -153,3 +153,25 @@ function errormsg(title, message) end term.popColor() end + +-- Does a normal file copy and adds hardcoded text to the beginning of the resulting file +-- Used in compose_files.lua and install_data.lua +function os.makeconfigtemplate(file_path, result_path) + if not os.copyfile(file_path, result_path) then + return false + end + local result_file = io.open(result_path, "r") + if not result_file then + return false + end + local file_content = result_file:read("*all") + result_file:close() + result_file = io.open(result_path, "w") + if not result_file then + return false, "Failed to open result file for writing." + end + result_file:write("\n") + result_file:write(file_content) + result_file:close() + return true +end From 37e92542c8c68f8c0c3661a63a42a70285bc9ea9 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Fri, 22 Nov 2024 11:10:18 +0000 Subject: [PATCH 08/11] rename func --- utils/buildactions/compose_files.lua | 2 +- utils/buildactions/install_data.lua | 2 +- utils/buildactions/utils.lua | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/buildactions/compose_files.lua b/utils/buildactions/compose_files.lua index 42bb664902f..a9fa9679567 100644 --- a/utils/buildactions/compose_files.lua +++ b/utils/buildactions/compose_files.lua @@ -25,7 +25,7 @@ newaction { -- Copy configs os.copydir("Server/mods/deathmatch", OUTPUT_DIR.."/server/mods/deathmatch", "*.conf") - os.makeconfigtemplate(OUTPUT_DIR.."/server/mods/deathmatch/mtaserver.conf", OUTPUT_DIR.."/server/mods/deathmatch/mtaserver.conf.template") + makeconfigtemplate(OUTPUT_DIR.."/server/mods/deathmatch/mtaserver.conf", OUTPUT_DIR.."/server/mods/deathmatch/mtaserver.conf.template") os.copydir("Server/mods/deathmatch", OUTPUT_DIR.."/server/mods/deathmatch", "*.xml") -- Copy compiled binaries diff --git a/utils/buildactions/install_data.lua b/utils/buildactions/install_data.lua index e05bc74fa07..0b9dff9c604 100644 --- a/utils/buildactions/install_data.lua +++ b/utils/buildactions/install_data.lua @@ -49,7 +49,7 @@ newaction { return end - if not os.makeconfigtemplate(BIN_DIR.."/server/mods/deathmatch/mtaserver.conf", BIN_DIR.."/server/mods/deathmatch/mtaserver.conf.template") then + if not makeconfigtemplate(BIN_DIR.."/server/mods/deathmatch/mtaserver.conf", BIN_DIR.."/server/mods/deathmatch/mtaserver.conf.template") then errormsg("ERROR: Could not copy mtaserver.conf to mtaserver.conf.template") os.exit(1) return diff --git a/utils/buildactions/utils.lua b/utils/buildactions/utils.lua index 97fd3deddb1..f4c8482099b 100644 --- a/utils/buildactions/utils.lua +++ b/utils/buildactions/utils.lua @@ -156,7 +156,7 @@ end -- Does a normal file copy and adds hardcoded text to the beginning of the resulting file -- Used in compose_files.lua and install_data.lua -function os.makeconfigtemplate(file_path, result_path) +function makeconfigtemplate(file_path, result_path) if not os.copyfile(file_path, result_path) then return false end From 8d4947af3be733b6c49ca459810accd1f3568f56 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Sun, 5 Jan 2025 14:58:20 +0000 Subject: [PATCH 09/11] del mtaserverconf.template --- .../mods/deathmatch/mtaserver.conf.template | 316 ------------------ 1 file changed, 316 deletions(-) delete mode 100644 Server/mods/deathmatch/mtaserver.conf.template diff --git a/Server/mods/deathmatch/mtaserver.conf.template b/Server/mods/deathmatch/mtaserver.conf.template deleted file mode 100644 index 1cb27e157ed..00000000000 --- a/Server/mods/deathmatch/mtaserver.conf.template +++ /dev/null @@ -1,316 +0,0 @@ - - - - Default MTA Server - - - - - - - - - - - - - - - - - - - - - - - - - - - auto - - - 22003 - - - 32 - - - 22005 - - - - - - 5 - - - 20 - - - - - - none - - - - - - - - - - - - - - - - 1 - - - - - - 1 - - - 0 - - - - - - medium - - - - 100 - - 1500 - - 500 - - 400 - - 2000 - - 400 - - 100 - - 100 - - - 1 - - - 30 - - - 0 - - - 150 - - - 0 - - - server-id.keys - - - logs/server.log - - - logs/server_auth.log - - - logs/db.log - - - - - - acl.xml - - - logs/scripts.log - - - 0 - - - 0 - - - 1 - - - 60 - - - 0 - - - 1 - - - 4 - - - - - - backups - - - 3 - - - 10 - - - 1 - - - 1 - - - Admin - - - 1 - - - 127.0.0.1 - - - 1 - - - 0 - - - 1 - - - 1000 - 100 - - - 1 - From d9fa84b23e784ceeb4aa60c169266c4173a0a578 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Sun, 5 Jan 2025 15:02:50 +0000 Subject: [PATCH 10/11] reviews --- Server/mods/deathmatch/logic/CMainConfig.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Server/mods/deathmatch/logic/CMainConfig.cpp b/Server/mods/deathmatch/logic/CMainConfig.cpp index 3d5bd7858f5..9c11d91cec4 100644 --- a/Server/mods/deathmatch/logic/CMainConfig.cpp +++ b/Server/mods/deathmatch/logic/CMainConfig.cpp @@ -899,13 +899,13 @@ bool CMainConfig::AddMissingSettings() if (!foundNode) { const std::string templateNodeValue = templateNode->GetTagContent(); - const std::string templateNodeComment = templateNode->GetCommentText(); + const SString templateNodeComment = templateNode->GetCommentText(); foundNode = m_pRootNode->CreateSubNode(templateNodeName.c_str(), previousNode); foundNode->SetTagContent(templateNodeValue.c_str()); foundNode->SetCommentText(templateNodeComment.c_str(), true); - CLogger::LogPrintf("Added missing '%s' setting to mtaserver.conf\n", &templateNodeName); + CLogger::LogPrintf("Added missing '%s' setting to mtaserver.conf\n", templateNodeName.c_str()); configChanged = true; } previousNode = foundNode; From bd5db2c4b69e8169b64f19362df549eb9c2d73ce Mon Sep 17 00:00:00 2001 From: Fernando Rocha <34967844+Fernando-A-Rocha@users.noreply.github.com> Date: Wed, 8 Jan 2025 14:04:44 +0000 Subject: [PATCH 11/11] Update CMainConfig.cpp --- Server/mods/deathmatch/logic/CMainConfig.cpp | 41 +++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/Server/mods/deathmatch/logic/CMainConfig.cpp b/Server/mods/deathmatch/logic/CMainConfig.cpp index 9c11d91cec4..3a6e6f961e3 100644 --- a/Server/mods/deathmatch/logic/CMainConfig.cpp +++ b/Server/mods/deathmatch/logic/CMainConfig.cpp @@ -894,8 +894,45 @@ bool CMainConfig::AddMissingSettings() // Skip certain optional nodes if (templateNodeName == "resource" || templateNodeName == "module") continue; - - CXMLNode* foundNode = m_pRootNode->FindSubNode(templateNodeName.c_str()); + + // Find node with exact same attributes + CXMLAttributes& templateAttributes = templateNode->GetAttributes(); + CXMLNode* foundNode = nullptr; + for (auto it2 = m_pRootNode->ChildrenBegin(); it2 != m_pRootNode->ChildrenEnd(); ++it2) + { + CXMLNode* tempNode = *it2; + if (tempNode->GetTagName() != templateNodeName) + continue; + + CXMLAttributes& attributes = tempNode->GetAttributes(); + bool attributesMatch = true; + + for (auto it3 = templateAttributes.ListBegin(); it3 != templateAttributes.ListEnd(); ++it3) + { + CXMLAttribute* templateAttribute = *it3; + const SString& attrName = templateAttribute->GetName(); + + // Don't check value attribute which is intended to be different + if (attrName == "value") + continue; + + const SString& attrValue = templateAttribute->GetValue(); + + CXMLAttribute* foundAttribute = attributes.Find(attrName); + if (!foundAttribute || foundAttribute->GetValue() != attrValue) + { + attributesMatch = false; + break; + } + } + + if (attributesMatch) + { + foundNode = tempNode; + break; + } + } + if (!foundNode) { const std::string templateNodeValue = templateNode->GetTagContent();