mirror of
https://github.com/JustArchiNET/ArchiSteamFarm
synced 2024-11-10 07:04:27 +00:00
6bc29e8c3f
commit 7501fd264b7248633c6853a6f232dfbf894b944a Author: Łukasz Domeradzki <JustArchi@JustArchi.net> Date: Mon Oct 21 12:18:54 2024 +0200 Remove CI artifact commit d6ad6e78e386d08b2b7aeb53992b4b987b08d729 Author: Łukasz Domeradzki <JustArchi@JustArchi.net> Date: Mon Oct 21 10:23:04 2024 +0200 Bump experiments commit d5553a52f3bc656c5dd1c280b9189bc48e4d417e Merge:6e34cdc2
4b3224a7
Author: Łukasz Domeradzki <JustArchi@JustArchi.net> Date: Mon Oct 21 10:19:16 2024 +0200 Merge branch 'main' into unified-experiments commit6e34cdc26c
Author: Łukasz Domeradzki <JustArchi@JustArchi.net> Date: Thu Oct 17 17:28:08 2024 +0200 Update experiments commit70b1c6e367
Merge:c22eb587
def6b675
Author: Łukasz Domeradzki <JustArchi@JustArchi.net> Date: Thu Oct 17 17:18:34 2024 +0200 Merge branch 'main' into unified-experiments commitc22eb5872e
Author: Łukasz Domeradzki <JustArchi@JustArchi.net> Date: Mon Oct 14 20:07:23 2024 +0200 Make it work commit9907d37504
Merge:de4b33c2
d166e198
Author: Łukasz Domeradzki <JustArchi@JustArchi.net> Date: Mon Oct 14 19:31:06 2024 +0200 Merge branch 'main' into unified-experiments commitde4b33c2c4
Author: Łukasz Domeradzki <JustArchi@JustArchi.net> Date: Sun Oct 13 20:22:32 2024 +0200 Fix docker build again commit60f3be0bd8
Author: Łukasz Domeradzki <JustArchi@JustArchi.net> Date: Sun Oct 13 20:18:27 2024 +0200 Fix docker build commit07502180c4
Author: Łukasz Domeradzki <JustArchi@JustArchi.net> Date: Sun Oct 13 20:15:18 2024 +0200 Commit missing part commit75fd1b8675
Author: Łukasz Domeradzki <JustArchi@JustArchi.net> Date: Sun Oct 13 20:12:12 2024 +0200 Craft some experiments
118 lines
4.3 KiB
C#
118 lines
4.3 KiB
C#
// ----------------------------------------------------------------------------------------------
|
|
// _ _ _ ____ _ _____
|
|
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
|
|
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
|
|
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
|
|
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
|
|
// ----------------------------------------------------------------------------------------------
|
|
// |
|
|
// Copyright 2015-2024 Łukasz "JustArchi" Domeradzki
|
|
// 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.
|
|
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using ArchiSteamFarm.Core;
|
|
using ArchiSteamFarm.NLog;
|
|
using SteamKit2;
|
|
using SteamKit2.Internal;
|
|
|
|
namespace ArchiSteamFarm.OfficialPlugins.MobileAuthenticator;
|
|
|
|
internal sealed class MobileAuthenticatorHandler : ClientMsgHandler {
|
|
private readonly ArchiLogger ArchiLogger;
|
|
private readonly TwoFactor UnifiedTwoFactorService;
|
|
|
|
internal MobileAuthenticatorHandler(ArchiLogger archiLogger, SteamUnifiedMessages steamUnifiedMessages) {
|
|
ArgumentNullException.ThrowIfNull(archiLogger);
|
|
ArgumentNullException.ThrowIfNull(steamUnifiedMessages);
|
|
|
|
ArchiLogger = archiLogger;
|
|
UnifiedTwoFactorService = steamUnifiedMessages.CreateService<TwoFactor>();
|
|
}
|
|
|
|
public override void HandleMsg(IPacketMsg packetMsg) => ArgumentNullException.ThrowIfNull(packetMsg);
|
|
|
|
internal async Task<CTwoFactor_AddAuthenticator_Response?> AddAuthenticator(ulong steamID, string deviceID) {
|
|
if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) {
|
|
throw new ArgumentOutOfRangeException(nameof(steamID));
|
|
}
|
|
|
|
ArgumentException.ThrowIfNullOrEmpty(deviceID);
|
|
|
|
if (Client == null) {
|
|
throw new InvalidOperationException(nameof(Client));
|
|
}
|
|
|
|
if (!Client.IsConnected) {
|
|
return null;
|
|
}
|
|
|
|
CTwoFactor_AddAuthenticator_Request request = new() {
|
|
authenticator_type = 1,
|
|
authenticator_time = Utilities.GetUnixTime(),
|
|
device_identifier = deviceID,
|
|
steamid = steamID
|
|
};
|
|
|
|
SteamUnifiedMessages.ServiceMethodResponse<CTwoFactor_AddAuthenticator_Response> response;
|
|
|
|
try {
|
|
response = await UnifiedTwoFactorService.AddAuthenticator(request).ToLongRunningTask().ConfigureAwait(false);
|
|
} catch (Exception e) {
|
|
ArchiLogger.LogGenericWarningException(e);
|
|
|
|
return null;
|
|
}
|
|
|
|
return response.Result == EResult.OK ? response.Body : null;
|
|
}
|
|
|
|
internal async Task<CTwoFactor_FinalizeAddAuthenticator_Response?> FinalizeAuthenticator(ulong steamID, string activationCode, string authenticatorCode, ulong authenticatorTime) {
|
|
if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) {
|
|
throw new ArgumentOutOfRangeException(nameof(steamID));
|
|
}
|
|
|
|
ArgumentException.ThrowIfNullOrEmpty(activationCode);
|
|
ArgumentException.ThrowIfNullOrEmpty(authenticatorCode);
|
|
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(authenticatorTime);
|
|
|
|
if (Client == null) {
|
|
throw new InvalidOperationException(nameof(Client));
|
|
}
|
|
|
|
if (!Client.IsConnected) {
|
|
return null;
|
|
}
|
|
|
|
CTwoFactor_FinalizeAddAuthenticator_Request request = new() {
|
|
activation_code = activationCode,
|
|
authenticator_code = authenticatorCode,
|
|
authenticator_time = authenticatorTime,
|
|
steamid = steamID
|
|
};
|
|
|
|
SteamUnifiedMessages.ServiceMethodResponse<CTwoFactor_FinalizeAddAuthenticator_Response> response;
|
|
|
|
try {
|
|
response = await UnifiedTwoFactorService.FinalizeAddAuthenticator(request).ToLongRunningTask().ConfigureAwait(false);
|
|
} catch (Exception e) {
|
|
ArchiLogger.LogGenericWarningException(e);
|
|
|
|
return null;
|
|
}
|
|
|
|
return response.Result == EResult.OK ? response.Body : null;
|
|
}
|
|
}
|