Permalink
Browse files

[10048] Move trade data to dynamic created structure.

Also possible fix old bug with spam trade cancel after logout.
  • Loading branch information...
1 parent 11961b9 commit d40b74a815a4229c4538a9eaa6d79b7d0c32294d VladimirMangos committed Jun 8, 2010
Showing with 152 additions and 123 deletions.
  1. +11 −22 src/game/Player.cpp
  2. +23 −7 src/game/Player.h
  3. +117 −93 src/game/TradeHandler.cpp
  4. +1 −1 src/shared/revision_nr.h
View
@@ -381,8 +381,7 @@ Player::Player (WorldSession *session): Unit(), m_achievementMgr(this), m_reputa
m_bHasDelayedTeleport = false;
m_teleport_options = 0;
- pTrader = 0;
- ClearTrade();
+ m_trade = NULL;
m_cinematic = 0;
@@ -11989,33 +11988,23 @@ void Player::SendSellError( uint8 msg, Creature* pCreature, uint64 guid, uint32
GetSession()->SendPacket(&data);
}
-void Player::ClearTrade()
-{
- tradeGold = 0;
- acceptTrade = false;
- for(int i = 0; i < TRADE_SLOT_COUNT; ++i)
- m_tradeItems[i].Clear();
-}
-
void Player::TradeCancel(bool sendback)
{
- if (pTrader)
+ if (m_trade)
{
+ Player* trader = m_trade->m_tradeWith;
+
// send yellow "Trade canceled" message to both traders
- WorldSession* ws;
- ws = GetSession();
if (sendback)
- ws->SendCancelTrade();
- ws = pTrader->GetSession();
- if (!ws->PlayerLogout())
- ws->SendCancelTrade();
+ GetSession()->SendCancelTrade();
+
+ trader->GetSession()->SendCancelTrade();
// cleanup
- ClearTrade();
- pTrader->ClearTrade();
- // prevent loss of reference
- pTrader->pTrader = NULL;
- pTrader = NULL;
+ delete m_trade;
+ m_trade = NULL;
+ delete trader->m_trade;
+ trader->m_trade = NULL;
}
}
View
@@ -1019,6 +1019,26 @@ struct BGData
bool HasTaxiPath() const { return taxiPath[0] && taxiPath[1]; }
};
+struct TradeData
+{
+ explicit TradeData(Player* tradeWith)
+ : m_tradeWith(tradeWith), m_acceptedTrade(false), m_tradeGold(0), m_tradeSpell(0) {}
+
+ Player* m_tradeWith;
+ bool m_acceptedTrade;
+ uint32 m_tradeGold;
+ uint32 m_tradeSpell;
+ ObjectGuid m_tradeItems[TRADE_SLOT_COUNT];
+
+ bool HasItem(ObjectGuid item_guid) const
+ {
+ for(int i = 0; i < TRADE_SLOT_COUNT; ++i)
+ if (m_tradeItems[i] == item_guid)
+ return true;
+ return false;
+ }
+};
+
class MANGOS_DLL_SPEC Player : public Unit
{
friend class WorldSession;
@@ -1280,10 +1300,9 @@ class MANGOS_DLL_SPEC Player : public Unit
bool BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32 item, uint8 count, uint8 bag, uint8 slot);
float GetReputationPriceDiscount( Creature const* pCreature ) const;
- Player* GetTrader() const { return pTrader; }
- void ClearTrade();
+ Player* GetTrader() const { return m_trade ? m_trade->m_tradeWith : NULL; }
void TradeCancel(bool sendback);
- Item* GetItemByTradeSlot(uint32 slot) const { return !m_tradeItems[slot].IsEmpty() ? GetItemByGuid(m_tradeItems[slot]) : NULL; }
+ Item* GetItemByTradeSlot(uint32 slot) const { return m_trade && !m_trade->m_tradeItems[slot].IsEmpty() ? GetItemByGuid(m_trade->m_tradeItems[slot]) : NULL; }
void UpdateEnchantTime(uint32 time);
void UpdateItemDuration(uint32 time, bool realtimeonly=false);
@@ -2463,10 +2482,7 @@ class MANGOS_DLL_SPEC Player : public Unit
int m_cinematic;
- Player *pTrader;
- bool acceptTrade;
- ObjectGuid m_tradeItems[TRADE_SLOT_COUNT];
- uint32 tradeGold;
+ TradeData* m_trade;
bool m_DailyQuestChanged;
bool m_WeeklyQuestChanged;
Oops, something went wrong.

0 comments on commit d40b74a

Please sign in to comment.