Skip to content
Permalink
Browse files

Merge remote-tracking branch 'upstream/master' into feature/lua-packages

  • Loading branch information...
patrikjuvonen committed Feb 22, 2019
2 parents 4f299a1 + 51b946d commit 8b7258194f5cc761e9a8fcc0404bd17b5243c99d
@@ -1,10 +1,8 @@
language: cpp
sudo: false
dist: xenial

matrix:
allow_failures:
- os: osx

include:
- compiler: gcc
addons:
@@ -23,13 +21,13 @@ matrix:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-4.0
- llvm-toolchain-xenial-6.0
packages:
- clang-4.0
- clang-6.0
- zip
env:
ENV_CXX=clang++-4.0
ENV_CC=clang-4.0
ENV_CXX=clang++-6.0
ENV_CC=clang-6.0
NIGHTLY_UPLOAD=0

before_script:
@@ -95,14 +95,11 @@ void CClientStreamElement::NotifyCreate()
m_bDoubleSided = IsDoubleSided();
SetDoubleSided(m_bDoubleSided);

if (!m_bStreamedIn)
{
m_bStreamedIn = true;
m_bAttemptingToStreamIn = false;
m_bStreamedIn = true;
m_bAttemptingToStreamIn = false;

CLuaArguments Arguments;
CallEvent("onClientElementStreamIn", Arguments, true);
}
CLuaArguments Arguments;
CallEvent("onClientElementStreamIn", Arguments, true);
}

void CClientStreamElement::NotifyUnableToCreate()
@@ -99,14 +99,14 @@ bool CResource::Load()
m_strResourceDirectoryPath = PathJoin(m_strAbsPath, m_strResourceName, "/");
m_strResourceCachePath = PathJoin(g_pServerInterface->GetServerModPath(), "resource-cache", "unzipped", m_strResourceName, "/");
m_strResourceZip = PathJoin(m_strAbsPath, m_strResourceName + ".zip");

if (m_bResourceIsZip)
{
if (!UnzipResource())
{
// Unregister EHS stuff
g_pGame->GetHTTPD()->UnregisterEHS(m_strResourceName.c_str());

return false;
}
}
@@ -466,74 +466,79 @@ void CResource::SetInfoValue(const char* szKey, const char* szValue, bool bSave)
}
}

bool CResource::GenerateChecksums()
std::future<SString> CResource::GenerateChecksumForFile(CResourceFile* pResourceFile)
{
std::vector<std::future<SString>> checksumTasks;
checksumTasks.reserve(m_ResourceFiles.size());
return SharedUtil::async([pResourceFile, this] {
SString strPath;

for (CResourceFile* pResourceFile : m_ResourceFiles)
{
checksumTasks.push_back(std::async(std::launch::async, [pResourceFile, this] {
SString strPath;

if (!GetFilePath(pResourceFile->GetName(), strPath))
return SString();

std::vector<char> buffer;
FileLoad(strPath, buffer);
uint uiFileSize = buffer.size();
const char* pFileContents = uiFileSize ? buffer.data() : "";
CChecksum Checksum = CChecksum::GenerateChecksumFromBuffer(pFileContents, uiFileSize);
pResourceFile->SetLastChecksum(Checksum);
pResourceFile->SetLastFileSize(uiFileSize);

// Check if file is blocked
char szHashResult[33];
CMD5Hasher::ConvertToHex(pResourceFile->GetLastChecksum().md5, szHashResult);
SString strBlockReason = m_pResourceManager->GetBlockedFileReason(szHashResult);

if (!strBlockReason.empty())
{
return SString("file '%s' is blocked (%s)", pResourceFile->GetName(), *strBlockReason);
}

// Copy file to http holding directory
switch (pResourceFile->GetType())
if (!GetFilePath(pResourceFile->GetName(), strPath))
return SString();

std::vector<char> buffer;
FileLoad(strPath, buffer);
uint uiFileSize = buffer.size();
const char* pFileContents = uiFileSize ? buffer.data() : "";
CChecksum Checksum = CChecksum::GenerateChecksumFromBuffer(pFileContents, uiFileSize);
pResourceFile->SetLastChecksum(Checksum);
pResourceFile->SetLastFileSize(uiFileSize);

// Check if file is blocked
char szHashResult[33];
CMD5Hasher::ConvertToHex(pResourceFile->GetLastChecksum().md5, szHashResult);
SString strBlockReason = m_pResourceManager->GetBlockedFileReason(szHashResult);

if (!strBlockReason.empty())
{
return SString("file '%s' is blocked (%s)", pResourceFile->GetName(), *strBlockReason);
}

// Copy file to http holding directory
switch (pResourceFile->GetType())
{
case CResourceFile::RESOURCE_FILE_TYPE_CLIENT_SCRIPT:
case CResourceFile::RESOURCE_FILE_TYPE_CLIENT_CONFIG:
case CResourceFile::RESOURCE_FILE_TYPE_CLIENT_FILE:
{
case CResourceFile::RESOURCE_FILE_TYPE_CLIENT_SCRIPT:
case CResourceFile::RESOURCE_FILE_TYPE_CLIENT_CONFIG:
case CResourceFile::RESOURCE_FILE_TYPE_CLIENT_FILE:
SString strCachedFilePath = pResourceFile->GetCachedPathFilename();

if (!g_pRealNetServer->ValidateHttpCacheFileName(strCachedFilePath))
{
SString strCachedFilePath = pResourceFile->GetCachedPathFilename();

if (!g_pRealNetServer->ValidateHttpCacheFileName(strCachedFilePath))
{
FileDelete(strCachedFilePath);
return SString("ERROR: Resource '%s' client filename '%s' not allowed\n", GetName().c_str(), *ExtractFilename(strCachedFilePath));
}

CChecksum cachedChecksum = CChecksum::GenerateChecksumFromFile(strCachedFilePath);

if (pResourceFile->GetLastChecksum() != cachedChecksum)
FileDelete(strCachedFilePath);
return SString("ERROR: Resource '%s' client filename '%s' not allowed\n", GetName().c_str(), *ExtractFilename(strCachedFilePath));
}

CChecksum cachedChecksum = CChecksum::GenerateChecksumFromFile(strCachedFilePath);

if (pResourceFile->GetLastChecksum() != cachedChecksum)
{
if (!FileSave(strCachedFilePath, pFileContents, uiFileSize))
{
if (!FileSave(strCachedFilePath, pFileContents, uiFileSize))
{
return SString("Could not copy '%s' to '%s'\n", *strPath, *strCachedFilePath);
}

// If script is 'no client cache', make sure there is no trace of it in the output dir
if (pResourceFile->IsNoClientCache())
FileDelete(pResourceFile->GetCachedPathFilename(true));
return SString("Could not copy '%s' to '%s'\n", *strPath, *strCachedFilePath);
}

break;

// If script is 'no client cache', make sure there is no trace of it in the output dir
if (pResourceFile->IsNoClientCache())
FileDelete(pResourceFile->GetCachedPathFilename(true));
}
default:
break;

break;
}

return SString();
}));
default:
break;
}

return SString();
});
}

bool CResource::GenerateChecksums()
{
std::vector<std::future<SString>> checksumTasks;
checksumTasks.reserve(m_ResourceFiles.size());

for (CResourceFile* pResourceFile : m_ResourceFiles)
{
checksumTasks.push_back(GenerateChecksumForFile(pResourceFile));
}

bool bOk = true;
@@ -562,6 +567,14 @@ bool CResource::GenerateChecksums()
bool CResource::HasResourceChanged()
{
std::string strPath;
if (IsResourceZip() )
{
// Zip file might have changed
CChecksum checksum = CChecksum::GenerateChecksumFromFile(m_strResourceZip);
if (checksum != m_zipHash)
return true;

}

for (CResourceFile* pResourceFile : m_ResourceFiles)
{
@@ -1319,7 +1332,8 @@ bool CResource::ReadIncludedHTML(CXMLNode* pRoot)
// This one is supposed to be default, but there's already a default page
if (bFoundDefault && bIsDefault)
{
CLogger::LogPrintf("Only one html item can be default per resource, ignoring %s in %s\n", strFilename.c_str(), m_strResourceName.c_str());
CLogger::LogPrintf("Only one html item can be default per resource, ignoring %s in %s\n", strFilename.c_str(),
m_strResourceName.c_str());
bIsDefault = false;
}

@@ -1328,8 +1342,8 @@ bool CResource::ReadIncludedHTML(CXMLNode* pRoot)
bFoundDefault = true;

// Create a new resource HTML file and add it to the list
auto pResourceFile = new CResourceHTMLItem(this, strFilename.c_str(), strFullFilename.c_str(), &Attributes, bIsDefault, bIsRaw, bIsRestricted,
m_bOOPEnabledInMetaXml);
auto pResourceFile = new CResourceHTMLItem(this, strFilename.c_str(), strFullFilename.c_str(), &Attributes, bIsDefault, bIsRaw,
bIsRestricted, m_bOOPEnabledInMetaXml);
m_ResourceFiles.push_back(pResourceFile);

// This is the first HTML file? Remember it
@@ -1345,8 +1359,7 @@ bool CResource::ReadIncludedHTML(CXMLNode* pRoot)
}
else
{
CLogger::LogPrintf("WARNING: Empty 'src' attribute from 'html' node of 'meta.xml' for resource '%s', ignoring\n",
m_strResourceName.c_str());
CLogger::LogPrintf("WARNING: Empty 'src' attribute from 'html' node of 'meta.xml' for resource '%s', ignoring\n", m_strResourceName.c_str());
}
}
else
@@ -1406,7 +1419,8 @@ bool CResource::ReadIncludedConfigs(CXMLNode* pRoot)

if (bClient && IsFilenameUsed(strFilename, true))
{
CLogger::LogPrintf("WARNING: Ignoring duplicate client config file in resource '%s': '%s'\n", m_strResourceName.c_str(), strFilename.c_str());
CLogger::LogPrintf("WARNING: Ignoring duplicate client config file in resource '%s': '%s'\n", m_strResourceName.c_str(),
strFilename.c_str());
bClient = false;
}
if (bServer && IsFilenameUsed(strFilename, false))
@@ -1433,8 +1447,7 @@ bool CResource::ReadIncludedConfigs(CXMLNode* pRoot)
}
else
{
CLogger::LogPrintf("WARNING: Empty 'src' attribute from 'config' node of 'meta.xml' for resource '%s', ignoring\n",
m_strResourceName.c_str());
CLogger::LogPrintf("WARNING: Empty 'src' attribute from 'config' node of 'meta.xml' for resource '%s', ignoring\n", m_strResourceName.c_str());
}
}
else
@@ -1499,8 +1512,7 @@ bool CResource::ReadIncludedFiles(CXMLNode* pRoot)
}
else
{
CLogger::LogPrintf("WARNING: Empty 'src' attribute from 'file' node of 'meta.xml' for resource '%s', ignoring\n",
m_strResourceName.c_str());
CLogger::LogPrintf("WARNING: Empty 'src' attribute from 'file' node of 'meta.xml' for resource '%s', ignoring\n", m_strResourceName.c_str());
}
}
else
@@ -1651,7 +1663,8 @@ bool CResource::ReadIncludedScripts(CXMLNode* pRoot)

if (bClient && IsFilenameUsed(strFilename, true))
{
CLogger::LogPrintf("WARNING: Ignoring duplicate client script file in resource '%s': '%s'\n", m_strResourceName.c_str(), strFilename.c_str());
CLogger::LogPrintf("WARNING: Ignoring duplicate client script file in resource '%s': '%s'\n", m_strResourceName.c_str(),
strFilename.c_str());
bClient = false;
}
if (bServer && IsFilenameUsed(strFilename, false))
@@ -1677,8 +1690,7 @@ bool CResource::ReadIncludedScripts(CXMLNode* pRoot)
}
else
{
CLogger::LogPrintf("WARNING: Empty 'src' attribute from 'script' node of 'meta.xml' for resource '%s', ignoring\n",
m_strResourceName.c_str());
CLogger::LogPrintf("WARNING: Empty 'src' attribute from 'script' node of 'meta.xml' for resource '%s', ignoring\n", m_strResourceName.c_str());
}
}
else
@@ -1742,8 +1754,7 @@ bool CResource::ReadIncludedMaps(CXMLNode* pRoot)
}
else
{
CLogger::LogPrintf("WARNING: Empty 'src' attribute from 'map' node of 'meta.xml' for resource '%s', ignoring\n",
m_strResourceName.c_str());
CLogger::LogPrintf("WARNING: Empty 'src' attribute from 'map' node of 'meta.xml' for resource '%s', ignoring\n", m_strResourceName.c_str());
}
}
else
@@ -2913,13 +2924,15 @@ bool CResource::UnzipResource()

if (ires != UNZ_OK)
return false;
}
while (unzGoToNextFile(m_zipfile) != UNZ_END_OF_LIST_OF_FILE);
} while (unzGoToNextFile(m_zipfile) != UNZ_END_OF_LIST_OF_FILE);
}

// Close the zip file
unzClose(m_zipfile);
m_zipfile = nullptr;

// Store the hash so we can figure out whether it has changed later
m_zipHash = CChecksum::GenerateChecksumFromFile(m_strResourceZip);
return true;
}

@@ -191,6 +191,7 @@ class CResource : public EHS
bool IsClientFilesOn() const noexcept { return m_bClientFiles; }

bool GenerateChecksums();
std::future<SString> GenerateChecksumForFile(CResourceFile* pResourceFile);
const CChecksum& GetLastMetaChecksum() { return m_metaChecksum; }
bool HasResourceChanged();
void ApplyUpgradeModifications();
@@ -366,6 +367,7 @@ class CResource : public EHS

CResourceManager* m_pResourceManager;


SString m_strResourceName;
SString m_strAbsPath; // Absolute path to containing directory i.e. /server/mods/deathmatch/resources
std::string m_strResourceZip; // Absolute path to zip file (if a zip) i.e. m_strAbsPath/resource_name.zip
@@ -398,6 +400,7 @@ class CResource : public EHS
std::string m_strCircularInclude;
SString m_strFailureReason;
unzFile m_zipfile = nullptr;
CChecksum m_zipHash;

bool m_bResourceIsZip;
bool m_bClientConfigs = true;
Oops, something went wrong.

0 comments on commit 8b72581

Please sign in to comment.
You can’t perform that action at this time.