예제 #1
0
        /// <summary>
        /// If we have to give items and we will be receiving items then check the tradeoffer
        ///
        /// Get more details about the items which will be traded from the offersResponse we got earlier
        ///
        /// bool shouldAcceptTrade will be checked before every tradecheck so if one method says we can accept the trade we do not have to make the other tradechecks (do not waste time)
        ///
        /// Check if the trade is a 1:2 trade
        /// Check if the trade is a 1:1 trade
        ///
        /// At the end check against if the amount of cards we want to accept is equal to the amount of cards which is requested from us
        /// </summary>
        /// <param name="_offersResponse"></param>
        /// <param name="_tradeOffer"></param>
        /// <param name="_partnerID"></param>
        /// <returns></returns>
        private async Task CheckTradeOffer(GetOffersResponse _offersResponse, TradeOffer _tradeOffer, SteamID _partnerID)
        {
            if (_tradeOffer.ItemsToGive != null && _tradeOffer.ItemsToReceive != null)
            {
                bool shouldAcceptTrade = false;

                List <TradeOfferItemDescription> ourItems   = FillItemsList(_tradeOffer.ItemsToGive, _offersResponse, ItemType.TRADING_CARD);
                List <TradeOfferItemDescription> theirItems = FillItemsList(_tradeOffer.ItemsToReceive, _offersResponse, ItemType.TRADING_CARD | ItemType.FOIL_TRADING_CARD);

                if (ourItems == null || theirItems == null)
                {
                    m_logger.Error("Some item returned null, we can't proceed with the trade.");

                    await m_tradeOfferWebAPI.DeclineTradeofferShortMessage(_tradeOffer.TradeOfferID).ConfigureAwait(false);

                    return;
                }

                int ourItemsCount = ourItems.Count;

                // Check 1:2 Trade
                if (m_botInfo.Accept1on2Trades && !shouldAcceptTrade)
                {
                    shouldAcceptTrade = CheckForOneOnTwoCardTrade(ourItems, theirItems);
                }

                // Check 1:1 same Set Trade
                if (m_botInfo.Accept1on1Trades && !shouldAcceptTrade)
                {
                    shouldAcceptTrade = CheckForOneOnOneCardTrade(ourItems, theirItems).Count == ourItemsCount;
                }

                if (_tradeOffer.ItemsToGive.Count > _tradeOffer.ItemsToReceive.Count)
                {
                    await m_tradeOfferWebAPI.DeclineTradeoffer(_tradeOffer.TradeOfferID, _partnerID).ConfigureAwait(false);

                    return;
                }

                if (shouldAcceptTrade)
                {
                    bool accepted = await m_tradeOfferWebAPI.AcceptTradeofferShortMessage(_tradeOffer.TradeOfferID).ConfigureAwait(false);

                    if (accepted)
                    {
                        await m_mobileHelper.ConfirmAllTrades(m_steamWeb.SteamLogin, m_steamWeb.SteamLoginSecure, m_steamWeb.SessionID).ConfigureAwait(false);
                    }
                    else
                    {
                        m_logger.Warning("tradeoffer couldn't be accepted, return true, so we can handle it next time.");
                    }

                    return;
                }
            }

            await m_tradeOfferWebAPI.DeclineTradeofferShortMessage(_tradeOffer.TradeOfferID).ConfigureAwait(false);
        }
예제 #2
0
        /// <summary>
        /// Check every item inside the list we are going to give away or we are going to receive
        /// The description we got earlier got all the items inside the trade, look there which item is ours or theirs so we have more informations about the item
        ///
        /// Enumerate trough all values of the enum ItemType
        /// If we want to allow trading cards and foil trading cards to be added to our itemslist, therefore use the binary OR operator "ItemType.TRADING_CARD | ItemType.FOIL_TRADING_CARD"
        /// If it is set inside our parameter "_items" use it on the switch and add the item to the list
        /// </summary>
        /// <param name="_listToCheck"></param>
        /// <param name="_offersResponse"></param>
        /// <param name="_items"></param>
        private List <TradeOfferItemDescription> FillItemsList(List <TradeOfferItem> _listToCheck, GetOffersResponse _offersResponse, ItemType _items)
        {
            List <TradeOfferItemDescription> itemListToFill = new List <TradeOfferItemDescription>();

            foreach (TradeOfferItem item in _listToCheck)
            {
                if (item.AppID == "753")
                {
                    TradeOfferItemDescription itemWithDescription = _offersResponse.Descriptions.First(_itemDescription => _itemDescription.ClassID == item.ClassID && _itemDescription.InstanceID == item.InstanceID);

                    Array checkTypeValues = Enum.GetValues(typeof(ItemType));

                    foreach (ItemType itemType in checkTypeValues)
                    {
                        if ((_items & itemType) == itemType)
                        {
                            switch (itemType)
                            {
                            case ItemType.BOOSTER_PACK:
                                if (itemWithDescription.Type.ToLower().Contains("booster pack"))
                                {
                                    itemListToFill.Add(itemWithDescription);
                                }
                                break;

                            case ItemType.EMOTICON:
                                if (itemWithDescription.Type.ToLower().Contains("emoticon"))
                                {
                                    itemListToFill.Add(itemWithDescription);
                                }
                                break;

                            case ItemType.PROFILE_BACKGROUND:
                                if (itemWithDescription.Type.ToLower().Contains("profile background"))
                                {
                                    itemListToFill.Add(itemWithDescription);
                                }
                                break;

                            case ItemType.STEAM_GEMS:
                                if (itemWithDescription.Type.Equals("Steam Gems"))
                                {
                                    itemListToFill.Add(itemWithDescription);
                                }
                                break;

                            case ItemType.FOIL_TRADING_CARD:
                                if (itemWithDescription.Type.ToLower().Contains("foil"))
                                {
                                    itemListToFill.Add(itemWithDescription);
                                }
                                break;

                            case ItemType.TRADING_CARD:
                                if (itemWithDescription.Type.ToLower().Contains("trading card") && !itemWithDescription.Type.ToLower().Contains("foil"))
                                {
                                    itemListToFill.Add(itemWithDescription);
                                }
                                break;
                            }
                        }
                    }
                }
            }

            return(itemListToFill);
        }
예제 #3
0
        /// <summary>
        /// First get the summary of our tradeoffers, so we know how much tradeoffers we do have to handle
        /// Initialize a counter, which will be increased after every handled tradeoffer
        /// Receive all active tradeoffers
        ///
        /// Check if the result is not null so we do not run into an error
        /// Go trough every tradeoffer and check if it is active and we did not reach the amount of offers to handle
        /// If it is active get the tradepartners ID so we can print a message with his ID in the accept or decline function
        /// If we have to give Items and do not receive any items decline the trade
        /// Check if the tradeoffer is a donation
        /// If it is not a donation go on and check if the tradeoffer is sent by an admin
        /// If it is sent by an admin accept it and continue with the next trade
        /// If it is not a donation, not sent by an admin and it seems like a fair trade, check for escrow and finally check the tradeitems itself if it is a fair trade
        /// </summary>
        /// <param name="_steamFriendsHelper"></param>
        /// <param name="_steamID"></param>
        public async Task CheckForTradeOffers(SteamFriendsHelper _steamFriendsHelper, SteamID _steamID)
        {
            TradeOffersSummaryResponse tradeOfferCountToHandle = await m_tradeOfferWebAPI.GetTradeOffersSummary().ConfigureAwait(false);

            int tradeOfferHandledCounter = 0;

            GetOffersResponse receivedOffers = await m_tradeOfferWebAPI.GetReceivedActiveTradeOffers(true).ConfigureAwait(false);

            if (receivedOffers.TradeOffersReceived != null)
            {
                foreach (TradeOffer tradeOffer in receivedOffers.TradeOffersReceived)
                {
                    if (tradeOfferHandledCounter >= tradeOfferCountToHandle.PendingReceivedCount)
                    {
                        break;
                    }

                    if (tradeOffer.TradeOfferState != ETradeOfferState.ETradeOfferStateActive)
                    {
                        continue;
                    }

                    if (tradeOffer.ConfirmationMethod == ETradeOfferConfirmationMethod.ETradeOfferConfirmationMethod_Email)
                    {
                        m_logger.Info($"Accept the trade offer {tradeOffer.TradeOfferID} via your email");
                        tradeOfferHandledCounter++;

                        continue;
                    }

                    //  If we were not logged on to the web or the authentication failed, go to the next tradeoffer and check it again
                    if (!await m_steamWeb.RefreshSessionIfNeeded().ConfigureAwait(false))
                    {
                        continue;
                    }

                    if (tradeOffer.ConfirmationMethod == ETradeOfferConfirmationMethod.ETradeOfferConfirmationMethod_MobileApp)
                    {
                        m_mobileHelper.ConfirmAllTrades(m_steamWeb.SteamLogin, m_steamWeb.SteamLoginSecure, m_steamWeb.SessionID);
                        tradeOfferHandledCounter++;

                        continue;
                    }

                    SteamID tradePartnerID = _steamFriendsHelper.GetSteamID(tradeOffer.AccountIDOther);

                    //  Check for a donation
                    if (m_botInfo.AcceptDonations && await TradeOfferIsDonation(tradeOffer, tradePartnerID).ConfigureAwait(false))
                    {
                        tradeOfferHandledCounter++;

                        continue;
                    }

                    //  Check for a tradeoffer from an admin
                    if (await AdminTradeOffer(_steamFriendsHelper, tradeOffer, tradePartnerID).ConfigureAwait(false))
                    {
                        m_mobileHelper.ConfirmAllTrades(m_steamWeb.SteamLogin, m_steamWeb.SteamLoginSecure, m_steamWeb.SessionID);
                        tradeOfferHandledCounter++;

                        continue;
                    }

                    //  Check if we have to give items but do not receive any items
                    if (tradeOffer.ItemsToGive != null && tradeOffer.ItemsToReceive == null)
                    {
                        await m_tradeOfferWebAPI.DeclineTradeofferShortMessage(tradeOffer.TradeOfferID).ConfigureAwait(false);

                        tradeOfferHandledCounter++;

                        continue;
                    }

                    //  If we do not want to accept escrow tradeoffers, check them here before going on
                    if (!m_botInfo.AcceptEscrow)
                    {
                        if (await CheckTradeOfferForEscrow(tradeOffer, tradePartnerID).ConfigureAwait(false))
                        {
                            tradeOfferHandledCounter++;

                            continue;
                        }
                    }

                    await CheckTradeOffer(receivedOffers, tradeOffer, tradePartnerID).ConfigureAwait(false);

                    tradeOfferHandledCounter++;
                }
            }
        }