From e3befa2072fd591384cb9ab9f82f976a2020837d Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Sat, 24 Jul 2010 01:38:09 +0400 Subject: [PATCH] [10254] Remove dependence auction data from auctioneer guid. * Field `auctioneerguid` replaced by `houseid` and table reanmed to `auction` (it list auctions and `id` is auction id). * Update related code. * SQL update fill `houseid` field by old `auctioneerguid` BUT: SQL update expect that you world DB named `mangos`. If this not true for your case you need modify SQL update BEFORE APPLY in 2 placed in part "mangos.creature AS c, mangos.creature_template AS ct" * Another small possitive result: now possible easy select auctions related to some auction store (1-3 is one team actions, 4-6 another team auction, and 7 is neutral auction store for both teams --- sql/characters.sql | 4 +- .../10254_01_characters_auctionhouse.sql | 30 ++++++++++++++ sql/updates/Makefile.am | 2 + src/game/AuctionHouseHandler.cpp | 3 +- src/game/AuctionHouseMgr.cpp | 39 ++++++------------- src/game/AuctionHouseMgr.h | 1 - src/game/Level3.cpp | 6 +-- src/game/ObjectMgr.cpp | 4 +- src/shared/revision_nr.h | 2 +- src/shared/revision_sql.h | 2 +- 10 files changed, 54 insertions(+), 39 deletions(-) create mode 100644 sql/updates/10254_01_characters_auctionhouse.sql diff --git a/sql/characters.sql b/sql/characters.sql index 72d073851..15043499a 100644 --- a/sql/characters.sql +++ b/sql/characters.sql @@ -21,7 +21,7 @@ DROP TABLE IF EXISTS `character_db_version`; CREATE TABLE `character_db_version` ( - `required_10160_02_characters_pet_aura` bit(1) default NULL + `required_10254_01_characters_auctionhouse` bit(1) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Last applied sql update to DB'; -- @@ -141,7 +141,7 @@ UNLOCK TABLES; DROP TABLE IF EXISTS `auctionhouse`; CREATE TABLE `auctionhouse` ( `id` int(11) unsigned NOT NULL default '0', - `auctioneerguid` int(11) unsigned NOT NULL default '0', + `houseid` int(11) unsigned NOT NULL default '0', `itemguid` int(11) unsigned NOT NULL default '0', `item_template` int(11) unsigned NOT NULL default '0' COMMENT 'Item Identifier', `itemowner` int(11) unsigned NOT NULL default '0', diff --git a/sql/updates/10254_01_characters_auctionhouse.sql b/sql/updates/10254_01_characters_auctionhouse.sql new file mode 100644 index 000000000..cd2c73856 --- /dev/null +++ b/sql/updates/10254_01_characters_auctionhouse.sql @@ -0,0 +1,30 @@ +ALTER TABLE character_db_version CHANGE COLUMN required_10160_02_characters_pet_aura required_10254_01_characters_auctionhouse bit; + +ALTER TABLE auctionhouse + ADD COLUMN houseid int(11) unsigned NOT NULL default '0' AFTER id; + +UPDATE auctionhouse, mangos.creature AS c, mangos.creature_template AS ct + SET houseid = + CASE ct.faction_A + WHEN 12 THEN 1 /* human */ + WHEN 29 THEN 6 /* orc, and generic for horde */ + WHEN 55 THEN 2 /* dwarf/gnome, and generic for alliance */ + WHEN 68 THEN 4 /* undead */ + WHEN 80 THEN 3 /* n-elf */ + WHEN 104 THEN 5 /* trolls */ + WHEN 120 THEN 7 /* booty bay, neutral */ + WHEN 474 THEN 7 /* gadgetzan, neutral */ + WHEN 534 THEN 2 /* Alliance Generic */ + WHEN 855 THEN 7 /* everlook, neutral */ + WHEN 1604 THEN 6 /* b-elfs, */ + WHEN 1638 THEN 2 /* exodar, alliance */ + ELSE 0 /* auction will canceled at loading */ + END + WHERE auctionhouse.auctioneerguid = c.guid AND c.id = ct.entry; + + +ALTER TABLE auctionhouse + DROP COLUMN auctioneerguid; + +DROP TABLE IF EXISTS auction; +RENAME TABLE auctionhouse TO auction; diff --git a/sql/updates/Makefile.am b/sql/updates/Makefile.am index 647301cc9..ea5672a15 100644 --- a/sql/updates/Makefile.am +++ b/sql/updates/Makefile.am @@ -122,6 +122,7 @@ pkgdata_DATA = \ 10244_01_mangos_command.sql \ 10251_01_mangos_command.sql \ 10252_01_mangos_reputation_reward_rate.sql \ + 10254_01_characters_auctionhouse.sql \ README ## Additional files to include when running 'make dist' @@ -224,4 +225,5 @@ EXTRA_DIST = \ 10244_01_mangos_command.sql \ 10251_01_mangos_command.sql \ 10252_01_mangos_reputation_reward_rate.sql \ + 10254_01_characters_auctionhouse.sql \ README diff --git a/src/game/AuctionHouseHandler.cpp b/src/game/AuctionHouseHandler.cpp index eef3024b0..002383f01 100644 --- a/src/game/AuctionHouseHandler.cpp +++ b/src/game/AuctionHouseHandler.cpp @@ -258,7 +258,6 @@ void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data ) AuctionEntry *AH = new AuctionEntry; AH->Id = sObjectMgr.GenerateAuctionID(); - AH->auctioneer = auctioneerGuid.GetCounter(); AH->item_guidlow = GUID_LOPART(item); AH->item_template = it->GetEntry(); AH->owner = pl->GetGUIDLow(); @@ -377,7 +376,7 @@ void WorldSession::HandleAuctionPlaceBid( WorldPacket & recv_data ) GetPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_BID, price); // after this update we should save player's money ... - CharacterDatabase.PExecute("UPDATE auctionhouse SET buyguid = '%u',lastbid = '%u' WHERE id = '%u'", auction->bidder, auction->bid, auction->Id); + CharacterDatabase.PExecute("UPDATE auction SET buyguid = '%u',lastbid = '%u' WHERE id = '%u'", auction->bidder, auction->bid, auction->Id); SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, AUCTION_OK, 0 ); } diff --git a/src/game/AuctionHouseMgr.cpp b/src/game/AuctionHouseMgr.cpp index 5359430e8..09b4c53e7 100644 --- a/src/game/AuctionHouseMgr.cpp +++ b/src/game/AuctionHouseMgr.cpp @@ -284,7 +284,7 @@ void AuctionHouseMgr::SendAuctionExpiredMail( AuctionEntry * auction ) void AuctionHouseMgr::LoadAuctionItems() { // data needs to be at first place for Item::LoadFromDB 0 1 2 3 - QueryResult *result = CharacterDatabase.Query( "SELECT data,text,itemguid,item_template FROM auctionhouse JOIN item_instance ON itemguid = guid" ); + QueryResult *result = CharacterDatabase.Query( "SELECT data,text,itemguid,item_template FROM auction JOIN item_instance ON itemguid = guid" ); if( !result ) { @@ -336,13 +336,13 @@ void AuctionHouseMgr::LoadAuctionItems() void AuctionHouseMgr::LoadAuctions() { - QueryResult *result = CharacterDatabase.Query("SELECT COUNT(*) FROM auctionhouse"); + QueryResult *result = CharacterDatabase.Query("SELECT COUNT(*) FROM auction"); if( !result ) { barGoLink bar(1); bar.step(); sLog.outString(); - sLog.outString(">> Loaded 0 auctions. DB table `auctionhouse` is empty."); + sLog.outString(">> Loaded 0 auctions. DB table `auction` is empty."); return; } @@ -355,17 +355,17 @@ void AuctionHouseMgr::LoadAuctions() barGoLink bar(1); bar.step(); sLog.outString(); - sLog.outString(">> Loaded 0 auctions. DB table `auctionhouse` is empty."); + sLog.outString(">> Loaded 0 auctions. DB table `auction` is empty."); return; } - result = CharacterDatabase.Query( "SELECT id,auctioneerguid,itemguid,item_template,itemowner,buyoutprice,time,buyguid,lastbid,startbid,deposit FROM auctionhouse" ); + result = CharacterDatabase.Query( "SELECT id,houseid,itemguid,item_template,itemowner,buyoutprice,time,buyguid,lastbid,startbid,deposit FROM auction" ); if( !result ) { barGoLink bar(1); bar.step(); sLog.outString(); - sLog.outString(">> Loaded 0 auctions. DB table `auctionhouse` is empty."); + sLog.outString(">> Loaded 0 auctions. DB table `auction` is empty."); return; } @@ -381,7 +381,7 @@ void AuctionHouseMgr::LoadAuctions() auction = new AuctionEntry; auction->Id = fields[0].GetUInt32(); - auction->auctioneer = fields[1].GetUInt32(); + uint32 houseid = fields[1].GetUInt32(); auction->item_guidlow = fields[2].GetUInt32(); auction->item_template = fields[3].GetUInt32(); auction->owner = fields[4].GetUInt32(); @@ -404,21 +404,9 @@ void AuctionHouseMgr::LoadAuctions() continue; } - CreatureData const* auctioneerData = sObjectMgr.GetCreatureData(auction->auctioneer); - if(!auctioneerData) - { - sLog.outError("Auction %u has not a existing auctioneer (GUID : %u), will mail to owner (GUID: %u)", - auction->Id, auction->auctioneer, auction->owner); - } + auction->auctionHouseEntry = sAuctionHouseStore.LookupEntry(houseid); - CreatureInfo const* auctioneerInfo = auctioneerData ? ObjectMgr::GetCreatureTemplate(auctioneerData->id) : NULL; - if(auctioneerData && !auctioneerInfo) - { - sLog.outError("Auction %u has not a existing auctioneer (GUID : %u Entry: %u), will mail to owner (GUID: %u)", - auction->Id, auction->auctioneer,auctioneerData->id, auction->owner); - } - - if (!auctioneerInfo) + if (!houseid) { // need for send mail, use goblin auctionhouse auction->auctionHouseEntry = sAuctionHouseStore.LookupEntry(7); @@ -439,9 +427,6 @@ void AuctionHouseMgr::LoadAuctions() continue; } - // always return pointer - auction->auctionHouseEntry = AuctionHouseMgr::GetAuctionHouseEntry(auctioneerInfo->faction_A); - GetAuctionsMap(auction->auctionHouseEntry)->AddAuction(auction); } while (result->NextRow()); @@ -711,13 +696,13 @@ uint32 AuctionEntry::GetAuctionOutBid() const void AuctionEntry::DeleteFromDB() const { //No SQL injection (Id is integer) - CharacterDatabase.PExecute("DELETE FROM auctionhouse WHERE id = '%u'",Id); + CharacterDatabase.PExecute("DELETE FROM auction WHERE id = '%u'",Id); } void AuctionEntry::SaveToDB() const { //No SQL injection (no strings) - CharacterDatabase.PExecute("INSERT INTO auctionhouse (id,auctioneerguid,itemguid,item_template,itemowner,buyoutprice,time,buyguid,lastbid,startbid,deposit) " + CharacterDatabase.PExecute("INSERT INTO auction (id,houseid,itemguid,item_template,itemowner,buyoutprice,time,buyguid,lastbid,startbid,deposit) " "VALUES ('%u', '%u', '%u', '%u', '%u', '%u', '" UI64FMTD "', '%u', '%u', '%u', '%u')", - Id, auctioneer, item_guidlow, item_template, owner, buyout, (uint64)expire_time, bidder, bid, startbid, deposit); + Id, auctionHouseEntry->houseId, item_guidlow, item_template, owner, buyout, (uint64)expire_time, bidder, bid, startbid, deposit); } diff --git a/src/game/AuctionHouseMgr.h b/src/game/AuctionHouseMgr.h index 3cbff33ef..841811081 100644 --- a/src/game/AuctionHouseMgr.h +++ b/src/game/AuctionHouseMgr.h @@ -47,7 +47,6 @@ enum AuctionAction struct AuctionEntry { uint32 Id; - uint32 auctioneer; // creature low guid uint32 item_guidlow; uint32 item_template; uint32 owner; diff --git a/src/game/Level3.cpp b/src/game/Level3.cpp index 0eed06721..81b78f457 100644 --- a/src/game/Level3.cpp +++ b/src/game/Level3.cpp @@ -2387,7 +2387,7 @@ bool ChatHandler::HandleListItemCommand(const char* args) // auction case uint32 auc_count = 0; - result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id); + result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM auction WHERE item_template='%u'",item_id); if(result) { auc_count = (*result)[0].GetUInt32(); @@ -2398,8 +2398,8 @@ bool ChatHandler::HandleListItemCommand(const char* args) { result=CharacterDatabase.PQuery( // 0 1 2 3 - "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name " - "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u", + "SELECT auction.itemguid, auction.itemowner, characters.account, characters.name " + "FROM auction,characters WHERE auction.item_template='%u' AND characters.guid = auction.itemowner LIMIT %u", item_id,uint32(count)); } else diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 7de27ec53..1cf758c2b 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -5858,7 +5858,7 @@ void ObjectMgr::SetHighestGuids() // Cleanup other tables from not existed guids (>=m_hiItemGuid) CharacterDatabase.PExecute("DELETE FROM character_inventory WHERE item >= '%u'", m_ItemGuids.GetNextAfterMaxUsed()); CharacterDatabase.PExecute("DELETE FROM mail_items WHERE item_guid >= '%u'", m_ItemGuids.GetNextAfterMaxUsed()); - CharacterDatabase.PExecute("DELETE FROM auctionhouse WHERE itemguid >= '%u'", m_ItemGuids.GetNextAfterMaxUsed()); + CharacterDatabase.PExecute("DELETE FROM auction WHERE itemguid >= '%u'", m_ItemGuids.GetNextAfterMaxUsed()); CharacterDatabase.PExecute("DELETE FROM guild_bank_item WHERE item_guid >= '%u'", m_ItemGuids.GetNextAfterMaxUsed()); result = WorldDatabase.Query("SELECT MAX(guid) FROM gameobject" ); @@ -5868,7 +5868,7 @@ void ObjectMgr::SetHighestGuids() delete result; } - result = CharacterDatabase.Query("SELECT MAX(id) FROM auctionhouse" ); + result = CharacterDatabase.Query("SELECT MAX(id) FROM auction" ); if( result ) { m_AuctionIds.Set((*result)[0].GetUInt32()+1); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 33450fd83..1af4e5bcb 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "10253" + #define REVISION_NR "10254" #endif // __REVISION_NR_H__ diff --git a/src/shared/revision_sql.h b/src/shared/revision_sql.h index 10ac0d37f..b09ba7e33 100644 --- a/src/shared/revision_sql.h +++ b/src/shared/revision_sql.h @@ -1,6 +1,6 @@ #ifndef __REVISION_SQL_H__ #define __REVISION_SQL_H__ - #define REVISION_DB_CHARACTERS "required_10160_02_characters_pet_aura" + #define REVISION_DB_CHARACTERS "required_10254_01_characters_auctionhouse" #define REVISION_DB_MANGOS "required_10252_01_mangos_reputation_reward_rate" #define REVISION_DB_REALMD "required_10008_01_realmd_realmd_db_version" #endif // __REVISION_SQL_H__