Drop not needed table 'item_text', add new column 'text' in table 'item_instance'. Original patch by Vladimir.

--HG--
branch : trunk
This commit is contained in:
n0n4m3
2010-04-14 12:43:42 +04:00
parent 61e71986f0
commit e3e5ca6227
16 changed files with 67 additions and 158 deletions
+1 -23
View File
@@ -1605,6 +1605,7 @@ CREATE TABLE `item_instance` (
`guid` int(11) unsigned NOT NULL default '0',
`owner_guid` int(11) unsigned NOT NULL default '0',
`data` longtext,
`text` longtext,
PRIMARY KEY (`guid`),
KEY `idx_owner_guid` (`owner_guid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='Item System';
@@ -1643,29 +1644,6 @@ LOCK TABLES `item_refund_instance` WRITE;
/*!40000 ALTER TABLE `item_refund_instance` DISABLE KEYS */;
/*!40000 ALTER TABLE `item_refund_instance` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `item_text`
--
DROP TABLE IF EXISTS `item_text`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `item_text` (
`id` int(11) unsigned NOT NULL default '0',
`text` longtext,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Item System';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `item_text`
--
LOCK TABLES `item_text` WRITE;
/*!40000 ALTER TABLE `item_text` DISABLE KEYS */;
/*!40000 ALTER TABLE `item_text` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `mail`
@@ -0,0 +1 @@
ALTER TABLE `item_instance` ADD COLUMN `text` longtext AFTER `data`;
@@ -0,0 +1 @@
DROP TABLE IF EXISTS `item_text`;
+3 -3
View File
@@ -254,7 +254,7 @@ void AuctionHouseMgr::SendAuctionExpiredMail(AuctionEntry * auction)
void AuctionHouseMgr::LoadAuctionItems()
{
// data needs to be at first place for Item::LoadFromDB
QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT data,itemguid,item_template FROM auctionhouse JOIN item_instance ON itemguid = guid");
QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT data, text, itemguid, item_template FROM auctionhouse JOIN item_instance ON itemguid = guid");
if (!result)
{
@@ -275,8 +275,8 @@ void AuctionHouseMgr::LoadAuctionItems()
bar.step();
fields = result->Fetch();
uint32 item_guid = fields[1].GetUInt32();
uint32 item_template = fields[2].GetUInt32();
uint32 item_guid = fields[2].GetUInt32();
uint32 item_template = fields[3].GetUInt32();
ItemPrototype const *proto = objmgr.GetItemPrototype(item_template);
+1 -1
View File
@@ -55,7 +55,7 @@ class Bag : public Item
// overwrite virtual Item::SaveToDB
void SaveToDB();
// overwrite virtual Item::LoadFromDB
bool LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result = QueryResult_AutoPtr(NULL));
bool LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result);
// overwrite virtual Item::DeleteFromDB
void DeleteFromDB();
+1 -1
View File
@@ -77,7 +77,7 @@ bool LoginQueryHolder::Initialize()
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADQUESTSTATUS, "SELECT quest,status,rewarded,explored,timer,mobcount1,mobcount2,mobcount3,mobcount4,itemcount1,itemcount2,itemcount3,itemcount4 FROM character_queststatus WHERE guid = '%u'", GUID_LOPART(m_guid));
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADDAILYQUESTSTATUS,"SELECT quest,time FROM character_queststatus_daily WHERE guid = '%u'", GUID_LOPART(m_guid));
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADREPUTATION, "SELECT faction,standing,flags FROM character_reputation WHERE guid = '%u'", GUID_LOPART(m_guid));
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADINVENTORY, "SELECT data,bag,slot,item,item_template FROM character_inventory JOIN item_instance ON character_inventory.item = item_instance.guid WHERE character_inventory.guid = '%u' ORDER BY bag,slot", GUID_LOPART(m_guid));
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADINVENTORY, "SELECT data,text,bag,slot,item,item_template FROM character_inventory JOIN item_instance ON character_inventory.item = item_instance.guid WHERE character_inventory.guid = '%u' ORDER BY bag,slot", GUID_LOPART(m_guid));
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADACTIONS, "SELECT a.button,a.action,a.type FROM character_action as a, characters as c WHERE a.guid = c.guid AND a.spec = c.activespec AND a.guid = '%u' ORDER BY button", GUID_LOPART(m_guid));
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADMAILCOUNT, "SELECT COUNT(id) FROM mail WHERE receiver = '%u' AND (checked & 1)=0 AND deliver_time <= '" UI64FMTD "'", GUID_LOPART(m_guid),(uint64)time(NULL));
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADMAILDATE, "SELECT MIN(deliver_time) FROM mail WHERE receiver = '%u' AND (checked & 1)=0", GUID_LOPART(m_guid));
+5 -5
View File
@@ -1115,17 +1115,17 @@ void Guild::LoadGuildBankFromDB()
// data needs to be at first place for Item::LoadFromDB
// 0 1 2 3 4
result = CharacterDatabase.PQuery("SELECT data, TabId, SlotId, item_guid, item_entry FROM guild_bank_item JOIN item_instance ON item_guid = guid WHERE guildid='%u' ORDER BY TabId", m_Id);
result = CharacterDatabase.PQuery("SELECT data, text, TabId, SlotId, item_guid, item_entry FROM guild_bank_item JOIN item_instance ON item_guid = guid WHERE guildid='%u' ORDER BY TabId", m_Id);
if (!result)
return;
do
{
Field *fields = result->Fetch();
uint8 TabId = fields[1].GetUInt8();
uint8 SlotId = fields[2].GetUInt8();
uint32 ItemGuid = fields[3].GetUInt32();
uint32 ItemEntry = fields[4].GetUInt32();
uint8 TabId = fields[2].GetUInt8();
uint8 SlotId = fields[3].GetUInt8();
uint32 ItemGuid = fields[4].GetUInt32();
uint32 ItemEntry = fields[5].GetUInt32();
if (TabId >= m_PurchasedTabs || TabId >= GUILD_BANK_MAX_TABS)
{
+8 -5
View File
@@ -308,20 +308,25 @@ void Item::SaveToDB()
{
case ITEM_NEW:
{
std::string text = m_text;
CharacterDatabase.escape_string(text);
std::ostringstream ss;
ss << "REPLACE INTO item_instance (guid,owner_guid,data) VALUES (" << guid << "," << GUID_LOPART(GetOwnerGUID()) << ",'";
ss << "REPLACE INTO item_instance (guid, owner_guid, data, text) VALUES (" << guid << "," << GUID_LOPART(GetOwnerGUID()) << ",'";
for (uint16 i = 0; i < m_valuesCount; ++i)
ss << GetUInt32Value(i) << " ";
ss << "')";
ss << "', '" << text << "')";
CharacterDatabase.Execute(ss.str().c_str());
}break;
case ITEM_CHANGED:
{
std::string text = m_text;
CharacterDatabase.escape_string(text);
std::ostringstream ss;
ss << "UPDATE item_instance SET data = '";
for (uint16 i = 0; i < m_valuesCount; ++i)
ss << GetUInt32Value(i) << " ";
ss << "', owner_guid = '" << GUID_LOPART(GetOwnerGUID()) << "' WHERE guid = '" << guid << "'";
ss << "', owner_guid = '" << GUID_LOPART(GetOwnerGUID());
ss << "', text = '" << text << "' WHERE guid = '" << guid << "'";
CharacterDatabase.Execute(ss.str().c_str());
@@ -330,8 +335,6 @@ void Item::SaveToDB()
}break;
case ITEM_REMOVED:
{
//if (GetUInt32Value(ITEM_FIELD_ITEM_TEXT_ID) > 0)
// CharacterDatabase.PExecute("DELETE FROM item_text WHERE id = '%u'", GetUInt32Value(ITEM_FIELD_ITEM_TEXT_ID));
CharacterDatabase.PExecute("DELETE FROM item_instance WHERE guid = '%u'", guid);
if (HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED))
CharacterDatabase.PExecute("DELETE FROM character_gifts WHERE item_guid = '%u'", GetGUIDLow());
+5 -1
View File
@@ -240,7 +240,7 @@ class Item : public Object
bool IsBindedNotWith(Player const* player) const;
bool IsBoundByEnchant() const;
virtual void SaveToDB();
virtual bool LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result = QueryResult_AutoPtr(NULL));
virtual bool LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result);
virtual void DeleteFromDB();
void DeleteFromInventoryDB();
void SaveRefundDataToDB();
@@ -293,6 +293,9 @@ class Item : public Object
uint32 GetEnchantmentDuration(EnchantmentSlot slot) const { return GetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1 + slot*MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_DURATION_OFFSET);}
uint32 GetEnchantmentCharges(EnchantmentSlot slot) const { return GetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1 + slot*MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_CHARGES_OFFSET);}
std::string const& GetText() const { return m_text; }
void SetText(std::string const& text) { m_text = text; }
void SendTimeUpdate(Player* owner);
void UpdateDuration(Player* owner, uint32 diff);
@@ -338,6 +341,7 @@ class Item : public Object
void BuildUpdate(UpdateDataMapType&);
private:
std::string m_text;
uint8 m_slot;
Bag *m_container;
ItemUpdateState uState;
+28
View File
@@ -1530,3 +1530,31 @@ void WorldSession::HandleItemRefund(WorldPacket &recv_data)
if (arenaRefund)
_player->ModifyArenaPoints(arenaRefund);
}
/**
* Handles the packet sent by the client when requesting information about item text.
*
* This function is called when player clicks on item which has some flag set
*/
void WorldSession::HandleItemTextQuery(WorldPacket & recv_data )
{
uint64 itemGuid;
recv_data >> itemGuid;
sLog.outDebug("CMSG_ITEM_TEXT_QUERY item guid: %u", GUID_LOPART(itemGuid));
WorldPacket data(SMSG_ITEM_TEXT_QUERY_RESPONSE, (4+10)); // guess size
if (Item *item = _player->GetItemByGuid(itemGuid))
{
data << uint8(0); // has text
data << uint64(itemGuid); // item guid
data << item->GetText();
}
else
{
data << uint8(1); // no text
}
SendPacket(&data);
}
+2 -25
View File
@@ -643,29 +643,6 @@ void WorldSession::HandleGetMailList(WorldPacket & recv_data)
_player->UpdateNextMailTimeAndUnreads();
}
///this function is called when client needs mail message body, or when player clicks on item which has ITEM_FIELD_ITEM_TEXT_ID > 0
void WorldSession::HandleItemTextQuery(WorldPacket & recv_data)
{
uint64 itemGuid;
recv_data >> itemGuid;
sLog.outDebug("CMSG_ITEM_TEXT_QUERY item guid: %u", GUID_LOPART(itemGuid));
WorldPacket data(SMSG_ITEM_TEXT_QUERY_RESPONSE, (4+10)); // guess size
if (Item *item = _player->GetItemByGuid(itemGuid))
{
data << uint8(0); // has text
data << uint64(itemGuid); // item guid
data << objmgr.GetItemText(item->GetGUIDLow()); // max 8000
}
else
{
data << uint8(1); // no text
}
SendPacket(&data);
}
//used when player copies mail body to his inventory
void WorldSession::HandleMailCreateTextItem(WorldPacket & recv_data)
{
@@ -704,10 +681,10 @@ void WorldSession::HandleMailCreateTextItem(WorldPacket & recv_data)
return;
}
objmgr.CreateItemText(bodyItem->GetGUIDLow(), mailTemplateEntry->content[GetSessionDbcLocale()]);
bodyItem->SetText(mailTemplateEntry->content[GetSessionDbcLocale()]);
}
else
objmgr.CreateItemText(bodyItem->GetGUIDLow(), m->body);
bodyItem->SetText(m->body);
bodyItem->SetUInt32Value(ITEM_FIELD_CREATOR, m->sender);
bodyItem->SetFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPER | ITEM_FLAGS_REFUNDABLE_2 | ITEM_FLAGS_UNK1);
-52
View File
@@ -4795,41 +4795,6 @@ void ObjectMgr::LoadGossipScripts()
// checks are done in LoadGossipMenuItems
}
void ObjectMgr::LoadItemTexts()
{
QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT id, text FROM item_text");
uint32 count = 0;
if (!result)
{
barGoLink bar(1);
bar.step();
sLog.outString();
sLog.outString(">> Loaded %u item pages", count);
return;
}
barGoLink bar(result->GetRowCount());
Field* fields;
do
{
bar.step();
fields = result->Fetch();
mItemTexts[ fields[0].GetUInt32() ] = fields[1].GetCppString();
++count;
} while (result->NextRow());
sLog.outString();
sLog.outString(">> Loaded %u item texts", count);
}
void ObjectMgr::LoadPageTexts()
{
sPageTextStore.Free(); // for reload case
@@ -5986,10 +5951,6 @@ void ObjectMgr::SetHighestGuids()
if (result)
m_mailid = (*result)[0].GetUInt32()+1;
result = CharacterDatabase.Query("SELECT MAX(id) FROM item_text");
if (result)
m_ItemTextId = (*result)[0].GetUInt32()+1;
result = CharacterDatabase.Query("SELECT MAX(guid) FROM corpse");
if (result)
m_hiCorpseGuid = (*result)[0].GetUInt32()+1;
@@ -6057,19 +6018,6 @@ uint32 ObjectMgr::GenerateMailID()
return m_mailid++;
}
void ObjectMgr::CreateItemText(uint32 guid, std::string text)
{
// insert new item text to container
mItemTexts[ guid ] = text;
// save new item text
CharacterDatabase.escape_string(text);
std::ostringstream query;
query << "INSERT INTO item_text (id,text) VALUES ( '" << guid << "', '" << text << "')";
CharacterDatabase.Execute(query.str().c_str()); //needs to be run this way, because mail body may be more than 1024 characters
}
uint32 ObjectMgr::GenerateLowGuid(HighGuid guidhigh)
{
switch(guidhigh)
-16
View File
@@ -667,7 +667,6 @@ class ObjectMgr
void LoadTavernAreaTriggers();
void LoadGameObjectForQuests();
void LoadItemTexts();
void LoadPageTexts();
void LoadPlayerInfo();
@@ -718,21 +717,9 @@ class ObjectMgr
uint32 GenerateAuctionID();
uint64 GenerateEquipmentSetGuid();
uint32 GenerateGuildId();
//uint32 GenerateItemTextID();
uint32 GenerateMailID();
uint32 GeneratePetNumber();
void CreateItemText(uint32 guid, std::string text);
void AddItemText(uint32 guid, std::string text) { mItemTexts[guid] = text; }
std::string GetItemText(uint32 id)
{
ItemTextMap::const_iterator itr = mItemTexts.find(id);
if (itr != mItemTexts.end())
return itr->second;
else
return "There is no info for this item";
}
typedef std::multimap<int32, uint32> ExclusiveQuestGroups;
ExclusiveQuestGroups mExclusiveQuestGroups;
@@ -1021,7 +1008,6 @@ class ObjectMgr
typedef UNORDERED_MAP<uint32, GossipText> GossipTextMap;
typedef UNORDERED_MAP<uint32, uint32> QuestAreaTriggerMap;
typedef UNORDERED_MAP<uint32, std::string> ItemTextMap;
typedef std::set<uint32> TavernAreaTriggerSet;
typedef std::set<uint32> GameObjectForQuestSet;
@@ -1029,8 +1015,6 @@ class ObjectMgr
GuildMap mGuildMap;
ArenaTeamMap mArenaTeamMap;
ItemTextMap mItemTexts;
QuestAreaTriggerMap mQuestAreaTriggerMap;
TavernAreaTriggerSet mTavernAreaTriggerSet;
GameObjectForQuestSet mGameObjectForQuestSet;
+11 -11
View File
@@ -4260,15 +4260,15 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC
if (has_items)
{
// data needs to be at first place for Item::LoadFromDB
QueryResult_AutoPtr resultItems = CharacterDatabase.PQuery("SELECT data,item_guid,item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE mail_id='%u'", mail_id);
QueryResult_AutoPtr resultItems = CharacterDatabase.PQuery("SELECT data,text,item_guid,item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE mail_id='%u'", mail_id);
if (resultItems)
{
do
{
Field *fields2 = resultItems->Fetch();
uint32 item_guidlow = fields2[1].GetUInt32();
uint32 item_template = fields2[2].GetUInt32();
uint32 item_guidlow = fields2[2].GetUInt32();
uint32 item_template = fields2[3].GetUInt32();
ItemPrototype const* itemProto = objmgr.GetItemPrototype(item_template);
if (!itemProto)
@@ -16366,7 +16366,7 @@ void Player::LoadCorpse()
void Player::_LoadInventory(QueryResult_AutoPtr result, uint32 timediff)
{
//QueryResult *result = CharacterDatabase.PQuery("SELECT data,bag,slot,item,item_template FROM character_inventory JOIN item_instance ON character_inventory.item = item_instance.guid WHERE character_inventory.guid = '%u' ORDER BY bag,slot", GetGUIDLow());
//QueryResult *result = CharacterDatabase.PQuery("SELECT data,text,bag,slot,item,item_template FROM character_inventory JOIN item_instance ON character_inventory.item = item_instance.guid WHERE character_inventory.guid = '%u' ORDER BY bag,slot", GetGUIDLow());
std::map<uint64, Bag*> bagMap; // fast guid lookup for bags
//NOTE: the "order by `bag`" is important because it makes sure
//the bagMap is filled before items in the bags are loaded
@@ -16384,10 +16384,10 @@ void Player::_LoadInventory(QueryResult_AutoPtr result, uint32 timediff)
do
{
Field *fields = result->Fetch();
uint32 bag_guid = fields[1].GetUInt32();
uint8 slot = fields[2].GetUInt8();
uint32 item_guid = fields[3].GetUInt32();
uint32 item_id = fields[4].GetUInt32();
uint32 bag_guid = fields[2].GetUInt32();
uint8 slot = fields[3].GetUInt8();
uint32 item_guid = fields[4].GetUInt32();
uint32 item_id = fields[5].GetUInt32();
ItemPrototype const * proto = objmgr.GetItemPrototype(item_id);
@@ -16560,15 +16560,15 @@ void Player::_LoadInventory(QueryResult_AutoPtr result, uint32 timediff)
void Player::_LoadMailedItems(Mail *mail)
{
// data needs to be at first place for Item::LoadFromDB
QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT data, item_guid, item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE mail_id='%u'", mail->messageID);
QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT data, text, item_guid, item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE mail_id='%u'", mail->messageID);
if (!result)
return;
do
{
Field *fields = result->Fetch();
uint32 item_guid_low = fields[1].GetUInt32();
uint32 item_template = fields[2].GetUInt32();
uint32 item_guid_low = fields[2].GetUInt32();
uint32 item_template = fields[3].GetUInt32();
mail->AddItem(item_guid_low, item_template);
-12
View File
@@ -660,18 +660,6 @@ DumpReturn PlayerDumpReader::LoadDump(const std::string& file, uint32 account, s
ROLLBACK(DUMP_FILE_BROKEN);
break;
}
case DTT_ITEM_TEXT: // item_text
{
// id
if (!changeGuid(line, 1, itemTexts, objmgr.m_ItemTextId))
ROLLBACK(DUMP_FILE_BROKEN);
// add it to cache
uint32 id= atoi(getnth(line,1).c_str());
std::string text = getnth(line,2);
objmgr.AddItemText(id,text);
break;
}
default:
sLog.outError("Unknown dump table type: %u",type);
break;
-3
View File
@@ -1350,9 +1350,6 @@ void World::SetInitialWorldSettings()
sLog.outString("Loading Items..."); // must be after LoadRandomEnchantmentsTable and LoadPageTexts
objmgr.LoadItemPrototypes();
sLog.outString("Loading Item Texts...");
objmgr.LoadItemTexts();
sLog.outString("Loading Creature Model Based Info Data...");
objmgr.LoadCreatureModelInfo();