2020-08-10 13:24:12 +02:00
// _ _ _ ____ _ _____
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
// |
2022-01-06 20:22:38 +01:00
// Copyright 2015-2022 Łukasz "JustArchi" Domeradzki
2020-08-10 13:24:12 +02:00
// Contact: JustArchi@JustArchi.net
// |
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// |
// http://www.apache.org/licenses/LICENSE-2.0
// |
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2020-08-23 20:45:24 +02:00
using System ;
2020-08-10 13:24:12 +02:00
using System.Collections.Generic ;
using System.Collections.Immutable ;
using System.Diagnostics.CodeAnalysis ;
2020-11-11 16:51:31 +01:00
using System.Globalization ;
2021-05-06 21:18:39 +02:00
using System.Linq ;
2021-05-08 01:37:22 +02:00
using ArchiSteamFarm.Core ;
2020-08-10 13:24:12 +02:00
using ArchiSteamFarm.Localization ;
2021-05-08 01:37:22 +02:00
using ArchiSteamFarm.Steam.Security ;
2020-08-10 13:24:12 +02:00
using Newtonsoft.Json ;
2021-11-10 21:23:24 +01:00
namespace ArchiSteamFarm.IPC.Requests ;
2020-08-10 14:02:28 +02:00
2021-11-10 21:23:24 +01:00
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
public sealed class TwoFactorAuthenticationConfirmationsRequest {
/// <summary>
/// Specifies the target action, whether we should accept the confirmations (true), or decline them (false).
/// </summary>
[JsonProperty(Required = Required.Always)]
public bool Accept { get ; private set ; }
2020-08-10 13:24:12 +02:00
2021-11-10 21:23:24 +01:00
/// <summary>
/// Specifies IDs of the confirmations that we're supposed to handle. CreatorID of the confirmation is equal to ID of the object that triggered it - e.g. ID of the trade offer, or ID of the market listing. If not provided, or empty array, all confirmation IDs are considered for an action.
/// </summary>
[JsonProperty(Required = Required.DisallowNull)]
public ImmutableHashSet < ulong > AcceptedCreatorIDs { get ; private set ; } = ImmutableHashSet < ulong > . Empty ;
2020-08-10 13:24:12 +02:00
2021-11-10 21:23:24 +01:00
/// <summary>
/// Specifies the type of confirmations to handle. If not provided, all confirmation types are considered for an action.
/// </summary>
[JsonProperty]
public Confirmation . EType ? AcceptedType { get ; private set ; }
2020-08-10 13:24:12 +02:00
2021-11-10 21:23:24 +01:00
/// <summary>
/// A helper property which works the same as <see cref="AcceptedCreatorIDs" /> but with values written as strings - for javascript compatibility purposes. Use either this one, or <see cref="AcceptedCreatorIDs" />, not both.
/// </summary>
2022-03-22 16:33:47 +01:00
[JsonProperty($"{SharedInfo.UlongCompatibilityStringPrefix}{nameof(AcceptedCreatorIDs)}", Required = Required.DisallowNull)]
2021-11-10 21:23:24 +01:00
public ImmutableHashSet < string > SAcceptedCreatorIDs {
get = > AcceptedCreatorIDs . Select ( static creatorID = > creatorID . ToString ( CultureInfo . InvariantCulture ) ) . ToImmutableHashSet ( ) ;
set {
2021-12-12 01:12:54 +01:00
ArgumentNullException . ThrowIfNull ( value ) ;
2020-08-10 13:24:12 +02:00
2021-11-10 21:23:24 +01:00
HashSet < ulong > acceptedCreatorIDs = new ( ) ;
2020-08-10 13:24:12 +02:00
2021-11-10 21:23:24 +01:00
foreach ( string creatorIDText in value ) {
if ( ! ulong . TryParse ( creatorIDText , out ulong creatorID ) | | ( creatorID = = 0 ) ) {
ASF . ArchiLogger . LogGenericError ( string . Format ( CultureInfo . CurrentCulture , Strings . ErrorIsInvalid , nameof ( SAcceptedCreatorIDs ) ) ) ;
2020-08-10 13:24:12 +02:00
2021-11-10 21:23:24 +01:00
return ;
2020-08-10 13:24:12 +02:00
}
2021-11-10 21:23:24 +01:00
acceptedCreatorIDs . Add ( creatorID ) ;
2020-08-10 13:24:12 +02:00
}
2021-11-10 21:23:24 +01:00
AcceptedCreatorIDs = acceptedCreatorIDs . ToImmutableHashSet ( ) ;
2020-08-10 13:24:12 +02:00
}
2021-11-10 21:23:24 +01:00
}
2020-08-10 13:24:12 +02:00
2021-11-10 21:23:24 +01:00
/// <summary>
/// Specifies whether we should wait for the confirmations to arrive, in case they're not available immediately. This option makes sense only if <see cref="AcceptedCreatorIDs" /> is specified as well, and in this case ASF will add a few more tries if needed to ensure that all specified IDs are handled. Useful if confirmations are generated with a delay on Steam network side, which happens fairly often.
/// </summary>
[JsonProperty(Required = Required.DisallowNull)]
public bool WaitIfNeeded { get ; private set ; }
2020-11-29 16:15:20 +01:00
2021-11-10 21:23:24 +01:00
[JsonConstructor]
private TwoFactorAuthenticationConfirmationsRequest ( ) { }
2020-08-10 13:24:12 +02:00
}