aboutsummaryrefslogtreecommitdiff
path: root/src/shared/Database
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/Database')
-rw-r--r--src/shared/Database/DBCEnums.h208
-rw-r--r--src/shared/Database/DBCStores.cpp16
-rw-r--r--src/shared/Database/DBCStores.h2
-rw-r--r--src/shared/Database/DBCStructure.h20
-rw-r--r--src/shared/Database/DBCfmt.cpp5
-rw-r--r--src/shared/Database/SQLStorageImpl.h428
6 files changed, 358 insertions, 321 deletions
diff --git a/src/shared/Database/DBCEnums.h b/src/shared/Database/DBCEnums.h
index 9050aae8daa..6ad7fdb127a 100644
--- a/src/shared/Database/DBCEnums.h
+++ b/src/shared/Database/DBCEnums.h
@@ -1,104 +1,104 @@
-/*
-* Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-
-#ifndef DBCENUMS_H
-#define DBCENUMS_H
-
-enum AreaTeams
-{
- AREATEAM_NONE = 0,
- AREATEAM_ALLY = 2,
- AREATEAM_HORDE = 4
-};
-
-enum AreaFlags
-{
- AREA_FLAG_SNOW = 0x00000001, // snow (only Dun Morogh, Naxxramas, Razorfen Downs and Winterspring)
- AREA_FLAG_UNK1 = 0x00000002, // unknown, (only Naxxramas and Razorfen Downs)
- AREA_FLAG_UNK2 = 0x00000004, // Only used on development map
- AREA_FLAG_SLAVE_CAPITAL = 0x00000008, // slave capital city flag?
- AREA_FLAG_UNK3 = 0x00000010, // unknown
- AREA_FLAG_SLAVE_CAPITAL2 = 0x00000020, // slave capital city flag?
- AREA_FLAG_UNK4 = 0x00000040, // many zones have this flag
- AREA_FLAG_ARENA = 0x00000080, // arena, both instanced and world arenas
- AREA_FLAG_CAPITAL = 0x00000100, // main capital city flag
- AREA_FLAG_CITY = 0x00000200, // only for one zone named "City" (where it located?)
- AREA_FLAG_OUTLAND = 0x00000400, // outland zones? (only Eye of the Storm not have this flag, but have 0x00004000 flag)
- AREA_FLAG_SANCTUARY = 0x00000800, // sanctuary area (PvP disabled)
- AREA_FLAG_NEED_FLY = 0x00001000, // only Netherwing Ledge, Socrethar's Seat, Tempest Keep, The Arcatraz, The Botanica, The Mechanar, Sorrow Wing Point, Dragonspine Ridge, Netherwing Mines, Dragonmaw Base Camp, Dragonmaw Skyway
- AREA_FLAG_UNUSED1 = 0x00002000, // not used now (no area/zones with this flag set in 2.4.2)
- AREA_FLAG_OUTLAND2 = 0x00004000, // outland zones? (only Circle of Blood Arena not have this flag, but have 0x00000400 flag)
- AREA_FLAG_PVP = 0x00008000, // pvp objective area? (Death's Door also has this flag although it's no pvp object area)
- AREA_FLAG_ARENA_INSTANCE = 0x00010000, // used by instanced arenas only
- AREA_FLAG_UNUSED2 = 0x00020000, // not used now (no area/zones with this flag set in 2.4.2)
- AREA_FLAG_UNK5 = 0x00040000, // just used for Amani Pass, Hatchet Hills
- AREA_FLAG_LOWLEVEL = 0x00100000 // used for some starting areas with area_level <=15
-};
-
-enum FactionTemplateFlags
-{
- FACTION_TEMPLATE_FLAG_CONTESTED_GUARD = 0x00001000, // faction will attack players that were involved in PvP combats
-};
-
-enum FactionMasks
-{
- FACTION_MASK_PLAYER = 1, // any player
- FACTION_MASK_ALLIANCE = 2, // player or creature from alliance team
- FACTION_MASK_HORDE = 4, // player or creature from horde team
- FACTION_MASK_MONSTER = 8 // aggressive creature from monster team
- // if none flags set then non-aggressive creature
-};
-
-enum MapTypes
-{
- MAP_COMMON = 0,
- MAP_INSTANCE = 1,
- MAP_RAID = 2,
- MAP_BATTLEGROUND = 3,
- MAP_ARENA = 4
-};
-
-enum AbilytyLearnType
-{
- ABILITY_LEARNED_ON_GET_PROFESSION_SKILL = 1,
- ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL = 2
-};
-
-enum ItemEnchantmentType
-{
- ITEM_ENCHANTMENT_TYPE_NONE = 0,
- ITEM_ENCHANTMENT_TYPE_COMBAT_SPELL = 1,
- ITEM_ENCHANTMENT_TYPE_DAMAGE = 2,
- ITEM_ENCHANTMENT_TYPE_EQUIP_SPELL = 3,
- ITEM_ENCHANTMENT_TYPE_RESISTANCE = 4,
- ITEM_ENCHANTMENT_TYPE_STAT = 5,
- ITEM_ENCHANTMENT_TYPE_TOTEM = 6
-};
-
-enum TotemCategoryType
-{
- TOTEM_CATEGORY_TYPE_KNIFE = 1,
- TOTEM_CATEGORY_TYPE_TOTEM = 2,
- TOTEM_CATEGORY_TYPE_ROD = 3,
- TOTEM_CATEGORY_TYPE_PICK = 21,
- TOTEM_CATEGORY_TYPE_STONE = 22,
- TOTEM_CATEGORY_TYPE_HAMMER = 23,
- TOTEM_CATEGORY_TYPE_SPANNER = 24
-};
-
-#endif
+/*
+* Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#ifndef DBCENUMS_H
+#define DBCENUMS_H
+
+enum AreaTeams
+{
+ AREATEAM_NONE = 0,
+ AREATEAM_ALLY = 2,
+ AREATEAM_HORDE = 4
+};
+
+enum AreaFlags
+{
+ AREA_FLAG_SNOW = 0x00000001, // snow (only Dun Morogh, Naxxramas, Razorfen Downs and Winterspring)
+ AREA_FLAG_UNK1 = 0x00000002, // unknown, (only Naxxramas and Razorfen Downs)
+ AREA_FLAG_UNK2 = 0x00000004, // Only used on development map
+ AREA_FLAG_SLAVE_CAPITAL = 0x00000008, // slave capital city flag?
+ AREA_FLAG_UNK3 = 0x00000010, // unknown
+ AREA_FLAG_SLAVE_CAPITAL2 = 0x00000020, // slave capital city flag?
+ AREA_FLAG_UNK4 = 0x00000040, // many zones have this flag
+ AREA_FLAG_ARENA = 0x00000080, // arena, both instanced and world arenas
+ AREA_FLAG_CAPITAL = 0x00000100, // main capital city flag
+ AREA_FLAG_CITY = 0x00000200, // only for one zone named "City" (where it located?)
+ AREA_FLAG_OUTLAND = 0x00000400, // outland zones? (only Eye of the Storm not have this flag, but have 0x00004000 flag)
+ AREA_FLAG_SANCTUARY = 0x00000800, // sanctuary area (PvP disabled)
+ AREA_FLAG_NEED_FLY = 0x00001000, // only Netherwing Ledge, Socrethar's Seat, Tempest Keep, The Arcatraz, The Botanica, The Mechanar, Sorrow Wing Point, Dragonspine Ridge, Netherwing Mines, Dragonmaw Base Camp, Dragonmaw Skyway
+ AREA_FLAG_UNUSED1 = 0x00002000, // not used now (no area/zones with this flag set in 2.4.2)
+ AREA_FLAG_OUTLAND2 = 0x00004000, // outland zones? (only Circle of Blood Arena not have this flag, but have 0x00000400 flag)
+ AREA_FLAG_PVP = 0x00008000, // pvp objective area? (Death's Door also has this flag although it's no pvp object area)
+ AREA_FLAG_ARENA_INSTANCE = 0x00010000, // used by instanced arenas only
+ AREA_FLAG_UNUSED2 = 0x00020000, // not used now (no area/zones with this flag set in 2.4.2)
+ AREA_FLAG_UNK5 = 0x00040000, // just used for Amani Pass, Hatchet Hills
+ AREA_FLAG_LOWLEVEL = 0x00100000 // used for some starting areas with area_level <=15
+};
+
+enum FactionTemplateFlags
+{
+ FACTION_TEMPLATE_FLAG_CONTESTED_GUARD = 0x00001000, // faction will attack players that were involved in PvP combats
+};
+
+enum FactionMasks
+{
+ FACTION_MASK_PLAYER = 1, // any player
+ FACTION_MASK_ALLIANCE = 2, // player or creature from alliance team
+ FACTION_MASK_HORDE = 4, // player or creature from horde team
+ FACTION_MASK_MONSTER = 8 // aggressive creature from monster team
+ // if none flags set then non-aggressive creature
+};
+
+enum MapTypes
+{
+ MAP_COMMON = 0,
+ MAP_INSTANCE = 1,
+ MAP_RAID = 2,
+ MAP_BATTLEGROUND = 3,
+ MAP_ARENA = 4
+};
+
+enum AbilytyLearnType
+{
+ ABILITY_LEARNED_ON_GET_PROFESSION_SKILL = 1,
+ ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL = 2
+};
+
+enum ItemEnchantmentType
+{
+ ITEM_ENCHANTMENT_TYPE_NONE = 0,
+ ITEM_ENCHANTMENT_TYPE_COMBAT_SPELL = 1,
+ ITEM_ENCHANTMENT_TYPE_DAMAGE = 2,
+ ITEM_ENCHANTMENT_TYPE_EQUIP_SPELL = 3,
+ ITEM_ENCHANTMENT_TYPE_RESISTANCE = 4,
+ ITEM_ENCHANTMENT_TYPE_STAT = 5,
+ ITEM_ENCHANTMENT_TYPE_TOTEM = 6
+};
+
+enum TotemCategoryType
+{
+ TOTEM_CATEGORY_TYPE_KNIFE = 1,
+ TOTEM_CATEGORY_TYPE_TOTEM = 2,
+ TOTEM_CATEGORY_TYPE_ROD = 3,
+ TOTEM_CATEGORY_TYPE_PICK = 21,
+ TOTEM_CATEGORY_TYPE_STONE = 22,
+ TOTEM_CATEGORY_TYPE_HAMMER = 23,
+ TOTEM_CATEGORY_TYPE_SPANNER = 24
+};
+
+#endif
diff --git a/src/shared/Database/DBCStores.cpp b/src/shared/Database/DBCStores.cpp
index 71e3483a1ab..03536daf738 100644
--- a/src/shared/Database/DBCStores.cpp
+++ b/src/shared/Database/DBCStores.cpp
@@ -38,6 +38,7 @@ static AreaFlagByMapID sAreaFlagByMapID; // for instances wit
DBCStorage <AreaTriggerEntry> sAreaTriggerStore(AreaTriggerEntryfmt);
DBCStorage <BankBagSlotPricesEntry> sBankBagSlotPricesStore(BankBagSlotPricesEntryfmt);
DBCStorage <BattlemasterListEntry> sBattlemasterListStore(BattlemasterListEntryfmt);
+DBCStorage <CharStartOutfitEntry> sCharStartOutfitStore(CharStartOutfitEntryfmt);
DBCStorage <CharTitlesEntry> sCharTitlesStore(CharTitlesEntryfmt);
DBCStorage <ChatChannelsEntry> sChatChannelsStore(ChatChannelsEntryfmt);
DBCStorage <ChrClassesEntry> sChrClassesStore(ChrClassesEntryfmt);
@@ -203,6 +204,8 @@ void LoadDBCStores(std::string dataPath)
LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaTriggerStore, dbcPath,"AreaTrigger.dbc");
LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBankBagSlotPricesStore, dbcPath,"BankBagSlotPrices.dbc");
LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBattlemasterListStore, dbcPath,"BattlemasterList.dbc");
+ LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCharStartOutfitStore, dbcPath,"CharStartOutfit.dbc");
+
LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCharTitlesStore, dbcPath,"CharTitles.dbc");
LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChatChannelsStore, dbcPath,"ChatChannels.dbc");
LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChrClassesStore, dbcPath,"ChrClasses.dbc");
@@ -494,13 +497,22 @@ uint32 GetTalentSpellCost(uint32 spellId)
return 0;
}
-AreaTableEntry const* GetAreaEntryByAreaID(uint32 area_id)
+int32 GetAreaFlagByAreaID(uint32 area_id)
{
AreaFlagByAreaID::iterator i = sAreaFlagByAreaID.find(area_id);
if(i == sAreaFlagByAreaID.end())
+ return -1;
+
+ return i->second;
+}
+
+AreaTableEntry const* GetAreaEntryByAreaID(uint32 area_id)
+{
+ int32 areaflag = GetAreaFlagByAreaID(area_id);
+ if(areaflag < 0)
return NULL;
- return sAreaStore.LookupEntry(i->second);
+ return sAreaStore.LookupEntry(areaflag );
}
AreaTableEntry const* GetAreaEntryByAreaFlagAndMap(uint32 area_flag,uint32 map_id)
diff --git a/src/shared/Database/DBCStores.h b/src/shared/Database/DBCStores.h
index 0375f20c7eb..399b94213fe 100644
--- a/src/shared/Database/DBCStores.h
+++ b/src/shared/Database/DBCStores.h
@@ -35,6 +35,7 @@ char* GetPetName(uint32 petfamily, uint32 dbclang);
uint32 GetTalentSpellCost(uint32 spellId);
TalentSpellPos const* GetTalentSpellPos(uint32 spellId);
+int32 GetAreaFlagByAreaID(uint32 area_id); // -1 if not found
AreaTableEntry const* GetAreaEntryByAreaID(uint32 area_id);
AreaTableEntry const* GetAreaEntryByAreaFlagAndMap(uint32 area_flag,uint32 map_id);
uint32 GetAreaFlagByMapId(uint32 mapid);
@@ -136,6 +137,7 @@ extern DBCStorage <AreaTriggerEntry> sAreaTriggerStore;
extern DBCStorage <BankBagSlotPricesEntry> sBankBagSlotPricesStore;
extern DBCStorage <BattlemasterListEntry> sBattlemasterListStore;
//extern DBCStorage <ChatChannelsEntry> sChatChannelsStore; -- accessed using function, no usable index
+extern DBCStorage <CharStartOutfitEntry> sCharStartOutfitStore;
extern DBCStorage <CharTitlesEntry> sCharTitlesStore;
extern DBCStorage <ChrClassesEntry> sChrClassesStore;
extern DBCStorage <ChrRacesEntry> sChrRacesStore;
diff --git a/src/shared/Database/DBCStructure.h b/src/shared/Database/DBCStructure.h
index a71f80ac8c7..a84b119664d 100644
--- a/src/shared/Database/DBCStructure.h
+++ b/src/shared/Database/DBCStructure.h
@@ -86,6 +86,21 @@ struct BattlemasterListEntry
// 32 unused
};
+#define MAX_OUTFIT_ITEMS 12
+// #define MAX_OUTFIT_ITEMS 24 // 12->24 in 3.0.x
+
+struct CharStartOutfitEntry
+{
+ //uint32 Id; // 0
+ uint32 RaceClassGender; // 1 (UNIT_FIELD_BYTES_0 & 0x00FFFFFF) comparable (0 byte = race, 1 byte = class, 2 byte = gender)
+ int32 ItemId[MAX_OUTFIT_ITEMS]; // 2-13
+ //int32 ItemDisplayId[MAX_OUTFIT_ITEMS]; // 14-25 not required at server side
+ //int32 ItemInventorySlot[MAX_OUTFIT_ITEMS]; // 26-37 not required at server side
+ //uint32 Unknown1; // 38, unique values (index-like with gaps ordered in other way as ids)
+ //uint32 Unknown2; // 39
+ //uint32 Unknown3; // 40
+};
+
struct CharTitlesEntry
{
uint32 ID; // 0, title ids, for example in Quest::GetCharTitleId()
@@ -229,6 +244,8 @@ struct FactionTemplateEntry
// helpers
bool IsFriendlyTo(FactionTemplateEntry const& entry) const
{
+ if(ID == entry.ID)
+ return true;
if(enemyFaction1 == entry.faction || enemyFaction2 == entry.faction || enemyFaction3 == entry.faction || enemyFaction4 == entry.faction )
return false;
if(friendFaction1 == entry.faction || friendFaction2 == entry.faction || friendFaction3 == entry.faction || friendFaction4 == entry.faction )
@@ -237,6 +254,8 @@ struct FactionTemplateEntry
}
bool IsHostileTo(FactionTemplateEntry const& entry) const
{
+ if(ID == entry.ID)
+ return false;
if(enemyFaction1 == entry.faction || enemyFaction2 == entry.faction || enemyFaction3 == entry.faction || enemyFaction4 == entry.faction )
return true;
if(friendFaction1 == entry.faction || friendFaction2 == entry.faction || friendFaction3 == entry.faction || friendFaction4 == entry.faction )
@@ -667,6 +686,7 @@ struct SpellRangeEntry
uint32 ID;
float minRange;
float maxRange;
+ uint32 flags;
};
struct SpellShapeshiftEntry
diff --git a/src/shared/Database/DBCfmt.cpp b/src/shared/Database/DBCfmt.cpp
index 64163664b49..57a81921d62 100644
--- a/src/shared/Database/DBCfmt.cpp
+++ b/src/shared/Database/DBCfmt.cpp
@@ -22,6 +22,9 @@ const char AreaTableEntryfmt[]="iiinixxxxxissssssssssssssssxixxxxxx";
const char AreaTriggerEntryfmt[]="niffffffff";
const char BankBagSlotPricesEntryfmt[]="ni";
const char BattlemasterListEntryfmt[]="niiixxxxxiiiixxssssssssssssssssxx";
+const char CharStartOutfitEntryfmt[]="diiiiiiiiiiiiixxxxxxxxxxxxxxxxxxxxxxxxxxx";
+// 3*12 new item fields in 3.0.x
+//const char CharStartOutfitEntryfmt[]="diiiiiiiiiiiiiiiiiiiiiiiiixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const char CharTitlesEntryfmt[]="nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxi";
const char ChatChannelsEntryfmt[]="iixssssssssssssssssxxxxxxxxxxxxxxxxxx";
// ChatChannelsEntryfmt, index not used (more compact store)
@@ -68,7 +71,7 @@ const char SpellFocusObjectfmt[]="nxxxxxxxxxxxxxxxxx";
const char SpellItemEnchantmentfmt[]="niiiiiixxxiiissssssssssssssssxiiii";
const char SpellItemEnchantmentConditionfmt[]="nbbbbbxxxxxbbbbbbbbbbiiiiiXXXXX";
const char SpellRadiusfmt[]="nfxf";
-const char SpellRangefmt[]="nffxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
+const char SpellRangefmt[]="nffixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const char SpellShapeshiftfmt[]="nxxxxxxxxxxxxxxxxxxiixixxxxxxxxxxxx";
const char StableSlotPricesfmt[] = "ni";
const char TalentEntryfmt[]="niiiiiiiixxxxixxixxxi";
diff --git a/src/shared/Database/SQLStorageImpl.h b/src/shared/Database/SQLStorageImpl.h
index 2ccd5724a07..4f10c6eee05 100644
--- a/src/shared/Database/SQLStorageImpl.h
+++ b/src/shared/Database/SQLStorageImpl.h
@@ -1,214 +1,214 @@
-/*
- * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "ProgressBar.h"
-#include "Log.h"
-#include "dbcfile.h"
-
-template<class T>
-template<class S, class D>
-void SQLStorageLoaderBase<T>::convert(uint32 field_pos, S src, D &dst)
-{
- dst = D(src);
-}
-
-template<class T>
-void SQLStorageLoaderBase<T>::convert_str_to_str(uint32 field_pos, char *src, char *&dst)
-{
- if(!src)
- {
- dst = new char[1];
- *dst = 0;
- }
- else
- {
- uint32 l = strlen(src) + 1;
- dst = new char[l];
- memcpy(dst, src, l);
- }
-}
-
-template<class T>
-template<class S>
-void SQLStorageLoaderBase<T>::convert_to_str(uint32 field_pos, S src, char * & dst)
-{
- dst = new char[1];
- *dst = 0;
-}
-
-template<class T>
-template<class D>
-void SQLStorageLoaderBase<T>::convert_from_str(uint32 field_pos, char * src, D& dst)
-{
- dst = 0;
-}
-
-template<class T>
-template<class V>
-void SQLStorageLoaderBase<T>::storeValue(V value, SQLStorage &store, char *p, int x, uint32 &offset)
-{
- T * subclass = (static_cast<T*>(this));
- switch(store.dst_format[x])
- {
- case FT_LOGIC:
- subclass->convert(x, value, *((bool*)(&p[offset])) );
- offset+=sizeof(bool);
- break;
- case FT_BYTE:
- subclass->convert(x, value, *((char*)(&p[offset])) );
- offset+=sizeof(char);
- break;
- case FT_INT:
- subclass->convert(x, value, *((uint32*)(&p[offset])) );
- offset+=sizeof(uint32);
- break;
- case FT_FLOAT:
- subclass->convert(x, value, *((float*)(&p[offset])) );
- offset+=sizeof(float);
- break;
- case FT_STRING:
- subclass->convert_to_str(x, value, *((char**)(&p[offset])) );
- offset+=sizeof(char*);
- break;
- }
-}
-
-template<class T>
-void SQLStorageLoaderBase<T>::storeValue(char * value, SQLStorage &store, char *p, int x, uint32 &offset)
-{
- T * subclass = (static_cast<T*>(this));
- switch(store.dst_format[x])
- {
- case FT_LOGIC:
- subclass->convert_from_str(x, value, *((bool*)(&p[offset])) );
- offset+=sizeof(bool);
- break;
- case FT_BYTE:
- subclass->convert_from_str(x, value, *((char*)(&p[offset])) );
- offset+=sizeof(char);
- break;
- case FT_INT:
- subclass->convert_from_str(x, value, *((uint32*)(&p[offset])) );
- offset+=sizeof(uint32);
- break;
- case FT_FLOAT:
- subclass->convert_from_str(x, value, *((float*)(&p[offset])) );
- offset+=sizeof(float);
- break;
- case FT_STRING:
- subclass->convert_str_to_str(x, value, *((char**)(&p[offset])) );
- offset+=sizeof(char*);
- break;
- }
-}
-
-template<class T>
-void SQLStorageLoaderBase<T>::Load(SQLStorage &store)
-{
- uint32 maxi;
- Field *fields;
- QueryResult *result = WorldDatabase.PQuery("SELECT MAX(%s) FROM %s", store.entry_field, store.table);
- if(!result)
- {
- sLog.outError("Error loading %s table (not exist?)\n", store.table);
- exit(1); // Stop server at loading non exited table or not accessable table
- }
-
- maxi = (*result)[0].GetUInt32()+1;
- delete result;
-
- result = WorldDatabase.PQuery("SELECT COUNT(*) FROM %s", store.table);
- if(result)
- {
- fields = result->Fetch();
- store.RecordCount = fields[0].GetUInt32();
- delete result;
- }
- else
- store.RecordCount = 0;
-
- result = WorldDatabase.PQuery("SELECT * FROM %s", store.table);
-
- if(!result)
- {
- sLog.outError("%s table is empty!\n", store.table);
- store.RecordCount = 0;
- return;
- }
-
- uint32 recordsize = 0;
- uint32 offset = 0;
-
- if(store.iNumFields != result->GetFieldCount())
- {
- store.RecordCount = 0;
- sLog.outError("Error in %s table, probably sql file format was updated (there should be %d fields in sql).\n", store.table, store.iNumFields);
- delete result;
- exit(1); // Stop server at loading broken or non-compatible table.
- }
-
- //get struct size
- uint32 sc=0;
- uint32 bo=0;
- uint32 bb=0;
- for(uint32 x=0; x< store.iNumFields; x++)
- if(store.dst_format[x]==FT_STRING)
- ++sc;
- else if (store.dst_format[x]==FT_LOGIC)
- ++bo;
- else if (store.dst_format[x]==FT_BYTE)
- ++bb;
- recordsize=(store.iNumFields-sc-bo-bb)*4+sc*sizeof(char*)+bo*sizeof(bool)+bb*sizeof(char);
-
- char** newIndex=new char*[maxi];
- memset(newIndex,0,maxi*sizeof(char*));
-
- char * _data= new char[store.RecordCount *recordsize];
- uint32 count=0;
- barGoLink bar( store.RecordCount );
- do
- {
- fields = result->Fetch();
- bar.step();
- char *p=(char*)&_data[recordsize*count];
- newIndex[fields[0].GetUInt32()]=p;
-
- offset=0;
- for(uint32 x = 0; x < store.iNumFields; x++)
- switch(store.src_format[x])
- {
- case FT_LOGIC:
- storeValue((bool)(fields[x].GetUInt32() > 0), store, p, x, offset); break;
- case FT_BYTE:
- storeValue((char)fields[x].GetUInt8(), store, p, x, offset); break;
- case FT_INT:
- storeValue((uint32)fields[x].GetUInt32(), store, p, x, offset); break;
- case FT_FLOAT:
- storeValue((float)fields[x].GetFloat(), store, p, x, offset); break;
- case FT_STRING:
- storeValue((char*)fields[x].GetString(), store, p, x, offset); break;
- }
- ++count;
- }while( result->NextRow() );
-
- delete result;
-
- store.pIndex = newIndex;
- store.MaxEntry = maxi;
- store.data = _data;
-}
+/*
+ * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "ProgressBar.h"
+#include "Log.h"
+#include "dbcfile.h"
+
+template<class T>
+template<class S, class D>
+void SQLStorageLoaderBase<T>::convert(uint32 field_pos, S src, D &dst)
+{
+ dst = D(src);
+}
+
+template<class T>
+void SQLStorageLoaderBase<T>::convert_str_to_str(uint32 field_pos, char *src, char *&dst)
+{
+ if(!src)
+ {
+ dst = new char[1];
+ *dst = 0;
+ }
+ else
+ {
+ uint32 l = strlen(src) + 1;
+ dst = new char[l];
+ memcpy(dst, src, l);
+ }
+}
+
+template<class T>
+template<class S>
+void SQLStorageLoaderBase<T>::convert_to_str(uint32 field_pos, S src, char * & dst)
+{
+ dst = new char[1];
+ *dst = 0;
+}
+
+template<class T>
+template<class D>
+void SQLStorageLoaderBase<T>::convert_from_str(uint32 field_pos, char * src, D& dst)
+{
+ dst = 0;
+}
+
+template<class T>
+template<class V>
+void SQLStorageLoaderBase<T>::storeValue(V value, SQLStorage &store, char *p, int x, uint32 &offset)
+{
+ T * subclass = (static_cast<T*>(this));
+ switch(store.dst_format[x])
+ {
+ case FT_LOGIC:
+ subclass->convert(x, value, *((bool*)(&p[offset])) );
+ offset+=sizeof(bool);
+ break;
+ case FT_BYTE:
+ subclass->convert(x, value, *((char*)(&p[offset])) );
+ offset+=sizeof(char);
+ break;
+ case FT_INT:
+ subclass->convert(x, value, *((uint32*)(&p[offset])) );
+ offset+=sizeof(uint32);
+ break;
+ case FT_FLOAT:
+ subclass->convert(x, value, *((float*)(&p[offset])) );
+ offset+=sizeof(float);
+ break;
+ case FT_STRING:
+ subclass->convert_to_str(x, value, *((char**)(&p[offset])) );
+ offset+=sizeof(char*);
+ break;
+ }
+}
+
+template<class T>
+void SQLStorageLoaderBase<T>::storeValue(char * value, SQLStorage &store, char *p, int x, uint32 &offset)
+{
+ T * subclass = (static_cast<T*>(this));
+ switch(store.dst_format[x])
+ {
+ case FT_LOGIC:
+ subclass->convert_from_str(x, value, *((bool*)(&p[offset])) );
+ offset+=sizeof(bool);
+ break;
+ case FT_BYTE:
+ subclass->convert_from_str(x, value, *((char*)(&p[offset])) );
+ offset+=sizeof(char);
+ break;
+ case FT_INT:
+ subclass->convert_from_str(x, value, *((uint32*)(&p[offset])) );
+ offset+=sizeof(uint32);
+ break;
+ case FT_FLOAT:
+ subclass->convert_from_str(x, value, *((float*)(&p[offset])) );
+ offset+=sizeof(float);
+ break;
+ case FT_STRING:
+ subclass->convert_str_to_str(x, value, *((char**)(&p[offset])) );
+ offset+=sizeof(char*);
+ break;
+ }
+}
+
+template<class T>
+void SQLStorageLoaderBase<T>::Load(SQLStorage &store)
+{
+ uint32 maxi;
+ Field *fields;
+ QueryResult *result = WorldDatabase.PQuery("SELECT MAX(%s) FROM %s", store.entry_field, store.table);
+ if(!result)
+ {
+ sLog.outError("Error loading %s table (not exist?)\n", store.table);
+ exit(1); // Stop server at loading non exited table or not accessable table
+ }
+
+ maxi = (*result)[0].GetUInt32()+1;
+ delete result;
+
+ result = WorldDatabase.PQuery("SELECT COUNT(*) FROM %s", store.table);
+ if(result)
+ {
+ fields = result->Fetch();
+ store.RecordCount = fields[0].GetUInt32();
+ delete result;
+ }
+ else
+ store.RecordCount = 0;
+
+ result = WorldDatabase.PQuery("SELECT * FROM %s", store.table);
+
+ if(!result)
+ {
+ sLog.outError("%s table is empty!\n", store.table);
+ store.RecordCount = 0;
+ return;
+ }
+
+ uint32 recordsize = 0;
+ uint32 offset = 0;
+
+ if(store.iNumFields != result->GetFieldCount())
+ {
+ store.RecordCount = 0;
+ sLog.outError("Error in %s table, probably sql file format was updated (there should be %d fields in sql).\n", store.table, store.iNumFields);
+ delete result;
+ exit(1); // Stop server at loading broken or non-compatible table.
+ }
+
+ //get struct size
+ uint32 sc=0;
+ uint32 bo=0;
+ uint32 bb=0;
+ for(uint32 x=0; x< store.iNumFields; x++)
+ if(store.dst_format[x]==FT_STRING)
+ ++sc;
+ else if (store.dst_format[x]==FT_LOGIC)
+ ++bo;
+ else if (store.dst_format[x]==FT_BYTE)
+ ++bb;
+ recordsize=(store.iNumFields-sc-bo-bb)*4+sc*sizeof(char*)+bo*sizeof(bool)+bb*sizeof(char);
+
+ char** newIndex=new char*[maxi];
+ memset(newIndex,0,maxi*sizeof(char*));
+
+ char * _data= new char[store.RecordCount *recordsize];
+ uint32 count=0;
+ barGoLink bar( store.RecordCount );
+ do
+ {
+ fields = result->Fetch();
+ bar.step();
+ char *p=(char*)&_data[recordsize*count];
+ newIndex[fields[0].GetUInt32()]=p;
+
+ offset=0;
+ for(uint32 x = 0; x < store.iNumFields; x++)
+ switch(store.src_format[x])
+ {
+ case FT_LOGIC:
+ storeValue((bool)(fields[x].GetUInt32() > 0), store, p, x, offset); break;
+ case FT_BYTE:
+ storeValue((char)fields[x].GetUInt8(), store, p, x, offset); break;
+ case FT_INT:
+ storeValue((uint32)fields[x].GetUInt32(), store, p, x, offset); break;
+ case FT_FLOAT:
+ storeValue((float)fields[x].GetFloat(), store, p, x, offset); break;
+ case FT_STRING:
+ storeValue((char*)fields[x].GetString(), store, p, x, offset); break;
+ }
+ ++count;
+ }while( result->NextRow() );
+
+ delete result;
+
+ store.pIndex = newIndex;
+ store.MaxEntry = maxi;
+ store.data = _data;
+}