From 07cb21d204f531adc19a8eca1c97c8c89c53e844 Mon Sep 17 00:00:00 2001 From: Mohab <133429578+MohabCodeX@users.noreply.github.com> Date: Sun, 21 Sep 2025 23:51:19 +0300 Subject: [PATCH] Refactor ACL request handling --- .../deathmatch/logic/CResource.AclRequest.cpp | 48 ----------------- Server/mods/deathmatch/logic/CResource.cpp | 13 ----- Server/mods/deathmatch/logic/CResource.h | 6 +-- .../deathmatch/logic/CResourceManager.cpp | 51 ++++++++++++------- 4 files changed, 34 insertions(+), 84 deletions(-) diff --git a/Server/mods/deathmatch/logic/CResource.AclRequest.cpp b/Server/mods/deathmatch/logic/CResource.AclRequest.cpp index 16fd39f9463..9e6dbbc5f67 100644 --- a/Server/mods/deathmatch/logic/CResource.AclRequest.cpp +++ b/Server/mods/deathmatch/logic/CResource.AclRequest.cpp @@ -369,51 +369,3 @@ bool CResource::FindAclRequest(SAclRequest& result) return pAclRight->GetAttributeValue("pending") != ""; } - -std::string CResource::CalculateACLRequestFingerprint() -{ - std::string strPath; - if (!GetFilePath("meta.xml", strPath)) - return {}; - - std::unique_ptr metaFile(g_pServerInterface->GetXML()->CreateXML(strPath.c_str())); - if (!metaFile || !metaFile->Parse()) - { - return {}; - } - - CXMLNode* root = metaFile->GetRootNode(); - if (!root) - { - return {}; - } - - std::ostringstream fingerprint; - CXMLNode* nodeAclRequest = root->FindSubNode("aclrequest", 0); - - if (nodeAclRequest) - { - for (std::uint8_t uiIndex = 0; true; uiIndex++) - { - CXMLNode* nodeRight = nodeAclRequest->FindSubNode("right", uiIndex); - if (!nodeRight) - break; - - std::string strName = nodeRight->GetAttributeValue("name"); - std::string strAccess = nodeRight->GetAttributeValue("access"); - - if (uiIndex > 0) - fingerprint << ";"; - - fingerprint << strName << ":" << strAccess; - } - } - - return fingerprint.str(); -} - -bool CResource::HasACLRequestsChanged() -{ - std::string strCurrentFingerprint = CalculateACLRequestFingerprint(); - return strCurrentFingerprint != m_strACLRequestFingerprint; -} diff --git a/Server/mods/deathmatch/logic/CResource.cpp b/Server/mods/deathmatch/logic/CResource.cpp index 59d0d29f7a4..fa1fe5c2f53 100644 --- a/Server/mods/deathmatch/logic/CResource.cpp +++ b/Server/mods/deathmatch/logic/CResource.cpp @@ -196,8 +196,6 @@ bool CResource::Load() else RemoveAutoPermissions(); - m_strACLRequestFingerprint = CalculateACLRequestFingerprint(); - // Find any map sync option m_bSyncMapElementData = true; m_bSyncMapElementDataDefined = false; @@ -353,7 +351,6 @@ bool CResource::Unload() m_strResourceZip = ""; m_strResourceCachePath = ""; m_strResourceDirectoryPath = ""; - m_strACLRequestFingerprint.clear(); m_eState = EResourceState::None; return true; @@ -405,8 +402,6 @@ CResource::~CResource() void CResource::TidyUp() { - RemoveAutoPermissions(); - // Close the zipfile stuff if (m_zipfile) unzClose(m_zipfile); @@ -683,11 +678,6 @@ bool CResource::HasResourceChanged() return true; } - if (HasACLRequestsChanged()) - { - return true; - } - return false; } @@ -1205,9 +1195,6 @@ bool CResource::Stop(bool bManualStop) // Clear the list of players where this resource is running std::exchange(m_isRunningForPlayer, {}); - // Remove ACL permissions when stopping - RemoveAutoPermissions(); - OnResourceStateChange("loaded"); m_eState = EResourceState::Loaded; return true; diff --git a/Server/mods/deathmatch/logic/CResource.h b/Server/mods/deathmatch/logic/CResource.h index eeb05f5c67a..20feea77107 100644 --- a/Server/mods/deathmatch/logic/CResource.h +++ b/Server/mods/deathmatch/logic/CResource.h @@ -335,8 +335,6 @@ class CResource : public EHS public: static std::list m_StartedResources; - -protected: SString GetAutoGroupName(); SString GetAutoAclName(); CAccessControlList* GetAutoAcl(); @@ -349,8 +347,7 @@ class CResource : public EHS void CommitAclRequest(const SAclRequest& request); bool FindAclRequest(SAclRequest& result); - std::string CalculateACLRequestFingerprint(); - bool HasACLRequestsChanged(); +protected: private: bool CheckState(); // if the resource has no Dependents, stop it, if it has, start it. returns true if the resource is started. @@ -453,7 +450,6 @@ class CResource : public EHS SString m_strMinServerReason; CChecksum m_metaChecksum; // Checksum of meta.xml last time this was loaded, generated in GenerateChecksums() - std::string m_strACLRequestFingerprint; uint m_uiFunctionRightCacheRevision = 0; CFastHashMap m_FunctionRightCacheMap; diff --git a/Server/mods/deathmatch/logic/CResourceManager.cpp b/Server/mods/deathmatch/logic/CResourceManager.cpp index 8e6d58c6b5a..24102eb63f2 100644 --- a/Server/mods/deathmatch/logic/CResourceManager.cpp +++ b/Server/mods/deathmatch/logic/CResourceManager.cpp @@ -172,27 +172,42 @@ bool CResourceManager::Refresh(bool bRefreshAll, const SString strJustThisResour if (!strJustThisResource.empty() && strJustThisResource != info.strName) continue; - if (!info.bPathIssue) - { - CResource* pResource = GetResource(info.strName); + if (info.bPathIssue) + continue; - if (bRefreshAll || !pResource || !pResource->CheckIfStartable()) - { - if (g_pServerInterface->IsRequestingExit()) - return false; + auto* pResource = GetResource(info.strName); - // Add the resource - Load(!info.bIsDir, info.strAbsPath, info.strName); - } - else if (bRefreshAll && pResource && pResource->HasResourceChanged()) - { - if (g_pServerInterface->IsRequestingExit()) - return false; - - // Resource exists but has changed, reload it - Load(!info.bIsDir, info.strAbsPath, info.strName); - } + if (bRefreshAll || !pResource || !pResource->CheckIfStartable()) + { + if (g_pServerInterface->IsRequestingExit()) + return false; + + // Add the resource + Load(!info.bIsDir, info.strAbsPath, info.strName); + continue; } + + if (!pResource) + continue; + + // For existing resources, refresh ACL permissions without full reload + std::string strPath; + if (!pResource->GetFilePath("meta.xml", strPath)) + continue; + + std::unique_ptr pMetaFile(g_pServerInterface->GetXML()->CreateXML(strPath.c_str())); + if (!pMetaFile || !pMetaFile->Parse()) + continue; + + CXMLNode* pRoot = pMetaFile->GetRootNode(); + if (!pRoot) + continue; + + CXMLNode* pNodeAclRequest = pRoot->FindSubNode("aclrequest", 0); + if (pNodeAclRequest) + pResource->RefreshAutoPermissions(pNodeAclRequest); + else + pResource->RemoveAutoPermissions(); } marker.Set("AddNew");