From 04b534bda180e8f4dcbdd00394b19fffcfa780d7 Mon Sep 17 00:00:00 2001 From: Archi Date: Tue, 19 Mar 2024 12:40:54 +0100 Subject: [PATCH] SK2 3.0 --- .../Commands.cs | 49 +++++-------------- .../MobileAuthenticatorHandler.cs | 1 - Directory.Packages.props | 2 +- 3 files changed, 14 insertions(+), 38 deletions(-) diff --git a/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/Commands.cs b/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/Commands.cs index 359e37583..7c05fa7ae 100644 --- a/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/Commands.cs +++ b/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/Commands.cs @@ -38,8 +38,6 @@ using SteamKit2.Internal; namespace ArchiSteamFarm.OfficialPlugins.MobileAuthenticator; internal static class Commands { - private const byte MaxFinalizationAttempts = 900 / Steam.Security.MobileAuthenticator.CodeInterval; - internal static async Task OnBotCommand(Bot bot, EAccess access, string message, string[] args, ulong steamID = 0) { ArgumentNullException.ThrowIfNull(bot); @@ -146,43 +144,22 @@ internal static class Commands { ulong steamTime = await mobileAuthenticator.GetSteamTime().ConfigureAwait(false); - bool successFinalizing = false; + string? code = mobileAuthenticator.GenerateTokenForTime(steamTime); - for (byte i = 0; i < MaxFinalizationAttempts; i++) { - if (i > 0) { - steamTime += Steam.Security.MobileAuthenticator.CodeInterval; - } - - string? code = mobileAuthenticator.GenerateTokenForTime(steamTime); - - if (string.IsNullOrEmpty(code)) { - return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(mobileAuthenticator.GenerateTokenForTime))); - } - - CTwoFactor_FinalizeAddAuthenticator_Response? response = await mobileAuthenticatorHandler.FinalizeAuthenticator(bot.SteamID, activationCode, code, steamTime).ConfigureAwait(false); - - if (response == null) { - return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(mobileAuthenticatorHandler.FinalizeAuthenticator))); - } - - if (response.want_more) { - // OK, whatever - continue; - } - - if (!response.success) { - EResult result = (EResult) response.status; - - return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, result)); - } - - successFinalizing = true; - - break; + if (string.IsNullOrEmpty(code)) { + return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(mobileAuthenticator.GenerateTokenForTime))); } - if (!successFinalizing) { - return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorRequestFailedTooManyTimes, MaxFinalizationAttempts)); + CTwoFactor_FinalizeAddAuthenticator_Response? response = await mobileAuthenticatorHandler.FinalizeAuthenticator(bot.SteamID, activationCode, code, steamTime).ConfigureAwait(false); + + if (response == null) { + return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(mobileAuthenticatorHandler.FinalizeAuthenticator))); + } + + if (!response.success) { + EResult result = (EResult) response.status; + + return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, result)); } if (!bot.TryImportAuthenticator(mobileAuthenticator)) { diff --git a/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/MobileAuthenticatorHandler.cs b/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/MobileAuthenticatorHandler.cs index a4888aa95..54c860146 100644 --- a/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/MobileAuthenticatorHandler.cs +++ b/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/MobileAuthenticatorHandler.cs @@ -63,7 +63,6 @@ internal sealed class MobileAuthenticatorHandler : ClientMsgHandler { authenticator_type = 1, authenticator_time = Utilities.GetUnixTime(), device_identifier = deviceID, - sms_phone_id = "1", steamid = steamID }; diff --git a/Directory.Packages.props b/Directory.Packages.props index a9ef738ce..54c51635b 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -10,7 +10,7 @@ - +