Core/Items: Fix a trading spoof exploit.

Closes #4713
This commit is contained in:
Machiavelli
2012-01-17 18:51:04 +01:00
parent 5dd6b8b2dc
commit 6a44399852
2 changed files with 22 additions and 4 deletions
+18 -2
View File
@@ -296,15 +296,24 @@ Item* TradeData::GetItem(TradeSlots slot) const
return m_items[slot] ? m_player->GetItemByGuid(m_items[slot]) : NULL; return m_items[slot] ? m_player->GetItemByGuid(m_items[slot]) : NULL;
} }
bool TradeData::HasItem(uint64 item_guid) const bool TradeData::HasItem(uint64 itemGuid) const
{ {
for (uint8 i = 0; i < TRADE_SLOT_COUNT; ++i) for (uint8 i = 0; i < TRADE_SLOT_COUNT; ++i)
if (m_items[i] == item_guid) if (m_items[i] == itemGuid)
return true; return true;
return false; return false;
} }
TradeSlots const TradeData::GetTradeSlotForItem(uint64 itemGuid)
{
for (uint8 i = 0; i < TRADE_SLOT_COUNT; ++i)
if (m_items[i] == itemGuid)
return TradeSlots(i);
return TRADE_SLOT_INVALID;
}
Item* TradeData::GetSpellCastItem() const Item* TradeData::GetSpellCastItem() const
{ {
return m_spellCastItem ? m_player->GetItemByGuid(m_spellCastItem) : NULL; return m_spellCastItem ? m_player->GetItemByGuid(m_spellCastItem) : NULL;
@@ -12874,6 +12883,13 @@ void Player::SplitItem(uint16 src, uint16 dst, uint32 count)
EquipItem(dest, pNewItem, true); EquipItem(dest, pNewItem, true);
AutoUnequipOffhandIfNeed(); AutoUnequipOffhandIfNeed();
} }
//! Update item count in trade window, prevent spoofing
//! Since pSrcItem has its count updated (see above), Item::GetCount() will return the new count
//! in the underlying packet builder function
TradeSlots const slot = GetTradeData()->GetTradeSlotForItem(pSrcItem->GetGUID());
if (slot != TRADE_SLOT_INVALID)
GetTradeData()->SetItem(slot, pSrcItem);
} }
void Player::SwapItem(uint16 src, uint16 dst) void Player::SwapItem(uint16 src, uint16 dst)
+4 -2
View File
@@ -686,7 +686,8 @@ enum TradeSlots
{ {
TRADE_SLOT_COUNT = 7, TRADE_SLOT_COUNT = 7,
TRADE_SLOT_TRADED_COUNT = 6, TRADE_SLOT_TRADED_COUNT = 6,
TRADE_SLOT_NONTRADED = 6 TRADE_SLOT_NONTRADED = 6,
TRADE_SLOT_INVALID = -1,
}; };
enum TransferAbortReason enum TransferAbortReason
@@ -1001,7 +1002,8 @@ class TradeData
TradeData* GetTraderData() const; TradeData* GetTraderData() const;
Item* GetItem(TradeSlots slot) const; Item* GetItem(TradeSlots slot) const;
bool HasItem(uint64 item_guid) const; bool HasItem(uint64 itemGuid) const;
TradeSlots const GetTradeSlotForItem(uint64 itemGuid);
void SetItem(TradeSlots slot, Item* item); void SetItem(TradeSlots slot, Item* item);
uint32 GetSpell() const { return m_spell; } uint32 GetSpell() const { return m_spell; }