From 77d9c775c17b55613abaf22204fd0a8ac8a5cc9f Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Wed, 1 Nov 2023 06:01:47 -0700 Subject: [PATCH] fix: save offline counterparty on market offer acceptance (#1764) 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. --- src/game/game.cpp | 21 +++++++------------ .../functions/core/game/game_functions.cpp | 2 -- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/game/game.cpp b/src/game/game.cpp index b3706b7bf38..76c83737f60 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -704,6 +704,7 @@ std::shared_ptr Game::getPlayerByID(uint32_t id, bool loadTmp /* = false if (!IOLoginData::loadPlayerById(tmpPlayer, id)) { return nullptr; } + tmpPlayer->setOnline(false); return tmpPlayer; } @@ -784,6 +785,7 @@ std::shared_ptr Game::getPlayerByGUID(const uint32_t &guid, bool loadTmp if (!IOLoginData::loadPlayerById(tmpPlayer, guid)) { return nullptr; } + tmpPlayer->setOnline(false); return tmpPlayer; } @@ -8593,13 +8595,10 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 return; } - std::shared_ptr buyerPlayer = getPlayerByGUID(offer.playerId); + std::shared_ptr buyerPlayer = getPlayerByGUID(offer.playerId, true); if (!buyerPlayer) { - buyerPlayer = std::make_shared(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()) { @@ -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 sellerPlayer = getPlayerByGUID(offer.playerId); + std::shared_ptr sellerPlayer = getPlayerByGUID(offer.playerId, true); if (!sellerPlayer) { - sellerPlayer = std::make_shared(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()) { diff --git a/src/lua/functions/core/game/game_functions.cpp b/src/lua/functions/core/game/game_functions.cpp index 99a277490ab..cab8c599a21 100644 --- a/src/lua/functions/core/game/game_functions.cpp +++ b/src/lua/functions/core/game/game_functions.cpp @@ -630,8 +630,6 @@ int GameFunctions::luaGameGetNormalizedPlayerName(lua_State* L) { std::shared_ptr player = g_game().getPlayerByName(name, true); if (player) { pushString(L, player->getName()); - if (!player->isOnline()) { - } } else { lua_pushnil(L); }