Skip to content

Fixes #4299 - Isolate Client Resource Cache by Server #4311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
50 changes: 47 additions & 3 deletions Client/mods/deathmatch/logic/CResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ CResource::CResource(unsigned short usNetID, const char* szResourceName, CClient
m_pResourceIMGRoot = new CClientDummy(g_pClientGame->GetManager(), INVALID_ELEMENT_ID, "imgroot");
m_pResourceIMGRoot->MakeSystemEntity();

m_strResourceDirectoryPath = SString("%s/resources/%s", g_pClientGame->GetFileCacheRoot(), *m_strResourceName);
m_strResourceDirectoryPath = SString("%s/resources/%s/%s", g_pClientGame->GetFileCacheRoot(), *GetServerCacheId(), *m_strResourceName);
m_strResourcePrivateDirectoryPath = PathJoin(CServerIdManager::GetSingleton()->GetConnectionPrivateDirectory(), m_strResourceName);

m_strResourcePrivateDirectoryPathOld = CServerIdManager::GetSingleton()->GetConnectionPrivateDirectory(true);
Expand Down Expand Up @@ -174,7 +174,15 @@ CDownloadableResource* CResource::AddResourceFile(CDownloadableResource::eResour
CChecksum serverChecksum, bool bAutoDownload)
{
// Create the resource file and add it to the list
SString strBuffer("%s\\resources\\%s\\%s", g_pClientGame->GetFileCacheRoot(), *m_strResourceName, szFileName);
SString strBuffer("%s\\resources\\%s\\%s\\%s", g_pClientGame->GetFileCacheRoot(), *GetServerCacheId(), *m_strResourceName, szFileName);

// Check for legacy resource and migrate if found
SString strLegacyPath("%s\\resources\\%s\\%s", g_pClientGame->GetFileCacheRoot(), *m_strResourceName, szFileName);
if (!FileExists(strBuffer) && FileExists(strLegacyPath))
{
MakeSureDirExists(strBuffer);
FileCopy(strLegacyPath, strBuffer);
}

// Reject duplicates
if (g_pClientGame->GetResourceManager()->IsResourceFile(strBuffer))
Expand All @@ -195,7 +203,15 @@ CDownloadableResource* CResource::AddResourceFile(CDownloadableResource::eResour
CDownloadableResource* CResource::AddConfigFile(const char* szFileName, uint uiDownloadSize, CChecksum serverChecksum)
{
// Create the config file and add it to the list
SString strBuffer("%s\\resources\\%s\\%s", g_pClientGame->GetFileCacheRoot(), *m_strResourceName, szFileName);
SString strBuffer("%s\\resources\\%s\\%s\\%s", g_pClientGame->GetFileCacheRoot(), *GetServerCacheId(), *m_strResourceName, szFileName);

// Check for legacy resource and migrate if found
SString strLegacyPath("%s\\resources\\%s\\%s", g_pClientGame->GetFileCacheRoot(), *m_strResourceName, szFileName);
if (!FileExists(strBuffer) && FileExists(strLegacyPath))
{
MakeSureDirExists(strBuffer);
FileCopy(strLegacyPath, strBuffer);
}

// Reject duplicates
if (g_pClientGame->GetResourceManager()->IsResourceFile(strBuffer))
Expand Down Expand Up @@ -416,6 +432,34 @@ void CResource::ShowCursor(bool bShow, bool bToggleControls)
}
}

SString CResource::GetServerCacheId()
{
static SString s_strCachedServerId;
static SString s_strLastPrivateDir;

SString strPrivateDir = CServerIdManager::GetSingleton()->GetConnectionPrivateDirectory();
if (strPrivateDir != s_strLastPrivateDir)
{
s_strLastPrivateDir = strPrivateDir;
s_strCachedServerId.clear();
}

if (s_strCachedServerId.empty())
{
if (!strPrivateDir.empty())
{
size_t slashPos = strPrivateDir.find_last_of("/\\");
if (slashPos != SString::npos)
s_strCachedServerId = strPrivateDir.substr(slashPos + 1);
}

if (s_strCachedServerId.empty())
s_strCachedServerId = "default";
}

return s_strCachedServerId;
}

SString CResource::GetResourceDirectoryPath(eAccessType accessType, const SString& strMetaPath)
{
// See if private files should be moved to a new directory
Expand Down
7 changes: 4 additions & 3 deletions Client/mods/deathmatch/logic/CResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ class CResource
const CMtaVersion& GetMinClientReq() const { return m_strMinClientReq; }
bool IsOOPEnabled() { return m_bOOPEnabled; }
void HandleDownloadedFileTrouble(CResourceFile* pResourceFile, bool bScript);
bool IsWaitingForInitialDownloads();
int GetDownloadPriorityGroup() { return m_iDownloadPriorityGroup; }
void SetDownloadPriorityGroup(int iDownloadPriorityGroup) { m_iDownloadPriorityGroup = iDownloadPriorityGroup; }
bool IsWaitingForInitialDownloads();
int GetDownloadPriorityGroup() { return m_iDownloadPriorityGroup; }
void SetDownloadPriorityGroup(int iDownloadPriorityGroup) { m_iDownloadPriorityGroup = iDownloadPriorityGroup; }

private:
SString GetServerCacheId();
unsigned short m_usNetID;
uint m_uiScriptID;
SString m_strResourceName;
Expand Down
Loading