SteamTradeOffersBot icon indicating copy to clipboard operation
SteamTradeOffersBot copied to clipboard

Tradeoffers events get attached multiple times

Open Koenig4443 opened this issue 8 years ago • 2 comments

My bots started behaving odd after running for a while - TradeOfferAccepted , TradeOfferNeedsConfirmation etc was beeing fired multiple times on the same offer. At first i thought it might be related to some threading i have implemented but im pretty sure its not.

One of the major issues with this was that when TradeOfferNeedsConfirmation was beeing called 2nd time it would fail (because it was allready confirmed 1st time this code ran) .. and because of this it would instantly cancel the trade.

i narrowed the problem down to the code in UserWebLogOn() beeing flawed i think:

        TradeOffers = new TradeOffers(SteamUser.SteamID, SteamWeb, ApiKey, TradeOfferRefreshRate);
        TradeOffers.TradeOfferChecked += TradeOffers_TradeOfferChecked;
        TradeOffers.TradeOfferReceived += TradeOffers_TradeOfferReceived;
        TradeOffers.TradeOfferAccepted += TradeOffers_TradeOfferAccepted;
        TradeOffers.TradeOfferDeclined += TradeOffers_TradeOfferDeclined;
        TradeOffers.TradeOfferCanceled += TradeOffers_TradeOfferCanceled;            
        TradeOffers.TradeOfferInvalid += TradeOffers_TradeOfferInvalid;
        TradeOffers.TradeOfferNeedsConfirmation += TradeOffers_TradeOfferNeedsConfirmation;
        TradeOffers.TradeOfferInEscrow += TradeOffers_TradeOfferInEscrow;
        TradeOffers.TradeOfferNoData += TradeOffers_TradeOfferNoData;

here it creates a new tradeoffers handler every time it logs in, and hooks up the functions , but it does not take into account that it might be a re-login. so the old tradeoffers handler (this is running on its own thread) keeps running in the background causing double polling of the offers.

a quick fix is to simply add the following code before hooking up the new tradeOffers object : if (TradeOffers != null) { TradeOffers.StopCheckingPendingTradeOffers(); }

im pretty sure this will cause the background threads to all exit ok, but there might be better cleanup needed.

Koenig4443 avatar Jun 20 '16 19:06 Koenig4443

same here ! my bot check multiple times on the same offer when disconnect and relogin .

quick fix is this ? http://pastebin.com/Nyc9ULKF

voz261 avatar Jan 26 '17 01:01 voz261

Hello ,

Yes confirmed. This will fix the problem.

Koenig4443 avatar Jan 26 '17 17:01 Koenig4443