Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on buy own offer in market #292

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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