aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2021-05-23 00:56:00 +0200
committerShauren <shauren.trinity@gmail.com>2021-05-23 01:39:08 +0200
commitce37c24481c6ab6863c1fc3be037aa56c54520ea (patch)
tree94fa467b22613b08fa95cd070c5da0a4d022f3ca /src
parent7f7ccfd6cddc8b6daec92390093f677bcd0a9aa4 (diff)
Core/PacketIO: Properly send inventory error when attempting to withdraw guild bank item into "any slot" when bags are full
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Entities/Player/Player.cpp2
-rw-r--r--src/server/game/Entities/Player/Player.h2
-rw-r--r--src/server/game/Guilds/Guild.cpp39
-rw-r--r--src/server/game/Guilds/Guild.h6
4 files changed, 32 insertions, 17 deletions
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index da7347c5457..d6f7cfb7bad 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -13663,7 +13663,7 @@ void Player::RemoveItemFromBuyBackSlot(uint32 slot, bool del)
}
}
-void Player::SendEquipError(InventoryResult msg, Item* item1 /*= nullptr*/, Item* item2 /*= nullptr*/, uint32 itemId /*= 0*/) const
+void Player::SendEquipError(InventoryResult msg, Item const* item1 /*= nullptr*/, Item const* item2 /*= nullptr*/, uint32 itemId /*= 0*/) const
{
WorldPackets::Item::InventoryChangeFailure failure;
failure.BagResult = msg;
diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h
index be5ff970462..9e64e1834d8 100644
--- a/src/server/game/Entities/Player/Player.h
+++ b/src/server/game/Entities/Player/Player.h
@@ -1382,7 +1382,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
void SetBuybackTimestamp(uint32 slot, uint32 timestamp) { SetUpdateFieldValue(m_values.ModifyValue(&Player::m_activePlayerData).ModifyValue(&UF::ActivePlayerData::BuybackTimestamp, slot), timestamp); }
Item* GetItemFromBuyBackSlot(uint32 slot);
void RemoveItemFromBuyBackSlot(uint32 slot, bool del);
- void SendEquipError(InventoryResult msg, Item* item1 = nullptr, Item* item2 = nullptr, uint32 itemId = 0) const;
+ void SendEquipError(InventoryResult msg, Item const* item1 = nullptr, Item const* item2 = nullptr, uint32 itemId = 0) const;
void SendBuyError(BuyResult msg, Creature* creature, uint32 item, uint32 param) const;
void SendSellError(SellResult msg, Creature* creature, ObjectGuid guid) const;
void AddWeaponProficiency(uint32 newflag) { m_WeaponProficiency |= newflag; }
diff --git a/src/server/game/Guilds/Guild.cpp b/src/server/game/Guilds/Guild.cpp
index 50caa2fae3e..ce259bc4715 100644
--- a/src/server/game/Guilds/Guild.cpp
+++ b/src/server/game/Guilds/Guild.cpp
@@ -785,13 +785,13 @@ bool Guild::MoveItemData::CheckItem(uint32& splitedAmount)
return true;
}
-bool Guild::MoveItemData::CanStore(Item* pItem, bool swap, bool sendError)
+InventoryResult Guild::MoveItemData::CanStore(Item* pItem, bool swap, bool sendError)
{
m_vec.clear();
InventoryResult msg = CanStore(pItem, swap);
if (sendError && msg != EQUIP_ERR_OK)
- m_pPlayer->SendEquipError(msg, pItem);
- return (msg == EQUIP_ERR_OK);
+ SendEquipError(msg, pItem);
+ return msg;
}
bool Guild::MoveItemData::CloneItem(uint32 count)
@@ -800,7 +800,7 @@ bool Guild::MoveItemData::CloneItem(uint32 count)
m_pClonedItem = m_pItem->CloneItem(count);
if (!m_pClonedItem)
{
- m_pPlayer->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, m_pItem);
+ SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, m_pItem);
return false;
}
return true;
@@ -821,6 +821,11 @@ inline void Guild::MoveItemData::CopySlots(SlotIds& ids) const
ids.insert(uint8(itr->pos));
}
+void Guild::MoveItemData::SendEquipError(InventoryResult result, Item const* item)
+{
+ m_pPlayer->SendEquipError(result, item);
+}
+
// PlayerMoveItemData
bool Guild::PlayerMoveItemData::InitItem()
{
@@ -830,13 +835,13 @@ bool Guild::PlayerMoveItemData::InitItem()
// Anti-WPE protection. Do not move non-empty bags to bank.
if (m_pItem->IsNotEmptyBag())
{
- m_pPlayer->SendEquipError(EQUIP_ERR_DESTROY_NONEMPTY_BAG, m_pItem);
+ SendEquipError(EQUIP_ERR_DESTROY_NONEMPTY_BAG, m_pItem);
m_pItem = nullptr;
}
// Bound items cannot be put into bank.
else if (!m_pItem->CanBeTraded())
{
- m_pPlayer->SendEquipError(EQUIP_ERR_CANT_SWAP, m_pItem);
+ SendEquipError(EQUIP_ERR_CANT_SWAP, m_pItem);
m_pItem = nullptr;
}
}
@@ -3228,12 +3233,16 @@ void Guild::_MoveItems(MoveItemData* pSrc, MoveItemData* pDest, uint32 splitedAm
else // 6. No split
{
// 6.1. Try to merge items in destination (pDest->GetItem() == nullptr)
- if (!Guild::_DoItemsMove(pSrc, pDest, false)) // Item could not be merged
+ InventoryResult mergeAttemptResult = Guild::_DoItemsMove(pSrc, pDest, false);
+ if (mergeAttemptResult != EQUIP_ERR_OK) // Item could not be merged
{
// 6.2. Try to swap items
// 6.2.1. Initialize destination item
if (!pDest->InitItem())
+ {
+ pSrc->SendEquipError(mergeAttemptResult, pSrc->GetItem(false));
return;
+ }
// 6.2.2. Check rights to store item in source (opposite direction)
if (!pSrc->HasStoreRights(pDest))
@@ -3250,20 +3259,24 @@ void Guild::_MoveItems(MoveItemData* pSrc, MoveItemData* pDest, uint32 splitedAm
_SendBankContentUpdate(pSrc, pDest);
}
-bool Guild::_DoItemsMove(MoveItemData* pSrc, MoveItemData* pDest, bool sendError, uint32 splitedAmount)
+InventoryResult Guild::_DoItemsMove(MoveItemData* pSrc, MoveItemData* pDest, bool sendError, uint32 splitedAmount)
{
Item* pDestItem = pDest->GetItem();
bool swap = (pDestItem != nullptr);
Item* pSrcItem = pSrc->GetItem(splitedAmount != 0);
// 1. Can store source item in destination
- if (!pDest->CanStore(pSrcItem, swap, sendError))
- return false;
+ InventoryResult destResult = pDest->CanStore(pSrcItem, swap, sendError);
+ if (destResult != EQUIP_ERR_OK)
+ return destResult;
// 2. Can store destination item in source
if (swap)
- if (!pSrc->CanStore(pDestItem, true, true))
- return false;
+ {
+ InventoryResult srcResult = pSrc->CanStore(pDestItem, true, true);
+ if (srcResult != EQUIP_ERR_OK)
+ return srcResult;
+ }
// GM LOG (@todo move to scripts)
pDest->LogAction(pSrc);
@@ -3291,7 +3304,7 @@ bool Guild::_DoItemsMove(MoveItemData* pSrc, MoveItemData* pDest, bool sendError
pSrc->StoreItem(trans, pDestItem);
CharacterDatabase.CommitTransaction(trans);
- return true;
+ return EQUIP_ERR_OK;
}
void Guild::_SendBankContentUpdate(MoveItemData* pSrc, MoveItemData* pDest) const
diff --git a/src/server/game/Guilds/Guild.h b/src/server/game/Guilds/Guild.h
index bd21c92d733..7a1bdaf79e5 100644
--- a/src/server/game/Guilds/Guild.h
+++ b/src/server/game/Guilds/Guild.h
@@ -633,7 +633,7 @@ class TC_GAME_API Guild
// Defines if player has rights to withdraw item from container
virtual bool HasWithdrawRights(MoveItemData* /*pOther*/) const { return true; }
// Checks if container can store specified item
- bool CanStore(Item* pItem, bool swap, bool sendError);
+ InventoryResult CanStore(Item* pItem, bool swap, bool sendError);
// Clones stored item
bool CloneItem(uint32 count);
// Remove item from container (if splited update items fields)
@@ -646,6 +646,8 @@ class TC_GAME_API Guild
virtual void LogAction(MoveItemData* pFrom) const;
// Copy slots id from position vector
void CopySlots(SlotIds& ids) const;
+ // Sends equip error to player
+ void SendEquipError(InventoryResult result, Item const* item);
Item* GetItem(bool isCloned = false) const { return isCloned ? m_pClonedItem : m_pItem; }
uint8 GetContainer() const { return m_container; }
@@ -932,7 +934,7 @@ class TC_GAME_API Guild
Item* _GetItem(uint8 tabId, uint8 slotId) const;
void _RemoveItem(CharacterDatabaseTransaction& trans, uint8 tabId, uint8 slotId);
void _MoveItems(MoveItemData* pSrc, MoveItemData* pDest, uint32 splitedAmount) const;
- static bool _DoItemsMove(MoveItemData* pSrc, MoveItemData* pDest, bool sendError, uint32 splitedAmount = 0);
+ static InventoryResult _DoItemsMove(MoveItemData* pSrc, MoveItemData* pDest, bool sendError, uint32 splitedAmount = 0);
void _SendBankContentUpdate(MoveItemData* pSrc, MoveItemData* pDest) const;
void _SendBankContentUpdate(uint8 tabId, SlotIds slots) const;