From 732097582531e268592763150b1858f1cb88bc58 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sun, 1 Sep 2024 16:02:35 +0200 Subject: [PATCH] Multiplayer: Removed actor bundle name from log messages Suggested by Mike: https://github.com/RigsOfRods/rigs-of-rods/pull/3171#issuecomment-2270072497 --- source/main/physics/ActorManager.cpp | 9 ++++++--- source/main/resources/CacheSystem.cpp | 19 ++++--------------- source/main/resources/CacheSystem.h | 2 +- source/main/utils/Utils.cpp | 15 +++++++++++++++ source/main/utils/Utils.h | 2 ++ 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/source/main/physics/ActorManager.cpp b/source/main/physics/ActorManager.cpp index 8cc08f6418..5845f5a7db 100644 --- a/source/main/physics/ActorManager.cpp +++ b/source/main/physics/ActorManager.cpp @@ -368,7 +368,10 @@ void ActorManager::HandleActorStreamData(std::vector packet_ { reg->name[127] = 0; // NOTE: The filename is by default in "Bundle-qualified" format, i.e. "mybundle.zip:myactor.truck" - std::string filename = SanitizeUtf8CString(reg->name); + std::string filename_maybe_bundlequalified = SanitizeUtf8CString(reg->name); + std::string filename; + std::string bundlename; + SplitBundleQualifiedFilename(filename_maybe_bundlequalified, /*out:*/ bundlename, /*out:*/ filename); RoRnet::UserInfo info; if (!App::GetNetwork()->GetUserInfo(reg->origin_sourceid, info)) @@ -390,14 +393,14 @@ void ActorManager::HandleActorStreamData(std::vector packet_ LOG("[RoR] Creating remote actor for " + TOSTRING(reg->origin_sourceid) + ":" + TOSTRING(reg->origin_streamid)); - CacheEntryPtr actor_entry = App::GetCacheSystem()->FindEntryByFilename(LT_AllBeam, /*partial:*/false, filename); + CacheEntryPtr actor_entry = App::GetCacheSystem()->FindEntryByFilename(LT_AllBeam, /*partial:*/false, filename_maybe_bundlequalified); if (!actor_entry) { App::GetConsole()->putMessage( Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_WARNING, _L("Mod not installed: ") + filename); - RoR::LogFormat("[RoR] Cannot create remote actor (not installed), filename: '%s'", filename.c_str()); + RoR::LogFormat("[RoR] Cannot create remote actor (not installed), filename: '%s'", filename_maybe_bundlequalified.c_str()); AddStreamMismatch(reg->origin_sourceid, reg->origin_streamid); reg->status = -1; } diff --git a/source/main/resources/CacheSystem.cpp b/source/main/resources/CacheSystem.cpp index ae10b612ad..6ec893e615 100644 --- a/source/main/resources/CacheSystem.cpp +++ b/source/main/resources/CacheSystem.cpp @@ -181,26 +181,15 @@ void CacheSystem::LoadModCache(CacheValidity validity) m_loaded = true; } -CacheEntryPtr CacheSystem::FindEntryByFilename(LoaderType type, bool partial, const std::string& _filename) +CacheEntryPtr CacheSystem::FindEntryByFilename(LoaderType type, bool partial, const std::string& _filename_maybe_bundlequalified) { - // The `_filename` may optionally be in "Bundle-qualified" format, i.e. "mybundle.zip:myactor.truck" + // "Bundle-qualified" format also specifies the ZIP/directory in modcache, i.e. "mybundle.zip:myactor.truck" // Like the filename, the bundle name lookup is case-insensitive. // ------------------------------------------------------------------------------------------------- std::string filename; std::string bundlename; - size_t colon_pos = _filename.find(':'); - if (colon_pos != std::string::npos) - { - // The name is in format "mybundle.zip:myactor.truck" - find all bundles with "myactor.truck" and choose the right one. - filename = _filename.substr(colon_pos + 1); - bundlename = _filename.substr(0, colon_pos); - } - else - { - filename = _filename; - } - + SplitBundleQualifiedFilename(_filename_maybe_bundlequalified, bundlename, filename); StringUtil::toLowerCase(filename); StringUtil::toLowerCase(bundlename); size_t partial_match_length = std::numeric_limits::max(); @@ -250,7 +239,7 @@ CacheEntryPtr CacheSystem::FindEntryByFilename(LoaderType type, bool partial, co if (log_candidates.size() > 0) { App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_NOTICE, - fmt::format(_LC("CacheSystem", "Mod '{}' was not found in cache; candidates ({}) are:"), _filename, log_candidates.size())); + fmt::format(_LC("CacheSystem", "Mod '{}' was not found in cache; candidates ({}) are:"), _filename_maybe_bundlequalified, log_candidates.size())); for (CacheEntryPtr& entry: log_candidates) { std::string bundle_name, bundle_path; diff --git a/source/main/resources/CacheSystem.h b/source/main/resources/CacheSystem.h index f4125199a8..78219e0cab 100644 --- a/source/main/resources/CacheSystem.h +++ b/source/main/resources/CacheSystem.h @@ -301,7 +301,7 @@ class CacheSystem /// @name Lookups /// @{ - CacheEntryPtr FindEntryByFilename(RoR::LoaderType type, bool partial, const std::string& filename); //!< Returns NULL if none found + CacheEntryPtr FindEntryByFilename(RoR::LoaderType type, bool partial, const std::string& _filename_maybe_bundlequalified); //!< Returns NULL if none found; "Bundle-qualified" format also specifies the ZIP/directory in modcache, i.e. "mybundle.zip:myactor.truck" CacheEntryPtr GetEntryByNumber(int modid); CacheEntryPtr FetchSkinByName(std::string const & skin_name); size_t Query(CacheQuery& query); diff --git a/source/main/utils/Utils.cpp b/source/main/utils/Utils.cpp index d73f0ae9f7..1841a96742 100644 --- a/source/main/utils/Utils.cpp +++ b/source/main/utils/Utils.cpp @@ -224,3 +224,18 @@ void RoR::CvarRemoveFileFromList(CVar* cvar, const std::string& filename) cvar->setStr(JoinStrVec(files, ",")); } + +void RoR::SplitBundleQualifiedFilename(const std::string& bundleQualifiedFilename, std::string& out_bundleName, std::string& out_filename) +{ + size_t pos = bundleQualifiedFilename.find(':'); + if (pos != std::string::npos) + { + out_bundleName = bundleQualifiedFilename.substr(0, pos); + out_filename = bundleQualifiedFilename.substr(pos + 1); + } + else + { + out_bundleName = ""; + out_filename = bundleQualifiedFilename; + } +} diff --git a/source/main/utils/Utils.h b/source/main/utils/Utils.h index ac247f3cd9..5c759843ac 100644 --- a/source/main/utils/Utils.h +++ b/source/main/utils/Utils.h @@ -108,4 +108,6 @@ std::string PrintMeshInfo(std::string const& title, Ogre::MeshPtr mesh); void CvarAddFileToList(CVar* cvar, const std::string& filename); void CvarRemoveFileFromList(CVar* cvar, const std::string& filename); +void SplitBundleQualifiedFilename(const std::string& bundleQualifiedFilename, std::string& out_bundleName, std::string& out_filename); + } // namespace RoR