mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-02-28 06:25:55 +00:00
feat(DB/Module): introduce module_string table (#19475)
This commit is contained in:
@@ -8544,6 +8544,98 @@ void ObjectMgr::LoadGameObjectForQuests()
|
||||
LOG_INFO("server.loading", " ");
|
||||
}
|
||||
|
||||
bool ObjectMgr::LoadModuleStrings()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
_moduleStringStore.clear(); // for reload case
|
||||
QueryResult result = WorldDatabase.Query("SELECT module, id, string FROM module_string");
|
||||
if (!result)
|
||||
{
|
||||
LOG_WARN("server.loading", ">> Loaded 0 module strings. DB table `module_string` is empty.");
|
||||
LOG_INFO("server.loading", " ");
|
||||
return false;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
std::string module = fields[0].Get<std::string>();
|
||||
uint32 id = fields[1].Get<uint32>();
|
||||
|
||||
std::pair<std::string, uint32> pairKey = std::make_pair(module, id);
|
||||
ModuleString& data = _moduleStringStore[pairKey];
|
||||
|
||||
AddLocaleString(fields[2].Get<std::string>(), LOCALE_enUS, data.Content);
|
||||
} while (result->NextRow());
|
||||
|
||||
LOG_INFO("server.loading", ">> Loaded {} Module Strings in {} ms", _moduleStringStore.size(), GetMSTimeDiffToNow(oldMSTime));
|
||||
LOG_INFO("server.loading", " ");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ObjectMgr::LoadModuleStringsLocale()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
QueryResult result = WorldDatabase.Query("SELECT module, id, locale, string FROM module_string_locale");
|
||||
if (!result)
|
||||
{
|
||||
LOG_WARN("server.loading", ">> Loaded 0 module strings locale. DB table `module_string_locale` is empty.");
|
||||
LOG_INFO("server.loading", " ");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 localeCount = 0;
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
std::string module = fields[0].Get<std::string>();
|
||||
uint32 id = fields[1].Get<uint32>();
|
||||
|
||||
std::pair<std::string, uint32> pairKey = std::make_pair(module, id);
|
||||
ModuleString& data = _moduleStringStore[pairKey];
|
||||
|
||||
ModuleStringContainer::iterator ms = _moduleStringStore.find(pairKey);
|
||||
if (ms == _moduleStringStore.end())
|
||||
{
|
||||
LOG_ERROR("sql.sql", "ModuleString (Module: {} Id: {}) found in table `module_string_locale` but does not exist in `module_string`. Skipped!", module, id);
|
||||
continue;
|
||||
}
|
||||
|
||||
LocaleConstant locale = GetLocaleByName(fields[2].Get<std::string>());
|
||||
if (locale == LOCALE_enUS)
|
||||
continue;
|
||||
|
||||
AddLocaleString(fields[3].Get<std::string>(), locale, data.Content);
|
||||
localeCount++;
|
||||
} while (result->NextRow());
|
||||
|
||||
LOG_INFO("server.loading", ">> Loaded {} Module Strings Locales in {} ms", localeCount, GetMSTimeDiffToNow(oldMSTime));
|
||||
LOG_INFO("server.loading", " ");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string const* ObjectMgr::GetModuleString(std::string module, uint32 id, LocaleConstant locale) const
|
||||
{
|
||||
ModuleString const* ms = GetModuleString(module, id);
|
||||
if (ms->Content.size())
|
||||
{
|
||||
if (ms->Content.size() > size_t(locale) && !ms->Content[locale].empty())
|
||||
return &ms->Content[locale];
|
||||
|
||||
return &ms->Content[DEFAULT_LOCALE];
|
||||
}
|
||||
|
||||
LOG_ERROR("sql.sql", "Module string module {} id {} not found in DB.", module, id);
|
||||
|
||||
return (std::string*)"error";
|
||||
}
|
||||
|
||||
bool ObjectMgr::LoadAcoreStrings()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
Reference in New Issue
Block a user