This commit is contained in:
Archi 2024-03-19 12:40:54 +01:00
parent 3620796d6d
commit 04b534bda1
No known key found for this signature in database
GPG key ID: 6B138B4C64555AEA
3 changed files with 14 additions and 38 deletions

View file

@ -38,8 +38,6 @@ using SteamKit2.Internal;
namespace ArchiSteamFarm.OfficialPlugins.MobileAuthenticator; namespace ArchiSteamFarm.OfficialPlugins.MobileAuthenticator;
internal static class Commands { internal static class Commands {
private const byte MaxFinalizationAttempts = 900 / Steam.Security.MobileAuthenticator.CodeInterval;
internal static async Task<string?> OnBotCommand(Bot bot, EAccess access, string message, string[] args, ulong steamID = 0) { internal static async Task<string?> OnBotCommand(Bot bot, EAccess access, string message, string[] args, ulong steamID = 0) {
ArgumentNullException.ThrowIfNull(bot); ArgumentNullException.ThrowIfNull(bot);
@ -146,43 +144,22 @@ internal static class Commands {
ulong steamTime = await mobileAuthenticator.GetSteamTime().ConfigureAwait(false); ulong steamTime = await mobileAuthenticator.GetSteamTime().ConfigureAwait(false);
bool successFinalizing = false; string? code = mobileAuthenticator.GenerateTokenForTime(steamTime);
for (byte i = 0; i < MaxFinalizationAttempts; i++) { if (string.IsNullOrEmpty(code)) {
if (i > 0) { return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(mobileAuthenticator.GenerateTokenForTime)));
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 (!successFinalizing) { CTwoFactor_FinalizeAddAuthenticator_Response? response = await mobileAuthenticatorHandler.FinalizeAuthenticator(bot.SteamID, activationCode, code, steamTime).ConfigureAwait(false);
return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorRequestFailedTooManyTimes, MaxFinalizationAttempts));
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)) { if (!bot.TryImportAuthenticator(mobileAuthenticator)) {

View file

@ -63,7 +63,6 @@ internal sealed class MobileAuthenticatorHandler : ClientMsgHandler {
authenticator_type = 1, authenticator_type = 1,
authenticator_time = Utilities.GetUnixTime(), authenticator_time = Utilities.GetUnixTime(),
device_identifier = deviceID, device_identifier = deviceID,
sms_phone_id = "1",
steamid = steamID steamid = steamID
}; };

View file

@ -10,7 +10,7 @@
<PackageVersion Include="MSTest" Version="3.2.2" /> <PackageVersion Include="MSTest" Version="3.2.2" />
<PackageVersion Include="Nito.AsyncEx.Coordination" Version="5.1.2" /> <PackageVersion Include="Nito.AsyncEx.Coordination" Version="5.1.2" />
<PackageVersion Include="NLog.Web.AspNetCore" Version="5.3.8" /> <PackageVersion Include="NLog.Web.AspNetCore" Version="5.3.8" />
<PackageVersion Include="SteamKit2" Version="2.5.0" /> <PackageVersion Include="SteamKit2" Version="3.0.0-Alpha.1" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" /> <PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" /> <PackageVersion Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
<PackageVersion Include="System.Composition" Version="8.0.0" /> <PackageVersion Include="System.Composition" Version="8.0.0" />