From c7b3d9e817fbc30e4de191932d428b4dddaedd2d Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Sun, 11 Feb 2024 19:00:39 -0800 Subject: [PATCH] close trade window (#1457) --- dGame/TradingManager.cpp | 12 +++++++----- dGame/TradingManager.h | 4 ++-- dGame/dGameMessages/GameMessages.cpp | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/dGame/TradingManager.cpp b/dGame/TradingManager.cpp index 3d9a209c..c7143354 100644 --- a/dGame/TradingManager.cpp +++ b/dGame/TradingManager.cpp @@ -104,7 +104,7 @@ void Trade::SetAccepted(LWOOBJID participant, bool value) { } Complete(); - TradingManager::Instance()->CancelTrade(m_TradeId); + TradingManager::Instance()->CancelTrade(LWOOBJID_EMPTY, m_TradeId, false); } } @@ -178,14 +178,14 @@ void Trade::Complete() { return; } -void Trade::Cancel() { +void Trade::Cancel(const LWOOBJID canceller) { auto* entityA = GetParticipantAEntity(); auto* entityB = GetParticipantBEntity(); if (entityA == nullptr || entityB == nullptr) return; - GameMessages::SendServerTradeCancel(entityA->GetObjectID(), entityA->GetSystemAddress()); - GameMessages::SendServerTradeCancel(entityB->GetObjectID(), entityB->GetSystemAddress()); + if (entityA->GetObjectID() != canceller || canceller == LWOOBJID_EMPTY) GameMessages::SendServerTradeCancel(entityA->GetObjectID(), entityA->GetSystemAddress()); + if (entityB->GetObjectID() != canceller || canceller == LWOOBJID_EMPTY) GameMessages::SendServerTradeCancel(entityB->GetObjectID(), entityB->GetSystemAddress()); } void Trade::SendUpdateToOther(LWOOBJID participant) { @@ -262,11 +262,13 @@ Trade* TradingManager::GetPlayerTrade(LWOOBJID playerId) const { return nullptr; } -void TradingManager::CancelTrade(LWOOBJID tradeId) { +void TradingManager::CancelTrade(const LWOOBJID canceller, LWOOBJID tradeId, const bool sendCancelMessage) { auto* trade = GetTrade(tradeId); if (trade == nullptr) return; + if (sendCancelMessage) trade->Cancel(canceller); + delete trade; trades.erase(tradeId); diff --git a/dGame/TradingManager.h b/dGame/TradingManager.h index ec0d332f..fa55aa9d 100644 --- a/dGame/TradingManager.h +++ b/dGame/TradingManager.h @@ -30,7 +30,7 @@ class Trade void SetAccepted(LWOOBJID participant, bool value); void Complete(); - void Cancel(); + void Cancel(const LWOOBJID canceller); void SendUpdateToOther(LWOOBJID participant); @@ -66,7 +66,7 @@ class TradingManager Trade* GetTrade(LWOOBJID tradeId) const; Trade* GetPlayerTrade(LWOOBJID playerId) const; - void CancelTrade(LWOOBJID tradeId); + void CancelTrade(const LWOOBJID canceller, LWOOBJID tradeId, const bool sendCancelMessage = true); Trade* NewTrade(LWOOBJID participantA, LWOOBJID participantB); private: diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 8b4d1f05..3c42f4db 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -3270,7 +3270,7 @@ void GameMessages::HandleClientTradeRequest(RakNet::BitStream* inStream, Entity* if (trade != nullptr) { if (!trade->IsParticipant(i64Invitee)) { - TradingManager::Instance()->CancelTrade(trade->GetTradeId()); + TradingManager::Instance()->CancelTrade(entity->GetObjectID(), trade->GetTradeId()); TradingManager::Instance()->NewTrade(entity->GetObjectID(), i64Invitee); } @@ -3295,7 +3295,7 @@ void GameMessages::HandleClientTradeCancel(RakNet::BitStream* inStream, Entity* LOG("Trade canceled from (%llu)", entity->GetObjectID()); - TradingManager::Instance()->CancelTrade(trade->GetTradeId()); + TradingManager::Instance()->CancelTrade(entity->GetObjectID(), trade->GetTradeId()); } void GameMessages::HandleClientTradeAccept(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) {