Skip to content

Commit e9ee4d8

Browse files
committed
Reduce update logging to downgrade attempts
1 parent f7fa39d commit e9ee4d8

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

Client/core/CVersionUpdater.cpp

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "CVersionUpdater.Util.hpp"
1515
#include "CNewsBrowser.h"
1616
#include "SharedUtil.Thread.h"
17+
#include <charconv>
1718

1819
///////////////////////////////////////////////////////////////
1920
//
@@ -2176,6 +2177,35 @@ void CVersionUpdater::_UseVersionQueryURLs()
21762177
m_JobInfo.bShowDownloadPercent = false;
21772178
}
21782179

2180+
/**
2181+
* @brief Extracts the revision from an update file name.
2182+
* @param fileName Name of the file
2183+
* @param revision Revision of the update
2184+
*/
2185+
static bool GetRevisionFromFileName(std::string_view fileName, std::uint32_t& revision)
2186+
{
2187+
revision = {};
2188+
2189+
// Example: mtasa-1.5.9-rc-21519-0-000-files-all-cksummed.rar
2190+
// Search for the delimiter before the revision ^^^^.
2191+
if (size_t revisionStart = fileName.find("-rc-"); revisionStart != std::string_view::npos)
2192+
{
2193+
revisionStart += 4;
2194+
2195+
// Example: mtasa-1.5.9-rc-21519-0-000-files-all-cksummed.rar
2196+
// Search for the delimiter after the revision ^.
2197+
if (size_t revisionStop = fileName.find('-', revisionStart); revisionStop != std::string_view::npos)
2198+
{
2199+
std::string_view raw = fileName.substr(revisionStart, revisionStop - revisionStart);
2200+
2201+
if (auto [ptr, ec] = std::from_chars(raw.data(), raw.data() + raw.size(), revision); ec == std::errc{})
2202+
return true;
2203+
}
2204+
}
2205+
2206+
return false;
2207+
}
2208+
21792209
///////////////////////////////////////////////////////////////
21802210
//
21812211
// CVersionUpdater::_ProcessPatchFileQuery
@@ -2303,16 +2333,20 @@ void CVersionUpdater::_ProcessPatchFileQuery()
23032333
// Report update response
23042334
if (!m_JobInfo.strStatus.empty() && m_JobInfo.strStatus != "noupdate" && !_strnicmp("mtasa-", m_JobInfo.strFilename.c_str(), 6))
23052335
{
2306-
unsigned short netRev = CCore::GetSingleton().GetNetwork()->GetNetRev();
2307-
unsigned short netRel = CCore::GetSingleton().GetNetwork()->GetNetRel();
2308-
SString playerVersion("%d.%d.%d-%d.%05d.%d.%03d", MTASA_VERSION_MAJOR, MTASA_VERSION_MINOR, MTASA_VERSION_MAINTENANCE, MTASA_VERSION_TYPE,
2309-
MTASA_VERSION_BUILD, netRev, netRel);
2310-
SString updateBuildType;
2311-
CVARS_GET("update_build_type", updateBuildType);
2336+
uint32_t revision{};
23122337

2313-
AddReportLog(5060, SString("Processing patch file '%s' [%s, %s] with '%s' (version: %s, channel: %s)", m_JobInfo.strFilename.c_str(),
2314-
m_JobInfo.iFilesize.ToString().c_str(), m_JobInfo.strMD5.c_str(), m_JobInfo.strStatus.c_str(), playerVersion.c_str(),
2315-
updateBuildType.c_str()));
2338+
if (GetRevisionFromFileName(m_JobInfo.strFilename, revision) && revision < MTASA_VERSION_BUILD)
2339+
{
2340+
unsigned short netRev = CCore::GetSingleton().GetNetwork()->GetNetRev();
2341+
unsigned short netRel = CCore::GetSingleton().GetNetwork()->GetNetRel();
2342+
2343+
SString playerVersion("%d.%d.%d-%d.%05d.%d.%03d", MTASA_VERSION_MAJOR, MTASA_VERSION_MINOR, MTASA_VERSION_MAINTENANCE, MTASA_VERSION_TYPE,
2344+
MTASA_VERSION_BUILD, netRev, netRel);
2345+
2346+
AddReportLog(5061, SString("Processing patch file '%s' [%s, %s] with '%s' (version: %s) from '%s'", m_JobInfo.strFilename.c_str(),
2347+
m_JobInfo.iFilesize.ToString().c_str(), m_JobInfo.strMD5.c_str(), m_JobInfo.strStatus.c_str(), playerVersion.c_str(),
2348+
m_strLastQueryURL.c_str()));
2349+
}
23162350
}
23172351
}
23182352

0 commit comments

Comments
 (0)