Skip to content

Commit

Permalink
Core/PacketIO: Implemented CMSG_BUSY_TRADE and CMSG_IGNORE_TRADE
Browse files Browse the repository at this point in the history
Co-Authored-By: Mykhailo Redko <[email protected]>
  • Loading branch information
killerwife and r4d1sh committed Jan 8, 2024
1 parent b376033 commit 5b7cb1a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/game/Entities/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6259,7 +6259,7 @@ bool Player::SetPosition(float x, float y, float z, float orientation, bool tele
SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POSITION);

if (GetTrader() && !IsWithinDistInMap(GetTrader(), INTERACTION_DISTANCE))
GetSession()->SendCancelTrade(); // will close both side trade windows
TradeCancel(true, TRADE_STATUS_TARGET_TO_FAR);

if (m_needsZoneUpdate)
{
Expand Down Expand Up @@ -11602,17 +11602,17 @@ void Player::SendSellError(SellResult msg, Creature* pCreature, ObjectGuid itemG
GetSession()->SendPacket(data);
}

void Player::TradeCancel(bool sendback)
void Player::TradeCancel(bool sendback, TradeStatus status /*= TRADE_STATUS_TRADE_CANCELED*/)
{
if (m_trade)
{
Player* trader = m_trade->GetTrader();

// send yellow "Trade canceled" message to both traders
if (sendback)
GetSession()->SendCancelTrade();
GetSession()->SendCancelTrade(status);

trader->GetSession()->SendCancelTrade();
trader->GetSession()->SendCancelTrade(status);

// cleanup
delete m_trade;
Expand Down
2 changes: 1 addition & 1 deletion src/game/Entities/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ class Player : public Unit

Player* GetTrader() const { return m_trade ? m_trade->GetTrader() : nullptr; }
TradeData* GetTradeData() const { return m_trade; }
void TradeCancel(bool sendback);
void TradeCancel(bool sendback, TradeStatus status = TRADE_STATUS_TRADE_CANCELED);

void UpdateEnchantTime(uint32 time);
void UpdateItemDuration(uint32 time, bool realtimeonly = false);
Expand Down
2 changes: 1 addition & 1 deletion src/game/Server/WorldSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ class WorldSession

void SendTradeStatus(const TradeStatusInfo& status) const;
void SendUpdateTrade(bool trader_state = true) const;
void SendCancelTrade();
void SendCancelTrade(TradeStatus status);

void SendPetitionQueryOpcode(ObjectGuid petitionguid) const;

Expand Down
15 changes: 4 additions & 11 deletions src/game/Trade/TradeHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ void WorldSession::SendTradeStatus(TradeStatusInfo const& info) const
void WorldSession::HandleIgnoreTradeOpcode(WorldPacket& /*recvPacket*/)
{
DEBUG_LOG("WORLD: Ignore Trade %u", _player->GetGUIDLow());
// recvPacket.print_storage();
_player->TradeCancel(true, TRADE_STATUS_IGNORE_YOU);
}

void WorldSession::HandleBusyTradeOpcode(WorldPacket& /*recvPacket*/)
{
DEBUG_LOG("WORLD: Busy Trade %u", _player->GetGUIDLow());
// recvPacket.print_storage();
_player->TradeCancel(true, TRADE_STATUS_BUSY);
}

void WorldSession::SendUpdateTrade(bool trader_state /*= true*/) const
Expand Down Expand Up @@ -528,13 +528,13 @@ void WorldSession::HandleBeginTradeOpcode(WorldPacket& /*recvPacket*/)
SendTradeStatus(info);
}

void WorldSession::SendCancelTrade()
void WorldSession::SendCancelTrade(TradeStatus status)
{
if (m_playerRecentlyLogout)
return;

TradeStatusInfo info;
info.Status = TRADE_STATUS_TRADE_CANCELED;
info.Status = status;
SendTradeStatus(info);
}

Expand Down Expand Up @@ -626,13 +626,6 @@ void WorldSession::HandleInitiateTradeOpcode(WorldPacket& recvPacket)
return;
}

if (pOther->GetSocial()->HasIgnore(GetPlayer()->GetObjectGuid()))
{
info.Status = TRADE_STATUS_IGNORE_YOU;
SendTradeStatus(info);
return;
}

// [XFACTION]: Reserve possibility to trade with each other for crossfaction group members (when no charms involved)
if (!_player->CanCooperate(pOther) && (pOther->HasCharmer() || _player->HasCharmer() || !pOther->IsInGroup(_player)))
{
Expand Down

0 comments on commit 5b7cb1a

Please sign in to comment.