diff options
-rw-r--r-- | sql/updates/world/2013_03_15_01_world_keychain_db2.sql | 43 | ||||
-rw-r--r-- | src/server/game/DataStores/DB2Stores.cpp | 23 | ||||
-rw-r--r-- | src/server/game/DataStores/DB2Stores.h | 22 | ||||
-rw-r--r-- | src/server/game/DataStores/DB2Structure.h | 8 | ||||
-rw-r--r-- | src/server/game/DataStores/DB2fmt.h | 9 | ||||
-rw-r--r-- | src/server/game/Globals/ObjectMgr.cpp | 37 | ||||
-rw-r--r-- | src/server/game/Globals/ObjectMgr.h | 7 | ||||
-rw-r--r-- | src/server/game/Handlers/ItemHandler.cpp | 17 | ||||
-rw-r--r-- | src/server/game/Handlers/MiscHandler.cpp | 46 | ||||
-rw-r--r-- | src/server/game/Server/WorldSession.h | 1 | ||||
-rw-r--r-- | src/server/game/World/World.cpp | 3 | ||||
-rw-r--r-- | src/server/shared/DataStores/DB2Store.h | 59 |
12 files changed, 210 insertions, 65 deletions
diff --git a/sql/updates/world/2013_03_15_01_world_keychain_db2.sql b/sql/updates/world/2013_03_15_01_world_keychain_db2.sql new file mode 100644 index 00000000000..b5756fc62d1 --- /dev/null +++ b/sql/updates/world/2013_03_15_01_world_keychain_db2.sql @@ -0,0 +1,43 @@ +DROP TABLE IF EXISTS `keychain_db2`; +CREATE TABLE `keychain_db2` ( + `keyId` INT UNSIGNED NOT NULL DEFAULT '0', + `k1` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k2` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k3` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k4` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k5` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k6` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k7` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k8` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k9` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k10` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k11` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k12` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k13` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k14` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k15` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k16` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k17` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k18` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k19` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k20` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k21` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k22` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k23` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k24` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k25` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k26` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k27` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k28` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k29` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k30` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k31` TINYINT UNSIGNED NOT NULL DEFAULT '0', + `k32` TINYINT UNSIGNED NOT NULL DEFAULT '0', + PRIMARY KEY (`keyId`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +INSERT INTO `keychain_db2` VALUES +(33, 53, 6, 164, 135, 117, 210, 209, 135, 247, 162, 85, 200, 76, 220, 107, 56, 80, 214, 44, 121, 29, 66, 81, 25, 41, 38, 208, 8, 235, 154, 58, 139), +(35, 16, 209, 60, 47, 154, 100, 204, 97, 125, 161, 79, 126, 191, 163, 7, 45, 64, 188, 199, 88, 141, 46, 153, 90, 143, 40, 6, 80, 29, 133, 217, 135), +(36, 3, 169, 217, 5, 156, 76, 33, 82, 75, 181, 233, 203, 230, 52, 67, 197, 57, 99, 27, 108, 100, 197, 93, 156, 174, 2, 248, 216, 244, 115, 164, 210), +(37, 119, 7, 189, 206, 199, 253, 234, 73, 232, 17, 162, 79, 0, 35, 222, 224, 7, 98, 132, 147, 229, 36, 19, 253, 79, 59, 198, 59, 48, 121, 97, 215); diff --git a/src/server/game/DataStores/DB2Stores.cpp b/src/server/game/DataStores/DB2Stores.cpp index dadcce42950..f4570a1c17e 100644 --- a/src/server/game/DataStores/DB2Stores.cpp +++ b/src/server/game/DataStores/DB2Stores.cpp @@ -16,23 +16,21 @@ */ #include "DB2Stores.h" -#include "Log.h" -#include "SharedDefines.h" -#include "SpellMgr.h" #include "DB2fmt.h" +#include "Common.h" +#include "Log.h" -#include <map> - -DB2Storage <ItemEntry> sItemStore(Itemfmt); -DB2Storage <ItemCurrencyCostEntry> sItemCurrencyCostStore(ItemCurrencyCostfmt); -DB2Storage <ItemExtendedCostEntry> sItemExtendedCostStore(ItemExtendedCostEntryfmt); -DB2Storage <ItemSparseEntry> sItemSparseStore (ItemSparsefmt); +DB2Storage<ItemEntry> sItemStore(Itemfmt); +DB2Storage<ItemCurrencyCostEntry> sItemCurrencyCostStore(ItemCurrencyCostfmt); +DB2Storage<ItemExtendedCostEntry> sItemExtendedCostStore(ItemExtendedCostEntryfmt); +DB2Storage<ItemSparseEntry> sItemSparseStore(ItemSparsefmt); +DB2Storage<KeyChainEntry> sKeyChainStore(KeyChainfmt); typedef std::list<std::string> StoreProblemList1; uint32 DB2FilesCount = 0; -static bool LoadDB2_assert_print(uint32 fsize, uint32 rsize, const std::string& filename) +static bool LoadDB2_assert_print(uint32 fsize, uint32 rsize, std::string const& filename) { sLog->outError(LOG_FILTER_GENERAL, "Size of '%s' setted by format string (%u) not equal size of C++ structure (%u).", filename.c_str(), fsize, rsize); @@ -51,7 +49,7 @@ struct LocalDB2Data }; template<class T> -inline void LoadDB2(StoreProblemList1& errlist, DB2Storage<T>& storage, const std::string& db2_path, const std::string& filename) +inline void LoadDB2(StoreProblemList1& 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)); @@ -74,7 +72,7 @@ inline void LoadDB2(StoreProblemList1& errlist, DB2Storage<T>& storage, const st } } -void LoadDB2Stores(const std::string& dataPath) +void LoadDB2Stores(std::string const& dataPath) { std::string db2Path = dataPath + "dbc/"; @@ -84,6 +82,7 @@ void LoadDB2Stores(const std::string& dataPath) 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/DB2Stores.h b/src/server/game/DataStores/DB2Stores.h index 6cf719da70b..f57da14419c 100644 --- a/src/server/game/DataStores/DB2Stores.h +++ b/src/server/game/DataStores/DB2Stores.h @@ -18,17 +18,25 @@ #ifndef TRINITY_DB2STORES_H #define TRINITY_DB2STORES_H -#include "Common.h" #include "DB2Store.h" #include "DB2Structure.h" +#include <string> -#include <list> +enum DB2Hash +{ + DB2_HASH_ITEM = 0x50238EC2, + DB2_HASH_ITEM_CURRENCY_COST = 0x6FE05AE9, + DB2_HASH_ITEM_EXTENDED_COST = 0xBB858355, + DB2_HASH_ITEM_SPARSE = 0x919BE54E, + DB2_HASH_KEYCHAIN = 0x6D8A2694, +}; -extern DB2Storage <ItemEntry> sItemStore; -extern DB2Storage <ItemCurrencyCostEntry> sItemCurrencyCostStore; -extern DB2Storage <ItemExtendedCostEntry> sItemExtendedCostStore; -extern DB2Storage <ItemSparseEntry> sItemSparseStore; +extern DB2Storage<ItemEntry> sItemStore; +extern DB2Storage<ItemCurrencyCostEntry> sItemCurrencyCostStore; +extern DB2Storage<ItemExtendedCostEntry> sItemExtendedCostStore; +extern DB2Storage<ItemSparseEntry> sItemSparseStore; +extern DB2Storage<KeyChainEntry> sKeyChainStore; -void LoadDB2Stores(const std::string& dataPath); +void LoadDB2Stores(std::string const& dataPath); #endif
\ No newline at end of file diff --git a/src/server/game/DataStores/DB2Structure.h b/src/server/game/DataStores/DB2Structure.h index a65136d7ccb..45b611180f4 100644 --- a/src/server/game/DataStores/DB2Structure.h +++ b/src/server/game/DataStores/DB2Structure.h @@ -148,6 +148,14 @@ struct ItemExtendedCostEntry //uint32 Unknown[5]; // 26-30 }; +#define KEYCHAIN_SIZE 32 + +struct KeyChainEntry +{ + uint32 Id; + uint8 Key[KEYCHAIN_SIZE]; +}; + // 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() diff --git a/src/server/game/DataStores/DB2fmt.h b/src/server/game/DataStores/DB2fmt.h index 3cc3a9b7693..e4b6801f36c 100644 --- a/src/server/game/DataStores/DB2fmt.h +++ b/src/server/game/DataStores/DB2fmt.h @@ -18,9 +18,10 @@ #ifndef TRINITY_DB2SFRM_H #define TRINITY_DB2SFRM_H -const char Itemfmt[]="niiiiiii"; -const char ItemCurrencyCostfmt[]="xn"; -const char ItemSparsefmt[]="niiiffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiifiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiisssssiiiiiiiiiiiiiiiiiiiiiifiiifii"; -const char ItemExtendedCostEntryfmt[]="nxxiiiiiiiiiiiixiiiiiiiiiixxxxx"; +char const Itemfmt[]="niiiiiii"; +char const ItemCurrencyCostfmt[]="xn"; +char const ItemSparsefmt[]="niiiffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiifiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiisssssiiiiiiiiiiiiiiiiiiiiiifiiifii"; +char const ItemExtendedCostEntryfmt[]="nxxiiiiiiiiiiiixiiiiiiiiiixxxxx"; +char const KeyChainfmt[]="nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; #endif diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 3b0cb8b736d..dfb84c23113 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -8737,7 +8737,7 @@ void ObjectMgr::LoadHotfixData() HotfixInfo info; info.Entry = fields[0].GetUInt32(); - info.Type = fields[1].GetUInt32(); + info.Type = DB2Hash(fields[1].GetUInt32()); info.Timestamp = fields[2].GetUInt64(); _hotfixData.push_back(info); @@ -8748,6 +8748,41 @@ void ObjectMgr::LoadHotfixData() sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded %u hotfix info entries in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); } +void ObjectMgr::LoadMissingKeyChains() +{ + uint32 oldMSTime = getMSTime(); + + QueryResult result = WorldDatabase.Query("SELECT keyId, k1, k2, k3, k4, k5, k6, k7, k8, " + "k9, k10, k11, k12, k13, k14, k15, k16, " + "k17, k18, k19, k20, k21, k22, k23, k24, " + "k25, k26, k27, k28, k29, k30, k31, k32 " + "FROM keychain_db2 ORDER BY keyId DESC"); + + if (!result) + { + sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded 0 KeyChain entries. DB table `keychain_db2` is empty."); + return; + } + + uint32 count = 0; + + do + { + Field* fields = result->Fetch(); + uint32 id = fields[0].GetUInt32();; + + KeyChainEntry* kce = sKeyChainStore.CreateEntry(id, true); + kce->Id = id; + for (uint32 i = 0; i < KEYCHAIN_SIZE; ++i) + kce->Key[i] = fields[1 + i].GetUInt8(); + + ++count; + } + while (result->NextRow()); + + sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded %u KeyChain entries in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); +} + void ObjectMgr::LoadFactionChangeSpells() { uint32 oldMSTime = getMSTime(); diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index 50d9baf292a..9987df7591f 100644 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -43,6 +43,7 @@ #include "ConditionMgr.h" #include <functional> #include "PhaseMgr.h" +#include "DB2Stores.h" class Item; class PhaseMgr; @@ -640,7 +641,7 @@ typedef UNORDERED_MAP<uint32, DungeonEncounterList> DungeonEncounterContainer; struct HotfixInfo { - uint32 Type; + DB2Hash Type; uint32 Timestamp; uint32 Entry; }; @@ -1228,7 +1229,7 @@ class ObjectMgr void LoadHotfixData(); HotfixData const& GetHotfixData() const { return _hotfixData; } - time_t GetHotfixDate(uint32 entry, uint32 type) const + time_t GetHotfixDate(uint32 entry, DB2Hash type) const { time_t ret = 0; for (HotfixData::const_iterator itr = _hotfixData.begin(); itr != _hotfixData.end(); ++itr) @@ -1239,6 +1240,8 @@ class ObjectMgr return ret ? ret : time(NULL); } + void LoadMissingKeyChains(); + private: // first free id for selected id type uint32 _auctionId; diff --git a/src/server/game/Handlers/ItemHandler.cpp b/src/server/game/Handlers/ItemHandler.cpp index 373c0d2a5e6..29af6fdc8f4 100644 --- a/src/server/game/Handlers/ItemHandler.cpp +++ b/src/server/game/Handlers/ItemHandler.cpp @@ -27,6 +27,7 @@ #include "UpdateData.h" #include "ObjectAccessor.h" #include "SpellInfo.h" +#include "DB2Stores.h" #include <vector> void WorldSession::HandleSplitItemOpcode(WorldPacket& recvData) @@ -284,16 +285,16 @@ void WorldSession::SendItemDb2Reply(uint32 entry) ItemTemplate const* proto = sObjectMgr->GetItemTemplate(entry); if (!proto) { - data << uint32(-1); // entry - data << uint32(DB2_REPLY_ITEM); + data << -int32(entry); // entry + data << uint32(DB2_HASH_ITEM); data << uint32(time(NULL)); // hotfix date data << uint32(0); // size of next block return; } data << uint32(entry); - data << uint32(DB2_REPLY_ITEM); - data << uint32(sObjectMgr->GetHotfixDate(entry, DB2_REPLY_ITEM)); + data << uint32(DB2_HASH_ITEM); + data << uint32(sObjectMgr->GetHotfixDate(entry, DB2_HASH_ITEM)); ByteBuffer buff; buff << uint32(entry); @@ -317,16 +318,16 @@ void WorldSession::SendItemSparseDb2Reply(uint32 entry) ItemTemplate const* proto = sObjectMgr->GetItemTemplate(entry); if (!proto) { - data << uint32(-1); // entry - data << uint32(DB2_REPLY_SPARSE); + data << -int32(entry); // entry + data << uint32(DB2_HASH_ITEM_SPARSE); data << uint32(time(NULL)); // hotfix date data << uint32(0); // size of next block return; } data << uint32(entry); - data << uint32(DB2_REPLY_SPARSE); - data << uint32(sObjectMgr->GetHotfixDate(entry, DB2_REPLY_SPARSE)); + data << uint32(DB2_HASH_ITEM_SPARSE); + data << uint32(sObjectMgr->GetHotfixDate(entry, DB2_HASH_ITEM_SPARSE)); ByteBuffer buff; buff << uint32(entry); diff --git a/src/server/game/Handlers/MiscHandler.cpp b/src/server/game/Handlers/MiscHandler.cpp index 94ef34e8dd7..a0a721c8971 100644 --- a/src/server/game/Handlers/MiscHandler.cpp +++ b/src/server/game/Handlers/MiscHandler.cpp @@ -55,6 +55,7 @@ #include "BattlegroundMgr.h" #include "Battlefield.h" #include "BattlefieldMgr.h" +#include "DB2Stores.h" void WorldSession::HandleRepopRequestOpcode(WorldPacket& recvData) { @@ -1894,22 +1895,61 @@ void WorldSession::HandleRequestHotfix(WorldPacket& recvPacket) switch (type) { - case DB2_REPLY_ITEM: + case DB2_HASH_ITEM: SendItemDb2Reply(entry); break; - case DB2_REPLY_SPARSE: + case DB2_HASH_ITEM_SPARSE: SendItemSparseDb2Reply(entry); break; + case DB2_HASH_KEYCHAIN: + SendKeyChainDb2Reply(entry); + break; default: - sLog->outError(LOG_FILTER_NETWORKIO, "CMSG_REQUEST_HOTFIX: Received unknown hotfix type: %u", type); + { + WorldPacket data(SMSG_DB_REPLY, 4 * 4); + data << -int32(entry); + data << uint32(type); + data << uint32(time(NULL)); + data << uint32(0); + SendPacket(&data); + + sLog->outError(LOG_FILTER_NETWORKIO, "CMSG_REQUEST_HOTFIX: Received unknown hotfix type: %u, entry %u", type, entry); recvPacket.rfinish(); break; + } } } delete[] guids; } +void WorldSession::SendKeyChainDb2Reply(uint32 entry) +{ + WorldPacket data(SMSG_DB_REPLY, 44); + KeyChainEntry const* keyChain = sKeyChainStore.LookupEntry(entry); + if (!keyChain) + { + data << -int32(entry); // entry + data << uint32(DB2_HASH_KEYCHAIN); + data << uint32(time(NULL)); // hotfix date + data << uint32(0); // size of next block + return; + } + + data << uint32(entry); + data << uint32(DB2_HASH_KEYCHAIN); + data << uint32(sObjectMgr->GetHotfixDate(entry, DB2_HASH_KEYCHAIN)); + + ByteBuffer buff; + buff << uint32(entry); + buff.append(keyChain->Key, KEYCHAIN_SIZE); + + data << uint32(buff.size()); + data.append(buff); + + SendPacket(&data); +} + void WorldSession::HandleUpdateMissileTrajectory(WorldPacket& recvPacket) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_UPDATE_MISSILE_TRAJECTORY"); diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h index c4a918c227a..9680ac0d5e5 100644 --- a/src/server/game/Server/WorldSession.h +++ b/src/server/game/Server/WorldSession.h @@ -647,6 +647,7 @@ class WorldSession void HandleAutoEquipItemOpcode(WorldPacket& recvPacket); void SendItemDb2Reply(uint32 entry); void SendItemSparseDb2Reply(uint32 entry); + void SendKeyChainDb2Reply(uint32 entry); void HandleSellItemOpcode(WorldPacket& recvPacket); void HandleBuyItemInSlotOpcode(WorldPacket& recvPacket); void HandleBuyItemOpcode(WorldPacket& recvPacket); diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index 018c5bc932a..c5d47dae56f 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -1842,6 +1842,9 @@ void World::SetInitialWorldSettings() sLog->outInfo(LOG_FILTER_GENERAL, "Loading hotfix info..."); sObjectMgr->LoadHotfixData(); + sLog->outInfo(LOG_FILTER_SERVER_LOADING, "Loading missing KeyChains..."); + sObjectMgr->LoadMissingKeyChains(); + uint32 startupDuration = GetMSTimeDiffToNow(startupBegin); sLog->outInfo(LOG_FILTER_WORLDSERVER, "World initialized in %u minutes %u seconds", (startupDuration / 60000), ((startupDuration % 60000) / 1000)); diff --git a/src/server/shared/DataStores/DB2Store.h b/src/server/shared/DataStores/DB2Store.h index 6ebca714fe6..c8f51bc96cb 100644 --- a/src/server/shared/DataStores/DB2Store.h +++ b/src/server/shared/DataStores/DB2Store.h @@ -34,37 +34,39 @@ class DB2Storage typedef std::list<char*> StringPoolList; typedef std::vector<T*> DataTableEx; public: - explicit DB2Storage(const char *f) : nCount(0), fieldCount(0), fmt(f), indexTable(NULL), m_dataTable(NULL) { } + explicit DB2Storage(char const* f) : nCount(0), fieldCount(0), fmt(f), indexTable(NULL), m_dataTable(NULL) { } ~DB2Storage() { Clear(); } - T const* LookupEntry(uint32 id) const { return (id>=nCount)?NULL:indexTable[id]; } - uint32 GetNumRows() const { return nCount; } + T const* LookupEntry(uint32 id) const { return (id >= nCount) ? NULL : indexTable[id]; } + uint32 GetNumRows() const { return nCount; } char const* GetFormat() const { return fmt; } uint32 GetFieldCount() const { return fieldCount; } - /// Copies the provided entry and stores it. - void AddEntry(uint32 id, const T* entry) + /// Copies the provided entry and stores it. + T* CreateEntry(uint32 id, bool evenIfExists = false) + { + if (evenIfExists && LookupEntry(id)) + return NULL; + + if (id >= nCount) { - if (LookupEntry(id)) - return; - - if (id >= nCount) - { - // reallocate index table - char** tmpIdxTable = new char*[id+1]; - memset(tmpIdxTable, 0, (id+1) * sizeof(char*)); - memcpy(tmpIdxTable, (char*)indexTable, nCount * sizeof(char*)); - delete[] ((char*)indexTable); - nCount = id + 1; - indexTable = (T**)tmpIdxTable; - } - - T* entryDst = new T; - memcpy((char*)entryDst, (char*)entry, sizeof(T)); - m_dataTableEx.push_back(entryDst); - indexTable[id] = entryDst; + // reallocate index table + char** tmpIdxTable = new char*[id + 1]; + memset(tmpIdxTable, 0, (id + 1) * sizeof(char*)); + memcpy(tmpIdxTable, (char*)indexTable, nCount * sizeof(char*)); + delete[] ((char*)indexTable); + nCount = id + 1; + indexTable = (T**)tmpIdxTable; } + T* entryDst = new T; + m_dataTableEx.push_back(entryDst); + indexTable[id] = entryDst; + return entryDst; + } + + void EraseEntry(uint32 id) { indexTable[id] = NULL; } + bool Load(char const* fn) { DB2FileLoader db2; @@ -111,22 +113,23 @@ public: delete[] ((char*)indexTable); indexTable = NULL; + delete[] ((char*)m_dataTable); m_dataTable = NULL; - for (typename DataTableEx::const_iterator itr = m_dataTableEx.begin(); itr != m_dataTableEx.end(); ++itr) - delete *itr; - m_dataTableEx.clear(); + + for (typename DataTableEx::iterator itr = m_dataTableEx.begin(); itr != m_dataTableEx.end(); ++itr) + delete *itr; + m_dataTableEx.clear(); while (!m_stringPoolList.empty()) { delete[] m_stringPoolList.front(); m_stringPoolList.pop_front(); } + nCount = 0; } - void EraseEntry(uint32 id) { indexTable[id] = NULL; } - private: uint32 nCount; uint32 fieldCount; |