Core/Players: Prevent trading, taking gold from mail and withdrawing from guild bank if it would put the player over gold cap.

Closes #4015
This commit is contained in:
Shauren committed 2013-02-01 11:38:55 +01:00
1 parent dc5e9c80fc
commit 0bf29d45d1
6 files changed
+52 -23

No files matched your search

+13 -11
View File
@@ -22049,26 +22049,28 @@ void Player::InitPrimaryProfessions()
SetFreePrimaryProfessions(sWorld->getIntConfig(CONFIG_MAX_PRIMARY_TRADE_SKILL));
}
void Player::ModifyMoney(int32 d)
bool Player::ModifyMoney(int32 amount, bool sendError /*= true*/)
{
sScriptMgr->OnPlayerMoneyChanged(this, d);
if (!amount)
return true;
if (d < 0)
SetMoney (GetMoney() > uint32(-d) ? GetMoney() + d : 0);
sScriptMgr->OnPlayerMoneyChanged(this, amount);
if (amount < 0)
SetMoney (GetMoney() > uint32(-amount) ? GetMoney() + amount : 0);
else
{
uint32 newAmount = 0;
if (GetMoney() < uint32(MAX_MONEY_AMOUNT - d))
newAmount = GetMoney() + d;
if (GetMoney() < uint32(MAX_MONEY_AMOUNT - amount))
SetMoney(GetMoney() + amount);
else
{
// "At Gold Limit"
newAmount = MAX_MONEY_AMOUNT;
if (d)
if (sendError)
SendEquipError(EQUIP_ERR_TOO_MUCH_GOLD, NULL, NULL);
return false;
}
SetMoney (newAmount);
}
return true;
}
Unit* Player::GetSelectedUnit() const
+1 -1
View File
@@ -1546,7 +1546,7 @@ class Player : public Unit, public GridObject<Player>
void setWeaponChangeTimer(uint32 time) {m_weaponChangeTimer = time;}
uint32 GetMoney() const { return GetUInt32Value(PLAYER_FIELD_COINAGE); }
void ModifyMoney(int32 d);
bool ModifyMoney(int32 amount, bool sendError = true);
bool HasEnoughMoney(uint32 amount) const { return (GetMoney() >= amount); }
bool HasEnoughMoney(int32 amount) const
{
+10 -6
View File
@@ -1755,16 +1755,20 @@ bool Guild::HandleMemberWithdrawMoney(WorldSession* session, uint32 amount, bool
sScriptMgr->OnGuildMemberWitdrawMoney(this, player, amount, repair);
SQLTransaction trans = CharacterDatabase.BeginTransaction();
// Add money to player (if required)
if (!repair)
{
if (!player->ModifyMoney(amount))
return false;
player->SaveGoldToDB(trans);
}
// Update remaining money amount
member->UpdateBankWithdrawValue(trans, GUILD_BANK_MAX_TABS, amount);
// Remove money from bank
_ModifyBankMoney(trans, amount, false);
// Add money to player (if required)
if (!repair)
{
player->ModifyMoney(amount);
player->SaveGoldToDB(trans);
}
// Log guild bank event
_LogBankEvent(trans, repair ? GUILD_BANK_LOG_REPAIR_MONEY : GUILD_BANK_LOG_WITHDRAW_MONEY, uint8(0), player->GetGUIDLow(), amount);
CharacterDatabase.CommitTransaction(trans);
+7 -2
View File
@@ -532,13 +532,18 @@ void WorldSession::HandleMailTakeMoney(WorldPacket& recvData)
return;
}
player->SendMailResult(mailId, MAIL_MONEY_TAKEN, MAIL_OK);
if (!player->ModifyMoney(m->money, false))
{
player->SendMailResult(mailId, MAIL_MONEY_TAKEN, MAIL_ERR_EQUIP_ERROR, EQUIP_ERR_TOO_MUCH_GOLD);
return;
}
player->ModifyMoney(m->money);
m->money = 0;
m->state = MAIL_STATE_CHANGED;
player->m_mailsUpdated = true;
player->SendMailResult(mailId, MAIL_MONEY_TAKEN, MAIL_OK);
// save money and mail to prevent cheating
SQLTransaction trans = CharacterDatabase.BeginTransaction();
player->SaveGoldToDB(trans);
+15
View File
@@ -292,6 +292,20 @@ void WorldSession::HandleAcceptTradeOpcode(WorldPacket& /*recvPacket*/)
return;
}
if (_player->GetMoney() >= uint32(MAX_MONEY_AMOUNT) - his_trade->GetMoney())
{
_player->SendEquipError(EQUIP_ERR_TOO_MUCH_GOLD, NULL, NULL);
my_trade->SetAccepted(false, true);
return;
}
if (trader->GetMoney() >= uint32(MAX_MONEY_AMOUNT) - my_trade->GetMoney())
{
trader->SendEquipError(EQUIP_ERR_TOO_MUCH_GOLD, NULL, NULL);
his_trade->SetAccepted(false, true);
return;
}
// not accept if some items now can't be trade (cheating)
for (uint8 i = 0; i < TRADE_SLOT_TRADED_COUNT; ++i)
{
@@ -302,6 +316,7 @@ void WorldSession::HandleAcceptTradeOpcode(WorldPacket& /*recvPacket*/)
SendTradeStatus(TRADE_STATUS_TRADE_CANCELED);
return;
}
if (item->IsBindedNotWith(trader))
{
SendTradeStatus(TRADE_STATUS_NOT_ELIGIBLE);
+6 -3
View File
@@ -1046,9 +1046,12 @@ public:
ChatHandler(target->GetSession()).PSendSysMessage(LANG_YOURS_MONEY_GIVEN, handler->GetNameLink().c_str(), moneyToAdd);
if (moneyToAdd >= MAX_MONEY_AMOUNT)
target->SetMoney(MAX_MONEY_AMOUNT);
else
target->ModifyMoney(moneyToAdd);
moneyToAdd = MAX_MONEY_AMOUNT;
if (targetMoney >= uint32(MAX_MONEY_AMOUNT) - moneyToAdd)
moneyToAdd -= targetMoney;
target->ModifyMoney(moneyToAdd);
}
sLog->outDebug(LOG_FILTER_GENERAL, handler->GetTrinityString(LANG_NEW_MONEY), targetMoney, moneyToAdd, target->GetMoney());