diff --git a/Admin/Manager.cs b/Admin/Manager.cs index 84e8f8b1..296fd802 100644 --- a/Admin/Manager.cs +++ b/Admin/Manager.cs @@ -75,6 +75,9 @@ namespace IW4MAdmin { try { + foreach (var Plugin in SharedLibrary.Plugins.PluginImporter.ActivePlugins) + await Plugin.OnLoadAsync(ServerInstance); + await ServerInstance.Initialize(); Servers.Add(ServerInstance); @@ -82,9 +85,6 @@ namespace IW4MAdmin var Status = new SharedLibrary.Helpers.AsyncStatus(ServerInstance, UPDATE_FREQUENCY); TaskStatuses.Add(Status); - foreach (var Plugin in SharedLibrary.Plugins.PluginImporter.ActivePlugins) - await Plugin.OnLoadAsync(ServerInstance); - Logger.WriteVerbose($"Now monitoring {ServerInstance.Hostname}"); } diff --git a/Admin/lib/SharedLibrary.dll b/Admin/lib/SharedLibrary.dll index 215d2676..1e1e4970 100644 Binary files a/Admin/lib/SharedLibrary.dll and b/Admin/lib/SharedLibrary.dll differ diff --git a/Plugins/FastRestart/Plugin.cs b/Plugins/FastRestart/Plugin.cs index 8137a786..6f3b5ffa 100644 --- a/Plugins/FastRestart/Plugin.cs +++ b/Plugins/FastRestart/Plugin.cs @@ -1,5 +1,6 @@ using System; using System.Threading.Tasks; +using System.Collections.Generic; using SharedLibrary; using SharedLibrary.Interfaces; @@ -19,11 +20,8 @@ namespace Plugin public override async Task ExecuteAsync(Event E) { - var Config = new FastRestartConfig() { Enabled = true }; - if (!new Configuration(E.Owner).Write(Config)) - await E.Origin.Tell("Failed to save the configuration file for fast restart"); - else - await E.Origin.Tell("Fast restarting is now enabled for this server"); + FastRestartPlugin.ConfigManager.UpdateProperty(E.Owner, new KeyValuePair("Enabled", true)); + await E.Origin.Tell("Fast restarting is now enabled for this server"); } } @@ -33,11 +31,8 @@ namespace Plugin public override async Task ExecuteAsync(Event E) { - var Config = new FastRestartConfig() { Enabled = false }; - if (!new Configuration(E.Owner).Write(Config)) - await E.Origin.Tell("Failed to save the configuration file for fast restart"); - else - await E.Origin.Tell("Fast restarting is now disabled for this server"); + FastRestartPlugin.ConfigManager.UpdateProperty(E.Owner, new KeyValuePair("Enabled", false)); + await E.Origin.Tell("Fast restarting is now disabled for this server"); } } @@ -46,6 +41,8 @@ namespace Plugin bool MatchEnded; DateTime MatchEndTime; + public static ConfigurationManager ConfigManager { get; private set; } + public string Name { get { return "Fast Restarter"; } } public float Version { get { return 1.0f; } } @@ -70,13 +67,16 @@ namespace Plugin public async Task OnLoadAsync(Server S) { - // this initializes the file if it doesn't exist already - new Configuration(S).Read(); + ConfigManager = new ConfigurationManager(typeof(FastRestartPlugin)); + ConfigManager.AddConfiguration(S); + + if (ConfigManager.GetConfiguration(S).Keys.Count == 0) + ConfigManager.AddProperty(S, new KeyValuePair("Enabled", false)); } public async Task OnTickAsync(Server S) { - if (!new Configuration(S).Read().Enabled) + if ((bool)ConfigManager.GetConfiguration(S)["Enabled"] == false) return; MatchEnded = (await S.GetDvarAsync("scr_gameended")).Value == 1; diff --git a/Plugins/VoteMap/Plugin.cs b/Plugins/VoteMap/Plugin.cs index f8a1afe2..fad69f6b 100644 --- a/Plugins/VoteMap/Plugin.cs +++ b/Plugins/VoteMap/Plugin.cs @@ -222,6 +222,7 @@ namespace Votemap_Plugin /// public async Task OnTickAsync(Server S) { + return; var serverVotes = getServerVotes(S.GetPort()); if (serverVotes != null) @@ -280,6 +281,7 @@ namespace Votemap_Plugin public async Task OnEventAsync(Event E, Server S) { + return; if (E.Type == Event.GType.Start) { serverVotingList.Add(new ServerVoting(S.GetPort())); diff --git a/SharedLibrary/Helpers/Configuration.cs b/SharedLibrary/Helpers/Configuration.cs deleted file mode 100644 index d8bdec09..00000000 --- a/SharedLibrary/Helpers/Configuration.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SharedLibrary.Helpers -{ - public class Configuration : Interfaces.Serialize - { - string FilePostfix; - public Configuration(Server S) - { - FilePostfix = $"_{S.GetIP()}_{S.GetPort()}.cfg"; - } - - public T Read() - { - try - { - return Read(); - } - - catch (Exceptions.SerializeException) - { - return default(T); - } - } - - public bool Write(T Data) - { - try - { - Write(Filename(), Data); - return true; - } - - catch(Exceptions.SerializeException) - { - return false; - } - } - - public override string Filename() - { - return $"config/{typeof(T).ToString()}_{FilePostfix}"; - } - - } -} diff --git a/SharedLibrary/Helpers/ConfigurationManager.cs b/SharedLibrary/Helpers/ConfigurationManager.cs new file mode 100644 index 00000000..b5777bef --- /dev/null +++ b/SharedLibrary/Helpers/ConfigurationManager.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; + +namespace SharedLibrary.Helpers +{ + public class ConfigurationManager + { + Dictionary> ConfigurationSet; + Type PluginType; + + public ConfigurationManager(Type PluginType) + { + ConfigurationSet = new Dictionary>(); + this.PluginType = PluginType; + } + + public void AddConfiguration(Server S) + { + try + { + var Config = Interfaces.Serialize>.Read($"config/{PluginType.ToString()}_{S.ToString()}.cfg"); + ConfigurationSet.Add(S.ToString(), Config); + } + + catch(Exceptions.SerializeException) + { + ConfigurationSet.Add(S.ToString(), new Dictionary()); + } + } + + public void AddProperty(Server S, KeyValuePair Property) + { + ConfigurationSet[S.ToString()].Add(Property.Key, Property.Value); + Interfaces.Serialize>.Write($"config/{PluginType.ToString()}_{S.ToString()}.cfg", ConfigurationSet[S.ToString()]); + } + + public void UpdateProperty(Server S, KeyValuePair Property) + { + ConfigurationSet[S.ToString()][Property.Key] = Property.Value; + Interfaces.Serialize>.Write($"config/{PluginType.ToString()}_{S.ToString()}.cfg", ConfigurationSet[S.ToString()]); + } + + public IDictionary GetConfiguration(Server S) + { + return ConfigurationSet[S.ToString()]; + } + } +} diff --git a/SharedLibrary/Interfaces/ISerializable.cs b/SharedLibrary/Interfaces/ISerializable.cs index 12f996aa..9a6f4484 100644 --- a/SharedLibrary/Interfaces/ISerializable.cs +++ b/SharedLibrary/Interfaces/ISerializable.cs @@ -23,7 +23,7 @@ namespace SharedLibrary.Interfaces catch (Exception e) { - throw new Exceptions.SerializeException($"Could not desialize file {filename}: {e.Message}"); + throw new Exceptions.SerializeException($"Could not deserialize file {filename}: {e.Message}"); } } diff --git a/SharedLibrary/SharedLibrary.csproj b/SharedLibrary/SharedLibrary.csproj index 9715bf8f..af6638ce 100644 --- a/SharedLibrary/SharedLibrary.csproj +++ b/SharedLibrary/SharedLibrary.csproj @@ -73,7 +73,7 @@ - +