From 14f58d5aec25796adc33f7f147eef111684e8561 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Sun, 29 Nov 2020 16:15:20 +0100 Subject: [PATCH] Code cleanup --- .../ExamplePlugin.cs | 8 +- ArchiSteamFarm/BotConfig.cs | 6 +- ArchiSteamFarm/GlobalConfig.cs | 112 +++++++++--------- ...actorAuthenticationConfirmationsRequest.cs | 24 ++-- 4 files changed, 75 insertions(+), 75 deletions(-) diff --git a/ArchiSteamFarm.CustomPlugins.ExamplePlugin/ExamplePlugin.cs b/ArchiSteamFarm.CustomPlugins.ExamplePlugin/ExamplePlugin.cs index fa6bceb54..6ce49ffe2 100644 --- a/ArchiSteamFarm.CustomPlugins.ExamplePlugin/ExamplePlugin.cs +++ b/ArchiSteamFarm.CustomPlugins.ExamplePlugin/ExamplePlugin.cs @@ -39,10 +39,6 @@ namespace ArchiSteamFarm.CustomPlugins.ExamplePlugin { // This will keep your code compact, efficient and less dependent. You can always add additional interfaces when you'll need them, this example project will inherit quite a bit of them to show you potential usage // ReSharper disable once UnusedType.Global - this is example plugin class that isn't used in our main code internal sealed class ExamplePlugin : IASF, IBot, IBotCommand, IBotConnection, IBotFriendRequest, IBotMessage, IBotModules, IBotTradeOffer { - // Plugins can expose custom properties for our GET /Api/Plugins API call, simply annotate them with [JsonProperty] (or keep public) - [JsonProperty] - public bool CustomIsEnabledField { get; private set; } = true; - // This is used for identification purposes, typically you want to use a friendly name of your plugin here, such as the name of your main class // Please note that this property can have direct dependencies only on structures that were initialized by the constructor, as it's possible to be called before OnLoaded() takes place public string Name => nameof(ExamplePlugin); @@ -51,6 +47,10 @@ namespace ArchiSteamFarm.CustomPlugins.ExamplePlugin { // Please note that this property can have direct dependencies only on structures that were initialized by the constructor, as it's possible to be called before OnLoaded() takes place public Version Version => typeof(ExamplePlugin).Assembly.GetName().Version ?? throw new InvalidOperationException(nameof(Version)); + // Plugins can expose custom properties for our GET /Api/Plugins API call, simply annotate them with [JsonProperty] (or keep public) + [JsonProperty] + public bool CustomIsEnabledField { get; private set; } = true; + // This method, apart from being called before any bot initialization takes place, allows you to read custom global config properties that are not recognized by ASF // Thanks to that, you can extend default ASF config with your own stuff, then parse it here in order to customize your plugin during runtime // Keep in mind that, as noted in the interface, additionalConfigProperties can be null if no custom, unrecognized properties are found by ASF, you should handle that case appropriately diff --git a/ArchiSteamFarm/BotConfig.cs b/ArchiSteamFarm/BotConfig.cs index 56a492556..f97eeb665 100644 --- a/ArchiSteamFarm/BotConfig.cs +++ b/ArchiSteamFarm/BotConfig.cs @@ -200,6 +200,9 @@ namespace ArchiSteamFarm { [JsonProperty(Required = Required.DisallowNull)] public bool ShutdownOnFarmingFinished { get; private set; } = DefaultShutdownOnFarmingFinished; + [JsonProperty(Required = Required.DisallowNull)] + public ulong SteamMasterClanID { get; private set; } = DefaultSteamMasterClanID; + [JsonProperty] public string? SteamTradeToken { get; private set; } = DefaultSteamTradeToken; @@ -215,9 +218,6 @@ namespace ArchiSteamFarm { [JsonProperty(Required = Required.DisallowNull)] public bool UseLoginKeys { get; private set; } = DefaultUseLoginKeys; - [JsonProperty(Required = Required.DisallowNull)] - public ulong SteamMasterClanID { get; private set; } = DefaultSteamMasterClanID; - [JsonExtensionData] internal Dictionary? AdditionalProperties { get; diff --git a/ArchiSteamFarm/GlobalConfig.cs b/ArchiSteamFarm/GlobalConfig.cs index 2972775c9..b9dcc83bc 100644 --- a/ArchiSteamFarm/GlobalConfig.cs +++ b/ArchiSteamFarm/GlobalConfig.cs @@ -126,6 +126,56 @@ namespace ArchiSteamFarm { private static readonly SemaphoreSlim WriteSemaphore = new(1, 1); + [JsonIgnore] + [PublicAPI] + public WebProxy? WebProxy { + get { + if (BackingWebProxy != null) { + return BackingWebProxy; + } + + if (string.IsNullOrEmpty(WebProxyText)) { + return null; + } + + Uri uri; + + try { + uri = new Uri(WebProxyText!); + } catch (UriFormatException e) { + ASF.ArchiLogger.LogGenericException(e); + + return null; + } + + WebProxy proxy = new() { + Address = uri, + BypassProxyOnLocal = true + }; + + if (!string.IsNullOrEmpty(WebProxyUsername) || !string.IsNullOrEmpty(WebProxyPassword)) { + NetworkCredential credentials = new(); + + if (!string.IsNullOrEmpty(WebProxyUsername)) { + credentials.UserName = WebProxyUsername; + } + + if (!string.IsNullOrEmpty(WebProxyPassword)) { + credentials.Password = WebProxyPassword; + } + + proxy.Credentials = credentials; + } + + BackingWebProxy = proxy; + + return proxy; + } + } + + [JsonProperty] + internal readonly string? IPCPassword = DefaultIPCPassword; + [JsonProperty(Required = Required.DisallowNull)] public bool AutoRestart { get; private set; } = DefaultAutoRestart; @@ -186,6 +236,12 @@ namespace ArchiSteamFarm { [JsonProperty] public string? SteamMessagePrefix { get; private set; } = DefaultSteamMessagePrefix; + [JsonProperty(Required = Required.DisallowNull)] + public ulong SteamOwnerID { get; private set; } = DefaultSteamOwnerID; + + [JsonProperty(Required = Required.DisallowNull)] + public ProtocolTypes SteamProtocols { get; private set; } = DefaultSteamProtocols; + [JsonProperty(Required = Required.DisallowNull)] public EUpdateChannel UpdateChannel { get; private set; } = DefaultUpdateChannel; @@ -195,68 +251,12 @@ namespace ArchiSteamFarm { [JsonProperty(Required = Required.DisallowNull)] public ushort WebLimiterDelay { get; private set; } = DefaultWebLimiterDelay; - [JsonIgnore] - [PublicAPI] - public WebProxy? WebProxy { - get { - if (BackingWebProxy != null) { - return BackingWebProxy; - } - - if (string.IsNullOrEmpty(WebProxyText)) { - return null; - } - - Uri uri; - - try { - uri = new Uri(WebProxyText!); - } catch (UriFormatException e) { - ASF.ArchiLogger.LogGenericException(e); - - return null; - } - - WebProxy proxy = new() { - Address = uri, - BypassProxyOnLocal = true - }; - - if (!string.IsNullOrEmpty(WebProxyUsername) || !string.IsNullOrEmpty(WebProxyPassword)) { - NetworkCredential credentials = new(); - - if (!string.IsNullOrEmpty(WebProxyUsername)) { - credentials.UserName = WebProxyUsername; - } - - if (!string.IsNullOrEmpty(WebProxyPassword)) { - credentials.Password = WebProxyPassword; - } - - proxy.Credentials = credentials; - } - - BackingWebProxy = proxy; - - return proxy; - } - } - [JsonProperty(PropertyName = nameof(WebProxy))] public string? WebProxyText { get; private set; } = DefaultWebProxyText; [JsonProperty] public string? WebProxyUsername { get; private set; } = DefaultWebProxyUsername; - [JsonProperty] - internal readonly string? IPCPassword = DefaultIPCPassword; - - [JsonProperty(Required = Required.DisallowNull)] - public ulong SteamOwnerID { get; private set; } = DefaultSteamOwnerID; - - [JsonProperty(Required = Required.DisallowNull)] - public ProtocolTypes SteamProtocols { get; private set; } = DefaultSteamProtocols; - [JsonExtensionData] internal Dictionary? AdditionalProperties { get; diff --git a/ArchiSteamFarm/IPC/Requests/TwoFactorAuthenticationConfirmationsRequest.cs b/ArchiSteamFarm/IPC/Requests/TwoFactorAuthenticationConfirmationsRequest.cs index d54f97290..3b16f6342 100644 --- a/ArchiSteamFarm/IPC/Requests/TwoFactorAuthenticationConfirmationsRequest.cs +++ b/ArchiSteamFarm/IPC/Requests/TwoFactorAuthenticationConfirmationsRequest.cs @@ -36,24 +36,18 @@ namespace ArchiSteamFarm.IPC.Requests { [JsonProperty(Required = Required.Always)] public bool Accept { get; private set; } - /// - /// Specifies the type of confirmations to handle. If not provided, all confirmation types are considered for an action. - /// - [JsonProperty(Required = Required.DisallowNull)] - public MobileAuthenticator.Confirmation.EType? AcceptedType { get; private set; } - - /// - /// Specifies whether we should wait for the confirmations to arrive, in case they're not available immediately. This option makes sense only if 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. - /// - [JsonProperty(Required = Required.DisallowNull)] - public bool WaitIfNeeded { get; private set; } - /// /// 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. /// [JsonProperty(Required = Required.DisallowNull)] public ImmutableHashSet? AcceptedCreatorIDs { get; private set; } + /// + /// Specifies the type of confirmations to handle. If not provided, all confirmation types are considered for an action. + /// + [JsonProperty(Required = Required.DisallowNull)] + public MobileAuthenticator.Confirmation.EType? AcceptedType { get; private set; } + /// /// A helper property which works the same as but with values written as strings - for javascript compatibility purposes. Use either this one, or , not both. /// @@ -80,6 +74,12 @@ namespace ArchiSteamFarm.IPC.Requests { } } + /// + /// Specifies whether we should wait for the confirmations to arrive, in case they're not available immediately. This option makes sense only if 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. + /// + [JsonProperty(Required = Required.DisallowNull)] + public bool WaitIfNeeded { get; private set; } + [JsonConstructor] private TwoFactorAuthenticationConfirmationsRequest() { } }