Skip to content
This repository has been archived by the owner on May 6, 2023. It is now read-only.

Commit

Permalink
Fixed reload network issue and config reading
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlOfDuty committed Dec 21, 2018
1 parent e877f30 commit bac5be7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
1 change: 1 addition & 0 deletions SCPDiscordPlugin/NetworkSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ private static void Connect(string address, int port)
public static void Disconnect()
{
socket.Disconnect(false);
socket = null;
}
/// ///////////////////////////////////////////////

Expand Down
56 changes: 31 additions & 25 deletions SCPDiscordPlugin/SCPDiscord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using YamlDotNet.Core;
using System.Threading.Tasks;

namespace SCPDiscord
{
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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"))
Expand All @@ -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)
Expand Down

0 comments on commit bac5be7

Please sign in to comment.