Example #1
0
        private void CheckPage(HtmlDocument htmlDocument)
        {
            if (htmlDocument == null)
            {
                return;
            }

            HtmlNodeCollection htmlNodeCollection = htmlDocument.DocumentNode.SelectNodes("//a[@class='btn_green_white_innerfade btn_small_thin']");

            if (htmlNodeCollection == null)
            {
                return;
            }

            foreach (HtmlNode htmlNode in htmlNodeCollection)
            {
                string steamLink = htmlNode.GetAttributeValue("href", null);
                if (steamLink == null)
                {
                    continue;
                }

                uint appID = (uint)Utilities.OnlyNumbers(steamLink);
                if (appID == 0)
                {
                    continue;
                }

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

                // We assume that every game has at least 2 hours played, until we actually check them
                GamesToFarm[appID] = 2;
            }
        }
Example #2
0
        internal async Task StartFarming()
        {
            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!");
                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.LogGenericWarning(Bot.BotName, "Couldn't get steamLink for one of the games: " + badgesPageNode.OuterHtml);
                        continue;
                    }

                    uint appID = (uint)Utilities.OnlyNumbers(steamLink);
                    if (appID == 0)
                    {
                        Logging.LogGenericWarning(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
                {
                    break;
                }
            }

            Logging.LogGenericInfo(Bot.BotName, "Farming finished!");
        }