diff --git a/src/PlayerbotMgr.cpp b/src/PlayerbotMgr.cpp index 6bdbf9b6..fe4a714f 100644 --- a/src/PlayerbotMgr.cpp +++ b/src/PlayerbotMgr.cpp @@ -1602,8 +1602,26 @@ void PlayerbotMgr::OnBotLoginInternal(Player* const bot) void PlayerbotMgr::OnPlayerLogin(Player* player) { + if (!player) + return; + + WorldSession* session = player->GetSession(); + if (!session) + { + LOG_WARN("playerbots", "Unable to register locale priority for player {} because the session is missing", player->GetName()); + return; + } + + // DB locale (source of bot text translation) + LocaleConstant const databaseLocale = session->GetSessionDbLocaleIndex(); + + // For bot texts (DB-driven), prefer the database locale with a safe fallback. + LocaleConstant usedLocale = databaseLocale; + if (usedLocale >= MAX_LOCALES) + usedLocale = LOCALE_enUS; // fallback + // set locale priority for bot texts - sPlayerbotTextMgr->AddLocalePriority(player->GetSession()->GetSessionDbcLocale()); + sPlayerbotTextMgr->AddLocalePriority(usedLocale); if (sPlayerbotAIConfig->selfBotLevel > 2) HandlePlayerbotCommand("self", player); @@ -1611,7 +1629,7 @@ void PlayerbotMgr::OnPlayerLogin(Player* player) if (!sPlayerbotAIConfig->botAutologin) return; - uint32 accountId = player->GetSession()->GetAccountId(); + uint32 accountId = session->GetAccountId(); QueryResult results = CharacterDatabase.Query("SELECT name FROM characters WHERE account = {}", accountId); if (results) { diff --git a/src/PlayerbotTextMgr.cpp b/src/PlayerbotTextMgr.cpp index 3caa96a7..1dce9a29 100644 --- a/src/PlayerbotTextMgr.cpp +++ b/src/PlayerbotTextMgr.cpp @@ -190,26 +190,29 @@ bool PlayerbotTextMgr::GetBotText(std::string name, std::string& text, std::map< void PlayerbotTextMgr::AddLocalePriority(uint32 locale) { - if (!locale) + if (locale >= MAX_LOCALES) + { + LOG_WARN("playerbots", "Ignoring locale {} for bot texts because it exceeds MAX_LOCALES ({})", locale, MAX_LOCALES - 1); return; + } botTextLocalePriority[locale]++; } uint32 PlayerbotTextMgr::GetLocalePriority() { - uint32 topLocale = 0; - // if no real players online, reset top locale - if (!sWorldSessionMgr->GetActiveSessionCount()) + uint32 const activeSessions = sWorldSessionMgr->GetActiveSessionCount(); + if (!activeSessions) { ResetLocalePriority(); return 0; } + uint32 topLocale = 0; for (uint8 i = 0; i < MAX_LOCALES; ++i) { - if (botTextLocalePriority[i] > topLocale) + if (botTextLocalePriority[i] > botTextLocalePriority[topLocale]) topLocale = i; }