コード例 #1
0
        internal async Task StartFarming()
        {
            if (NowFarming || ManualMode || Bot.PlayingBlocked)
            {
                return;
            }

            await FarmingSemaphore.WaitAsync().ConfigureAwait(false);

            if (NowFarming || ManualMode || Bot.PlayingBlocked)
            {
                FarmingSemaphore.Release();                 // We have nothing to do, don't forget to release semaphore
                return;
            }

            if (!await IsAnythingToFarm().ConfigureAwait(false))
            {
                FarmingSemaphore.Release();                 // We have nothing to do, don't forget to release semaphore
                Logging.LogGenericInfo("We don't have anything to farm on this account!", Bot.BotName);
                await Bot.OnFarmingFinished(false).ConfigureAwait(false);

                return;
            }

            Logging.LogGenericInfo("We have a total of " + GamesToFarm.Count + " games to farm on this account...", Bot.BotName);

            // This is the last moment for final check if we can farm
            if (Bot.PlayingBlocked)
            {
                Logging.LogGenericInfo("But account is currently occupied, so farming is stopped!");
                FarmingSemaphore.Release();                 // We have nothing to do, don't forget to release semaphore
                return;
            }

            KeepFarming = NowFarming = true;
            FarmingSemaphore.Release();             // From this point we allow other calls to shut us down

            do
            {
                // Now the algorithm used for farming depends on whether account is restricted or not
                if (Bot.BotConfig.CardDropsRestricted)                   // If we have restricted card drops, we use complex algorithm
                {
                    Logging.LogGenericInfo("Chosen farming algorithm: Complex", Bot.BotName);
                    while (GamesToFarm.Count > 0)
                    {
                        HashSet <uint> gamesToFarmSolo = GetGamesToFarmSolo(GamesToFarm);
                        if (gamesToFarmSolo.Count > 0)
                        {
                            while (gamesToFarmSolo.Count > 0)
                            {
                                uint appID = gamesToFarmSolo.First();
                                if (await FarmSolo(appID).ConfigureAwait(false))
                                {
                                    gamesToFarmSolo.Remove(appID);
                                    gamesToFarmSolo.TrimExcess();
                                }
                                else
                                {
                                    NowFarming = false;
                                    return;
                                }
                            }
                        }
                        else
                        {
                            if (FarmMultiple())
                            {
                                Logging.LogGenericInfo("Done farming: " + string.Join(", ", GamesToFarm.Keys), Bot.BotName);
                            }
                            else
                            {
                                NowFarming = false;
                                return;
                            }
                        }
                    }
                }
                else                     // If we have unrestricted card drops, we use simple algorithm
                {
                    Logging.LogGenericInfo("Chosen farming algorithm: Simple", Bot.BotName);
                    while (GamesToFarm.Count > 0)
                    {
                        uint appID = GamesToFarm.Keys.FirstOrDefault();
                        if (await FarmSolo(appID).ConfigureAwait(false))
                        {
                            continue;
                        }

                        NowFarming = false;
                        return;
                    }
                }
            } while (await IsAnythingToFarm().ConfigureAwait(false));

            CurrentGamesFarming.ClearAndTrim();
            NowFarming = false;

            Logging.LogGenericInfo("Farming finished!", Bot.BotName);
            await Bot.OnFarmingFinished(true).ConfigureAwait(false);
        }
コード例 #2
0
        internal async Task StartFarming()
        {
            if (NowFarming || Paused || !Bot.IsPlayingPossible)
            {
                return;
            }

            if (!Bot.CanReceiveSteamCards)
            {
                await Bot.OnFarmingFinished(false).ConfigureAwait(false);

                return;
            }

            await FarmingInitializationSemaphore.WaitAsync().ConfigureAwait(false);

            try {
                if (NowFarming || Paused || !Bot.IsPlayingPossible)
                {
                    return;
                }

                bool?isAnythingToFarm = await IsAnythingToFarm().ConfigureAwait(false);

                if (isAnythingToFarm == null)
                {
                    return;
                }

                if (!isAnythingToFarm.Value)
                {
                    Bot.ArchiLogger.LogGenericInfo(Strings.NothingToIdle);
                    await Bot.OnFarmingFinished(false).ConfigureAwait(false);

                    return;
                }

                if (GamesToFarm.Count == 0)
                {
                    Bot.ArchiLogger.LogNullError(nameof(GamesToFarm));
                    return;
                }

                Bot.ArchiLogger.LogGenericInfo(string.Format(Strings.GamesToIdle, GamesToFarm.Count, GamesToFarm.Sum(game => game.CardsRemaining), TimeRemaining.ToHumanReadable()));

                // This is the last moment for final check if we can farm
                if (!Bot.IsPlayingPossible)
                {
                    Bot.ArchiLogger.LogGenericInfo(Strings.PlayingNotAvailable);
                    return;
                }

                if (Bot.PlayingWasBlocked)
                {
                    for (byte i = 0; (i < Bot.MinPlayingBlockedTTL) && Bot.IsPlayingPossible; i++)
                    {
                        await Task.Delay(1000).ConfigureAwait(false);
                    }

                    if (!Bot.IsPlayingPossible)
                    {
                        Bot.ArchiLogger.LogGenericInfo(Strings.PlayingNotAvailable);
                        return;
                    }
                }

                KeepFarming = NowFarming = true;
                Utilities.InBackground(Farm, true);
            } finally {
                FarmingInitializationSemaphore.Release();
            }
        }
コード例 #3
0
ファイル: CardsFarmer.cs プロジェクト: xmdszzz/ArchiSteamFarm
        internal async Task StartFarming()
        {
            if (NowFarming || Paused || !Bot.IsPlayingPossible)
            {
                return;
            }

            if (!Bot.CanReceiveSteamCards || (Bot.BotConfig.IdlePriorityQueueOnly && !Bot.BotDatabase.HasIdlingPriorityAppIDs))
            {
                Bot.ArchiLogger.LogGenericInfo(Strings.NothingToIdle);
                await Bot.OnFarmingFinished(false).ConfigureAwait(false);

                return;
            }

            await FarmingInitializationSemaphore.WaitAsync().ConfigureAwait(false);

            try {
                if (NowFarming || Paused || !Bot.IsPlayingPossible)
                {
                    return;
                }

                bool?isAnythingToFarm = await IsAnythingToFarm().ConfigureAwait(false);

                if (!isAnythingToFarm.HasValue)
                {
                    return;
                }

                if (!isAnythingToFarm.Value)
                {
                    Bot.ArchiLogger.LogGenericInfo(Strings.NothingToIdle);
                    await Bot.OnFarmingFinished(false).ConfigureAwait(false);

                    return;
                }

                if (GamesToFarm.Count == 0)
                {
                    Bot.ArchiLogger.LogNullError(nameof(GamesToFarm));

                    return;
                }

                // This is the last moment for final check if we can farm
                if (!Bot.IsPlayingPossible)
                {
                    Bot.ArchiLogger.LogGenericInfo(Strings.PlayingNotAvailable);

                    return;
                }

                if (Bot.PlayingWasBlocked)
                {
                    Bot.ArchiLogger.LogGenericInfo(string.Format(Strings.BotExtraIdlingCooldown, TimeSpan.FromSeconds(Bot.MinPlayingBlockedTTL).ToHumanReadable()));

                    for (byte i = 0; (i < Bot.MinPlayingBlockedTTL) && Bot.IsPlayingPossible && Bot.PlayingWasBlocked; i++)
                    {
                        await Task.Delay(1000).ConfigureAwait(false);
                    }

                    if (!Bot.IsPlayingPossible)
                    {
                        Bot.ArchiLogger.LogGenericInfo(Strings.PlayingNotAvailable);

                        return;
                    }
                }

                KeepFarming = NowFarming = true;
                Utilities.InBackground(Farm, true);
            } finally {
                FarmingInitializationSemaphore.Release();
            }
        }
コード例 #4
0
        internal async Task StartFarming()
        {
            await Semaphore.WaitAsync().ConfigureAwait(false);

            if (ManualMode)
            {
                Semaphore.Release();                 // We have nothing to do, don't forget to release semaphore
                return;
            }

            if (!await IsAnythingToFarm().ConfigureAwait(false))
            {
                Semaphore.Release();                 // We have nothing to do, don't forget to release semaphore
                return;
            }

            Logging.LogGenericInfo("We have a total of " + GamesToFarm.Count + " games to farm on this account...", Bot.BotName);
            NowFarming = true;
            Semaphore.Release();             // From this point we allow other calls to shut us down

            bool farmedSomething = false;

            // Now the algorithm used for farming depends on whether account is restricted or not
            if (Bot.CardDropsRestricted)               // If we have restricted card drops, we use complex algorithm
            {
                Logging.LogGenericInfo("Chosen farming algorithm: Complex", Bot.BotName);
                while (GamesToFarm.Count > 0)
                {
                    List <uint> gamesToFarmSolo = GetGamesToFarmSolo(GamesToFarm);
                    if (gamesToFarmSolo.Count > 0)
                    {
                        while (gamesToFarmSolo.Count > 0)
                        {
                            uint appID = gamesToFarmSolo[0];
                            if (await FarmSolo(appID).ConfigureAwait(false))
                            {
                                farmedSomething = true;
                                Logging.LogGenericInfo("Done farming: " + appID, Bot.BotName);
                                gamesToFarmSolo.Remove(appID);
                                gamesToFarmSolo.TrimExcess();
                            }
                            else
                            {
                                NowFarming = false;
                                return;
                            }
                        }
                    }
                    else
                    {
                        if (FarmMultiple(GamesToFarm))
                        {
                            farmedSomething = true;
                            Logging.LogGenericInfo("Done farming: " + string.Join(", ", GamesToFarm.Keys), Bot.BotName);
                        }
                        else
                        {
                            NowFarming = false;
                            return;
                        }
                    }
                }
            }
            else                 // If we have unrestricted card drops, we use simple algorithm
            {
                Logging.LogGenericInfo("Chosen farming algorithm: Simple", Bot.BotName);
                while (GamesToFarm.Count > 0)
                {
                    uint appID = GetAnyGameToFarm(GamesToFarm);
                    if (await FarmSolo(appID).ConfigureAwait(false))
                    {
                        farmedSomething = true;
                        Logging.LogGenericInfo("Done farming: " + appID, Bot.BotName);
                    }
                    else
                    {
                        NowFarming = false;
                        return;
                    }
                }
            }

            CurrentGamesFarming.Clear();
            CurrentGamesFarming.TrimExcess();
            NowFarming = false;
            Logging.LogGenericInfo("Farming finished!", Bot.BotName);
            await Bot.OnFarmingFinished(farmedSomething).ConfigureAwait(false);
        }
コード例 #5
0
        internal async Task StartFarming()
        {
            if (NowFarming || Paused || !Bot.IsFarmingPossible)
            {
                return;
            }

            await FarmingSemaphore.WaitAsync().ConfigureAwait(false);

            try {
                if (NowFarming || Paused || !Bot.IsFarmingPossible)
                {
                    return;
                }

                if (!await IsAnythingToFarm().ConfigureAwait(false))
                {
                    Bot.ArchiLogger.LogGenericInfo("We don't have anything to farm on this account!");
                    await Bot.OnFarmingFinished(false).ConfigureAwait(false);

                    return;
                }

                Bot.ArchiLogger.LogGenericInfo("We have a total of " + GamesToFarm.Count + " games (" + GamesToFarm.Sum(game => game.CardsRemaining) + " cards) to farm on this account...");

                // This is the last moment for final check if we can farm
                if (!Bot.IsFarmingPossible)
                {
                    Bot.ArchiLogger.LogGenericInfo("But account is currently occupied, so farming is stopped!");
                    return;
                }

                KeepFarming = NowFarming = true;
            } finally {
                FarmingSemaphore.Release();
            }

            do
            {
                // Now the algorithm used for farming depends on whether account is restricted or not
                if (Bot.BotConfig.CardDropsRestricted)                   // If we have restricted card drops, we use complex algorithm
                {
                    Bot.ArchiLogger.LogGenericInfo("Chosen farming algorithm: Complex");
                    while (GamesToFarm.Count > 0)
                    {
                        HashSet <Game> gamesToFarmSolo = GamesToFarm.Count > 1 ? new HashSet <Game>(GamesToFarm.Where(game => game.HoursPlayed >= 2)) : new HashSet <Game>(GamesToFarm);
                        if (gamesToFarmSolo.Count > 0)
                        {
                            while (gamesToFarmSolo.Count > 0)
                            {
                                Game game = gamesToFarmSolo.First();
                                if (await FarmSolo(game).ConfigureAwait(false))
                                {
                                    gamesToFarmSolo.Remove(game);
                                }
                                else
                                {
                                    NowFarming = false;
                                    return;
                                }
                            }
                        }
                        else
                        {
                            if (FarmMultiple(GamesToFarm.OrderByDescending(game => game.HoursPlayed).Take(MaxGamesPlayedConcurrently)))
                            {
                                Bot.ArchiLogger.LogGenericInfo("Done farming: " + string.Join(", ", GamesToFarm.Select(game => game.AppID)));
                            }
                            else
                            {
                                NowFarming = false;
                                return;
                            }
                        }
                    }
                }
                else                     // If we have unrestricted card drops, we use simple algorithm
                {
                    Bot.ArchiLogger.LogGenericInfo("Chosen farming algorithm: Simple");
                    while (GamesToFarm.Count > 0)
                    {
                        Game game = GamesToFarm.First();
                        if (await FarmSolo(game).ConfigureAwait(false))
                        {
                            continue;
                        }

                        NowFarming = false;
                        return;
                    }
                }
            } while (await IsAnythingToFarm().ConfigureAwait(false));

            CurrentGamesFarming.ClearAndTrim();
            NowFarming = false;

            Bot.ArchiLogger.LogGenericInfo("Farming finished!");
            await Bot.OnFarmingFinished(true).ConfigureAwait(false);
        }
コード例 #6
0
        internal async Task StartFarming()
        {
            if (NowFarming || ManualMode)
            {
                return;
            }

            await Semaphore.WaitAsync().ConfigureAwait(false);

            if (NowFarming || ManualMode)
            {
                Semaphore.Release();                 // We have nothing to do, don't forget to release semaphore
                return;
            }

            if (!await IsAnythingToFarm().ConfigureAwait(false))
            {
                Semaphore.Release();                 // We have nothing to do, don't forget to release semaphore
                Logging.LogGenericInfo("We don't have anything to farm on this account!", Bot.BotName);
                return;
            }

            Logging.LogGenericInfo("We have a total of " + GamesToFarm.Count + " games to farm on this account...", Bot.BotName);
            NowFarming = true;
            Semaphore.Release();             // From this point we allow other calls to shut us down

            bool farmedSomething = false;

            // Now the algorithm used for farming depends on whether account is restricted or not
            if (Bot.BotConfig.CardDropsRestricted)               // If we have restricted card drops, we use complex algorithm
            {
                Logging.LogGenericInfo("Chosen farming algorithm: Complex", Bot.BotName);
                while (GamesToFarm.Count > 0)
                {
                    HashSet <uint> gamesToFarmSolo = GetGamesToFarmSolo(GamesToFarm);
                    if (gamesToFarmSolo.Count > 0)
                    {
                        while (gamesToFarmSolo.Count > 0)
                        {
                            uint appID = gamesToFarmSolo.First();
                            if (await FarmSolo(appID).ConfigureAwait(false))
                            {
                                farmedSomething = true;
                                gamesToFarmSolo.Remove(appID);
                                gamesToFarmSolo.TrimExcess();
                            }
                            else
                            {
                                NowFarming = false;
                                return;
                            }
                        }
                    }
                    else
                    {
                        if (FarmMultiple())
                        {
                            Logging.LogGenericInfo("Done farming: " + string.Join(", ", GamesToFarm.Keys), Bot.BotName);
                        }
                        else
                        {
                            NowFarming = false;
                            return;
                        }
                    }
                }
            }
            else                 // If we have unrestricted card drops, we use simple algorithm
            {
                Logging.LogGenericInfo("Chosen farming algorithm: Simple", Bot.BotName);
                while (GamesToFarm.Count > 0)
                {
                    uint appID = GamesToFarm.Keys.FirstOrDefault();
                    if (await FarmSolo(appID).ConfigureAwait(false))
                    {
                        farmedSomething = true;
                    }
                    else
                    {
                        NowFarming = false;
                        return;
                    }
                }
            }

            CurrentGamesFarming.Clear();
            CurrentGamesFarming.TrimExcess();
            NowFarming = false;

            // We finished our queue for now, make sure that everything is indeed farmed before proceeding further
            // Some games could be added in the meantime
            if (await IsAnythingToFarm().ConfigureAwait(false))
            {
                StartFarming().Forget();
                return;
            }

            Logging.LogGenericInfo("Farming finished!", Bot.BotName);
            await Bot.OnFarmingFinished(farmedSomething).ConfigureAwait(false);
        }
コード例 #7
0
        internal async Task StartFarming()
        {
            await StopFarming().ConfigureAwait(false);

            await Semaphore.WaitAsync().ConfigureAwait(false);

            if (NowFarming)
            {
                Semaphore.Release();
                return;
            }

            Logging.LogGenericInfo(Bot.BotName, "Checking badges...");

            // Find the number of badge pages
            HtmlDocument badgesDocument = await Bot.ArchiWebHandler.GetBadgePage(1).ConfigureAwait(false);

            if (badgesDocument == null)
            {
                Logging.LogGenericWarning(Bot.BotName, "Could not get badges information, farming is stopped!");
                Semaphore.Release();
                return;
            }

            var maxPages = 1;
            HtmlNodeCollection badgesPagesNodeCollection = badgesDocument.DocumentNode.SelectNodes("//a[@class='pagelink']");

            if (badgesPagesNodeCollection != null)
            {
                maxPages = (badgesPagesNodeCollection.Count / 2) + 1;                 // Don't do this at home
            }

            // Find APPIDs we need to farm
            List <uint> appIDs = new List <uint>();

            for (var page = 1; page <= maxPages; page++)
            {
                Logging.LogGenericInfo(Bot.BotName, "Checking page: " + page + "/" + maxPages);

                if (page > 1)                   // Because we fetched page number 1 already
                {
                    badgesDocument = await Bot.ArchiWebHandler.GetBadgePage(page).ConfigureAwait(false);

                    if (badgesDocument == null)
                    {
                        break;
                    }
                }

                HtmlNodeCollection badgesPageNodes = badgesDocument.DocumentNode.SelectNodes("//a[@class='btn_green_white_innerfade btn_small_thin']");
                if (badgesPageNodes == null)
                {
                    continue;
                }

                foreach (HtmlNode badgesPageNode in badgesPageNodes)
                {
                    string steamLink = badgesPageNode.GetAttributeValue("href", null);
                    if (steamLink == null)
                    {
                        Logging.LogGenericError(Bot.BotName, "Couldn't get steamLink for one of the games: " + badgesPageNode.OuterHtml);
                        continue;
                    }

                    uint appID = (uint)Utilities.OnlyNumbers(steamLink);
                    if (appID == 0)
                    {
                        Logging.LogGenericError(Bot.BotName, "Couldn't get appID for one of the games: " + badgesPageNode.OuterHtml);
                        continue;
                    }

                    if (Bot.Blacklist.Contains(appID))
                    {
                        continue;
                    }

                    appIDs.Add(appID);
                }
            }

            // Start farming
            while (appIDs.Count > 0)
            {
                Logging.LogGenericInfo(Bot.BotName, "Farming in progress...");
                uint appID = appIDs[0];
                if (await Farm(appID).ConfigureAwait(false))
                {
                    appIDs.Remove(appID);
                }
                else
                {
                    return;
                }
            }

            Logging.LogGenericInfo(Bot.BotName, "Farming finished!");
            await Bot.OnFarmingFinished().ConfigureAwait(false);
        }