Skip to content

Commit

Permalink
Fix crash on buy own offer in market (#292)
Browse files Browse the repository at this point in the history
Removed some unnecessary delete pointers
  • Loading branch information
dudantas committed Apr 4, 2022
1 parent 77f152e commit d488fae
Showing 1 changed file with 12 additions and 33 deletions.
45 changes: 12 additions & 33 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7676,9 +7676,6 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16

if (player == buyerPlayer || player->getAccount() == buyerPlayer->getAccount()) {
player->sendTextMessage(MESSAGE_MARKET, "You cannot accept your own offer.");
if (buyerPlayer->isOffline()) {
delete buyerPlayer;
}
return;
}

Expand All @@ -7687,8 +7684,7 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16
account.LoadAccountDB(player->getAccount());
uint32_t coins;
account.GetCoins(&coins);
if (amount > coins)
{
if (amount > coins) {
return;
}

Expand All @@ -7710,6 +7706,9 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16
if (it.stackable) {
uint16_t tmpAmount = amount;
for (Item* item : itemList) {
if (!item) {
continue;
}
uint16_t removeCount = std::min<uint16_t>(tmpAmount, item->getItemCount());
tmpAmount -= removeCount;
internalRemoveItem(item, removeCount);
Expand All @@ -7720,6 +7719,9 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16
}
} else {
for (Item* item : itemList) {
if (!item) {
continue;
}
internalRemoveItem(item);
}
}
Expand Down Expand Up @@ -7774,42 +7776,19 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16
Player *sellerPlayer = getPlayerByGUID(offer.playerId);
if (!sellerPlayer) {
sellerPlayer = new Player(nullptr);

if (!IOLoginData::loadPlayerById(sellerPlayer, offer.playerId)) {
if (sellerPlayer != nullptr) {
delete sellerPlayer;
return;
}
delete sellerPlayer;
return;
}
}

if (player == sellerPlayer ||
player->getAccount() == sellerPlayer->getAccount()) {
if (player == sellerPlayer || player->getAccount() == sellerPlayer->getAccount()) {
player->sendTextMessage(MESSAGE_MARKET, "You cannot accept your own offer.");

if (sellerPlayer->isOffline()) {
if (sellerPlayer != nullptr) {
delete sellerPlayer;
return;
}
}
if (sellerPlayer != nullptr) {
delete sellerPlayer;
return;
}
return;
}

if (totalPrice > (player->getBankBalance() + player->getMoney())) {
if (sellerPlayer->isOffline()) {
if (sellerPlayer != nullptr) {
delete sellerPlayer;
return;
}
}
if (sellerPlayer != nullptr) {
delete sellerPlayer;
return;
}
return;
}

// Have enough money on the bank
Expand Down

0 comments on commit d488fae

Please sign in to comment.