diff --git a/Admin/Command.cs b/Admin/Command.cs index e6cf9c71a..d7a74219a 100644 --- a/Admin/Command.cs +++ b/Admin/Command.cs @@ -189,22 +189,24 @@ namespace IW4MAdmin else { int count = 0; - String _commands = String.Empty; + StringBuilder helpResponse = new StringBuilder(); + List test = E.Owner.getCommands(); - foreach (Command C in E.Owner.getCommands()) + foreach (Command C in test) { if (E.Origin.Level >= C.Permission) { - _commands = _commands + " [^3" + C.Name + "^7] "; + helpResponse.Append(" [^3" + C.Name + "^7] "); if (count >= 4) { - E.Origin.Tell(_commands); - _commands = String.Empty; + E.Origin.Tell(helpResponse.ToString()); + helpResponse = new StringBuilder(); count = 0; } count++; } } + E.Origin.Tell(helpResponse.ToString()); E.Origin.Tell("Type !help to get command usage example"); } } diff --git a/Admin/Plugins.cs b/Admin/Plugins.cs index 43a7803b2..03c6a8eb9 100644 --- a/Admin/Plugins.cs +++ b/Admin/Plugins.cs @@ -8,14 +8,12 @@ namespace IW4MAdmin { public class PluginImporter { - public static List potentialCommands; - public static List potentialNotifies; + public static List potentialCommands = new List(); + public static List potentialPlugins = new List(); public static bool Load() { string[] dllFileNames = null; - potentialCommands = new List(); - potentialNotifies = new List(); if (Directory.Exists(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\plugins")) dllFileNames = Directory.GetFiles(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\plugins", "*.dll"); @@ -35,8 +33,8 @@ namespace IW4MAdmin ICollection assemblies = new List(dllFileNames.Length); foreach (string dllFile in dllFileNames) { - AssemblyName an = AssemblyName.GetAssemblyName(dllFile); - Assembly assembly = Assembly.Load(an); + byte[] rawDLL = File.ReadAllBytes(dllFile); // because we want to update the plugin without restarting + Assembly assembly = Assembly.Load(rawDLL); assemblies.Add(assembly); } @@ -52,8 +50,21 @@ namespace IW4MAdmin { Object notifyObject = Activator.CreateInstance(assemblyType); Plugin newNotify = (Plugin)notifyObject; - potentialNotifies.Add(newNotify); - newNotify.onLoad(); + potentialPlugins.Add(newNotify); + + try + { + newNotify.onLoad(); + } + + catch (Exception E) + { + Program.getManager().mainLog.Write("There was an error starting \"" + newNotify.Name + "\" plugin", Log.Level.Debug); + Program.getManager().mainLog.Write("Error Message: " + E.Message, Log.Level.Debug); + Program.getManager().mainLog.Write("Error Trace: " + E.StackTrace, Log.Level.Debug); + continue; + } + Program.getManager().mainLog.Write("Loaded plugin \"" + newNotify.Name + "\"" + " [" + newNotify.Version + "]", Log.Level.Debug); totalLoaded++; } @@ -73,5 +84,28 @@ namespace IW4MAdmin Program.getManager().mainLog.Write("Loaded " + totalLoaded + " plugins.", Log.Level.Production); return true; } + + public static void Unload() + { + foreach (Plugin P in potentialPlugins) + { + try + { + P.onUnload(); + } + + catch (Exception E) + { + Program.getManager().mainLog.Write("There was an error unloading \"" + P.Name + "\" plugin", Log.Level.Debug); + Program.getManager().mainLog.Write("Error Message: " + E.Message, Log.Level.Debug); + Program.getManager().mainLog.Write("Error Trace: " + E.StackTrace, Log.Level.Debug); + continue; + } + } + + potentialCommands = new List(); + potentialPlugins = new List(); + + } } } diff --git a/Admin/Server.cs b/Admin/Server.cs index bcf9424d0..45aa43e0f 100644 --- a/Admin/Server.cs +++ b/Admin/Server.cs @@ -428,7 +428,7 @@ namespace IW4MAdmin { Event curEvent = events.Peek(); processEvent(curEvent); - foreach (Plugin P in PluginImporter.potentialNotifies) + foreach (Plugin P in PluginImporter.potentialPlugins) { try { @@ -884,6 +884,7 @@ namespace IW4MAdmin initMaps(); initMessages(); initRules(); + PluginImporter.Unload(); PluginImporter.Load(); return true; } diff --git a/Admin/lib/SharedLibary.dll b/Admin/lib/SharedLibary.dll index ce631ff94..9c9a72cb1 100644 Binary files a/Admin/lib/SharedLibary.dll and b/Admin/lib/SharedLibary.dll differ diff --git a/Admin/plugins/SamplePlugin.dll b/Admin/plugins/SamplePlugin.dll index df6183d27..5eb61a6df 100644 Binary files a/Admin/plugins/SamplePlugin.dll and b/Admin/plugins/SamplePlugin.dll differ diff --git a/Admin/plugins/WebfrontPlugin.dll b/Admin/plugins/WebfrontPlugin.dll index 38d4afa92..8ac2cbfed 100644 Binary files a/Admin/plugins/WebfrontPlugin.dll and b/Admin/plugins/WebfrontPlugin.dll differ diff --git a/Release Build/lib/SharedLibary.dll b/Release Build/lib/SharedLibary.dll index ce631ff94..9c9a72cb1 100644 Binary files a/Release Build/lib/SharedLibary.dll and b/Release Build/lib/SharedLibary.dll differ diff --git a/Release Build/plugins/SamplePlugin.dll b/Release Build/plugins/SamplePlugin.dll index df6183d27..5eb61a6df 100644 Binary files a/Release Build/plugins/SamplePlugin.dll and b/Release Build/plugins/SamplePlugin.dll differ diff --git a/SamplePlugin/Main.cs b/SamplePlugin/Main.cs index f1ec7207f..1a5f7e81f 100644 --- a/SamplePlugin/Main.cs +++ b/SamplePlugin/Main.cs @@ -118,6 +118,11 @@ namespace SamplePlugin playerStats = new StatsDB("stats.rm"); } + public override void onUnload() + { + + } + public override string Name { get { return "Basic Stats"; } diff --git a/SharedLibary/Player.cs b/SharedLibary/Player.cs index 11d986fac..88fa4ae71 100644 --- a/SharedLibary/Player.cs +++ b/SharedLibary/Player.cs @@ -130,22 +130,22 @@ namespace SharedLibrary public void Kick(String Message) { - currentServer.Kick(Message, this); + lastEvent.Owner.Kick(Message, this); } public void tempBan(String Message) { - currentServer.tempBan(Message, this); + lastEvent.Owner.tempBan(Message, this); } public void Ban(String Message, Player Sender) { - currentServer.Ban(Message, this, Sender); + lastEvent.Owner.Ban(Message, this, Sender); } public void Alert() { - currentServer.Alert(this); + lastEvent.Owner.Alert(this); } public String Name { get; private set; } diff --git a/SharedLibary/Plugin.cs b/SharedLibary/Plugin.cs index d155c8f1b..c600d78d6 100644 --- a/SharedLibary/Plugin.cs +++ b/SharedLibary/Plugin.cs @@ -8,6 +8,7 @@ namespace SharedLibrary public abstract class Plugin { public abstract void onLoad(); + public abstract void onUnload(); public abstract void onEvent(Event E); //for logging purposes diff --git a/Webfront Plugin/Main.cs b/Webfront Plugin/Main.cs index c577b20bf..cb2a8b11e 100644 --- a/Webfront Plugin/Main.cs +++ b/Webfront Plugin/Main.cs @@ -7,6 +7,7 @@ namespace Webfront_Plugin public class Webfront : Plugin { private static Manager webManager; + private static Thread webManagerThread; public override void onEvent(Event E) { @@ -28,12 +29,18 @@ namespace Webfront_Plugin public override void onLoad() { webManager = new Manager(); - Thread webManagerThread = new Thread(new ThreadStart(webManager.Init)); + webManagerThread = new Thread(new ThreadStart(webManager.Init)); webManagerThread.Name = "Webfront"; webManagerThread.Start(); } + public override void onUnload() + { + webManager.webScheduler.Stop(); + webManagerThread.Join(); + } + public override String Name { get { return "Webfront"; }