/// <summary> /// Get the amount of cards we can farm /// We need to clear one discoveryqueue for one card, which contains 12 AppID's /// /// For every card generate a new discoveryqueue and clear every appid in this queue /// </summary> public async Task <string> ExploreDiscoveryQueues() { int cardsToEarn = 0; string responseToAdmin = ""; if (!await m_steamWeb.RefreshSessionIfNeeded().ConfigureAwait(false)) { responseToAdmin = "Could not reauthenticate."; } cardsToEarn = await GetCardsToEarnFromDiscoveryQueue().ConfigureAwait(false); if (cardsToEarn != 0) { for (int i = 0; i < cardsToEarn; i++) { RequestNewDiscoveryQueueResponse discoveryQueue = await GenerateNewDiscoveryQueue().ConfigureAwait(false); foreach (uint appID in discoveryQueue.Queue) { string urlToApp = $"http://{m_steamWeb.m_SteamStoreHost}/app/{appID}"; NameValueCollection data = new NameValueCollection() { { "sessionid", m_steamWeb.SessionID }, { "appid_to_clear_from_queue", appID.ToString() } }; string response = await m_steamWeb.m_WebHelper.GetStringFromRequest(urlToApp, data, false).ConfigureAwait(false); } } } if (string.IsNullOrEmpty(responseToAdmin)) { responseToAdmin = cardsToEarn == 0 ? "There were no cards to earn from discoveryqueues" : $"Successfully explored {cardsToEarn} discoveryqueues"; } return(responseToAdmin); }
/// <summary> /// Initialize the cancellationtoken so we can interrupt the method on lost connection /// Create a new task with the cancellationtoken /// While the task is not cancelled get all badges to farm /// If we do not have any badge to farm, remove the playing status so we are shown as online /// /// If we have some badges to farm start a new while loop and start to farm this badge /// Check every 5 minutes if we have still some cards left to farm for this badge /// If we do not have any left, leave the while loop /// /// If we are not comming out from the while loop check every 5 minutes for new badges to farm /// If we are comming out fron the while loop we want to check for the next badge to farm, therefore we do not wait 5 minuts /// </summary> /// <param name="_steamClient"></param> public void StartFarmCards(SteamClient _steamClient) { m_cardFarmCancellationTokenSource = new CancellationTokenSource(); bool checkForNewGame = false; Task.Run(async() => { while (!m_cardFarmCancellationTokenSource.Token.IsCancellationRequested) { if (!await m_steamWeb.RefreshSessionIfNeeded().ConfigureAwait(false)) { continue; } List <GameToFarm> gamesToFarm = await m_steamUserWebAPI.GetBadgesToFarm().ConfigureAwait(false); bool isRunning = (gamesToFarm.Count > 0); if (!isRunning) { m_gamesLibraryHelper.SetGamePlaying(0); } while (isRunning && !m_cardFarmCancellationTokenSource.Token.IsCancellationRequested) { m_gamesLibraryHelper.SetGamePlaying(Convert.ToInt32(gamesToFarm.First().AppID)); try { await Task.Delay(TimeSpan.FromMinutes(5), m_cardFarmCancellationTokenSource.Token).ConfigureAwait(false); } catch (Exception) { break; } if (!await m_steamWeb.RefreshSessionIfNeeded().ConfigureAwait(false)) { continue; } isRunning = await m_steamUserWebAPI.GetGameCardsRemainingForGame(Convert.ToUInt32(gamesToFarm.First().AppID)).ConfigureAwait(false) > 0; if (!isRunning) { checkForNewGame = true; } } if (!checkForNewGame) { try { await Task.Delay(TimeSpan.FromMinutes(5), m_cardFarmCancellationTokenSource.Token).ConfigureAwait(false); } catch (Exception) { break; } } checkForNewGame = false; } m_logger.Warning("Cancelled the CardFarmTask."); m_cardFarmCancellationTokenSource.Dispose(); }, m_cardFarmCancellationTokenSource.Token); }
/// <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++; } } }