[9052] Fixed possible crash at fake items swap packet.

This commit is contained in:
VladimirMangos 2009-12-24 01:23:40 +03:00
parent 0e42b18946
commit 391133cb8f
2 changed files with 14 additions and 7 deletions

View file

@ -11221,12 +11221,12 @@ void Player::SwapItem( uint16 src, uint16 dst )
Item *pSrcItem = GetItemByPos( srcbag, srcslot ); Item *pSrcItem = GetItemByPos( srcbag, srcslot );
Item *pDstItem = GetItemByPos( dstbag, dstslot ); Item *pDstItem = GetItemByPos( dstbag, dstslot );
if( !pSrcItem ) if (!pSrcItem)
return; return;
sLog.outDebug( "STORAGE: SwapItem bag = %u, slot = %u, item = %u", dstbag, dstslot, pSrcItem->GetEntry()); sLog.outDebug( "STORAGE: SwapItem bag = %u, slot = %u, item = %u", dstbag, dstslot, pSrcItem->GetEntry());
if(!isAlive() ) if (!isAlive())
{ {
SendEquipError( EQUIP_ERR_YOU_ARE_DEAD, pSrcItem, pDstItem ); SendEquipError( EQUIP_ERR_YOU_ARE_DEAD, pSrcItem, pDstItem );
return; return;
@ -11234,7 +11234,7 @@ void Player::SwapItem( uint16 src, uint16 dst )
// SRC checks // SRC checks
if(pSrcItem->m_lootGenerated) // prevent swap looting item if (pSrcItem->m_lootGenerated) // prevent swap looting item
{ {
//best error message found for attempting to swap while looting //best error message found for attempting to swap while looting
SendEquipError( EQUIP_ERR_CANT_DO_RIGHT_NOW, pSrcItem, NULL ); SendEquipError( EQUIP_ERR_CANT_DO_RIGHT_NOW, pSrcItem, NULL );
@ -11242,11 +11242,11 @@ void Player::SwapItem( uint16 src, uint16 dst )
} }
// check unequip potability for equipped items and bank bags // check unequip potability for equipped items and bank bags
if(IsEquipmentPos ( src ) || IsBagPos ( src )) if (IsEquipmentPos(src) || IsBagPos(src))
{ {
// bags can be swapped with empty bag slots, or with empty bag (items move possibility checked later) // bags can be swapped with empty bag slots, or with empty bag (items move possibility checked later)
uint8 msg = CanUnequipItem( src, !IsBagPos ( src ) || IsBagPos ( dst ) || (pDstItem && pDstItem->IsBag() && ((Bag*)pDstItem)->IsEmpty())); uint8 msg = CanUnequipItem( src, !IsBagPos ( src ) || IsBagPos ( dst ) || (pDstItem && pDstItem->IsBag() && ((Bag*)pDstItem)->IsEmpty()));
if(msg != EQUIP_ERR_OK) if (msg != EQUIP_ERR_OK)
{ {
SendEquipError( msg, pSrcItem, pDstItem ); SendEquipError( msg, pSrcItem, pDstItem );
return; return;
@ -11254,12 +11254,19 @@ void Player::SwapItem( uint16 src, uint16 dst )
} }
// prevent put equipped/bank bag in self // prevent put equipped/bank bag in self
if( IsBagPos ( src ) && srcslot == dstbag) if (IsBagPos(src) && srcslot == dstbag)
{ {
SendEquipError( EQUIP_ERR_NONEMPTY_BAG_OVER_OTHER_BAG, pSrcItem, pDstItem ); SendEquipError( EQUIP_ERR_NONEMPTY_BAG_OVER_OTHER_BAG, pSrcItem, pDstItem );
return; return;
} }
// prevent put equipped/bank bag in self
if (IsBagPos(dst) && dstslot == srcbag)
{
SendEquipError( EQUIP_ERR_NONEMPTY_BAG_OVER_OTHER_BAG, pDstItem, pSrcItem );
return;
}
// DST checks // DST checks
if (pDstItem) if (pDstItem)

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "9051" #define REVISION_NR "9052"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__