From bac5be7ba48b180b418bf408480d467a78a4b825 Mon Sep 17 00:00:00 2001 From: Karl Essinger Date: Sat, 22 Dec 2018 00:21:34 +0100 Subject: [PATCH] Fixed reload network issue and config reading --- SCPDiscordPlugin/NetworkSystem.cs | 1 + SCPDiscordPlugin/SCPDiscord.cs | 56 +++++++++++++++++-------------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/SCPDiscordPlugin/NetworkSystem.cs b/SCPDiscordPlugin/NetworkSystem.cs index d01bcd1a..7ee2d807 100644 --- a/SCPDiscordPlugin/NetworkSystem.cs +++ b/SCPDiscordPlugin/NetworkSystem.cs @@ -183,6 +183,7 @@ private static void Connect(string address, int port) public static void Disconnect() { socket.Disconnect(false); + socket = null; } /// /////////////////////////////////////////////// diff --git a/SCPDiscordPlugin/SCPDiscord.cs b/SCPDiscordPlugin/SCPDiscord.cs index f58a2274..5c63ffc6 100644 --- a/SCPDiscordPlugin/SCPDiscord.cs +++ b/SCPDiscordPlugin/SCPDiscord.cs @@ -16,6 +16,7 @@ using Newtonsoft.Json.Linq; using Newtonsoft.Json; using YamlDotNet.Core; +using System.Threading.Tasks; namespace SCPDiscord { @@ -24,7 +25,7 @@ namespace SCPDiscord name = "SCPDiscord", description = "SCP:SL - Discord bridge.", id = "karlofduty.scpdiscord", - version = "1.0.0-B", + version = "1.0.0-C", SmodMajor = 3, SmodMinor = 2, SmodRevision = 0 @@ -55,6 +56,33 @@ public override void Register() this.AddConfig(new Smod2.Config.ConfigSetting("scpdiscord_config", "config.yml", Smod2.Config.SettingType.STRING, true, "Name of the config file to use, by default 'config.yml'")); } + public override void OnEnable() + { + plugin = this; + + serverStartTime.Start(); + this.AddCommand("scpd_rc", new ReconnectCommand(this)); + this.AddCommand("scpd_reconnect", new ReconnectCommand(this)); + this.AddCommand("scpd_reload", new ReloadCommand(this)); + this.AddCommand("scpd_unsync", new UnsyncCommand(this)); + this.AddCommand("scpd_verbose", new VerboseCommand(this)); + this.AddCommand("scpd_debug", new DebugCommand(this)); + + + Task.Run(() => + { + Thread.Sleep(2000); + SetUpFileSystem(); + LoadConfig(); + roleSync = new RoleSync(this); + + Language.Reload(); + Thread connectionThread = new Thread(new ThreadStart(() => new StartNetworkSystem(plugin))); + connectionThread.Start(); + this.Info("SCPDiscord " + this.Details.version + " enabled."); + }); + } + class ReconnectCommand : ICommandHandler { private SCPDiscord plugin; @@ -109,6 +137,7 @@ public string[] OnCall(ICommandSender sender, string[] args) { plugin.Info("Reloading plugin..."); Config.Reload(plugin); + plugin.Info("Successfully loaded config '" + plugin.GetConfigString("scpdiscord_config") + "'."); Language.Reload(); plugin.roleSync.Reload(); if(NetworkSystem.IsConnected()) @@ -201,29 +230,6 @@ public string[] OnCall(ICommandSender sender, string[] args) } } - public override void OnEnable() - { - Thread.Sleep(2000); - plugin = this; - - serverStartTime.Start(); - this.AddCommand("scpd_rc", new ReconnectCommand(this)); - this.AddCommand("scpd_reconnect", new ReconnectCommand(this)); - this.AddCommand("scpd_reload", new ReloadCommand(this)); - this.AddCommand("scpd_unsync", new UnsyncCommand(this)); - this.AddCommand("scpd_verbose", new VerboseCommand(this)); - this.AddCommand("scpd_debug", new DebugCommand(this)); - - SetUpFileSystem(); - LoadConfig(); - roleSync = new RoleSync(this); - - Language.Reload(); - Thread connectionThread = new Thread(new ThreadStart(() => new StartNetworkSystem(plugin))); - connectionThread.Start(); - this.Info("SCPDiscord " + this.Details.version + " enabled."); - } - public void SetUpFileSystem() { if (!Directory.Exists(FileManager.GetAppFolder() + "SCPDiscord")) @@ -248,7 +254,7 @@ public void LoadConfig() { try { - Config.Reload(this); + Config.Reload(plugin); this.Info("Successfully loaded config '" + GetConfigString("scpdiscord_config") + "'."); } catch (Exception e)