Optimize login music scanning and warden debug formatting

This commit is contained in:
Kelsi 2026-02-25 09:50:33 -08:00
parent c26353eda1
commit 52accfde80
3 changed files with 60 additions and 44 deletions

View file

@ -121,6 +121,8 @@ private:
bool musicInitAttempted = false; bool musicInitAttempted = false;
bool musicPlaying = false; bool musicPlaying = false;
bool missingIntroTracksLogged_ = false; bool missingIntroTracksLogged_ = false;
bool introTracksScanned_ = false;
std::vector<std::string> introTracks_;
bool loginMusicVolumeAdjusted_ = false; bool loginMusicVolumeAdjusted_ = false;
int savedMusicVolume_ = 30; int savedMusicVolume_ = 30;
}; };

View file

@ -3512,16 +3512,19 @@ void GameHandler::handleWardenData(network::Packet& packet) {
// Decrypt the payload // Decrypt the payload
std::vector<uint8_t> decrypted = wardenCrypto_->decrypt(data); std::vector<uint8_t> 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; std::string hex;
size_t logSize = std::min(decrypted.size(), size_t(256)); size_t logSize = std::min(decrypted.size(), size_t(256));
hex.reserve(logSize * 3); hex.reserve(logSize * 3);
for (size_t i = 0; i < logSize; ++i) { 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)"; hex += "... (" + std::to_string(decrypted.size() - 64) + " more)";
}
LOG_DEBUG("Warden: Decrypted (", decrypted.size(), " bytes): ", hex); LOG_DEBUG("Warden: Decrypted (", decrypted.size(), " bytes): ", hex);
} }

View file

@ -220,6 +220,9 @@ void AuthScreen::render(auth::AuthHandler& authHandler) {
music->update(ImGui::GetIO().DeltaTime); music->update(ImGui::GetIO().DeltaTime);
if (!music->isPlaying()) { if (!music->isPlaying()) {
static std::mt19937 rng(std::random_device{}()); static std::mt19937 rng(std::random_device{}());
if (!introTracksScanned_) {
introTracksScanned_ = true;
// Tracks in assets/ root // Tracks in assets/ root
static const std::array<const char*, 1> kRootTracks = { static const std::array<const char*, 1> kRootTracks = {
"Raise the Mug, Sound the Warcry.mp3", "Raise the Mug, Sound the Warcry.mp3",
@ -239,38 +242,46 @@ void AuthScreen::render(auth::AuthHandler& authHandler) {
"You No Take Candle!.mp3", "You No Take Candle!.mp3",
}; };
std::vector<std::string> availableTracks;
auto tryAddTrack = [&](const std::filesystem::path& base, const char* track) { auto tryAddTrack = [&](const std::filesystem::path& base, const char* track) {
std::filesystem::path p = base / track; std::filesystem::path p = base / track;
if (std::filesystem::exists(p)) { if (std::filesystem::exists(p)) {
availableTracks.push_back(p.string()); introTracks_.push_back(p.string());
} }
}; };
for (const char* track : kRootTracks) { for (const char* track : kRootTracks) {
tryAddTrack("assets", track); tryAddTrack("assets", track);
if (availableTracks.empty()) if (introTracks_.empty()) {
tryAddTrack(std::filesystem::current_path() / "assets", track); tryAddTrack(std::filesystem::current_path() / "assets", track);
} }
}
for (const char* track : kOriginalTracks) { for (const char* track : kOriginalTracks) {
tryAddTrack(std::filesystem::path("assets") / "Original Music", track); tryAddTrack(std::filesystem::path("assets") / "Original Music", track);
tryAddTrack(std::filesystem::current_path() / "assets" / "Original Music", track); tryAddTrack(std::filesystem::current_path() / "assets" / "Original Music", track);
} }
if (!availableTracks.empty()) { std::sort(introTracks_.begin(), introTracks_.end());
std::uniform_int_distribution<size_t> pick(0, availableTracks.size() - 1); introTracks_.erase(std::unique(introTracks_.begin(), introTracks_.end()), introTracks_.end());
const std::string& path = availableTracks[pick(rng)]; }
if (!introTracks_.empty()) {
std::uniform_int_distribution<size_t> pick(0, introTracks_.size() - 1);
const size_t idx = pick(rng);
const std::string path = introTracks_[idx];
music->playFilePath(path, true, 1800.0f); music->playFilePath(path, true, 1800.0f);
LOG_INFO("AuthScreen: Playing login intro track: ", path);
musicPlaying = music->isPlaying(); musicPlaying = music->isPlaying();
if (musicPlaying) {
LOG_INFO("AuthScreen: Playing login intro track: ", path);
} else { } else {
if (!missingIntroTracksLogged_) { // 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/"); LOG_WARNING("AuthScreen: No login intro tracks found in assets/");
missingIntroTracksLogged_ = true; missingIntroTracksLogged_ = true;
} }
} }
} }
} }
}
ImGui::SetNextWindowSize(ImVec2(500, 400), ImGuiCond_FirstUseEver); ImGui::SetNextWindowSize(ImVec2(500, 400), ImGuiCond_FirstUseEver);
ImGui::Begin("Authentication", nullptr, ImGuiWindowFlags_NoCollapse); ImGui::Begin("Authentication", nullptr, ImGuiWindowFlags_NoCollapse);