Skip to content

Commit

Permalink
Multiplayer: Removed actor bundle name from log messages
Browse files Browse the repository at this point in the history
Suggested by Mike: RigsOfRods#3171 (comment)
  • Loading branch information
ohlidalp committed Sep 1, 2024
1 parent a372b8c commit bb2cbbb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
9 changes: 6 additions & 3 deletions source/main/physics/ActorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,10 @@ void ActorManager::HandleActorStreamData(std::vector<RoR::NetRecvPacket> 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))
Expand All @@ -399,14 +402,14 @@ void ActorManager::HandleActorStreamData(std::vector<RoR::NetRecvPacket> 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;
}
Expand Down
19 changes: 4 additions & 15 deletions source/main/resources/CacheSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>::max();
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion source/main/resources/CacheSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions source/main/utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 2 additions & 0 deletions source/main/utils/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bb2cbbb

Please sign in to comment.