From 52accfde80e8a6f5aec63955a5138cd13909b036 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 25 Feb 2026 09:50:33 -0800 Subject: [PATCH] Optimize login music scanning and warden debug formatting --- include/ui/auth_screen.hpp | 2 + src/game/game_handler.cpp | 11 +++-- src/ui/auth_screen.cpp | 91 +++++++++++++++++++++----------------- 3 files changed, 60 insertions(+), 44 deletions(-) diff --git a/include/ui/auth_screen.hpp b/include/ui/auth_screen.hpp index 9f34ff46..e1dbdde7 100644 --- a/include/ui/auth_screen.hpp +++ b/include/ui/auth_screen.hpp @@ -121,6 +121,8 @@ private: bool musicInitAttempted = false; bool musicPlaying = false; bool missingIntroTracksLogged_ = false; + bool introTracksScanned_ = false; + std::vector introTracks_; bool loginMusicVolumeAdjusted_ = false; int savedMusicVolume_ = 30; }; diff --git a/src/game/game_handler.cpp b/src/game/game_handler.cpp index 6887e8ee..4f1c844a 100644 --- a/src/game/game_handler.cpp +++ b/src/game/game_handler.cpp @@ -3512,16 +3512,19 @@ void GameHandler::handleWardenData(network::Packet& packet) { // Decrypt the payload std::vector decrypted = wardenCrypto_->decrypt(data); - // Log decrypted data - { + // Avoid expensive hex formatting when DEBUG logs are disabled. + if (core::Logger::getInstance().shouldLog(core::LogLevel::DEBUG)) { std::string hex; size_t logSize = std::min(decrypted.size(), size_t(256)); hex.reserve(logSize * 3); for (size_t i = 0; i < logSize; ++i) { - char b[4]; snprintf(b, sizeof(b), "%02x ", decrypted[i]); hex += b; + char b[4]; + snprintf(b, sizeof(b), "%02x ", decrypted[i]); + hex += b; } - if (decrypted.size() > 64) + if (decrypted.size() > 64) { hex += "... (" + std::to_string(decrypted.size() - 64) + " more)"; + } LOG_DEBUG("Warden: Decrypted (", decrypted.size(), " bytes): ", hex); } diff --git a/src/ui/auth_screen.cpp b/src/ui/auth_screen.cpp index 6b63cd3f..f57133d5 100644 --- a/src/ui/auth_screen.cpp +++ b/src/ui/auth_screen.cpp @@ -220,53 +220,64 @@ void AuthScreen::render(auth::AuthHandler& authHandler) { music->update(ImGui::GetIO().DeltaTime); if (!music->isPlaying()) { static std::mt19937 rng(std::random_device{}()); - // Tracks in assets/ root - static const std::array kRootTracks = { - "Raise the Mug, Sound the Warcry.mp3", - }; - // Tracks in assets/Original Music/ - static const std::array kOriginalTracks = { - "Gold on the Tide in Booty Bay.mp3", - "Lanterns Over Lordaeron.mp3", - "Loot the Dogs.mp3", - "One More Pull.mp3", - "Roll Need Greed.mp3", - "RunBackPolka.mp3", - "The Barrens Has No End.mp3", - "The Bone Collector.mp3", - "Wanderwewill.mp3", - "WHO PULLED_.mp3", - "You No Take Candle!.mp3", - }; + if (!introTracksScanned_) { + introTracksScanned_ = true; - std::vector availableTracks; - auto tryAddTrack = [&](const std::filesystem::path& base, const char* track) { - std::filesystem::path p = base / track; - if (std::filesystem::exists(p)) { - availableTracks.push_back(p.string()); + // Tracks in assets/ root + static const std::array kRootTracks = { + "Raise the Mug, Sound the Warcry.mp3", + }; + // Tracks in assets/Original Music/ + static const std::array kOriginalTracks = { + "Gold on the Tide in Booty Bay.mp3", + "Lanterns Over Lordaeron.mp3", + "Loot the Dogs.mp3", + "One More Pull.mp3", + "Roll Need Greed.mp3", + "RunBackPolka.mp3", + "The Barrens Has No End.mp3", + "The Bone Collector.mp3", + "Wanderwewill.mp3", + "WHO PULLED_.mp3", + "You No Take Candle!.mp3", + }; + + auto tryAddTrack = [&](const std::filesystem::path& base, const char* track) { + std::filesystem::path p = base / track; + if (std::filesystem::exists(p)) { + introTracks_.push_back(p.string()); + } + }; + for (const char* track : kRootTracks) { + tryAddTrack("assets", track); + if (introTracks_.empty()) { + tryAddTrack(std::filesystem::current_path() / "assets", track); + } } - }; - for (const char* track : kRootTracks) { - tryAddTrack("assets", track); - if (availableTracks.empty()) - tryAddTrack(std::filesystem::current_path() / "assets", track); - } - for (const char* track : kOriginalTracks) { - tryAddTrack(std::filesystem::path("assets") / "Original Music", track); - tryAddTrack(std::filesystem::current_path() / "assets" / "Original Music", track); + for (const char* track : kOriginalTracks) { + tryAddTrack(std::filesystem::path("assets") / "Original Music", track); + tryAddTrack(std::filesystem::current_path() / "assets" / "Original Music", track); + } + + std::sort(introTracks_.begin(), introTracks_.end()); + introTracks_.erase(std::unique(introTracks_.begin(), introTracks_.end()), introTracks_.end()); } - if (!availableTracks.empty()) { - std::uniform_int_distribution pick(0, availableTracks.size() - 1); - const std::string& path = availableTracks[pick(rng)]; + if (!introTracks_.empty()) { + std::uniform_int_distribution pick(0, introTracks_.size() - 1); + const size_t idx = pick(rng); + const std::string path = introTracks_[idx]; music->playFilePath(path, true, 1800.0f); - LOG_INFO("AuthScreen: Playing login intro track: ", path); musicPlaying = music->isPlaying(); - } else { - if (!missingIntroTracksLogged_) { - LOG_WARNING("AuthScreen: No login intro tracks found in assets/"); - missingIntroTracksLogged_ = true; + if (musicPlaying) { + LOG_INFO("AuthScreen: Playing login intro track: ", path); + } else { + // Drop bad paths to avoid retrying the same failed file every frame. + introTracks_.erase(introTracks_.begin() + idx); } + } else if (!missingIntroTracksLogged_) { + LOG_WARNING("AuthScreen: No login intro tracks found in assets/"); + missingIntroTracksLogged_ = true; } } }