diff options
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/Database/DBCEnums.h | 104 | ||||
-rw-r--r-- | src/shared/Database/DBCStores.cpp | 35 | ||||
-rw-r--r-- | src/shared/Database/DBCStores.h | 5 | ||||
-rw-r--r-- | src/shared/Database/DBCStructure.h | 119 | ||||
-rw-r--r-- | src/shared/Database/SQLStorage.cpp | 160 | ||||
-rw-r--r-- | src/shared/Database/SQLStorage.h | 68 | ||||
-rw-r--r-- | src/shared/Database/SQLStorageImpl.h | 214 | ||||
-rw-r--r-- | src/shared/Database/dbcfile.cpp | 4 | ||||
-rw-r--r-- | src/shared/Database/dbcfile.h | 4 | ||||
-rw-r--r-- | src/shared/ProgressBar.cpp | 4 | ||||
-rw-r--r-- | src/shared/ProgressBar.h | 4 |
11 files changed, 446 insertions, 275 deletions
diff --git a/src/shared/Database/DBCEnums.h b/src/shared/Database/DBCEnums.h new file mode 100644 index 00000000000..6ad7fdb127a --- /dev/null +++ b/src/shared/Database/DBCEnums.h @@ -0,0 +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 diff --git a/src/shared/Database/DBCStores.cpp b/src/shared/Database/DBCStores.cpp index 020cd53e61d..71e3483a1ab 100644 --- a/src/shared/Database/DBCStores.cpp +++ b/src/shared/Database/DBCStores.cpp @@ -10,12 +10,12 @@ * * 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 + * 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 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "DBCStores.h" @@ -121,21 +121,9 @@ DBCStorage <TaxiPathEntry> sTaxiPathStore(TaxiPathEntryfmt); // DBC used only for initialization sTaxiPathSetBySource at startup. TaxiPathNodesByPath sTaxiPathNodesByPath; -struct TaxiPathNodeEntry -{ - uint32 path; - uint32 index; - uint32 mapid; - float x; - float y; - float z; - uint32 actionFlag; - uint32 delay; -}; -static DBCStorage <TaxiPathNodeEntry> sTaxiPathNodeStore(TaxiPathNodeEntryfmt); +static DBCStorage <TaxiPathNodeEntry> sTaxiPathNodeStore(TaxiPathNodeEntryfmt); DBCStorage <TotemCategoryEntry> sTotemCategoryStore(TotemCategoryEntryfmt); - DBCStorage <WorldMapAreaEntry> sWorldMapAreaStore(WorldMapAreaEntryfmt); DBCStorage <WorldSafeLocsEntry> sWorldSafeLocsStore(WorldSafeLocsEntryfmt); @@ -235,7 +223,7 @@ void LoadDBCStores(std::string dataPath) flist.push_back(i); } } - + LoadDBC(availableDbcLocales,bar,bad_dbc_files,sFactionTemplateStore, dbcPath,"FactionTemplate.dbc"); LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGemPropertiesStore, dbcPath,"GemProperties.dbc"); @@ -283,21 +271,21 @@ void LoadDBCStores(std::string dataPath) for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j) { SkillLineAbilityEntry const *skillLine = sSkillLineAbilityStore.LookupEntry(j); - + if(!skillLine) continue; SpellEntry const* spellInfo = sSpellStore.LookupEntry(skillLine->spellId); if(spellInfo && (spellInfo->Attributes & 0x1D0) == 0x1D0) - { + { for (unsigned int i = 1; i < sCreatureFamilyStore.GetNumRows(); ++i) { CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(i); if(!cFamily) continue; - if(skillLine->skillId != cFamily->skillLine && skillLine->skillId != cFamily->skillLine2) + if(skillLine->skillId != cFamily->skillLine[0] && skillLine->skillId != cFamily->skillLine[1]) continue; sPetFamilySpellsStore[i].insert(spellInfo->Id); @@ -309,7 +297,6 @@ void LoadDBCStores(std::string dataPath) LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellDurationStore, dbcPath,"SpellDuration.dbc"); LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellFocusObjectStore, dbcPath,"SpellFocusObject.dbc"); LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentStore,dbcPath,"SpellItemEnchantment.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentConditionStore,dbcPath,"SpellItemEnchantmentCondition.dbc"); LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRadiusStore, dbcPath,"SpellRadius.dbc"); LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRangeStore, dbcPath,"SpellRange.dbc"); @@ -455,11 +442,11 @@ void LoadDBCStores(std::string dataPath) // check at up-to-date DBC files (2425 is last item extended cost added in 2.4.3) // check at up-to-date DBC files (71 is last char title added in 2.4.3) // check at up-to-date DBC files (1768 is last area added in 2.4.3) - if( !sSpellStore.LookupEntry(53085) || - !sSkillLineAbilityStore.LookupEntry(17514) || + if( !sSpellStore.LookupEntry(53085) || + !sSkillLineAbilityStore.LookupEntry(17514) || !sMapStore.LookupEntry(598) || - !sGemPropertiesStore.LookupEntry(1127) || - !sItemExtendedCostStore.LookupEntry(2425) || + !sGemPropertiesStore.LookupEntry(1127) || + !sItemExtendedCostStore.LookupEntry(2425) || !sCharTitlesStore.LookupEntry(71) || !sAreaStore.LookupEntry(1768) ) { diff --git a/src/shared/Database/DBCStores.h b/src/shared/Database/DBCStores.h index 2c17935d9f5..0375f20c7eb 100644 --- a/src/shared/Database/DBCStores.h +++ b/src/shared/Database/DBCStores.h @@ -10,12 +10,12 @@ * * 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 + * 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 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef DBCSTORES_H @@ -75,7 +75,6 @@ class DBCStorage bool Load(char const* fn) { - DBCFile dbc; // Check if load was sucessful, only then continue if(!dbc.Load(fn, fmt)) diff --git a/src/shared/Database/DBCStructure.h b/src/shared/Database/DBCStructure.h index b57b031ef55..a71f80ac8c7 100644 --- a/src/shared/Database/DBCStructure.h +++ b/src/shared/Database/DBCStructure.h @@ -10,17 +10,18 @@ * * 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 + * 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 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef DBCSTRUCTURE_H #define DBCSTRUCTURE_H +#include "DBCEnums.h" #include "Platform/Define.h" #include <map> @@ -36,42 +37,6 @@ #pragma pack(push,1) #endif -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 -}; - struct AreaTableEntry { uint32 ID; // 0 @@ -179,7 +144,7 @@ struct ChrRacesEntry //char* string2[16]; // 48-63 used for DBC language detection/selection // 64 string flags, unused // 65-67 unused - uint32 addon; // 68 (0 - original race, 1 - tbc addon, ...) + uint32 addon; // 68 (0 - original race, 1 - tbc addon, ...) }; struct CreatureDisplayInfoEntry @@ -193,12 +158,11 @@ struct CreatureDisplayInfoEntry struct CreatureFamilyEntry { uint32 ID; // 0 - float minScale; // 1 - uint32 minScaleLevel; // 2 0/1 + float minScale; // 1 + uint32 minScaleLevel; // 2 0/1 float maxScale; // 3 uint32 maxScaleLevel; // 4 0/60 - uint32 skillLine; // 5 - uint32 skillLine2; // 6 + uint32 skillLine[2]; // 5-6 uint32 petFoodMask; // 7 char* Name[16]; // 8-23 // 24 string flags, unused @@ -244,15 +208,6 @@ struct FactionEntry // 52 string flags, unused }; -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 -}; - struct FactionTemplateEntry { uint32 ID; // 0 @@ -301,6 +256,7 @@ struct GemPropertiesEntry }; #define GT_MAX_LEVEL 100 + struct GtCombatRatingsEntry { float ratio; @@ -431,15 +387,6 @@ struct MailTemplateEntry //char* content[16]; // 18-33 }; -enum MapTypes -{ - MAP_COMMON = 0, - MAP_INSTANCE = 1, - MAP_RAID = 2, - MAP_BATTLEGROUND = 3, - MAP_ARENA = 4 -}; - struct MapEntry { uint32 MapID; // 0 @@ -545,12 +492,6 @@ struct SkillLineEntry uint32 spellIcon; // 37 }; -enum AbilytyLearnType -{ - ABILITY_LEARNED_ON_GET_PROFESSION_SKILL = 1, - ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL = 2 -}; - struct SkillLineAbilityEntry { uint32 id; // 0, INDEX @@ -758,17 +699,6 @@ struct SpellDurationEntry int32 Duration[3]; }; -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 -}; - struct SpellItemEnchantmentEntry { uint32 ID; // 0 @@ -826,14 +756,6 @@ struct TalentTabEntry //char* internalname; // 22 }; -struct TaxiPathEntry -{ - uint32 ID; - uint32 from; - uint32 to; - uint32 price; -}; - struct TaxiNodesEntry { uint32 ID; // 0 @@ -847,15 +769,24 @@ struct TaxiNodesEntry uint32 alliance_mount_type; // 24 }; -enum TotemCategoryType +struct TaxiPathEntry +{ + uint32 ID; + uint32 from; + uint32 to; + uint32 price; +}; + +struct TaxiPathNodeEntry { - 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 + uint32 path; + uint32 index; + uint32 mapid; + float x; + float y; + float z; + uint32 actionFlag; + uint32 delay; }; struct TotemCategoryEntry diff --git a/src/shared/Database/SQLStorage.cpp b/src/shared/Database/SQLStorage.cpp index b9168cbc416..720e6e3e683 100644 --- a/src/shared/Database/SQLStorage.cpp +++ b/src/shared/Database/SQLStorage.cpp @@ -10,18 +10,16 @@ * * 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 + * 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 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "SQLStorage.h" -#include "ProgressBar.h" -#include "Log.h" -#include "dbcfile.h" +#include "SQLStorageImpl.h" #ifdef DO_POSTGRESQL extern DatabasePostgre WorldDatabase; @@ -29,165 +27,57 @@ extern DatabasePostgre WorldDatabase; extern DatabaseMysql WorldDatabase; #endif -const char CreatureInfofmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiisiilliiis"; +const char CreatureInfosrcfmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiisiilliiis"; +const char CreatureInfodstfmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiisiilliiii"; const char CreatureDataAddonInfofmt[]="iiiiiiis"; const char CreatureModelfmt[]="iffbi"; const char CreatureInfoAddonInfofmt[]="iiiiiiis"; const char EquipmentInfofmt[]="iiiiiiiiii"; -const char GameObjectInfofmt[]="iiissiifiiiiiiiiiiiiiiiiiiiiiiiis"; -const char ItemPrototypefmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifsiiiii"; +const char GameObjectInfosrcfmt[]="iiissiifiiiiiiiiiiiiiiiiiiiiiiiis"; +const char GameObjectInfodstfmt[]="iiissiifiiiiiiiiiiiiiiiiiiiiiiiii"; +const char ItemPrototypesrcfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifsiiiii"; +const char ItemPrototypedstfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifiiiiii"; const char PageTextfmt[]="isi"; const char SpellThreatfmt[]="ii"; -const char InstanceTemplatefmt[]="iiiiiiffffs"; +const char InstanceTemplatesrcfmt[]="iiiiiiffffs"; +const char InstanceTemplatedstfmt[]="iiiiiiffffi"; -SQLStorage sCreatureStorage(CreatureInfofmt,"entry","creature_template"); +SQLStorage sCreatureStorage(CreatureInfosrcfmt, CreatureInfodstfmt, "entry","creature_template"); SQLStorage sCreatureDataAddonStorage(CreatureDataAddonInfofmt,"guid","creature_addon"); SQLStorage sCreatureModelStorage(CreatureModelfmt,"modelid","creature_model_info"); SQLStorage sCreatureInfoAddonStorage(CreatureInfoAddonInfofmt,"entry","creature_template_addon"); SQLStorage sEquipmentStorage(EquipmentInfofmt,"entry","creature_equip_template"); -SQLStorage sGOStorage(GameObjectInfofmt,"entry","gameobject_template"); -SQLStorage sItemStorage(ItemPrototypefmt,"entry","item_template"); +SQLStorage sGOStorage(GameObjectInfosrcfmt, GameObjectInfodstfmt, "entry","gameobject_template"); +SQLStorage sItemStorage(ItemPrototypesrcfmt, ItemPrototypedstfmt, "entry","item_template"); SQLStorage sPageTextStore(PageTextfmt,"entry","page_text"); SQLStorage sSpellThreatStore(SpellThreatfmt,"entry","spell_threat"); -SQLStorage sInstanceTemplate(InstanceTemplatefmt,"map","instance_template"); +SQLStorage sInstanceTemplate(InstanceTemplatesrcfmt, InstanceTemplatedstfmt, "map","instance_template"); void SQLStorage::Free () { uint32 offset=0; for(uint32 x=0;x<iNumFields;x++) - if (format[x]==FT_STRING) + if (dst_format[x]==FT_STRING) { for(uint32 y=0;y<MaxEntry;y++) if(pIndex[y]) delete [] *(char**)((char*)(pIndex[y])+offset); - offset+=sizeof(char*); + offset += sizeof(char*); } - else if (format[x]==FT_LOGIC) - offset+=sizeof(bool); - else if (format[x]==FT_BYTE) - offset+=sizeof(char); + else if (dst_format[x]==FT_LOGIC) + offset += sizeof(bool); + else if (dst_format[x]==FT_BYTE) + offset += sizeof(char); else - offset+=4; + offset += 4; delete [] pIndex; delete [] data; } -void SQLStorage::Load () +void SQLStorage::Load() { - uint32 maxi; - Field *fields; - QueryResult *result = WorldDatabase.PQuery("SELECT MAX(%s) FROM %s",entry_field,table); - if(!result) - { - sLog.outError("Error loading %s table (not exist?)\n",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",table); - if(result) - { - fields = result->Fetch(); - RecordCount=fields[0].GetUInt32(); - delete result; - } - else - RecordCount = 0; - - result = WorldDatabase.PQuery("SELECT * FROM %s",table); - - if(!result) - { - sLog.outError("%s table is empty!\n",table); - RecordCount = 0; - return; - } - - uint32 recordsize=0; - uint32 offset=0; - - if(iNumFields!=result->GetFieldCount()) - { - RecordCount = 0; - sLog.outError("Error in %s table, probably sql file format was updated (there should be %d fields in sql).\n",table,iNumFields); - delete result; - exit(1); // Stop server at loading broken or non-compatiable table. - } - - //get struct size - uint32 sc=0; - uint32 bo=0; - uint32 bb=0; - for(uint32 x=0;x<iNumFields;x++) - if(format[x]==FT_STRING) - ++sc; - else if (format[x]==FT_LOGIC) - ++bo; - else if (format[x]==FT_BYTE) - ++bb; - recordsize=(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[RecordCount *recordsize]; - uint32 count=0; - barGoLink bar( 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<iNumFields;x++) - switch(format[x]) - { - case FT_LOGIC: - *((bool*)(&p[offset]))=(fields[x].GetUInt32()>0); - offset+=sizeof(bool); - break; - case FT_BYTE: - *((char*)(&p[offset]))=(fields[x].GetUInt8()); - offset+=sizeof(char); - break; - case FT_INT: - *((uint32*)(&p[offset]))=fields[x].GetUInt32(); - offset+=sizeof(uint32); - break; - case FT_FLOAT: - *((float*)(&p[offset]))=fields[x].GetFloat(); - offset+=sizeof(float); - break; - case FT_STRING: - char const* tmp = fields[x].GetString(); - char* st; - if(!tmp) - { - st=new char[1]; - *st=0; - } - else - { - uint32 l=strlen(tmp)+1; - st=new char[l]; - memcpy(st,tmp,l); - } - *((char**)(&p[offset]))=st; - offset+=sizeof(char*); - break; - } - ++count; - }while( result->NextRow() ); - - delete result; - - pIndex =newIndex; - MaxEntry=maxi; - data=_data; + SQLStorageLoader loader; + loader.Load(*this); } diff --git a/src/shared/Database/SQLStorage.h b/src/shared/Database/SQLStorage.h index 5131a73fe4d..2d154f4e1ca 100644 --- a/src/shared/Database/SQLStorage.h +++ b/src/shared/Database/SQLStorage.h @@ -10,12 +10,12 @@ * * 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 + * 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 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef SQLSTORAGE_H @@ -26,18 +26,26 @@ class SQLStorage { + template<class T> + friend struct SQLStorageLoaderBase; + public: - SQLStorage(const char*fmt,const char * _entry_field,const char * sqlname) + SQLStorage(const char* fmt, const char * _entry_field, const char * sqlname) { - format=fmt; - entry_field = _entry_field; - table=sqlname; - data=NULL; - pIndex=NULL; - iNumFields =strlen(fmt); - MaxEntry = 0; + src_format = fmt; + dst_format = fmt; + init(_entry_field, sqlname); + } + + SQLStorage(const char* src_fmt, const char* dst_fmt, const char * _entry_field, const char * sqlname) + { + src_format = src_fmt; + dst_format = dst_fmt; + init(_entry_field, sqlname); } + + ~SQLStorage() { Free(); @@ -56,15 +64,53 @@ class SQLStorage uint32 RecordCount; uint32 MaxEntry; uint32 iNumFields; + void Load(); void Free(); + private: + void init(const char * _entry_field, const char * sqlname) + { + entry_field = _entry_field; + table=sqlname; + data=NULL; + pIndex=NULL; + iNumFields = strlen(src_format); + MaxEntry = 0; + } + char** pIndex; char *data; - const char *format; + const char *src_format; + const char *dst_format; const char *table; const char *entry_field; //bool HasString; }; + +template <class T> +struct SQLStorageLoaderBase +{ + public: + void Load(SQLStorage &storage); + + template<class S, class D> + void convert(uint32 field_pos, S src, D &dst); + template<class S> + void convert_to_str(uint32 field_pos, S src, char * & dst); + template<class D> + void convert_from_str(uint32 field_pos, char * src, D& dst); + void convert_str_to_str(uint32 field_pos, char *src, char *&dst); + + private: + template<class V> + void storeValue(V value, SQLStorage &store, char *p, int x, uint32 &offset); + void storeValue(char * value, SQLStorage &store, char *p, int x, uint32 &offset); +}; + +struct SQLStorageLoader : public SQLStorageLoaderBase<SQLStorageLoader> +{ +}; + #endif diff --git a/src/shared/Database/SQLStorageImpl.h b/src/shared/Database/SQLStorageImpl.h new file mode 100644 index 00000000000..4f10c6eee05 --- /dev/null +++ b/src/shared/Database/SQLStorageImpl.h @@ -0,0 +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; +} diff --git a/src/shared/Database/dbcfile.cpp b/src/shared/Database/dbcfile.cpp index 07f7b662e73..c6c12a99b8b 100644 --- a/src/shared/Database/dbcfile.cpp +++ b/src/shared/Database/dbcfile.cpp @@ -10,12 +10,12 @@ * * 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 + * 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 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <stdio.h> diff --git a/src/shared/Database/dbcfile.h b/src/shared/Database/dbcfile.h index cc2f117d6d1..8d0b2e45451 100644 --- a/src/shared/Database/dbcfile.h +++ b/src/shared/Database/dbcfile.h @@ -10,12 +10,12 @@ * * 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 + * 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 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef DBCFILE_H diff --git a/src/shared/ProgressBar.cpp b/src/shared/ProgressBar.cpp index 724e749c1d9..f4163a6133e 100644 --- a/src/shared/ProgressBar.cpp +++ b/src/shared/ProgressBar.cpp @@ -10,12 +10,12 @@ * * 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 + * 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 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "ProgressBar.h" diff --git a/src/shared/ProgressBar.h b/src/shared/ProgressBar.h index de73596dd55..98720c90385 100644 --- a/src/shared/ProgressBar.h +++ b/src/shared/ProgressBar.h @@ -10,12 +10,12 @@ * * 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 + * 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 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef TRINITYCORE_PROGRESSBAR_H #define TRINITYCORE_PROGRESSBAR_H |