mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Misc: Changed GetLocaleByName to return invalid value on invalid input instead of LOCALE_enUS
* Also added IsValidLocale helper function
This commit is contained in:
@@ -33,11 +33,11 @@ char const* localeNames[TOTAL_LOCALES] =
|
||||
"itIT"
|
||||
};
|
||||
|
||||
LocaleConstant GetLocaleByName(const std::string& name)
|
||||
LocaleConstant GetLocaleByName(std::string const& name)
|
||||
{
|
||||
for (uint32 i = 0; i < TOTAL_LOCALES; ++i)
|
||||
if (name == localeNames[i])
|
||||
return LocaleConstant(i);
|
||||
|
||||
return LOCALE_enUS; // including enGB case
|
||||
return TOTAL_LOCALES;
|
||||
}
|
||||
|
||||
@@ -101,6 +101,11 @@ TC_COMMON_API extern char const* localeNames[TOTAL_LOCALES];
|
||||
|
||||
TC_COMMON_API LocaleConstant GetLocaleByName(std::string const& name);
|
||||
|
||||
constexpr inline bool IsValidLocale(LocaleConstant locale)
|
||||
{
|
||||
return locale < TOTAL_LOCALES&& locale != LOCALE_none;
|
||||
}
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
struct LocalizedString
|
||||
|
||||
@@ -218,7 +218,7 @@ uint32 Battlenet::Session::HandleLogon(authentication::v1::LogonRequest const* l
|
||||
return ERROR_BAD_PLATFORM;
|
||||
}
|
||||
|
||||
if (GetLocaleByName(logonRequest->locale()) == LOCALE_enUS && logonRequest->locale() != "enUS")
|
||||
if (!IsValidLocale(GetLocaleByName(logonRequest->locale())))
|
||||
{
|
||||
TC_LOG_DEBUG("session", "[Battlenet::LogonRequest] %s attempted to log in with unsupported locale (using %s)!", GetClientInfo().c_str(), logonRequest->locale().c_str());
|
||||
return ERROR_BAD_LOCALE;
|
||||
|
||||
@@ -1300,7 +1300,7 @@ void AchievementGlobalMgr::LoadRewardLocales()
|
||||
|
||||
AchievementRewardLocale& data = _achievementRewardLocales[id];
|
||||
LocaleConstant locale = GetLocaleByName(localeName);
|
||||
if (locale == LOCALE_enUS)
|
||||
if (!IsValidLocale(locale) || locale == LOCALE_enUS)
|
||||
continue;
|
||||
|
||||
ObjectMgr::AddLocaleString(fields[2].GetString(), locale, data.Subject);
|
||||
|
||||
@@ -336,7 +336,7 @@ void ObjectMgr::LoadCreatureLocales()
|
||||
std::string localeName = fields[1].GetString();
|
||||
|
||||
LocaleConstant locale = GetLocaleByName(localeName);
|
||||
if (locale == LOCALE_enUS)
|
||||
if (!IsValidLocale(locale) || locale == LOCALE_enUS)
|
||||
continue;
|
||||
|
||||
CreatureLocale& data = _creatureLocaleStore[id];
|
||||
@@ -371,7 +371,7 @@ void ObjectMgr::LoadGossipMenuItemsLocales()
|
||||
std::string localeName = fields[2].GetString();
|
||||
|
||||
LocaleConstant locale = GetLocaleByName(localeName);
|
||||
if (locale == LOCALE_enUS)
|
||||
if (!IsValidLocale(locale) || locale == LOCALE_enUS)
|
||||
continue;
|
||||
|
||||
GossipMenuItemsLocale& data = _gossipMenuItemsLocaleStore[std::make_pair(menuId, optionIndex)];
|
||||
@@ -401,7 +401,7 @@ void ObjectMgr::LoadPointOfInterestLocales()
|
||||
std::string localeName = fields[1].GetString();
|
||||
|
||||
LocaleConstant locale = GetLocaleByName(localeName);
|
||||
if (locale == LOCALE_enUS)
|
||||
if (!IsValidLocale(locale) || locale == LOCALE_enUS)
|
||||
continue;
|
||||
|
||||
PointOfInterestLocale& data = _pointOfInterestLocaleStore[id];
|
||||
@@ -4758,7 +4758,7 @@ void ObjectMgr::LoadQuestTemplateLocale()
|
||||
std::string localeName = fields[1].GetString();
|
||||
|
||||
LocaleConstant locale = GetLocaleByName(localeName);
|
||||
if (locale == LOCALE_enUS)
|
||||
if (!IsValidLocale(locale) || locale == LOCALE_enUS)
|
||||
continue;
|
||||
|
||||
QuestTemplateLocale& data = _questTemplateLocaleStore[id];
|
||||
@@ -4794,7 +4794,7 @@ void ObjectMgr::LoadQuestObjectivesLocale()
|
||||
std::string localeName = fields[1].GetString();
|
||||
|
||||
LocaleConstant locale = GetLocaleByName(localeName);
|
||||
if (locale == LOCALE_enUS)
|
||||
if (!IsValidLocale(locale) || locale == LOCALE_enUS)
|
||||
continue;
|
||||
|
||||
QuestObjectivesLocale& data = _questObjectivesLocaleStore[id];
|
||||
@@ -4847,7 +4847,7 @@ void ObjectMgr::LoadQuestGreetingLocales()
|
||||
std::string localeName = fields[2].GetString();
|
||||
|
||||
LocaleConstant locale = GetLocaleByName(localeName);
|
||||
if (locale == LOCALE_enUS)
|
||||
if (!IsValidLocale(locale) || locale == LOCALE_enUS)
|
||||
continue;
|
||||
|
||||
QuestGreetingLocale& data = _questGreetingLocaleStore[type][id];
|
||||
@@ -4877,7 +4877,7 @@ void ObjectMgr::LoadQuestOfferRewardLocale()
|
||||
std::string localeName = fields[1].GetString();
|
||||
|
||||
LocaleConstant locale = GetLocaleByName(localeName);
|
||||
if (locale == LOCALE_enUS)
|
||||
if (!IsValidLocale(locale) || locale == LOCALE_enUS)
|
||||
continue;
|
||||
|
||||
QuestOfferRewardLocale& data = _questOfferRewardLocaleStore[id];
|
||||
@@ -4905,7 +4905,7 @@ void ObjectMgr::LoadQuestRequestItemsLocale()
|
||||
std::string localeName = fields[1].GetString();
|
||||
|
||||
LocaleConstant locale = GetLocaleByName(localeName);
|
||||
if (locale == LOCALE_enUS)
|
||||
if (!IsValidLocale(locale) || locale == LOCALE_enUS)
|
||||
continue;
|
||||
|
||||
QuestRequestItemsLocale& data = _questRequestItemsLocaleStore[id];
|
||||
@@ -5545,7 +5545,7 @@ void ObjectMgr::LoadPageTextLocales()
|
||||
std::string localeName = fields[1].GetString();
|
||||
|
||||
LocaleConstant locale = GetLocaleByName(localeName);
|
||||
if (locale == LOCALE_enUS)
|
||||
if (!IsValidLocale(locale) || locale == LOCALE_enUS)
|
||||
continue;
|
||||
|
||||
PageTextLocale& data = _pageTextLocaleStore[id];
|
||||
@@ -6943,7 +6943,7 @@ void ObjectMgr::LoadGameObjectLocales()
|
||||
std::string localeName = fields[1].GetString();
|
||||
|
||||
LocaleConstant locale = GetLocaleByName(localeName);
|
||||
if (locale == LOCALE_enUS)
|
||||
if (!IsValidLocale(locale) || locale == LOCALE_enUS)
|
||||
continue;
|
||||
|
||||
GameObjectLocale& data = _gameObjectLocaleStore[id];
|
||||
@@ -8728,7 +8728,7 @@ void ObjectMgr::LoadTrainers()
|
||||
std::string localeName = fields[1].GetString();
|
||||
|
||||
LocaleConstant locale = GetLocaleByName(localeName);
|
||||
if (locale == LOCALE_enUS)
|
||||
if (!IsValidLocale(locale) || locale == LOCALE_enUS)
|
||||
continue;
|
||||
|
||||
if (Trainer::Trainer* trainer = Trinity::Containers::MapGetValuePtr(_trainers, trainerId))
|
||||
@@ -10477,7 +10477,7 @@ void ObjectMgr::LoadPlayerChoicesLocale()
|
||||
}
|
||||
|
||||
LocaleConstant locale = GetLocaleByName(localeName);
|
||||
if (locale == LOCALE_enUS)
|
||||
if (!IsValidLocale(locale) || locale == LOCALE_enUS)
|
||||
continue;
|
||||
|
||||
PlayerChoiceLocale& data = _playerChoiceLocales[choiceId];
|
||||
@@ -10518,7 +10518,7 @@ void ObjectMgr::LoadPlayerChoicesLocale()
|
||||
}
|
||||
|
||||
LocaleConstant locale = GetLocaleByName(localeName);
|
||||
if (locale == LOCALE_enUS)
|
||||
if (!IsValidLocale(locale) || locale == LOCALE_enUS)
|
||||
continue;
|
||||
|
||||
PlayerChoiceResponseLocale& data = itr->second.Responses[responseId];
|
||||
|
||||
@@ -197,7 +197,7 @@ void CreatureTextMgr::LoadCreatureTextLocales()
|
||||
std::string localeName = fields[3].GetString();
|
||||
|
||||
LocaleConstant locale = GetLocaleByName(localeName);
|
||||
if (locale == LOCALE_enUS)
|
||||
if (!IsValidLocale(locale) || locale == LOCALE_enUS)
|
||||
continue;
|
||||
|
||||
CreatureTextLocale& data = mLocaleTextMap[CreatureTextId(creatureId, groupId, id)];
|
||||
|
||||
Reference in New Issue
Block a user