From eef66cebf301699e46fcbdd4bfc56d61c93242d1 Mon Sep 17 00:00:00 2001 From: Archi Date: Sat, 2 Dec 2023 17:00:50 +0100 Subject: [PATCH] Add session data for SDA compatibility --- .../Commands.cs | 2 +- .../MaFileData.cs | 12 +++++- .../MaFileSessionData.cs | 39 +++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/MaFileSessionData.cs diff --git a/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/Commands.cs b/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/Commands.cs index 0ae7d3089..97d22c305 100644 --- a/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/Commands.cs +++ b/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/Commands.cs @@ -357,7 +357,7 @@ internal static class Commands { return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, result)); } - MaFileData maFileData = new(response, deviceID); + MaFileData maFileData = new(response, bot.SteamID, deviceID); string maFilePendingPath = $"{bot.GetFilePath(Bot.EFileType.MobileAuthenticator)}.PENDING"; string json = JsonConvert.SerializeObject(maFileData, Formatting.Indented); diff --git a/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/MaFileData.cs b/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/MaFileData.cs index 414a7545e..2328cdae2 100644 --- a/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/MaFileData.cs +++ b/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/MaFileData.cs @@ -21,6 +21,7 @@ using System; using Newtonsoft.Json; +using SteamKit2; using SteamKit2.Internal; namespace ArchiSteamFarm.OfficialPlugins.MobileAuthenticator; @@ -47,6 +48,9 @@ internal sealed class MaFileData { [JsonProperty("server_time", Required = Required.Always)] internal readonly ulong ServerTime; + [JsonProperty(Required = Required.Always)] + internal readonly MaFileSessionData Session; + [JsonProperty("shared_secret", Required = Required.Always)] internal readonly string SharedSecret; @@ -59,8 +63,13 @@ internal sealed class MaFileData { [JsonProperty("uri", Required = Required.Always)] internal readonly string Uri; - internal MaFileData(CTwoFactor_AddAuthenticator_Response data, string deviceID) { + internal MaFileData(CTwoFactor_AddAuthenticator_Response data, ulong steamID, string deviceID) { ArgumentNullException.ThrowIfNull(data); + + if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { + throw new ArgumentOutOfRangeException(nameof(steamID)); + } + ArgumentException.ThrowIfNullOrEmpty(deviceID); AccountName = data.account_name; @@ -70,6 +79,7 @@ internal sealed class MaFileData { Secret1 = Convert.ToBase64String(data.secret_1); SerialNumber = data.serial_number; ServerTime = data.server_time; + Session = new MaFileSessionData(steamID); SharedSecret = Convert.ToBase64String(data.shared_secret); Status = data.status; TokenGid = data.token_gid; diff --git a/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/MaFileSessionData.cs b/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/MaFileSessionData.cs new file mode 100644 index 000000000..1e8368a31 --- /dev/null +++ b/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/MaFileSessionData.cs @@ -0,0 +1,39 @@ +// _ _ _ ____ _ _____ +// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ +// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ +// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | +// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| +// | +// Copyright 2015-2023 Ɓ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 Newtonsoft.Json; +using SteamKit2; + +namespace ArchiSteamFarm.OfficialPlugins.MobileAuthenticator; + +internal sealed class MaFileSessionData { + [JsonProperty(Required = Required.Always)] + internal readonly ulong SteamID; + + internal MaFileSessionData(ulong steamID) { + if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { + throw new ArgumentOutOfRangeException(nameof(steamID)); + } + + SteamID = steamID; + } +}