mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 14:10:53 +00:00
Introduce concept of official plugins
This commit is contained in:
@@ -36,7 +36,7 @@ using SteamKit2;
|
||||
namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
||||
[Export(typeof(IPlugin))]
|
||||
[UsedImplicitly]
|
||||
internal sealed class SteamTokenDumperPlugin : IASF, IBot, IBotSteamClient, ISteamPICSChanges {
|
||||
internal sealed class SteamTokenDumperPlugin : OfficialPlugin, IASF, IBot, IBotSteamClient, ISteamPICSChanges {
|
||||
private static readonly ConcurrentDictionary<Bot, IDisposable> BotSubscriptions = new ConcurrentDictionary<Bot, IDisposable>();
|
||||
private static readonly ConcurrentDictionary<Bot, (SemaphoreSlim RefreshSemaphore, Timer RefreshTimer)> BotSynchronizations = new ConcurrentDictionary<Bot, (SemaphoreSlim RefreshSemaphore, Timer RefreshTimer)>();
|
||||
private static readonly SemaphoreSlim SubmissionSemaphore = new SemaphoreSlim(1, 1);
|
||||
@@ -45,9 +45,9 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
||||
private static GlobalCache GlobalCache;
|
||||
private static bool IsEnabled;
|
||||
|
||||
public string Name => nameof(SteamTokenDumperPlugin);
|
||||
public override string Name => nameof(SteamTokenDumperPlugin);
|
||||
|
||||
public Version Version => typeof(SteamTokenDumperPlugin).Assembly.GetName().Version ?? throw new ArgumentNullException(nameof(Version));
|
||||
public override Version Version => typeof(SteamTokenDumperPlugin).Assembly.GetName().Version ?? throw new ArgumentNullException(nameof(Version));
|
||||
|
||||
public Task<uint> GetPreferredChangeNumberToStartFrom() => Task.FromResult(IsEnabled ? GlobalCache?.LastChangeNumber ?? 0 : 0);
|
||||
|
||||
@@ -146,7 +146,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
||||
|
||||
public IReadOnlyCollection<ClientMsgHandler> OnBotSteamHandlersInit(Bot bot) => null;
|
||||
|
||||
public void OnLoaded() { }
|
||||
public override void OnLoaded() { }
|
||||
|
||||
public async void OnPICSChanges(uint currentChangeNumber, IReadOnlyDictionary<uint, SteamApps.PICSChangesCallback.PICSChangeData> appChanges, IReadOnlyDictionary<uint, SteamApps.PICSChangesCallback.PICSChangeData> packageChanges) {
|
||||
if ((currentChangeNumber == 0) || (appChanges == null) || (packageChanges == null)) {
|
||||
|
||||
@@ -22,3 +22,4 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("ArchiSteamFarm.Tests")]
|
||||
[assembly: InternalsVisibleTo("ArchiSteamFarm.OfficialPlugins.SteamTokenDumper")]
|
||||
|
||||
32
ArchiSteamFarm/Plugins/OfficialPlugin.cs
Normal file
32
ArchiSteamFarm/Plugins/OfficialPlugin.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
// _ _ _ ____ _ _____
|
||||
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
|
||||
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
|
||||
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
|
||||
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
|
||||
// |
|
||||
// Copyright 2015-2020 Ł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;
|
||||
|
||||
namespace ArchiSteamFarm.Plugins {
|
||||
internal abstract class OfficialPlugin : IPlugin {
|
||||
public abstract string Name { get; }
|
||||
public abstract Version Version { get; }
|
||||
public abstract void OnLoaded();
|
||||
|
||||
internal bool HasSameVersion() => Version == SharedInfo.Version;
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,9 @@ using SteamKit2;
|
||||
|
||||
namespace ArchiSteamFarm.Plugins {
|
||||
internal static class PluginsCore {
|
||||
internal static bool HasActivePluginsLoaded => ActivePlugins?.Count > 0;
|
||||
internal static bool HasCustomPluginsLoaded => !HasActivePluginsLoaded || ActivePlugins.All(plugin => plugin is OfficialPlugin officialPlugin && officialPlugin.HasSameVersion());
|
||||
|
||||
private static bool HasActivePluginsLoaded => ActivePlugins?.Count > 0;
|
||||
|
||||
[ImportMany]
|
||||
private static ImmutableHashSet<IPlugin> ActivePlugins { get; set; }
|
||||
@@ -147,10 +149,13 @@ namespace ArchiSteamFarm.Plugins {
|
||||
}
|
||||
|
||||
ActivePlugins = activePlugins.ToImmutableHashSet();
|
||||
ASF.ArchiLogger.LogGenericInfo(Strings.PluginsWarning);
|
||||
|
||||
// Loading plugins changes the program identifier, refresh the console title
|
||||
Console.Title = SharedInfo.ProgramIdentifier;
|
||||
if (HasCustomPluginsLoaded) {
|
||||
ASF.ArchiLogger.LogGenericInfo(Strings.PluginsWarning);
|
||||
|
||||
// Loading plugins changes the program identifier, refresh the console title
|
||||
Console.Title = SharedInfo.ProgramIdentifier;
|
||||
}
|
||||
|
||||
return invalidPlugins.Count == 0;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace ArchiSteamFarm {
|
||||
internal static string ProgramIdentifier => PublicIdentifier + " V" + Version + " (" + BuildInfo.Variant + "/" + ModuleVersion + " | " + OS.Variant + ")";
|
||||
|
||||
[NotNull]
|
||||
internal static string PublicIdentifier => AssemblyName + (BuildInfo.IsCustomBuild ? "-custom" : PluginsCore.HasActivePluginsLoaded ? "-modded" : "");
|
||||
internal static string PublicIdentifier => AssemblyName + (BuildInfo.IsCustomBuild ? "-custom" : PluginsCore.HasCustomPluginsLoaded ? "-modded" : "");
|
||||
|
||||
[NotNull]
|
||||
internal static Version Version => Assembly.GetEntryAssembly()?.GetName().Version ?? throw new ArgumentNullException(nameof(Version));
|
||||
|
||||
Reference in New Issue
Block a user