diff --git a/ArchiSteamFarm/Steam/Bot.cs b/ArchiSteamFarm/Steam/Bot.cs index d65fe9f7c..1a404be0d 100644 --- a/ArchiSteamFarm/Steam/Bot.cs +++ b/ArchiSteamFarm/Steam/Bot.cs @@ -177,6 +177,11 @@ namespace ArchiSteamFarm.Steam { } } + /// + /// Login keys are not guaranteed to be valid, we should use them only if we don't have full details available from the user + /// + private bool ShouldUseLoginKeys => BotConfig.UseLoginKeys && (!BotConfig.IsSteamPasswordSet || string.IsNullOrEmpty(BotConfig.DecryptedSteamPassword) || !HasMobileAuthenticator); + [JsonProperty(PropertyName = SharedInfo.UlongCompatibilityStringPrefix + nameof(SteamID))] private string SSteamID => SteamID.ToString(CultureInfo.InvariantCulture); @@ -961,10 +966,12 @@ namespace ArchiSteamFarm.Steam { switch (inputType) { case ASF.EUserInputType.Login: BotConfig.SteamLogin = inputValue; + BotConfig.IsSteamLoginSet = false; break; case ASF.EUserInputType.Password: BotConfig.DecryptedSteamPassword = inputValue; + BotConfig.IsSteamPasswordSet = false; break; case ASF.EUserInputType.SteamGuard: @@ -981,6 +988,7 @@ namespace ArchiSteamFarm.Steam { } BotConfig.SteamParentalCode = inputValue; + BotConfig.IsSteamParentalCodeSet = false; break; case ASF.EUserInputType.TwoFactorAuthentication: @@ -2320,15 +2328,12 @@ namespace ArchiSteamFarm.Steam { string? loginKey = null; - if (BotConfig.UseLoginKeys) { - // Login keys are not guaranteed to be valid, we should use them only if we don't have full details available from the user - if (string.IsNullOrEmpty(BotConfig.DecryptedSteamPassword) || (string.IsNullOrEmpty(AuthCode) && string.IsNullOrEmpty(TwoFactorCode) && !HasMobileAuthenticator)) { - loginKey = BotDatabase.LoginKey; + if (ShouldUseLoginKeys && string.IsNullOrEmpty(AuthCode) && string.IsNullOrEmpty(TwoFactorCode)) { + loginKey = BotDatabase.LoginKey; - // Decrypt login key if needed - if (!string.IsNullOrEmpty(loginKey) && (loginKey!.Length > 19) && (BotConfig.PasswordFormat != ArchiCryptoHelper.ECryptoMethod.PlainText)) { - loginKey = ArchiCryptoHelper.Decrypt(BotConfig.PasswordFormat, loginKey); - } + // Decrypt login key if needed + if (!string.IsNullOrEmpty(loginKey) && (loginKey!.Length > 19) && (BotConfig.PasswordFormat != ArchiCryptoHelper.ECryptoMethod.PlainText)) { + loginKey = ArchiCryptoHelper.Decrypt(BotConfig.PasswordFormat, loginKey); } } else { // If we're not using login keys, ensure we don't have any saved @@ -2388,7 +2393,7 @@ namespace ArchiSteamFarm.Steam { LoginKey = loginKey, Password = password, SentryFileHash = sentryFileHash, - ShouldRememberPassword = BotConfig.UseLoginKeys, + ShouldRememberPassword = ShouldUseLoginKeys, TwoFactorCode = TwoFactorCode, Username = username }; @@ -3004,7 +3009,7 @@ namespace ArchiSteamFarm.Steam { throw new ArgumentNullException(nameof(callback)); } - if (!BotConfig.UseLoginKeys) { + if (!ShouldUseLoginKeys) { return; } diff --git a/ArchiSteamFarm/Steam/Storage/BotConfig.cs b/ArchiSteamFarm/Steam/Storage/BotConfig.cs index 69083e7f2..419d1785f 100644 --- a/ArchiSteamFarm/Steam/Storage/BotConfig.cs +++ b/ArchiSteamFarm/Steam/Storage/BotConfig.cs @@ -212,7 +212,7 @@ namespace ArchiSteamFarm.Steam.Storage { public string? SteamLogin { get => BackingSteamLogin; - set { + internal set { IsSteamLoginSet = true; BackingSteamLogin = value; } @@ -225,7 +225,7 @@ namespace ArchiSteamFarm.Steam.Storage { public string? SteamParentalCode { get => BackingSteamParentalCode; - set { + internal set { IsSteamParentalCodeSet = true; BackingSteamParentalCode = value; } @@ -235,7 +235,7 @@ namespace ArchiSteamFarm.Steam.Storage { public string? SteamPassword { get => BackingSteamPassword; - set { + internal set { IsSteamPasswordSet = true; BackingSteamPassword = value; } @@ -296,9 +296,9 @@ namespace ArchiSteamFarm.Steam.Storage { } } - internal bool IsSteamLoginSet { get; private set; } - internal bool IsSteamParentalCodeSet { get; private set; } - internal bool IsSteamPasswordSet { get; private set; } + internal bool IsSteamLoginSet { get; set; } + internal bool IsSteamParentalCodeSet { get; set; } + internal bool IsSteamPasswordSet { get; set; } internal bool Saving { get; set; } private string? BackingSteamLogin = DefaultSteamLogin; @@ -561,10 +561,10 @@ namespace ArchiSteamFarm.Steam.Storage { public bool ShouldSerializeShutdownOnFarmingFinished() => !Saving || (ShutdownOnFarmingFinished != DefaultShutdownOnFarmingFinished); public bool ShouldSerializeSkipRefundableGames() => !Saving || (SkipRefundableGames != DefaultSkipRefundableGames); public bool ShouldSerializeSSteamMasterClanID() => !Saving; - public bool ShouldSerializeSteamLogin() => Saving && (SteamLogin != DefaultSteamLogin); + public bool ShouldSerializeSteamLogin() => Saving && IsSteamLoginSet && (SteamLogin != DefaultSteamLogin); public bool ShouldSerializeSteamMasterClanID() => !Saving || (SteamMasterClanID != DefaultSteamMasterClanID); - public bool ShouldSerializeSteamParentalCode() => Saving && (SteamParentalCode != DefaultSteamParentalCode); - public bool ShouldSerializeSteamPassword() => Saving && (SteamPassword != DefaultSteamPassword); + public bool ShouldSerializeSteamParentalCode() => Saving && IsSteamParentalCodeSet && (SteamParentalCode != DefaultSteamParentalCode); + public bool ShouldSerializeSteamPassword() => Saving && IsSteamPasswordSet && (SteamPassword != DefaultSteamPassword); public bool ShouldSerializeSteamTradeToken() => !Saving || (SteamTradeToken != DefaultSteamTradeToken); public bool ShouldSerializeSteamUserPermissions() => !Saving || ((SteamUserPermissions != DefaultSteamUserPermissions) && ((SteamUserPermissions.Count != DefaultSteamUserPermissions.Count) || SteamUserPermissions.Except(DefaultSteamUserPermissions).Any())); public bool ShouldSerializeTradingPreferences() => !Saving || (TradingPreferences != DefaultTradingPreferences); diff --git a/ArchiSteamFarm/Storage/GlobalConfig.cs b/ArchiSteamFarm/Storage/GlobalConfig.cs index dd8e9ed72..5282d10d0 100644 --- a/ArchiSteamFarm/Storage/GlobalConfig.cs +++ b/ArchiSteamFarm/Storage/GlobalConfig.cs @@ -444,7 +444,7 @@ namespace ArchiSteamFarm.Storage { public bool ShouldSerializeUpdateChannel() => !Saving || (UpdateChannel != DefaultUpdateChannel); public bool ShouldSerializeUpdatePeriod() => !Saving || (UpdatePeriod != DefaultUpdatePeriod); public bool ShouldSerializeWebLimiterDelay() => !Saving || (WebLimiterDelay != DefaultWebLimiterDelay); - public bool ShouldSerializeWebProxyPassword() => Saving && (WebProxyPassword != DefaultWebProxyPassword); + public bool ShouldSerializeWebProxyPassword() => Saving && IsWebProxyPasswordSet && (WebProxyPassword != DefaultWebProxyPassword); public bool ShouldSerializeWebProxyText() => !Saving || (WebProxyText != DefaultWebProxyText); public bool ShouldSerializeWebProxyUsername() => !Saving || (WebProxyUsername != DefaultWebProxyUsername);