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: save offline counterparty on market offer acceptance #1764

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
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
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