Core/Player: Fix item refund exploit

This commit is contained in:
Machiavelli
2011-08-07 15:57:26 +02:00
parent 5429158b3f
commit 04c2f2929e
4 changed files with 28 additions and 15 deletions
+18 -6
View File
@@ -7263,20 +7263,26 @@ void Player::SetArenaPoints(uint32 value)
AddKnownCurrency(ITEM_ARENA_POINTS_ID);
}
void Player::ModifyHonorPoints(int32 value)
void Player::ModifyHonorPoints(int32 value, SQLTransaction* trans /*=NULL*/)
{
int32 newValue = int32(GetHonorPoints()) + value;
if (newValue < 0)
newValue = 0;
SetHonorPoints(uint32(newValue));
if (trans && !trans->null())
(*trans)->PAppend("UPDATE characters SET totalHonorPoints=%u WHERE guid=%u", newValue, GetGUIDLow());
}
void Player::ModifyArenaPoints(int32 value)
void Player::ModifyArenaPoints(int32 value, SQLTransaction* trans /*=NULL*/)
{
int32 newValue = int32(GetArenaPoints()) + value;
if (newValue < 0)
newValue = 0;
SetArenaPoints(uint32(newValue));
if (trans && !trans->null())
(*trans)->PAppend("UPDATE characters SET arenaPoints=%u WHERE guid=%u", newValue, GetGUIDLow());
}
uint32 Player::GetGuildIdFromDB(uint64 guid)
@@ -24549,8 +24555,11 @@ void Player::RefundItem(Item *item)
uint32 moneyRefund = item->GetPaidMoney(); // item-> will be invalidated in DestroyItem
// Save all relevant data to DB to prevent desynchronisation exploits
SQLTransaction trans = CharacterDatabase.BeginTransaction();
// Delete any references to the refund data
item->SetNotRefundable(this);
item->SetNotRefundable(this, true, &trans);
// Destroy item
DestroyItem(item->GetBagSlot(), item->GetSlot(), true);
@@ -24572,16 +24581,19 @@ void Player::RefundItem(Item *item)
// Grant back money
if (moneyRefund)
ModifyMoney(moneyRefund);
ModifyMoney(moneyRefund); // Saved in SaveInventoryAndGoldToDB
// Grant back Honor points
if (uint32 honorRefund = iece->reqhonorpoints)
ModifyHonorPoints(honorRefund);
ModifyHonorPoints(honorRefund, &trans);
// Grant back Arena points
if (uint32 arenaRefund = iece->reqarenapoints)
ModifyArenaPoints(arenaRefund);
ModifyArenaPoints(arenaRefund, &trans);
SaveInventoryAndGoldToDB(trans);
CharacterDatabase.CommitTransaction(trans);
}
void Player::SetRandomWinner(bool isWinner)
+2 -2
View File
@@ -2034,8 +2034,8 @@ class Player : public Unit, public GridObject<Player>
bool RewardHonor(Unit *pVictim, uint32 groupsize, int32 honor = -1, bool pvptoken = false);
uint32 GetHonorPoints() const { return GetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY); }
uint32 GetArenaPoints() const { return GetUInt32Value(PLAYER_FIELD_ARENA_CURRENCY); }
void ModifyHonorPoints(int32 value);
void ModifyArenaPoints(int32 value);
void ModifyHonorPoints(int32 value, SQLTransaction* trans = NULL); //! If trans is specified, honor save query will be added to trans
void ModifyArenaPoints(int32 value, SQLTransaction* trans = NULL); //! If trans is specified, arena point save query will be added to trans
uint32 GetMaxPersonalArenaRatingRequirement(uint32 minarenaslot) const;
void SetHonorPoints(uint32 value);
void SetArenaPoints(uint32 value);