Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 48 additions & 3 deletions Server/mods/deathmatch/logic/CResource.AclRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ bool CResource::HasAutoPermissions(CXMLNode* pNodeAclRequest)
///////////////////////////////////////////////////////////////
void CResource::RefreshAutoPermissions(CXMLNode* pNodeAclRequest)
{
// Check if permissions already active
if (HasAutoPermissions(pNodeAclRequest))
return;

// Ensure group and acl exist
CAccessControlListGroup* pAutoGroup = g_pGame->GetACLManager()->AddGroup(GetAutoGroupName());
Expand Down Expand Up @@ -372,3 +369,51 @@ 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<CXMLFile> 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;
}
13 changes: 13 additions & 0 deletions Server/mods/deathmatch/logic/CResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ bool CResource::Load()
else
RemoveAutoPermissions();

m_strACLRequestFingerprint = CalculateACLRequestFingerprint();

// Find any map sync option
m_bSyncMapElementData = true;
m_bSyncMapElementDataDefined = false;
Expand Down Expand Up @@ -351,6 +353,7 @@ bool CResource::Unload()
m_strResourceZip = "";
m_strResourceCachePath = "";
m_strResourceDirectoryPath = "";
m_strACLRequestFingerprint.clear();
m_eState = EResourceState::None;

return true;
Expand Down Expand Up @@ -402,6 +405,8 @@ CResource::~CResource()

void CResource::TidyUp()
{
RemoveAutoPermissions();

// Close the zipfile stuff
if (m_zipfile)
unzClose(m_zipfile);
Expand Down Expand Up @@ -678,6 +683,11 @@ bool CResource::HasResourceChanged()
return true;
}

if (HasACLRequestsChanged())
{
return true;
}

return false;
}

Expand Down Expand Up @@ -1195,6 +1205,9 @@ 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;
Expand Down
6 changes: 5 additions & 1 deletion Server/mods/deathmatch/logic/CResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,10 @@ class CResource : public EHS
void RefreshAutoPermissions(CXMLNode* pNodeAclRequest);

void CommitAclRequest(const SAclRequest& request);
bool FindAclRequest(SAclRequest& request);
bool FindAclRequest(SAclRequest& result);

std::string CalculateACLRequestFingerprint();
bool HasACLRequestsChanged();

private:
bool CheckState(); // if the resource has no Dependents, stop it, if it has, start it. returns true if the resource is started.
Expand Down Expand Up @@ -450,6 +453,7 @@ 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<lua_CFunction, bool> m_FunctionRightCacheMap;
Expand Down
8 changes: 8 additions & 0 deletions Server/mods/deathmatch/logic/CResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ bool CResourceManager::Refresh(bool bRefreshAll, const SString strJustThisResour
// Add the resource
Load(!info.bIsDir, info.strAbsPath, info.strName);
}
else if (pResource && pResource->HasResourceChanged())
{
if (g_pServerInterface->IsRequestingExit())
return false;

// Resource exists but has changed, reload it
Load(!info.bIsDir, info.strAbsPath, info.strName);
}
}
}

Expand Down
Loading