Skip to content

Commit

Permalink
fix: save offline counterparty on market offer acceptance (#1764)
Browse files Browse the repository at this point in the history
Players were getting loaded with online = true which made it so we tried to save players asynchronously even when they were offline, causing market transactions to not always save correctly.
  • Loading branch information
luan authored Nov 1, 2023
1 parent 2a3a028 commit 77d9c77
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
21 changes: 8 additions & 13 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ std::shared_ptr<Player> Game::getPlayerByID(uint32_t id, bool loadTmp /* = false
if (!IOLoginData::loadPlayerById(tmpPlayer, id)) {
return nullptr;
}
tmpPlayer->setOnline(false);
return tmpPlayer;
}

Expand Down Expand Up @@ -784,6 +785,7 @@ std::shared_ptr<Player> Game::getPlayerByGUID(const uint32_t &guid, bool loadTmp
if (!IOLoginData::loadPlayerById(tmpPlayer, guid)) {
return nullptr;
}
tmpPlayer->setOnline(false);
return tmpPlayer;
}

Expand Down Expand Up @@ -8593,13 +8595,10 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16
return;
}

std::shared_ptr<Player> buyerPlayer = getPlayerByGUID(offer.playerId);
std::shared_ptr<Player> buyerPlayer = getPlayerByGUID(offer.playerId, true);
if (!buyerPlayer) {
buyerPlayer = std::make_shared<Player>(nullptr);
if (!IOLoginData::loadPlayerById(buyerPlayer, offer.playerId)) {
offerStatus << "Failed to load buyer player " << player->getName();
return;
}
offerStatus << "Failed to load buyer player " << player->getName();
return;
}

if (!buyerPlayer->getAccount()) {
Expand Down Expand Up @@ -8697,14 +8696,10 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16
g_saveManager().savePlayer(buyerPlayer);
}
} else if (offer.type == MARKETACTION_SELL) {
std::shared_ptr<Player> sellerPlayer = getPlayerByGUID(offer.playerId);
std::shared_ptr<Player> sellerPlayer = getPlayerByGUID(offer.playerId, true);
if (!sellerPlayer) {
sellerPlayer = std::make_shared<Player>(nullptr);
if (!IOLoginData::loadPlayerById(sellerPlayer, offer.playerId)) {
offerStatus << "Failed to load seller player";

return;
}
offerStatus << "Failed to load seller player";
return;
}

if (player == sellerPlayer || player->getAccount() == sellerPlayer->getAccount()) {
Expand Down
2 changes: 0 additions & 2 deletions src/lua/functions/core/game/game_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,6 @@ int GameFunctions::luaGameGetNormalizedPlayerName(lua_State* L) {
std::shared_ptr<Player> player = g_game().getPlayerByName(name, true);
if (player) {
pushString(L, player->getName());
if (!player->isOnline()) {
}
} else {
lua_pushnil(L);
}
Expand Down

0 comments on commit 77d9c77

Please sign in to comment.