diff options
Diffstat (limited to 'src/server/game/Globals/ObjectMgr.cpp')
-rw-r--r-- | src/server/game/Globals/ObjectMgr.cpp | 96 |
1 files changed, 16 insertions, 80 deletions
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 475774831ba..50d8ffec5ae 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -7673,112 +7673,48 @@ void ObjectMgr::LoadGameObjectForQuests() TC_LOG_INFO("server.loading", ">> Loaded %u GameObjects for quests in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); } -bool ObjectMgr::LoadTrinityStrings(const char* table, int32 min_value, int32 max_value) +bool ObjectMgr::LoadTrinityStrings() { uint32 oldMSTime = getMSTime(); - int32 start_value = min_value; - int32 end_value = max_value; - // some string can have negative indexes range - if (start_value < 0) - { - if (end_value >= start_value) - { - TC_LOG_ERROR("sql.sql", "Table '%s' attempt loaded with invalid range (%d - %d), strings not loaded.", table, min_value, max_value); - return false; - } - - // real range (max+1, min+1) exaple: (-10, -1000) -> -999...-10+1 - std::swap(start_value, end_value); - ++start_value; - ++end_value; - } - else - { - if (start_value >= end_value) - { - TC_LOG_ERROR("sql.sql", "Table '%s' attempt loaded with invalid range (%d - %d), strings not loaded.", table, min_value, max_value); - return false; - } - } - - // cleanup affected map part for reloading case - for (TrinityStringLocaleContainer::iterator itr = _trinityStringLocaleStore.begin(); itr != _trinityStringLocaleStore.end();) - { - if (itr->first >= start_value && itr->first < end_value) - _trinityStringLocaleStore.erase(itr++); - else - ++itr; - } - - QueryResult result = WorldDatabase.PQuery("SELECT entry, content_default, content_loc1, content_loc2, content_loc3, content_loc4, content_loc5, content_loc6, content_loc7, content_loc8 FROM %s", table); + _trinityStringStore.clear(); // for reload case + QueryResult result = WorldDatabase.Query("SELECT entry, content_default, content_loc1, content_loc2, content_loc3, content_loc4, content_loc5, content_loc6, content_loc7, content_loc8 FROM trinity_string"); if (!result) { - if (min_value == MIN_TRINITY_STRING_ID) // error only in case internal strings - TC_LOG_ERROR("server.loading", ">> Loaded 0 trinity strings. DB table `%s` is empty. Cannot continue.", table); - else - TC_LOG_INFO("server.loading", ">> Loaded 0 string templates. DB table `%s` is empty.", table); - + TC_LOG_ERROR("server.loading", ">> Loaded 0 trinity strings. DB table `trinity_string` is empty."); return false; } - uint32 count = 0; - do { Field* fields = result->Fetch(); - int32 entry = fields[0].GetInt32(); - - if (entry == 0) - { - TC_LOG_ERROR("sql.sql", "Table `%s` contain reserved entry 0, ignored.", table); - continue; - } - else if (entry < start_value || entry >= end_value) - { - TC_LOG_ERROR("sql.sql", "Table `%s` contain entry %i out of allowed range (%d - %d), ignored.", table, entry, min_value, max_value); - continue; - } - - TrinityStringLocale& data = _trinityStringLocaleStore[entry]; + uint32 entry = fields[0].GetUInt32(); - if (!data.Content.empty()) - { - TC_LOG_ERROR("sql.sql", "Table `%s` contain data for already loaded entry %i (from another table?), ignored.", table, entry); - continue; - } + TrinityString& data = _trinityStringStore[entry]; - data.Content.resize(1); - ++count; + data.Content.resize(DEFAULT_LOCALE + 1); for (int8 i = TOTAL_LOCALES - 1; i >= 0; --i) AddLocaleString(fields[i + 1].GetString(), LocaleConstant(i), data.Content); - } while (result->NextRow()); - - if (min_value == MIN_TRINITY_STRING_ID) - TC_LOG_INFO("server.loading", ">> Loaded %u Trinity strings from table %s in %u ms", count, table, GetMSTimeDiffToNow(oldMSTime)); - else - TC_LOG_INFO("server.loading", ">> Loaded %u string templates from %s in %u ms", count, table, GetMSTimeDiffToNow(oldMSTime)); + } + while (result->NextRow()); + TC_LOG_INFO("server.loading", ">> Loaded " SZFMTD " trinity strings in %u ms", _trinityStringStore.size(), GetMSTimeDiffToNow(oldMSTime)); return true; } -const char *ObjectMgr::GetTrinityString(int32 entry, LocaleConstant locale_idx) const +char const* ObjectMgr::GetTrinityString(uint32 entry, LocaleConstant locale) const { - if (TrinityStringLocale const* msl = GetTrinityStringLocale(entry)) + if (TrinityString const* ts = GetTrinityString(entry)) { - if (msl->Content.size() > size_t(locale_idx) && !msl->Content[locale_idx].empty()) - return msl->Content[locale_idx].c_str(); - - return msl->Content[DEFAULT_LOCALE].c_str(); + if (ts->Content.size() > size_t(locale) && !ts->Content[locale].empty()) + return ts->Content[locale].c_str(); + return ts->Content[DEFAULT_LOCALE].c_str(); } - if (entry > 0) - TC_LOG_ERROR("sql.sql", "Entry %i not found in `trinity_string` table.", entry); - else - TC_LOG_ERROR("sql.sql", "Trinity string entry %i not found in DB.", entry); + TC_LOG_ERROR("sql.sql", "Trinity string entry %u not found in DB.", entry); return "<error>"; } |