mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-17 09:15:28 +00:00
fix: a changed trade offer takes both accepts back
A player could change their offer after the other player gave the final accept, and the trade completed with the new offer on their own accept. Both clients drop their accepts when an offer changes, the one that changed it and the one that receives the update, so the trade now does the same and both players have to accept the offers as they are. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "GameDependencies.h"
|
||||
#include "TradingManager.h"
|
||||
|
||||
namespace {
|
||||
@@ -12,6 +13,17 @@ namespace {
|
||||
{ 400, { 1727, 2, false, true } },
|
||||
};
|
||||
|
||||
class TradeAcceptTest : public GameDependenciesTest {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
SetUpDependencies();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
TearDownDependencies();
|
||||
}
|
||||
};
|
||||
|
||||
std::optional<HeldTradeItem> FindHeld(const LWOOBJID itemId) {
|
||||
const auto it = g_Held.find(itemId);
|
||||
if (it == g_Held.end()) return std::nullopt;
|
||||
@@ -80,3 +92,34 @@ TEST(TradeOfferTest, AnOfferFillsTheSlotsOfTheTradeWindowAtMost) {
|
||||
offered.push_back({ Trade::MaxOfferedItems + 1, 1727, 1 });
|
||||
EXPECT_FALSE(Trade::ResolveOffer(offered, findAny).has_value());
|
||||
}
|
||||
|
||||
TEST_F(TradeAcceptTest, OnlyTheFinalAcceptCounts) {
|
||||
Trade trade(1, 10, 20);
|
||||
EXPECT_FALSE(trade.GetAccepted(10));
|
||||
|
||||
trade.SetAccepted(10, true);
|
||||
EXPECT_FALSE(trade.GetAccepted(10));
|
||||
|
||||
trade.SetAccepted(10, false);
|
||||
EXPECT_TRUE(trade.GetAccepted(10));
|
||||
EXPECT_FALSE(trade.GetAccepted(20));
|
||||
// Not a participant
|
||||
EXPECT_FALSE(trade.GetAccepted(30));
|
||||
}
|
||||
|
||||
TEST_F(TradeAcceptTest, AChangedOfferTakesBothAcceptsBack) {
|
||||
Trade trade(1, 10, 20);
|
||||
trade.SetAccepted(10, false);
|
||||
ASSERT_TRUE(trade.GetAccepted(10));
|
||||
|
||||
// What the update handler does once the new offer is stored
|
||||
trade.SetItems(20, { { 100, 1727, 1 } });
|
||||
trade.ResetAccepted();
|
||||
EXPECT_FALSE(trade.GetAccepted(10));
|
||||
EXPECT_FALSE(trade.GetAccepted(20));
|
||||
|
||||
// The other player's accept alone does not complete the trade, both have to accept again
|
||||
trade.SetAccepted(20, false);
|
||||
EXPECT_TRUE(trade.GetAccepted(20));
|
||||
EXPECT_FALSE(trade.GetAccepted(10));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user