internal Confirmation(uint id, ulong key, Steam.ConfirmationDetails.EType type) { if ((id == 0) || (key == 0) || (type == Steam.ConfirmationDetails.EType.Unknown)) { throw new ArgumentNullException(nameof(id) + " || " + nameof(key) + " || " + nameof(type)); } ID = id; Key = key; Type = type; }
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 LimitConfirmationsRequestsAsync().ConfigureAwait(false); 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); }
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(); }); } } }