Skip to content

Commit 07cb21d

Browse files
committed
Refactor ACL request handling
1 parent 50be993 commit 07cb21d

File tree

4 files changed

+34
-84
lines changed

4 files changed

+34
-84
lines changed

Server/mods/deathmatch/logic/CResource.AclRequest.cpp

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -369,51 +369,3 @@ bool CResource::FindAclRequest(SAclRequest& result)
369369

370370
return pAclRight->GetAttributeValue("pending") != "";
371371
}
372-
373-
std::string CResource::CalculateACLRequestFingerprint()
374-
{
375-
std::string strPath;
376-
if (!GetFilePath("meta.xml", strPath))
377-
return {};
378-
379-
std::unique_ptr<CXMLFile> metaFile(g_pServerInterface->GetXML()->CreateXML(strPath.c_str()));
380-
if (!metaFile || !metaFile->Parse())
381-
{
382-
return {};
383-
}
384-
385-
CXMLNode* root = metaFile->GetRootNode();
386-
if (!root)
387-
{
388-
return {};
389-
}
390-
391-
std::ostringstream fingerprint;
392-
CXMLNode* nodeAclRequest = root->FindSubNode("aclrequest", 0);
393-
394-
if (nodeAclRequest)
395-
{
396-
for (std::uint8_t uiIndex = 0; true; uiIndex++)
397-
{
398-
CXMLNode* nodeRight = nodeAclRequest->FindSubNode("right", uiIndex);
399-
if (!nodeRight)
400-
break;
401-
402-
std::string strName = nodeRight->GetAttributeValue("name");
403-
std::string strAccess = nodeRight->GetAttributeValue("access");
404-
405-
if (uiIndex > 0)
406-
fingerprint << ";";
407-
408-
fingerprint << strName << ":" << strAccess;
409-
}
410-
}
411-
412-
return fingerprint.str();
413-
}
414-
415-
bool CResource::HasACLRequestsChanged()
416-
{
417-
std::string strCurrentFingerprint = CalculateACLRequestFingerprint();
418-
return strCurrentFingerprint != m_strACLRequestFingerprint;
419-
}

Server/mods/deathmatch/logic/CResource.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ bool CResource::Load()
196196
else
197197
RemoveAutoPermissions();
198198

199-
m_strACLRequestFingerprint = CalculateACLRequestFingerprint();
200-
201199
// Find any map sync option
202200
m_bSyncMapElementData = true;
203201
m_bSyncMapElementDataDefined = false;
@@ -353,7 +351,6 @@ bool CResource::Unload()
353351
m_strResourceZip = "";
354352
m_strResourceCachePath = "";
355353
m_strResourceDirectoryPath = "";
356-
m_strACLRequestFingerprint.clear();
357354
m_eState = EResourceState::None;
358355

359356
return true;
@@ -405,8 +402,6 @@ CResource::~CResource()
405402

406403
void CResource::TidyUp()
407404
{
408-
RemoveAutoPermissions();
409-
410405
// Close the zipfile stuff
411406
if (m_zipfile)
412407
unzClose(m_zipfile);
@@ -683,11 +678,6 @@ bool CResource::HasResourceChanged()
683678
return true;
684679
}
685680

686-
if (HasACLRequestsChanged())
687-
{
688-
return true;
689-
}
690-
691681
return false;
692682
}
693683

@@ -1205,9 +1195,6 @@ bool CResource::Stop(bool bManualStop)
12051195
// Clear the list of players where this resource is running
12061196
std::exchange(m_isRunningForPlayer, {});
12071197

1208-
// Remove ACL permissions when stopping
1209-
RemoveAutoPermissions();
1210-
12111198
OnResourceStateChange("loaded");
12121199
m_eState = EResourceState::Loaded;
12131200
return true;

Server/mods/deathmatch/logic/CResource.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,6 @@ class CResource : public EHS
335335

336336
public:
337337
static std::list<CResource*> m_StartedResources;
338-
339-
protected:
340338
SString GetAutoGroupName();
341339
SString GetAutoAclName();
342340
CAccessControlList* GetAutoAcl();
@@ -349,8 +347,7 @@ class CResource : public EHS
349347
void CommitAclRequest(const SAclRequest& request);
350348
bool FindAclRequest(SAclRequest& result);
351349

352-
std::string CalculateACLRequestFingerprint();
353-
bool HasACLRequestsChanged();
350+
protected:
354351

355352
private:
356353
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
453450
SString m_strMinServerReason;
454451

455452
CChecksum m_metaChecksum; // Checksum of meta.xml last time this was loaded, generated in GenerateChecksums()
456-
std::string m_strACLRequestFingerprint;
457453

458454
uint m_uiFunctionRightCacheRevision = 0;
459455
CFastHashMap<lua_CFunction, bool> m_FunctionRightCacheMap;

Server/mods/deathmatch/logic/CResourceManager.cpp

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -172,27 +172,42 @@ bool CResourceManager::Refresh(bool bRefreshAll, const SString strJustThisResour
172172
if (!strJustThisResource.empty() && strJustThisResource != info.strName)
173173
continue;
174174

175-
if (!info.bPathIssue)
176-
{
177-
CResource* pResource = GetResource(info.strName);
175+
if (info.bPathIssue)
176+
continue;
178177

179-
if (bRefreshAll || !pResource || !pResource->CheckIfStartable())
180-
{
181-
if (g_pServerInterface->IsRequestingExit())
182-
return false;
178+
auto* pResource = GetResource(info.strName);
183179

184-
// Add the resource
185-
Load(!info.bIsDir, info.strAbsPath, info.strName);
186-
}
187-
else if (bRefreshAll && pResource && pResource->HasResourceChanged())
188-
{
189-
if (g_pServerInterface->IsRequestingExit())
190-
return false;
191-
192-
// Resource exists but has changed, reload it
193-
Load(!info.bIsDir, info.strAbsPath, info.strName);
194-
}
180+
if (bRefreshAll || !pResource || !pResource->CheckIfStartable())
181+
{
182+
if (g_pServerInterface->IsRequestingExit())
183+
return false;
184+
185+
// Add the resource
186+
Load(!info.bIsDir, info.strAbsPath, info.strName);
187+
continue;
195188
}
189+
190+
if (!pResource)
191+
continue;
192+
193+
// For existing resources, refresh ACL permissions without full reload
194+
std::string strPath;
195+
if (!pResource->GetFilePath("meta.xml", strPath))
196+
continue;
197+
198+
std::unique_ptr<CXMLFile> pMetaFile(g_pServerInterface->GetXML()->CreateXML(strPath.c_str()));
199+
if (!pMetaFile || !pMetaFile->Parse())
200+
continue;
201+
202+
CXMLNode* pRoot = pMetaFile->GetRootNode();
203+
if (!pRoot)
204+
continue;
205+
206+
CXMLNode* pNodeAclRequest = pRoot->FindSubNode("aclrequest", 0);
207+
if (pNodeAclRequest)
208+
pResource->RefreshAutoPermissions(pNodeAclRequest);
209+
else
210+
pResource->RemoveAutoPermissions();
196211
}
197212

198213
marker.Set("AddNew");

0 commit comments

Comments
 (0)