mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
fix(trade): tell the requester what became of a trade request
The client puts ServerTradeInitialReply in chat: "Trade invitation sent.", "User not in zone.", "Player out of range." or "Player already trading." (LWOTradeComponent::SendMessage). Live sent INVITESENT, with the invitee's name, to every trade request, also the one that accepts an invitation. The server sent none, so a request to a player not in the world went unanswered. A request to a player who is in a trade with someone else is now refused with ALREADYTRADING. Before, a second trade was made with that player in it, and which of the two their messages went to depended on map order. Out of range is not sent: there is no evidence of the distance. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -402,3 +402,9 @@ void TradingManager::NewTrade(LWOOBJID participantA, LWOOBJID participantB) {
|
||||
|
||||
LOG("Created new trade between (%llu) <-> (%llu)", participantA, participantB);
|
||||
}
|
||||
|
||||
eTradeInviteResult TradingManager::InviteResult(const bool inviteeFound, const Trade* const inviteeTrade, const LWOOBJID requester) {
|
||||
if (!inviteeFound) return eTradeInviteResult::NOT_FOUND;
|
||||
if (inviteeTrade && !inviteeTrade->IsParticipant(requester)) return eTradeInviteResult::ALREADY_TRADING;
|
||||
return eTradeInviteResult::INVITE_SENT;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,17 @@ struct HeldTradeItem {
|
||||
|
||||
struct LwoNameValue;
|
||||
|
||||
// ServerTradeInitialReply's resultType: what became of a trade request, told to the player who sent it. The client
|
||||
// puts it in chat ("Trade invitation sent.", "User not in zone.", "Player out of range.", "Player already trading.";
|
||||
// LWOTradeComponent::SendMessage).
|
||||
enum class eTradeInviteResult : int32_t {
|
||||
NOT_FOUND = 0,
|
||||
INVITE_SENT,
|
||||
OUT_OF_RANGE,
|
||||
ALREADY_TRADING,
|
||||
GENERAL_ERROR
|
||||
};
|
||||
|
||||
class InventoryComponent;
|
||||
|
||||
class Trade {
|
||||
@@ -130,6 +141,10 @@ public:
|
||||
void CancelTrade(const LWOOBJID canceller, LWOOBJID tradeId, const bool sendCancelMessage = true);
|
||||
void NewTrade(LWOOBJID participantA, LWOOBJID participantB);
|
||||
|
||||
// The reply to requester's trade request to an invitee who is (or is not) in this world: an invitee in a trade
|
||||
// with someone else is already trading
|
||||
static eTradeInviteResult InviteResult(bool inviteeFound, const Trade* inviteeTrade, LWOOBJID requester);
|
||||
|
||||
private:
|
||||
static TradingManager* m_Address; //For singleton method
|
||||
|
||||
|
||||
@@ -136,8 +136,22 @@ namespace GameMessages {
|
||||
}
|
||||
|
||||
auto* invitee = Game::entityManager->GetEntity(i64Invitee);
|
||||
const bool inviteeFound = invitee != nullptr && invitee->IsPlayer();
|
||||
|
||||
if (invitee != nullptr && invitee->IsPlayer()) {
|
||||
// Live told the requester what became of the request (ServerTradeInitialReply), also when the request
|
||||
// accepts an invitation
|
||||
const auto result = TradingManager::InviteResult(inviteeFound, inviteeFound ? TradingManager::Instance()->GetPlayerTrade(i64Invitee).get() : nullptr, entity.GetObjectID());
|
||||
const auto sendReply = [&]() {
|
||||
ServerTradeInitialReply reply;
|
||||
reply.target = entity.GetObjectID();
|
||||
reply.i64Invitee = i64Invitee;
|
||||
reply.resultType = static_cast<int32_t>(result);
|
||||
if (inviteeFound && invitee->GetCharacter()) reply.wsName = GeneralUtils::UTF8ToUTF16(invitee->GetCharacter()->GetName());
|
||||
reply.Send(sysAddr);
|
||||
};
|
||||
if (result != eTradeInviteResult::INVITE_SENT) sendReply();
|
||||
|
||||
if (result == eTradeInviteResult::INVITE_SENT) {
|
||||
character = invitee->GetCharacter();
|
||||
if (!character || !character->GetParentUser()) return;
|
||||
|
||||
@@ -165,6 +179,8 @@ namespace GameMessages {
|
||||
TradingManager::Instance()->NewTrade(entity.GetObjectID(), i64Invitee);
|
||||
}
|
||||
|
||||
sendReply();
|
||||
|
||||
ServerTradeInvite invite;
|
||||
invite.target = i64Invitee;
|
||||
invite.bNeedInvitePopUp = bNeedInvitePopUp;
|
||||
|
||||
@@ -162,3 +162,17 @@ TEST_F(TradeAcceptTest, AChangedOfferTakesBothAcceptsBack) {
|
||||
EXPECT_TRUE(trade.GetAccepted(20));
|
||||
EXPECT_FALSE(trade.GetAccepted(10));
|
||||
}
|
||||
|
||||
// The requester hears what became of a trade request (ServerTradeInitialReply)
|
||||
TEST_F(TradeAcceptTest, ATradeRequestIsAnsweredAsLiveAnsweredIt) {
|
||||
EXPECT_EQ(TradingManager::InviteResult(false, nullptr, 10), eTradeInviteResult::NOT_FOUND);
|
||||
EXPECT_EQ(TradingManager::InviteResult(true, nullptr, 10), eTradeInviteResult::INVITE_SENT);
|
||||
|
||||
// Accepting an invitation is a request to the player who sent it, who is in a trade with the requester
|
||||
Trade withRequester(1, 20, 10);
|
||||
EXPECT_EQ(TradingManager::InviteResult(true, &withRequester, 10), eTradeInviteResult::INVITE_SENT);
|
||||
|
||||
// An invitee in a trade with someone else stays in it
|
||||
Trade withSomeoneElse(2, 20, 30);
|
||||
EXPECT_EQ(TradingManager::InviteResult(true, &withSomeoneElse, 10), eTradeInviteResult::ALREADY_TRADING);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user