mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-16 08:25:28 +00:00
Closes #868
This commit is contained in:
@@ -20,9 +20,10 @@
|
||||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ArchiSteamFarm.Json;
|
||||
@@ -33,95 +34,123 @@ using SteamKit2;
|
||||
namespace ArchiSteamFarm {
|
||||
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
|
||||
internal sealed class BotConfig {
|
||||
private const bool DefaultAcceptGifts = false;
|
||||
private const bool DefaultAutoSteamSaleEvent = false;
|
||||
private const EBotBehaviour DefaultBotBehaviour = EBotBehaviour.None;
|
||||
private const string DefaultCustomGamePlayedWhileFarming = null;
|
||||
private const string DefaultCustomGamePlayedWhileIdle = null;
|
||||
private const bool DefaultEnabled = false;
|
||||
private const byte DefaultHoursUntilCardDrops = 3;
|
||||
private const bool DefaultIdlePriorityQueueOnly = false;
|
||||
private const bool DefaultIdleRefundableGames = true;
|
||||
private const EPersonaState DefaultOnlineStatus = EPersonaState.Online;
|
||||
private const CryptoHelper.ECryptoMethod DefaultPasswordFormat = CryptoHelper.ECryptoMethod.PlainText;
|
||||
private const bool DefaultPaused = false;
|
||||
private const ERedeemingPreferences DefaultRedeemingPreferences = ERedeemingPreferences.None;
|
||||
private const bool DefaultSendOnFarmingFinished = false;
|
||||
private const byte DefaultSendTradePeriod = 0;
|
||||
private const bool DefaultShutdownOnFarmingFinished = false;
|
||||
private const string DefaultSteamLogin = null;
|
||||
private const ulong DefaultSteamMasterClanID = 0;
|
||||
private const string DefaultSteamParentalPIN = "0";
|
||||
private const string DefaultSteamPassword = null;
|
||||
private const string DefaultSteamTradeToken = null;
|
||||
private const ETradingPreferences DefaultTradingPreferences = ETradingPreferences.None;
|
||||
private const bool DefaultUseLoginKeys = true;
|
||||
|
||||
private static readonly ImmutableHashSet<EFarmingOrder> DefaultFarmingOrders = ImmutableHashSet<EFarmingOrder>.Empty;
|
||||
private static readonly ImmutableHashSet<uint> DefaultGamesPlayedWhileIdle = ImmutableHashSet<uint>.Empty;
|
||||
private static readonly ImmutableHashSet<Steam.Asset.EType> DefaultLootableTypes = ImmutableHashSet.Create(Steam.Asset.EType.BoosterPack, Steam.Asset.EType.FoilTradingCard, Steam.Asset.EType.TradingCard);
|
||||
private static readonly ImmutableHashSet<Steam.Asset.EType> DefaultMatchableTypes = ImmutableHashSet.Create(Steam.Asset.EType.TradingCard);
|
||||
private static readonly ImmutableDictionary<ulong, EPermission> DefaultSteamUserPermissions = ImmutableDictionary<ulong, EPermission>.Empty;
|
||||
|
||||
private static readonly SemaphoreSlim WriteSemaphore = new SemaphoreSlim(1, 1);
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly bool AcceptGifts;
|
||||
internal readonly bool AcceptGifts = DefaultAcceptGifts;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly bool AutoSteamSaleEvent;
|
||||
internal readonly bool AutoSteamSaleEvent = DefaultAutoSteamSaleEvent;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly EBotBehaviour BotBehaviour;
|
||||
internal readonly EBotBehaviour BotBehaviour = DefaultBotBehaviour;
|
||||
|
||||
[JsonProperty]
|
||||
internal readonly string CustomGamePlayedWhileFarming;
|
||||
internal readonly string CustomGamePlayedWhileFarming = DefaultCustomGamePlayedWhileFarming;
|
||||
|
||||
[JsonProperty]
|
||||
internal readonly string CustomGamePlayedWhileIdle;
|
||||
internal readonly string CustomGamePlayedWhileIdle = DefaultCustomGamePlayedWhileIdle;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly bool Enabled;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly HashSet<EFarmingOrder> FarmingOrders = new HashSet<EFarmingOrder>();
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly HashSet<uint> GamesPlayedWhileIdle = new HashSet<uint>();
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly byte HoursUntilCardDrops = 3;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly bool IdlePriorityQueueOnly;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly bool IdleRefundableGames = true;
|
||||
internal readonly bool Enabled = DefaultEnabled;
|
||||
|
||||
[JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Replace, Required = Required.DisallowNull)]
|
||||
internal readonly HashSet<Steam.Asset.EType> LootableTypes = new HashSet<Steam.Asset.EType> {
|
||||
Steam.Asset.EType.BoosterPack,
|
||||
Steam.Asset.EType.FoilTradingCard,
|
||||
Steam.Asset.EType.TradingCard
|
||||
};
|
||||
internal readonly ImmutableHashSet<EFarmingOrder> FarmingOrders = DefaultFarmingOrders;
|
||||
|
||||
[JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Replace, Required = Required.DisallowNull)]
|
||||
internal readonly HashSet<Steam.Asset.EType> MatchableTypes = new HashSet<Steam.Asset.EType> { Steam.Asset.EType.TradingCard };
|
||||
internal readonly ImmutableHashSet<uint> GamesPlayedWhileIdle = DefaultGamesPlayedWhileIdle;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly EPersonaState OnlineStatus = EPersonaState.Online;
|
||||
internal readonly byte HoursUntilCardDrops = DefaultHoursUntilCardDrops;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly CryptoHelper.ECryptoMethod PasswordFormat;
|
||||
internal readonly bool IdlePriorityQueueOnly = DefaultIdlePriorityQueueOnly;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly bool Paused;
|
||||
internal readonly bool IdleRefundableGames = DefaultIdleRefundableGames;
|
||||
|
||||
[JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Replace, Required = Required.DisallowNull)]
|
||||
internal readonly ImmutableHashSet<Steam.Asset.EType> LootableTypes = DefaultLootableTypes;
|
||||
|
||||
[JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Replace, Required = Required.DisallowNull)]
|
||||
internal readonly ImmutableHashSet<Steam.Asset.EType> MatchableTypes = DefaultMatchableTypes;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly ERedeemingPreferences RedeemingPreferences;
|
||||
internal readonly EPersonaState OnlineStatus = DefaultOnlineStatus;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly bool SendOnFarmingFinished;
|
||||
internal readonly CryptoHelper.ECryptoMethod PasswordFormat = DefaultPasswordFormat;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly byte SendTradePeriod;
|
||||
internal readonly bool Paused = DefaultPaused;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly bool ShutdownOnFarmingFinished;
|
||||
internal readonly ERedeemingPreferences RedeemingPreferences = DefaultRedeemingPreferences;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly bool SendOnFarmingFinished = DefaultSendOnFarmingFinished;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly byte SendTradePeriod = DefaultSendTradePeriod;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly bool ShutdownOnFarmingFinished = DefaultShutdownOnFarmingFinished;
|
||||
|
||||
[JsonProperty]
|
||||
internal readonly string SteamTradeToken;
|
||||
internal readonly string SteamTradeToken = DefaultSteamTradeToken;
|
||||
|
||||
[JsonProperty(ObjectCreationHandling = ObjectCreationHandling.Replace, Required = Required.DisallowNull)]
|
||||
internal readonly ImmutableDictionary<ulong, EPermission> SteamUserPermissions = DefaultSteamUserPermissions;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly Dictionary<ulong, EPermission> SteamUserPermissions = new Dictionary<ulong, EPermission>();
|
||||
internal readonly ETradingPreferences TradingPreferences = DefaultTradingPreferences;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly ETradingPreferences TradingPreferences;
|
||||
internal readonly bool UseLoginKeys = DefaultUseLoginKeys;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly bool UseLoginKeys = true;
|
||||
internal bool ShouldSerializeEverything { private get; set; } = true;
|
||||
|
||||
[JsonProperty]
|
||||
internal string SteamLogin { get; set; }
|
||||
internal string SteamLogin { get; set; } = DefaultSteamLogin;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal ulong SteamMasterClanID { get; private set; }
|
||||
internal ulong SteamMasterClanID { get; private set; } = DefaultSteamMasterClanID;
|
||||
|
||||
[JsonProperty]
|
||||
internal string SteamParentalPIN { get; set; } = "0";
|
||||
internal string SteamParentalPIN { get; set; } = DefaultSteamParentalPIN;
|
||||
|
||||
[JsonProperty]
|
||||
internal string SteamPassword { get; set; }
|
||||
internal string SteamPassword { get; set; } = DefaultSteamPassword;
|
||||
|
||||
private bool ShouldSerializeSensitiveDetails = true;
|
||||
|
||||
@@ -138,10 +167,6 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShouldSerializeSteamLogin() => ShouldSerializeSensitiveDetails;
|
||||
public bool ShouldSerializeSteamParentalPIN() => ShouldSerializeSensitiveDetails;
|
||||
public bool ShouldSerializeSteamPassword() => ShouldSerializeSensitiveDetails;
|
||||
|
||||
internal static async Task<BotConfig> Load(string filePath) {
|
||||
if (string.IsNullOrEmpty(filePath)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(filePath));
|
||||
@@ -217,11 +242,9 @@ namespace ArchiSteamFarm {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (EPermission permission in botConfig.SteamUserPermissions.Values) {
|
||||
if (!Enum.IsDefined(typeof(EPermission), permission)) {
|
||||
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(botConfig.SteamUserPermissions), permission));
|
||||
return null;
|
||||
}
|
||||
foreach (EPermission permission in botConfig.SteamUserPermissions.Values.Where(permission => !Enum.IsDefined(typeof(EPermission), permission))) {
|
||||
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(botConfig.SteamUserPermissions), permission));
|
||||
return null;
|
||||
}
|
||||
|
||||
if (botConfig.TradingPreferences > ETradingPreferences.All) {
|
||||
@@ -235,6 +258,7 @@ namespace ArchiSteamFarm {
|
||||
botConfig.SteamPassword = CryptoHelper.Decrypt(botConfig.PasswordFormat, botConfig.SteamPassword);
|
||||
}
|
||||
|
||||
botConfig.ShouldSerializeEverything = false;
|
||||
botConfig.ShouldSerializeSensitiveDetails = false;
|
||||
return botConfig;
|
||||
}
|
||||
@@ -329,5 +353,38 @@ namespace ArchiSteamFarm {
|
||||
DontAcceptBotTrades = 8,
|
||||
All = AcceptDonations | SteamTradeMatcher | MatchEverything | DontAcceptBotTrades
|
||||
}
|
||||
|
||||
// ReSharper disable UnusedMember.Global
|
||||
public bool ShouldSerializeAcceptGifts() => ShouldSerializeEverything || (AcceptGifts != DefaultAcceptGifts);
|
||||
public bool ShouldSerializeAutoSteamSaleEvent() => ShouldSerializeEverything || (AutoSteamSaleEvent != DefaultAutoSteamSaleEvent);
|
||||
public bool ShouldSerializeBotBehaviour() => ShouldSerializeEverything || (BotBehaviour != DefaultBotBehaviour);
|
||||
public bool ShouldSerializeCustomGamePlayedWhileFarming() => ShouldSerializeEverything || (CustomGamePlayedWhileFarming != DefaultCustomGamePlayedWhileFarming);
|
||||
public bool ShouldSerializeCustomGamePlayedWhileIdle() => ShouldSerializeEverything || (CustomGamePlayedWhileIdle != DefaultCustomGamePlayedWhileIdle);
|
||||
public bool ShouldSerializeEnabled() => ShouldSerializeEverything || (Enabled != DefaultEnabled);
|
||||
public bool ShouldSerializeFarmingOrders() => ShouldSerializeEverything || ((FarmingOrders != DefaultFarmingOrders) && !FarmingOrders.SetEquals(DefaultFarmingOrders));
|
||||
public bool ShouldSerializeGamesPlayedWhileIdle() => ShouldSerializeEverything || ((GamesPlayedWhileIdle != DefaultGamesPlayedWhileIdle) && !GamesPlayedWhileIdle.SetEquals(DefaultGamesPlayedWhileIdle));
|
||||
public bool ShouldSerializeHoursUntilCardDrops() => ShouldSerializeEverything || (HoursUntilCardDrops != DefaultHoursUntilCardDrops);
|
||||
public bool ShouldSerializeIdlePriorityQueueOnly() => ShouldSerializeEverything || (IdlePriorityQueueOnly != DefaultIdlePriorityQueueOnly);
|
||||
public bool ShouldSerializeIdleRefundableGames() => ShouldSerializeEverything || (IdleRefundableGames != DefaultIdleRefundableGames);
|
||||
public bool ShouldSerializeLootableTypes() => ShouldSerializeEverything || ((LootableTypes != DefaultLootableTypes) && !LootableTypes.SetEquals(DefaultLootableTypes));
|
||||
public bool ShouldSerializeMatchableTypes() => ShouldSerializeEverything || ((MatchableTypes != DefaultMatchableTypes) && !MatchableTypes.SetEquals(DefaultMatchableTypes));
|
||||
public bool ShouldSerializeOnlineStatus() => ShouldSerializeEverything || (OnlineStatus != DefaultOnlineStatus);
|
||||
public bool ShouldSerializePasswordFormat() => ShouldSerializeEverything || (PasswordFormat != DefaultPasswordFormat);
|
||||
public bool ShouldSerializePaused() => ShouldSerializeEverything || (Paused != DefaultPaused);
|
||||
public bool ShouldSerializeRedeemingPreferences() => ShouldSerializeEverything || (RedeemingPreferences != DefaultRedeemingPreferences);
|
||||
public bool ShouldSerializeSendOnFarmingFinished() => ShouldSerializeEverything || (SendOnFarmingFinished != DefaultSendOnFarmingFinished);
|
||||
public bool ShouldSerializeSendTradePeriod() => ShouldSerializeEverything || (SendTradePeriod != DefaultSendTradePeriod);
|
||||
public bool ShouldSerializeShutdownOnFarmingFinished() => ShouldSerializeEverything || (ShutdownOnFarmingFinished != DefaultShutdownOnFarmingFinished);
|
||||
public bool ShouldSerializeSSteamMasterClanID() => ShouldSerializeEverything; // We never serialize helper properties
|
||||
public bool ShouldSerializeSteamLogin() => ShouldSerializeSensitiveDetails && (ShouldSerializeEverything || (SteamLogin != DefaultSteamLogin));
|
||||
public bool ShouldSerializeSteamMasterClanID() => ShouldSerializeEverything || (SteamMasterClanID != DefaultSteamMasterClanID);
|
||||
public bool ShouldSerializeSteamParentalPIN() => ShouldSerializeSensitiveDetails && (ShouldSerializeEverything || (SteamParentalPIN != DefaultSteamParentalPIN));
|
||||
public bool ShouldSerializeSteamPassword() => ShouldSerializeSensitiveDetails && (ShouldSerializeEverything || (SteamPassword != DefaultSteamPassword));
|
||||
public bool ShouldSerializeSteamTradeToken() => ShouldSerializeEverything || (SteamTradeToken != DefaultSteamTradeToken);
|
||||
public bool ShouldSerializeSteamUserPermissions() => ShouldSerializeEverything || ((SteamUserPermissions != DefaultSteamUserPermissions) && ((SteamUserPermissions.Count != DefaultSteamUserPermissions.Count) || SteamUserPermissions.Except(DefaultSteamUserPermissions).Any()));
|
||||
public bool ShouldSerializeTradingPreferences() => ShouldSerializeEverything || (TradingPreferences != DefaultTradingPreferences);
|
||||
public bool ShouldSerializeUseLoginKeys() => ShouldSerializeEverything || (UseLoginKeys != DefaultUseLoginKeys);
|
||||
|
||||
// ReSharper restore UnusedMember.Global
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user