From a00782527d7b355afd47417a769187f420a1d58a Mon Sep 17 00:00:00 2001 From: JustArchi Date: Fri, 15 Feb 2019 21:20:44 +0100 Subject: [PATCH] Add handling for one more deviceID + misc optimization --- ArchiSteamFarm/ArchiWebHandler.cs | 2 +- ArchiSteamFarm/MobileAuthenticator.cs | 4 ++-- ArchiSteamFarm/Utilities.cs | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index c1bdeeeb5..055debbc5 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -2238,7 +2238,7 @@ namespace ArchiSteamFarm { text = text.Substring(keyIndex); - if ((text.Length != 32) || !Utilities.IsValidHexadecimalString(text)) { + if ((text.Length != 32) || !Utilities.IsValidHexadecimalText(text)) { Bot.ArchiLogger.LogNullError(nameof(text)); return (ESteamApiKeyState.Error, null); diff --git a/ArchiSteamFarm/MobileAuthenticator.cs b/ArchiSteamFarm/MobileAuthenticator.cs index 87bccb035..675db00d3 100644 --- a/ArchiSteamFarm/MobileAuthenticator.cs +++ b/ArchiSteamFarm/MobileAuthenticator.cs @@ -303,7 +303,7 @@ namespace ArchiSteamFarm { // Dashes are optional in the ID, strip them off for comparison string hash = deviceID.Replace("-", ""); - return (hash.Length > 0) && Utilities.IsValidHexadecimalString(hash); + return (hash.Length > 0) && (Utilities.IsValidDigitsText(hash) || Utilities.IsValidHexadecimalText(hash)); } private string GenerateConfirmationHash(uint time, string tag = null) { @@ -398,7 +398,7 @@ namespace ArchiSteamFarm { uint fullCode = BitConverter.ToUInt32(bytes, 0) & 0x7fffffff; // Build the alphanumeric code - StringBuilder code = new StringBuilder(); + StringBuilder code = new StringBuilder(CodeDigits, CodeDigits); for (byte i = 0; i < CodeDigits; i++) { code.Append(CodeCharacters[fullCode % CodeCharacters.Length]); diff --git a/ArchiSteamFarm/Utilities.cs b/ArchiSteamFarm/Utilities.cs index eda883f43..d8af8fa2f 100644 --- a/ArchiSteamFarm/Utilities.cs +++ b/ArchiSteamFarm/Utilities.cs @@ -161,7 +161,18 @@ namespace ArchiSteamFarm { } [PublicAPI] - public static bool IsValidHexadecimalString(string text) { + public static bool IsValidDigitsText(string text) { + if (string.IsNullOrEmpty(text)) { + ASF.ArchiLogger.LogNullError(nameof(text)); + + return false; + } + + return text.All(char.IsDigit); + } + + [PublicAPI] + public static bool IsValidHexadecimalText(string text) { if (string.IsNullOrEmpty(text)) { ASF.ArchiLogger.LogNullError(nameof(text)); @@ -178,7 +189,7 @@ namespace ArchiSteamFarm { string lastHex; if (text.Length >= split) { - StringBuilder hex = new StringBuilder(split); + StringBuilder hex = new StringBuilder(split, 16); foreach (char character in text) { hex.Append(character);