diff options
| author | Shauren <shauren.trinity@gmail.com> | 2013-03-17 16:04:52 +0100 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2013-03-17 16:04:52 +0100 |
| commit | df3954521ee5e543173f804193cd2f8e40edac3a (patch) | |
| tree | 64b8a7af702fd0e902ca0e81beb76ef8bcfea06c /src/server/game | |
| parent | ffe25145eb905a34225714251e2a0b1daf6e0ff8 (diff) | |
Core/DataStores: Implemented using locales in .db2 stores
Diffstat (limited to 'src/server/game')
| -rw-r--r-- | src/server/game/DataStores/DB2Stores.cpp | 50 | ||||
| -rw-r--r-- | src/server/game/DataStores/DB2Structure.h | 20 | ||||
| -rw-r--r-- | src/server/game/DataStores/DB2Utility.cpp | 12 | ||||
| -rw-r--r-- | src/server/game/DataStores/DB2Utility.h | 4 | ||||
| -rw-r--r-- | src/server/game/DataStores/DBCEnums.h | 2 | ||||
| -rw-r--r-- | src/server/game/Globals/ObjectMgr.cpp | 4 | ||||
| -rw-r--r-- | src/server/game/Handlers/MiscHandler.cpp | 2 | ||||
| -rw-r--r-- | src/server/game/World/World.cpp | 54 | ||||
| -rw-r--r-- | src/server/game/World/World.h | 1 |
9 files changed, 62 insertions, 87 deletions
diff --git a/src/server/game/DataStores/DB2Stores.cpp b/src/server/game/DataStores/DB2Stores.cpp index 59926cd2b5c..68bf07418f5 100644 --- a/src/server/game/DataStores/DB2Stores.cpp +++ b/src/server/game/DataStores/DB2Stores.cpp @@ -20,6 +20,7 @@ #include "DB2Utility.h" #include "Common.h" #include "Log.h" +#include "World.h" DB2Storage<ItemEntry> sItemStore(Itemfmt, &DB2Utilities::HasItemEntry, &DB2Utilities::WriteItemDbReply); DB2Storage<ItemCurrencyCostEntry> sItemCurrencyCostStore(ItemCurrencyCostfmt); @@ -27,7 +28,7 @@ DB2Storage<ItemExtendedCostEntry> sItemExtendedCostStore(ItemExtendedCostEntryfm DB2Storage<ItemSparseEntry> sItemSparseStore(ItemSparsefmt, &DB2Utilities::HasItemSparseEntry, &DB2Utilities::WriteItemSparseDbReply); DB2Storage<KeyChainEntry> sKeyChainStore(KeyChainfmt); -typedef std::list<std::string> StoreProblemList1; +typedef std::list<std::string> DB2StoreProblemList; typedef std::map<uint32 /*hash*/, DB2StorageBase*> DB2StorageMap; DB2StorageMap DB2Stores; @@ -42,18 +43,8 @@ static bool LoadDB2_assert_print(uint32 fsize, uint32 rsize, std::string const& return false; } -struct LocalDB2Data -{ - LocalDB2Data(LocaleConstant loc) : defaultLocale(loc), availableDb2Locales(0xFFFFFFFF) {} - - LocaleConstant defaultLocale; - - // bitmasks for index of fullLocaleNameList - uint32 availableDb2Locales; -}; - template<class T> -inline void LoadDB2(StoreProblemList1& errlist, DB2Storage<T>& storage, std::string const& db2_path, std::string const& filename) +inline void LoadDB2(uint32& availableDb2Locales, DB2StoreProblemList& errlist, DB2Storage<T>& storage, std::string const& db2_path, std::string const& filename) { // compatibility format and C++ structure sizes ASSERT(DB2FileLoader::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDB2_assert_print(DB2FileLoader::GetFormatRecordSize(storage.GetFormat()), sizeof(T), filename)); @@ -61,7 +52,26 @@ inline void LoadDB2(StoreProblemList1& errlist, DB2Storage<T>& storage, std::str ++DB2FilesCount; std::string db2_filename = db2_path + filename; - if (!storage.Load(db2_filename.c_str())) + if (storage.Load(db2_filename.c_str(), uint32(sWorld->GetDefaultDbcLocale()))) + { + for (uint32 i = 0; i < TOTAL_LOCALES; ++i) + { + if (!(availableDb2Locales & (1 << i))) + continue; + + if (uint32(sWorld->GetDefaultDbcLocale()) == i) + continue; + + std::string localizedName(db2_path); + localizedName.append(localeNames[i]); + localizedName.push_back('/'); + localizedName.append(filename); + + if (!storage.LoadStringsFrom(localizedName.c_str(), i)) + availableDb2Locales &= ~(1<<i); // mark as not available for speedup next checks + } + } + else { // sort problematic db2 to (1) non compatible and (2) nonexistent if (FILE* f = fopen(db2_filename.c_str(), "rb")) @@ -82,13 +92,15 @@ void LoadDB2Stores(std::string const& dataPath) { std::string db2Path = dataPath + "dbc/"; - StoreProblemList1 bad_db2_files; + DB2StoreProblemList bad_db2_files; + uint32 availableDb2Locales = 0xFF; + + LoadDB2(availableDb2Locales, bad_db2_files, sItemStore, db2Path, "Item.db2"); + LoadDB2(availableDb2Locales, bad_db2_files, sItemCurrencyCostStore, db2Path, "ItemCurrencyCost.db2"); + LoadDB2(availableDb2Locales, bad_db2_files, sItemSparseStore, db2Path, "Item-sparse.db2"); + LoadDB2(availableDb2Locales, bad_db2_files, sItemExtendedCostStore, db2Path, "ItemExtendedCost.db2"); + LoadDB2(availableDb2Locales, bad_db2_files, sKeyChainStore, db2Path, "KeyChain.db2"); - LoadDB2(bad_db2_files, sItemStore, db2Path, "Item.db2"); - LoadDB2(bad_db2_files, sItemCurrencyCostStore, db2Path, "ItemCurrencyCost.db2"); - LoadDB2(bad_db2_files, sItemSparseStore, db2Path, "Item-sparse.db2"); - LoadDB2(bad_db2_files, sItemExtendedCostStore, db2Path, "ItemExtendedCost.db2"); - LoadDB2(bad_db2_files, sKeyChainStore, db2Path, "KeyChain.db2"); // error checks if (bad_db2_files.size() >= DB2FilesCount) { diff --git a/src/server/game/DataStores/DB2Structure.h b/src/server/game/DataStores/DB2Structure.h index 45b611180f4..81b3301ade0 100644 --- a/src/server/game/DataStores/DB2Structure.h +++ b/src/server/game/DataStores/DB2Structure.h @@ -19,18 +19,8 @@ #define TRINITY_DB2STRUCTURE_H #include "Common.h" -#include "DBCEnums.h" -#include "Define.h" -#include "Path.h" -#include "Util.h" -#include "Vehicle.h" -#include "SharedDefines.h" #include "ItemPrototype.h" -#include <map> -#include <set> -#include <vector> - // GCC has alternative #pragma pack(N) syntax and old gcc version does not support pack(push, N), also any gcc version does not support it at some platform #if defined(__GNUC__) #pragma pack(1) @@ -98,11 +88,11 @@ struct ItemSparseEntry int32 SpellCategory[MAX_ITEM_PROTO_SPELLS]; // 85 - 89 int32 SpellCategoryCooldown[MAX_ITEM_PROTO_SPELLS]; // 90 - 94 uint32 Bonding; // 95 - char* Name; // 96 - char* Name2; // 97 - char* Name3; // 98 - char* Name4; // 99 - char* Description; // 100 + LocalizedString* Name; // 96 + LocalizedString* Name2; // 97 + LocalizedString* Name3; // 98 + LocalizedString* Name4; // 99 + LocalizedString* Description; // 100 uint32 PageText; // 101 uint32 LanguageID; // 102 uint32 PageMaterial; // 103 diff --git a/src/server/game/DataStores/DB2Utility.cpp b/src/server/game/DataStores/DB2Utility.cpp index 4ff06298660..3cb0f40cf3d 100644 --- a/src/server/game/DataStores/DB2Utility.cpp +++ b/src/server/game/DataStores/DB2Utility.cpp @@ -33,7 +33,7 @@ bool DB2Utilities::HasItemSparseEntry(DB2Storage<ItemSparseEntry> const& /*store return ItemExists(id); } -void DB2Utilities::WriteItemDbReply(DB2Storage<ItemEntry> const& /*store*/, uint32 id, ByteBuffer& buffer) +void DB2Utilities::WriteItemDbReply(DB2Storage<ItemEntry> const& /*store*/, uint32 id, uint32 /*locale*/, ByteBuffer& buffer) { ItemTemplate const* proto = sObjectMgr->GetItemTemplate(id); ASSERT(proto); @@ -48,11 +48,13 @@ void DB2Utilities::WriteItemDbReply(DB2Storage<ItemEntry> const& /*store*/, uint buffer << uint32(proto->Sheath); } -void DB2Utilities::WriteItemSparseDbReply(DB2Storage<ItemSparseEntry> const& /*store*/, uint32 id, ByteBuffer& buffer) +void DB2Utilities::WriteItemSparseDbReply(DB2Storage<ItemSparseEntry> const& /*store*/, uint32 id, uint32 locale, ByteBuffer& buffer) { ItemTemplate const* proto = sObjectMgr->GetItemTemplate(id); ASSERT(proto); + ItemLocale const* localeData = locale ? sObjectMgr->GetItemLocale(id) : NULL; + buffer << uint32(proto->ItemId); buffer << uint32(proto->Quality); buffer << uint32(proto->Flags); @@ -117,6 +119,9 @@ void DB2Utilities::WriteItemSparseDbReply(DB2Storage<ItemSparseEntry> const& /*s // item name std::string name = proto->Name1; + if (localeData) + ObjectMgr::GetLocaleString(localeData->Name, locale, name); + buffer << uint16(name.length()); if (name.length()) buffer << name; @@ -125,6 +130,9 @@ void DB2Utilities::WriteItemSparseDbReply(DB2Storage<ItemSparseEntry> const& /*s buffer << uint16(0); std::string desc = proto->Description; + if (localeData) + ObjectMgr::GetLocaleString(localeData->Description, locale, desc); + buffer << uint16(desc.length()); if (desc.length()) buffer << desc; diff --git a/src/server/game/DataStores/DB2Utility.h b/src/server/game/DataStores/DB2Utility.h index 120ffd1cd27..82ef692d320 100644 --- a/src/server/game/DataStores/DB2Utility.h +++ b/src/server/game/DataStores/DB2Utility.h @@ -33,8 +33,8 @@ namespace DB2Utilities bool HasItemSparseEntry(DB2Storage<ItemSparseEntry> const& store, uint32 id); // - void WriteItemDbReply(DB2Storage<ItemEntry> const& store, uint32 id, ByteBuffer& buffer); - void WriteItemSparseDbReply(DB2Storage<ItemSparseEntry> const& store, uint32 id, ByteBuffer& buffer); + void WriteItemDbReply(DB2Storage<ItemEntry> const& store, uint32 id, uint32 locale, ByteBuffer& buffer); + void WriteItemSparseDbReply(DB2Storage<ItemSparseEntry> const& store, uint32 id, uint32 locale, ByteBuffer& buffer); } #endif // DB2PACKETWRITER_H diff --git a/src/server/game/DataStores/DBCEnums.h b/src/server/game/DataStores/DBCEnums.h index fc94b49a336..1daf69f0b5f 100644 --- a/src/server/game/DataStores/DBCEnums.h +++ b/src/server/game/DataStores/DBCEnums.h @@ -80,7 +80,7 @@ enum AchievementFlags ACHIEVEMENT_FLAG_SHOW_CRITERIA_MEMBERS = 0x00010000 // }; -enum +enum AchievementCriteriaLimits { MAX_CRITERIA_REQUIREMENTS = 2, MAX_ADDITIONAL_CRITERIA_CONDITIONS = 3 diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index e9181cebbc3..c897219604f 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -2392,7 +2392,7 @@ void ObjectMgr::LoadItemTemplates() itemTemplate.Class = db2Data->Class; itemTemplate.SubClass = db2Data->SubClass; itemTemplate.SoundOverrideSubclass = db2Data->SoundOverrideSubclass; - itemTemplate.Name1 = sparse->Name; + itemTemplate.Name1 = sparse->Name->Str[sWorld->GetDefaultDbcLocale()]; itemTemplate.DisplayInfoID = db2Data->DisplayId; itemTemplate.Quality = sparse->Quality; itemTemplate.Flags = sparse->Flags; @@ -2448,7 +2448,7 @@ void ObjectMgr::LoadItemTemplates() itemTemplate.SpellPPMRate = 0.0f; itemTemplate.Bonding = sparse->Bonding; - itemTemplate.Description = sparse->Description; + itemTemplate.Description = sparse->Description->Str[sWorld->GetDefaultDbcLocale()]; itemTemplate.PageText = sparse->PageText; itemTemplate.LanguageID = sparse->LanguageID; itemTemplate.PageMaterial = sparse->PageMaterial; diff --git a/src/server/game/Handlers/MiscHandler.cpp b/src/server/game/Handlers/MiscHandler.cpp index 2d454dae927..c64e4ae915f 100644 --- a/src/server/game/Handlers/MiscHandler.cpp +++ b/src/server/game/Handlers/MiscHandler.cpp @@ -1919,7 +1919,7 @@ void WorldSession::HandleRequestHotfix(WorldPacket& recvPacket) size_t sizePos = data.wpos(); data << uint32(0); // size of next block - store->WriteRecord(entry, data); + store->WriteRecord(entry, uint32(GetSessionDbcLocale()), data); data.put<uint32>(sizePos, data.wpos() - sizePos - 4); SendPacket(&data); diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index c5d47dae56f..71439254647 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -407,6 +407,16 @@ void World::LoadConfigSettings(bool reload) sLog->LoadFromConfig(); } + m_defaultDbcLocale = LocaleConstant(ConfigMgr::GetIntDefault("DBC.Locale", 0)); + + if (m_defaultDbcLocale >= TOTAL_LOCALES) + { + sLog->outError(LOG_FILTER_SERVER_LOADING, "Incorrect DBC.Locale! Must be >= 0 and < %d (set to 0)", TOTAL_LOCALES); + m_defaultDbcLocale = LOCALE_enUS; + } + + sLog->outInfo(LOG_FILTER_SERVER_LOADING, "Using %s DBC Locale", localeNames[m_defaultDbcLocale]); + ///- Read the player limit and the Message of the day from the config file SetPlayerAmountLimit(ConfigMgr::GetIntDefault("PlayerLimit", 100)); SetMotd(ConfigMgr::GetStringDefault("Motd", "Welcome to a Trinity Core Server.")); @@ -1328,7 +1338,6 @@ void World::SetInitialWorldSettings() sLog->outInfo(LOG_FILTER_SERVER_LOADING, "Initialize data stores..."); LoadDBCStores(m_dataPath); LoadDB2Stores(m_dataPath); - DetectDBCLang(); sLog->outInfo(LOG_FILTER_SERVER_LOADING, "Loading SpellInfo store..."); sSpellMgr->LoadSpellInfoStore(); @@ -1853,49 +1862,6 @@ void World::SetInitialWorldSettings() sLog->SetRealmId(realmId); } -void World::DetectDBCLang() -{ - uint8 m_lang_confid = ConfigMgr::GetIntDefault("DBC.Locale", 0); - - if (m_lang_confid >= TOTAL_LOCALES) - { - sLog->outError(LOG_FILTER_SERVER_LOADING, "Incorrect DBC.Locale! Must be >= 0 and < %d (set to 0)", TOTAL_LOCALES); - m_lang_confid = LOCALE_enUS; - } - - /*ChrRacesEntry const* race = sChrRacesStore.LookupEntry(1); - - std::string availableLocalsStr; - - uint8 default_locale = TOTAL_LOCALES; - for (uint8 i = default_locale-1; i < TOTAL_LOCALES; --i) // -1 will be 255 due to uint8 - { - if (race->name[i][0] != '\0') // check by race names - { - default_locale = i; - m_availableDbcLocaleMask |= (1 << i); - availableLocalsStr += localeNames[i]; - availableLocalsStr += " "; - } - } - - if (default_locale != m_lang_confid && m_lang_confid < TOTAL_LOCALES && - (m_availableDbcLocaleMask & (1 << m_lang_confid))) - { - default_locale = m_lang_confid; - } - - if (default_locale >= TOTAL_LOCALES) - { - sLog->outError(LOG_FILTER_SERVER_LOADING, "Unable to determine your DBC Locale! (corrupt DBC?)"); - exit(1); - }*/ - - m_defaultDbcLocale = LocaleConstant(m_lang_confid); - - sLog->outInfo(LOG_FILTER_SERVER_LOADING, "Using %s DBC Locale", localeNames[m_defaultDbcLocale]); -} - void World::RecordTimeDiff(const char *text, ...) { if (m_updateTimeCount != 1) diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h index d7c20b08941..1aa93ce5486 100644 --- a/src/server/game/World/World.h +++ b/src/server/game/World/World.h @@ -809,7 +809,6 @@ class World AccountTypes m_allowedSecurityLevel; LocaleConstant m_defaultDbcLocale; // from config for one from loaded DBC locales uint32 m_availableDbcLocaleMask; // by loaded DBC - void DetectDBCLang(); bool m_allowMovement; std::string m_motd; std::string m_dataPath; |
