aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--[-rwxr-xr-x]src/server/game/Entities/Player/Player.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index 0076d58b4e8..161563b1127 100755..100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -20515,16 +20515,25 @@ bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32
}
}
- uint32 price = crItem->IsGoldRequired(pProto) ? pProto->BuyPrice * count : 0;
+ uint32 price = 0;
+ if(crItem->IsGoldRequired(pProto) && pProto->BuyPrice > 0) //Assume price cannot be negative (do not know why it is int32)
+ {
+ uint32 maxCount = MAX_MONEY_AMOUNT / pProto->BuyPrice;
+ if((uint32)count > maxCount)
+ {
+ sLog->outError("Player %s tried to buy %u item id %u, causing overflow", GetName(), (uint32)count, pProto->ItemId);
+ count = (uint8)maxCount;
+ }
+ price = pProto->BuyPrice * count; //it should not exceed MAX_MONEY_AMOUNT
- // reputation discount
- if (price)
+ // reputation discount
price = uint32(floor(price * GetReputationPriceDiscount(creature)));
- if (!HasEnoughMoney(price))
- {
- SendBuyError(BUY_ERR_NOT_ENOUGHT_MONEY, creature, item, 0);
- return false;
+ if (!HasEnoughMoney(price))
+ {
+ SendBuyError(BUY_ERR_NOT_ENOUGHT_MONEY, creature, item, 0);
+ return false;
+ }
}
if ((bag == NULL_BAG && slot == NULL_SLOT) || IsInventoryPos(bag, slot))