Example #1
0
        private static async Task LimitConfirmationsRequestsAsync()
        {
            if (Program.GlobalConfig.ConfirmationsLimiterDelay == 0)
            {
                return;
            }

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

            Utilities.InBackground(
                async() => {
                await Task.Delay(Program.GlobalConfig.ConfirmationsLimiterDelay * 1000).ConfigureAwait(false);
                ConfirmationsSemaphore.Release();
            }
                );
        }
Example #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();
            }
        }
        internal async Task <HashSet <Confirmation> > GetConfirmations(Steam.ConfirmationDetails.EType acceptedType = Steam.ConfirmationDetails.EType.Unknown)
        {
            if (!HasCorrectDeviceID)
            {
                Bot.ArchiLogger.LogGenericError(Strings.ErrorMobileAuthenticatorInvalidDeviceID);
                return(null);
            }

            uint time = await GetSteamTime().ConfigureAwait(false);

            if (time == 0)
            {
                Bot.ArchiLogger.LogNullError(nameof(time));
                return(null);
            }

            string confirmationHash = GenerateConfirmationHash(time, "conf");

            if (string.IsNullOrEmpty(confirmationHash))
            {
                Bot.ArchiLogger.LogNullError(nameof(confirmationHash));
                return(null);
            }

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

            try {
                HtmlDocument htmlDocument = await Bot.ArchiWebHandler.GetConfirmations(DeviceID, confirmationHash, time).ConfigureAwait(false);

                HtmlNodeCollection confirmationNodes = htmlDocument?.DocumentNode.SelectNodes("//div[@class='mobileconf_list_entry']");
                if (confirmationNodes == null)
                {
                    return(null);
                }

                HashSet <Confirmation> result = new HashSet <Confirmation>();

                foreach (HtmlNode confirmationNode in confirmationNodes)
                {
                    string idText = confirmationNode.GetAttributeValue("data-confid", null);
                    if (string.IsNullOrEmpty(idText))
                    {
                        Bot.ArchiLogger.LogNullError(nameof(idText));
                        return(null);
                    }

                    if (!ulong.TryParse(idText, out ulong id) || (id == 0))
                    {
                        Bot.ArchiLogger.LogNullError(nameof(id));
                        return(null);
                    }

                    string keyText = confirmationNode.GetAttributeValue("data-key", null);
                    if (string.IsNullOrEmpty(keyText))
                    {
                        Bot.ArchiLogger.LogNullError(nameof(keyText));
                        return(null);
                    }

                    if (!ulong.TryParse(keyText, out ulong key) || (key == 0))
                    {
                        Bot.ArchiLogger.LogNullError(nameof(key));
                        return(null);
                    }

                    string typeText = confirmationNode.GetAttributeValue("data-type", null);
                    if (string.IsNullOrEmpty(typeText))
                    {
                        Bot.ArchiLogger.LogNullError(nameof(typeText));
                        return(null);
                    }

                    if (!Enum.TryParse(typeText, out Steam.ConfirmationDetails.EType type) || (type == Steam.ConfirmationDetails.EType.Unknown))
                    {
                        Bot.ArchiLogger.LogNullError(nameof(type));
                        return(null);
                    }

                    if (!Enum.IsDefined(typeof(Steam.ConfirmationDetails.EType), type))
                    {
                        Bot.ArchiLogger.LogGenericError(string.Format(Strings.WarningUnknownValuePleaseReport, nameof(type), type));
                        return(null);
                    }

                    if ((acceptedType != Steam.ConfirmationDetails.EType.Unknown) && (acceptedType != type))
                    {
                        continue;
                    }

                    result.Add(new Confirmation(id, key));
                }

                return(result);
            } finally {
                if (Program.GlobalConfig.ConfirmationsLimiterDelay == 0)
                {
                    ConfirmationsSemaphore.Release();
                }
                else
                {
                    Utilities.InBackground(async() => {
                        await Task.Delay(Program.GlobalConfig.ConfirmationsLimiterDelay * 1000).ConfigureAwait(false);
                        ConfirmationsSemaphore.Release();
                    });
                }
            }
        }
Example #4
0
        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();
            }
        }
Example #5
0
        internal async Task <HashSet <Confirmation> > GetConfirmations(Steam.ConfirmationDetails.EType acceptedType = Steam.ConfirmationDetails.EType.Unknown)
        {
            if (!HasCorrectDeviceID)
            {
                Bot.ArchiLogger.LogGenericError(Strings.ErrorMobileAuthenticatorInvalidDeviceID);
                return(null);
            }

            uint time = await GetSteamTime().ConfigureAwait(false);

            if (time == 0)
            {
                Bot.ArchiLogger.LogNullError(nameof(time));
                return(null);
            }

            string confirmationHash = GenerateConfirmationKey(time, "conf");

            if (string.IsNullOrEmpty(confirmationHash))
            {
                Bot.ArchiLogger.LogNullError(nameof(confirmationHash));
                return(null);
            }

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

            try {
                HtmlDocument htmlDocument = await Bot.ArchiWebHandler.GetConfirmations(DeviceID, confirmationHash, time).ConfigureAwait(false);

                HtmlNodeCollection confirmationNodes = htmlDocument?.DocumentNode.SelectNodes("//div[@class='mobileconf_list_entry']");
                if (confirmationNodes == null)
                {
                    return(null);
                }

                HashSet <Confirmation> result = new HashSet <Confirmation>();

                foreach (HtmlNode confirmationNode in confirmationNodes)
                {
                    string idString = confirmationNode.GetAttributeValue("data-confid", null);
                    if (string.IsNullOrEmpty(idString))
                    {
                        Bot.ArchiLogger.LogNullError(nameof(idString));
                        return(null);
                    }

                    if (!ulong.TryParse(idString, out ulong id) || (id == 0))
                    {
                        Bot.ArchiLogger.LogNullError(nameof(id));
                        return(null);
                    }

                    string keyString = confirmationNode.GetAttributeValue("data-key", null);
                    if (string.IsNullOrEmpty(keyString))
                    {
                        Bot.ArchiLogger.LogNullError(nameof(keyString));
                        return(null);
                    }

                    if (!ulong.TryParse(keyString, out ulong key) || (key == 0))
                    {
                        Bot.ArchiLogger.LogNullError(nameof(key));
                        return(null);
                    }

                    HtmlNode descriptionNode = confirmationNode.SelectSingleNode(".//div[@class='mobileconf_list_entry_description']/div");
                    if (descriptionNode == null)
                    {
                        Bot.ArchiLogger.LogNullError(nameof(descriptionNode));
                        return(null);
                    }

                    Steam.ConfirmationDetails.EType type;

                    string description = descriptionNode.InnerText;
                    if (description.StartsWith("Sell ", StringComparison.Ordinal))
                    {
                        type = Steam.ConfirmationDetails.EType.Market;
                    }
                    else if (description.StartsWith("Trade ", StringComparison.Ordinal) || description.Equals("Error loading trade details"))
                    {
                        type = Steam.ConfirmationDetails.EType.Trade;
                    }
                    else
                    {
                        Bot.ArchiLogger.LogGenericError(string.Format(Strings.WarningUnknownValuePleaseReport, nameof(description), description));
                        type = Steam.ConfirmationDetails.EType.Other;
                    }

                    if ((acceptedType != Steam.ConfirmationDetails.EType.Unknown) && (acceptedType != type))
                    {
                        continue;
                    }

                    result.Add(new Confirmation(id, key));
                }

                return(result);
            } finally {
                if (Program.GlobalConfig.ConfirmationsLimiterDelay == 0)
                {
                    ConfirmationsSemaphore.Release();
                }
                else
                {
                    Utilities.InBackground(async() => {
                        await Task.Delay(Program.GlobalConfig.ConfirmationsLimiterDelay * 1000).ConfigureAwait(false);
                        ConfirmationsSemaphore.Release();
                    });
                }
            }
        }