diff --git a/TGCommandLine/AdminCommands.cs b/TGCommandLine/AdminCommands.cs
index b50ef3201f..9838c8eece 100644
--- a/TGCommandLine/AdminCommands.cs
+++ b/TGCommandLine/AdminCommands.cs
@@ -18,7 +18,7 @@ namespace TGCommandLine
}
}
- class AdminMoveServerCommand : Command
+ class AdminMoveServerCommand : ConsoleCommand
{
public AdminMoveServerCommand()
{
@@ -43,7 +43,7 @@ namespace TGCommandLine
return "Move the server installation (BYOND, Repo, Game) to a new location. Nothing else may be running for this task to complete";
}
}
- class AdminRecreateStaticCommand : Command
+ class AdminRecreateStaticCommand : ConsoleCommand
{
public AdminRecreateStaticCommand()
{
@@ -63,7 +63,7 @@ namespace TGCommandLine
}
}
- class AdminSetPortCommand : Command
+ class AdminSetPortCommand : ConsoleCommand
{
public AdminSetPortCommand()
{
@@ -98,7 +98,8 @@ namespace TGCommandLine
}
}
- class AdminViewPortCommand : Command {
+ class AdminViewPortCommand : ConsoleCommand
+ {
public AdminViewPortCommand()
{
Keyword = "view-port";
@@ -116,7 +117,7 @@ namespace TGCommandLine
}
}
- class AdminViewGroupCommand : Command
+ class AdminViewGroupCommand : ConsoleCommand
{
public AdminViewGroupCommand()
{
@@ -135,7 +136,7 @@ namespace TGCommandLine
}
}
- class AdminSetGroupCommand : Command
+ class AdminSetGroupCommand : ConsoleCommand
{
public AdminSetGroupCommand()
{
@@ -168,7 +169,7 @@ namespace TGCommandLine
}
}
- class AdminClearGroupCommand : Command
+ class AdminClearGroupCommand : ConsoleCommand
{
public AdminClearGroupCommand()
{
diff --git a/TGCommandLine/BYONDCommands.cs b/TGCommandLine/BYONDCommands.cs
index 12b0c1a420..875cca63a1 100644
--- a/TGCommandLine/BYONDCommands.cs
+++ b/TGCommandLine/BYONDCommands.cs
@@ -19,7 +19,7 @@ namespace TGCommandLine
}
}
- class BYONDVersionCommand : Command
+ class BYONDVersionCommand : ConsoleCommand
{
public BYONDVersionCommand()
{
@@ -48,7 +48,7 @@ namespace TGCommandLine
}
- class BYONDStatusCommand : Command
+ class BYONDStatusCommand : ConsoleCommand
{
public BYONDStatusCommand()
{
@@ -88,7 +88,7 @@ namespace TGCommandLine
}
}
- class BYONDUpdateCommand : Command
+ class BYONDUpdateCommand : ConsoleCommand
{
public BYONDUpdateCommand()
{
diff --git a/TGCommandLine/ChatCommands.cs b/TGCommandLine/ChatCommands.cs
index b5b8ee41e4..268fc39d6a 100644
--- a/TGCommandLine/ChatCommands.cs
+++ b/TGCommandLine/ChatCommands.cs
@@ -29,7 +29,7 @@ namespace TGCommandLine
return "Manages the Discord bot";
}
}
- class IRCNickCommand : Command
+ class IRCNickCommand : ConsoleCommand
{
public IRCNickCommand()
{
@@ -57,7 +57,7 @@ namespace TGCommandLine
}
}
- class ChatJoinCommand : Command
+ class ChatJoinCommand : ConsoleCommand
{
readonly int providerIndex;
public ChatJoinCommand(ChatProvider pI)
@@ -136,7 +136,7 @@ namespace TGCommandLine
}
}
- class ChatPartCommand : Command
+ class ChatPartCommand : ConsoleCommand
{
readonly int providerIndex;
public ChatPartCommand(ChatProvider pI)
@@ -206,7 +206,7 @@ namespace TGCommandLine
return ExitCode.Normal;
}
}
- class ChatListAdminsCommand : Command
+ class ChatListAdminsCommand : ConsoleCommand
{
readonly int providerIndex;
public ChatListAdminsCommand(ChatProvider pI)
@@ -265,7 +265,7 @@ namespace TGCommandLine
return ExitCode.Normal;
}
}
- class ChatReconnectCommand : Command
+ class ChatReconnectCommand : ConsoleCommand
{
readonly ChatProvider providerIndex;
public ChatReconnectCommand(ChatProvider pI)
@@ -290,7 +290,7 @@ namespace TGCommandLine
return ExitCode.Normal;
}
}
- class ChatAddminCommand : Command
+ class ChatAddminCommand : ConsoleCommand
{
readonly int providerIndex;
public ChatAddminCommand(ChatProvider pI)
@@ -337,7 +337,7 @@ namespace TGCommandLine
return ExitCode.Normal;
}
}
- class IRCAuthModeCommand : Command
+ class IRCAuthModeCommand : ConsoleCommand
{
public IRCAuthModeCommand()
{
@@ -376,7 +376,7 @@ namespace TGCommandLine
return ExitCode.Normal;
}
}
- class DiscordAuthModeCommand : Command
+ class DiscordAuthModeCommand : ConsoleCommand
{
public DiscordAuthModeCommand()
{
@@ -415,7 +415,7 @@ namespace TGCommandLine
return ExitCode.Normal;
}
}
- class IRCAuthLevelCommand : Command
+ class IRCAuthLevelCommand : ConsoleCommand
{
public IRCAuthLevelCommand()
{
@@ -463,7 +463,7 @@ namespace TGCommandLine
return ExitCode.Normal;
}
}
- class ChatDeadminCommand : Command
+ class ChatDeadminCommand : ConsoleCommand
{
readonly int providerIndex;
public ChatDeadminCommand(ChatProvider pI)
@@ -511,7 +511,7 @@ namespace TGCommandLine
}
}
- class IRCAuthCommand : Command
+ class IRCAuthCommand : ConsoleCommand
{
public IRCAuthCommand()
{
@@ -539,7 +539,7 @@ namespace TGCommandLine
}
}
- class IRCDisableAuthCommand : Command
+ class IRCDisableAuthCommand : ConsoleCommand
{
public IRCDisableAuthCommand()
{
@@ -561,7 +561,7 @@ namespace TGCommandLine
}
}
- class ChatStatusCommand : Command
+ class ChatStatusCommand : ConsoleCommand
{
readonly int providerIndex;
public ChatStatusCommand(ChatProvider pI)
@@ -594,7 +594,7 @@ namespace TGCommandLine
return ExitCode.Normal;
}
}
- class ChatEnableCommand : Command
+ class ChatEnableCommand : ConsoleCommand
{
readonly int providerIndex;
public ChatEnableCommand(ChatProvider pI)
@@ -622,7 +622,7 @@ namespace TGCommandLine
return ExitCode.Normal;
}
}
- class ChatDisableCommand : Command
+ class ChatDisableCommand : ConsoleCommand
{
readonly int providerIndex;
public ChatDisableCommand(ChatProvider pI)
@@ -651,7 +651,7 @@ namespace TGCommandLine
}
}
- class IRCServerCommand : Command
+ class IRCServerCommand : ConsoleCommand
{
public IRCServerCommand()
{
@@ -696,7 +696,7 @@ namespace TGCommandLine
}
}
- class DiscordSetTokenCommand : Command
+ class DiscordSetTokenCommand : ConsoleCommand
{
public DiscordSetTokenCommand()
{
diff --git a/TGCommandLine/ConfigCommands.cs b/TGCommandLine/ConfigCommands.cs
index 16192311e4..3f203877bb 100644
--- a/TGCommandLine/ConfigCommands.cs
+++ b/TGCommandLine/ConfigCommands.cs
@@ -18,7 +18,7 @@ namespace TGCommandLine
return "Manage settings";
}
}
- class ConfigDeleteCommand : Command
+ class ConfigDeleteCommand : ConsoleCommand
{
public ConfigDeleteCommand()
{
@@ -46,7 +46,7 @@ namespace TGCommandLine
}
}
- class ConfigListCommand : Command
+ class ConfigListCommand : ConsoleCommand
{
public ConfigListCommand()
{
@@ -79,7 +79,7 @@ namespace TGCommandLine
}
}
- class ConfigServerDirectoryCommand : Command
+ class ConfigServerDirectoryCommand : ConsoleCommand
{
public ConfigServerDirectoryCommand()
{
@@ -98,7 +98,7 @@ namespace TGCommandLine
}
}
- class ConfigDownloadCommand : Command
+ class ConfigDownloadCommand : ConsoleCommand
{
public ConfigDownloadCommand()
{
@@ -136,7 +136,7 @@ namespace TGCommandLine
}
}
- class ConfigUploadCommand : Command
+ class ConfigUploadCommand : ConsoleCommand
{
public ConfigUploadCommand()
{
diff --git a/TGCommandLine/ConsoleCommand.cs b/TGCommandLine/ConsoleCommand.cs
new file mode 100644
index 0000000000..8584017716
--- /dev/null
+++ b/TGCommandLine/ConsoleCommand.cs
@@ -0,0 +1,12 @@
+using TGServiceInterface;
+
+namespace TGCommandLine
+{
+ abstract class ConsoleCommand : Command
+ {
+ ///
+ /// The currently in use by the
+ ///
+ public static Interface Interface;
+ }
+}
diff --git a/TGCommandLine/DDCommands.cs b/TGCommandLine/DDCommands.cs
index e14f763eae..a0d073b9be 100644
--- a/TGCommandLine/DDCommands.cs
+++ b/TGCommandLine/DDCommands.cs
@@ -18,7 +18,7 @@ namespace TGCommandLine
}
}
- class DDWorldAnnounceCommand : Command
+ class DDWorldAnnounceCommand : ConsoleCommand
{
public DDWorldAnnounceCommand()
{
@@ -44,7 +44,7 @@ namespace TGCommandLine
}
}
- class DDStartCommand : Command
+ class DDStartCommand : ConsoleCommand
{
public DDStartCommand()
{
@@ -64,7 +64,7 @@ namespace TGCommandLine
}
}
- class DDStopCommand : Command
+ class DDStopCommand : ConsoleCommand
{
public DDStopCommand()
{
@@ -98,7 +98,7 @@ namespace TGCommandLine
return res == null ? ExitCode.Normal : ExitCode.ServerError;
}
}
- class DDRestartCommand : Command
+ class DDRestartCommand : ConsoleCommand
{
public DDRestartCommand()
{
@@ -132,7 +132,7 @@ namespace TGCommandLine
return "Restarts the server and watchdog optionally waiting for the current round to end";
}
}
- class DDStatusCommand : Command
+ class DDStatusCommand : ConsoleCommand
{
public DDStatusCommand()
{
@@ -157,7 +157,7 @@ namespace TGCommandLine
}
}
- class DDAutostartCommand : Command
+ class DDAutostartCommand : ConsoleCommand
{
public DDAutostartCommand()
{
@@ -195,7 +195,7 @@ namespace TGCommandLine
return "Change or check autostarting of the game server with the service";
}
}
- class DDWebclientCommand : Command
+ class DDWebclientCommand : ConsoleCommand
{
public DDWebclientCommand()
{
@@ -234,7 +234,7 @@ namespace TGCommandLine
}
}
- class DDPortCommand : Command
+ class DDPortCommand : ConsoleCommand
{
public DDPortCommand()
{
@@ -270,7 +270,7 @@ namespace TGCommandLine
}
}
- class DDSecurityCommand : Command
+ class DDSecurityCommand : ConsoleCommand
{
public DDSecurityCommand()
{
diff --git a/TGCommandLine/DMCommands.cs b/TGCommandLine/DMCommands.cs
index 4a61f9e13d..acdd7bf686 100644
--- a/TGCommandLine/DMCommands.cs
+++ b/TGCommandLine/DMCommands.cs
@@ -19,7 +19,7 @@ namespace TGCommandLine
}
}
- class DMCompileCommand : Command
+ class DMCompileCommand : ConsoleCommand
{
public DMCompileCommand()
{
@@ -75,7 +75,7 @@ namespace TGCommandLine
return "Starts a compile/update job optionally waiting for completion";
}
}
- class DMStatusCommand : Command
+ class DMStatusCommand : ConsoleCommand
{
public DMStatusCommand()
{
@@ -123,7 +123,7 @@ namespace TGCommandLine
}
}
- class DMSetProjectNameCommand : Command
+ class DMSetProjectNameCommand : ConsoleCommand
{
public DMSetProjectNameCommand()
{
@@ -147,7 +147,7 @@ namespace TGCommandLine
}
}
- class DMInitializeCommand : Command
+ class DMInitializeCommand : ConsoleCommand
{
public DMInitializeCommand()
{
@@ -197,7 +197,7 @@ namespace TGCommandLine
}
}
- class DMCancelCommand : Command
+ class DMCancelCommand : ConsoleCommand
{
public DMCancelCommand()
{
diff --git a/TGCommandLine/Program.cs b/TGCommandLine/Program.cs
index 1cc910a9cd..494cbd8bd6 100644
--- a/TGCommandLine/Program.cs
+++ b/TGCommandLine/Program.cs
@@ -9,6 +9,8 @@ namespace TGCommandLine
class Program
{
+ static bool interactive = false;
+ static Interface currentInterface;
static Command.ExitCode RunCommandLine(IList argsAsList)
{
//first lookup the connection string
@@ -51,7 +53,7 @@ namespace TGCommandLine
}
argsAsList.RemoveAt(I);
argsAsList.RemoveAt(I);
- Interface.SetRemoteLoginInformation(address, port, username, password);
+ ReplaceInterface(new Interface(address, port, username, password));
break;
}
}
@@ -62,7 +64,7 @@ namespace TGCommandLine
return Command.ExitCode.BadCommand;
}
- var res = Interface.VerifyConnection();
+ var res = currentInterface.VerifyConnection();
if (res != null)
{
Console.WriteLine("Unable to connect to service: " + res);
@@ -70,13 +72,13 @@ namespace TGCommandLine
return Command.ExitCode.ConnectionError;
}
- if (!Interface.Authenticate())
+ if (!currentInterface.Authenticate())
{
Console.WriteLine("Authentication error: Username/password/windows identity is not authorized!");
return Command.ExitCode.ConnectionError;
}
- if (!SentVMMWarning && Interface.VersionMismatch(out string error))
+ if (!SentVMMWarning && currentInterface.VersionMismatch(out string error))
{
SentVMMWarning = true;
Console.WriteLine(error);
@@ -84,7 +86,7 @@ namespace TGCommandLine
try
{
- return new CLICommand().DoRun(argsAsList);
+ return new CLICommand(currentInterface).DoRun(argsAsList);
}
catch (Exception e)
{
@@ -92,6 +94,24 @@ namespace TGCommandLine
return Command.ExitCode.ConnectionError;
};
}
+
+ static void ReplaceInterface(Interface I)
+ {
+
+ if (!interactive)
+ I.SetBadCertificateHandler((message) =>
+ {
+ foreach (var J in Environment.GetCommandLineArgs())
+ if (J.ToLower() == "--disable-ssl-verification") //im just not even going to document this because i hate it so much
+ return true;
+ return false;
+ });
+ else
+ I.SetBadCertificateHandler(BadCertificateInteractive);
+ currentInterface = I;
+ ConsoleCommand.Interface = I;
+ }
+
public static string ReadLineSecure()
{
string result = "";
@@ -138,20 +158,10 @@ namespace TGCommandLine
static int Main(string[] args)
{
+ ReplaceInterface(new Interface());
Command.OutputProcVar.Value = Console.WriteLine;
if (args.Length != 0)
- {
- Interface.SetBadCertificateHandler((message) => {
- foreach (var I in args)
- if (I.ToLower() == "--disable-ssl-verification") //im just not even going to document this because i hate it so much
- return true;
- return false;
- });
- //allow self signed certs in debug mode
return (int)RunCommandLine(new List(args));
- }
-
- Interface.SetBadCertificateHandler(BadCertificateInteractive);
Console.WriteLine("Type 'remote' to connect to a remote service");
//interactive mode
@@ -179,22 +189,22 @@ namespace TGCommandLine
var username = Console.ReadLine();
Console.Write("Enter password: ");
var password = ReadLineSecure();
- Interface.SetRemoteLoginInformation(address, port, username, password);
- var res = Interface.VerifyConnection();
+ ReplaceInterface(new Interface(address, port, username, password));
+ var res = currentInterface.VerifyConnection();
if (res != null)
{
Console.WriteLine("Unable to connect: " + res);
- Interface.MakeLocalConnection();
+ ReplaceInterface(new Interface());
}
- else if (!Interface.Authenticate())
+ else if (!currentInterface.Authenticate())
{
Console.WriteLine("Authentication error: Username/password/windows identity is not authorized! Returning to local mode...");
- Interface.MakeLocalConnection();
+ ReplaceInterface(new Interface());
}
else
{
Console.WriteLine("Connected remotely");
- if (Interface.VersionMismatch(out res))
+ if (currentInterface.VersionMismatch(out res))
{
SentVMMWarning = true;
Console.WriteLine(res);
@@ -204,7 +214,7 @@ namespace TGCommandLine
break;
case "disconnect":
SentVMMWarning = false;
- Interface.MakeLocalConnection();
+ ReplaceInterface(new Interface());
Console.WriteLine("Switch to local mode");
break;
case "quit":
@@ -212,7 +222,7 @@ namespace TGCommandLine
return (int)Command.ExitCode.Normal;
#if DEBUG
case "debug-upgrade":
- Interface.GetComponent().PrepareForUpdate();
+ currentInterface.GetComponent().PrepareForUpdate();
return (int)Command.ExitCode.Normal;
#endif
default:
diff --git a/TGCommandLine/RepoCommands.cs b/TGCommandLine/RepoCommands.cs
index 04d646e8f2..4d6d9e1204 100644
--- a/TGCommandLine/RepoCommands.cs
+++ b/TGCommandLine/RepoCommands.cs
@@ -18,7 +18,7 @@ namespace TGCommandLine
}
}
- class RepoUpdateJsonCommand : Command
+ class RepoUpdateJsonCommand : ConsoleCommand
{
public RepoUpdateJsonCommand()
{
@@ -42,7 +42,7 @@ namespace TGCommandLine
}
}
- class RepoSetupCommand : Command
+ class RepoSetupCommand : ConsoleCommand
{
public RepoSetupCommand()
{
@@ -70,7 +70,7 @@ namespace TGCommandLine
}
}
- class RepoStatusCommand : Command
+ class RepoStatusCommand : ConsoleCommand
{
public RepoStatusCommand()
{
@@ -123,7 +123,7 @@ namespace TGCommandLine
}
}
- class RepoResetCommand : Command
+ class RepoResetCommand : ConsoleCommand
{
public RepoResetCommand()
{
@@ -145,7 +145,7 @@ namespace TGCommandLine
}
}
- class RepoUpdateCommand : Command
+ class RepoUpdateCommand : ConsoleCommand
{
public RepoUpdateCommand()
{
@@ -180,7 +180,7 @@ namespace TGCommandLine
return "";
}
}
- class RepoGenChangelogCommand : Command
+ class RepoGenChangelogCommand : ConsoleCommand
{
public RepoGenChangelogCommand()
{
@@ -200,7 +200,7 @@ namespace TGCommandLine
return "Compiles the html changelog";
}
}
- class RepoPushChangelogCommand : Command
+ class RepoPushChangelogCommand : ConsoleCommand
{
public RepoPushChangelogCommand()
{
@@ -219,7 +219,7 @@ namespace TGCommandLine
return "Pushes the html changelog if the SSH authentication is configured correctly";
}
}
- class RepoSetEmailCommand : Command
+ class RepoSetEmailCommand : ConsoleCommand
{
public RepoSetEmailCommand()
{
@@ -241,7 +241,7 @@ namespace TGCommandLine
return "Set the e-mail used for commits";
}
}
- class RepoSetNameCommand : Command
+ class RepoSetNameCommand : ConsoleCommand
{
public RepoSetNameCommand()
{
@@ -262,7 +262,7 @@ namespace TGCommandLine
return "Set the name used for commits";
}
}
- class RepoPythonPathCommand : Command
+ class RepoPythonPathCommand : ConsoleCommand
{
public RepoPythonPathCommand()
{
@@ -284,7 +284,7 @@ namespace TGCommandLine
}
}
- class RepoMergePRCommand : Command
+ class RepoMergePRCommand : ConsoleCommand
{
public RepoMergePRCommand()
{
@@ -319,7 +319,7 @@ namespace TGCommandLine
}
}
- class RepoListPRsCommand : Command
+ class RepoListPRsCommand : ConsoleCommand
{
public RepoListPRsCommand()
{
@@ -346,7 +346,7 @@ namespace TGCommandLine
}
}
- class RepoListBackupsCommand : Command
+ class RepoListBackupsCommand : ConsoleCommand
{
public RepoListBackupsCommand()
{
@@ -372,7 +372,7 @@ namespace TGCommandLine
return ExitCode.Normal;
}
}
- class RepoCheckoutCommand : Command
+ class RepoCheckoutCommand : ConsoleCommand
{
public RepoCheckoutCommand()
{
diff --git a/TGCommandLine/RootCommands.cs b/TGCommandLine/RootCommands.cs
index e78740e7e0..37c6cb00db 100644
--- a/TGCommandLine/RootCommands.cs
+++ b/TGCommandLine/RootCommands.cs
@@ -7,10 +7,10 @@ namespace TGCommandLine
{
class CLICommand : RootCommand
{
- public CLICommand()
+ public CLICommand(Interface I)
{
var tmp = new List { new UpdateCommand(), new TestmergeCommand(), new RepoCommand(), new BYONDCommand(), new DMCommand(), new DDCommand(), new ConfigCommand(), new IRCCommand(), new DiscordCommand(), new AutoUpdateCommand(), new SetAutoUpdateCommand() };
- if (Interface.VerifyConnection() == null && Interface.Authenticate() && Interface.AuthenticateAdmin())
+ if (I.VerifyConnection() == null && I.Authenticate() && I.AuthenticateAdmin())
tmp.Add(new AdminCommand());
Children = tmp.ToArray();
}
@@ -21,7 +21,7 @@ namespace TGCommandLine
base.PrintHelp();
}
}
- class AutoUpdateCommand : Command
+ class AutoUpdateCommand : ConsoleCommand
{
public AutoUpdateCommand()
{
@@ -40,7 +40,7 @@ namespace TGCommandLine
return ExitCode.Normal;
}
}
- class SetAutoUpdateCommand : Command
+ class SetAutoUpdateCommand : ConsoleCommand
{
public SetAutoUpdateCommand()
{
@@ -79,7 +79,7 @@ namespace TGCommandLine
}
}
- class UpdateCommand : Command
+ class UpdateCommand : ConsoleCommand
{
public UpdateCommand()
{
@@ -140,7 +140,7 @@ namespace TGCommandLine
}
}
- class TestmergeCommand : Command
+ class TestmergeCommand : ConsoleCommand
{
public TestmergeCommand()
{
diff --git a/TGCommandLine/TGCommandLine.csproj b/TGCommandLine/TGCommandLine.csproj
index 528c4e11fd..dc4522573e 100644
--- a/TGCommandLine/TGCommandLine.csproj
+++ b/TGCommandLine/TGCommandLine.csproj
@@ -44,6 +44,7 @@
+
diff --git a/TGControlPanel/ByondPage.cs b/TGControlPanel/ByondPage.cs
index 7f120c3705..df284edc12 100644
--- a/TGControlPanel/ByondPage.cs
+++ b/TGControlPanel/ByondPage.cs
@@ -5,7 +5,7 @@ using TGServiceInterface.Components;
namespace TGControlPanel
{
- partial class Main
+ partial class ControlPanel
{
string lastReadError = null;
void InitBYONDPage()
diff --git a/TGControlPanel/ChatPage.cs b/TGControlPanel/ChatPage.cs
index 1bf6460e54..bea75efbff 100644
--- a/TGControlPanel/ChatPage.cs
+++ b/TGControlPanel/ChatPage.cs
@@ -6,7 +6,7 @@ using TGServiceInterface.Components;
namespace TGControlPanel
{
- partial class Main
+ partial class ControlPanel
{
bool updatingChat = false;
diff --git a/TGControlPanel/Main.Designer.cs b/TGControlPanel/ControlPanel.Designer.cs
similarity index 99%
rename from TGControlPanel/Main.Designer.cs
rename to TGControlPanel/ControlPanel.Designer.cs
index 3f787f03be..76beb7fd0a 100644
--- a/TGControlPanel/Main.Designer.cs
+++ b/TGControlPanel/ControlPanel.Designer.cs
@@ -1,6 +1,6 @@
namespace TGControlPanel
{
- partial class Main
+ partial class ControlPanel
{
///
/// Required designer variable.
@@ -15,6 +15,7 @@
{
if (disposing && (components != null))
{
+ Interface.Dispose();
components.Dispose();
}
base.Dispose(disposing);
@@ -28,7 +29,7 @@
///
private void InitializeComponent()
{
- System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Main));
+ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ControlPanel));
this.RepoBGW = new System.ComponentModel.BackgroundWorker();
this.FullUpdateWorker = new System.ComponentModel.BackgroundWorker();
this.ServerStartBGW = new System.ComponentModel.BackgroundWorker();
diff --git a/TGControlPanel/Main.cs b/TGControlPanel/ControlPanel.cs
similarity index 66%
rename from TGControlPanel/Main.cs
rename to TGControlPanel/ControlPanel.cs
index 4c1e9af2e7..e4ce2968b6 100644
--- a/TGControlPanel/Main.cs
+++ b/TGControlPanel/ControlPanel.cs
@@ -1,60 +1,77 @@
-using System;
-using System.Drawing;
-using System.Windows.Forms;
-using TGServiceInterface;
-
-namespace TGControlPanel
-{
- ///
- /// The main form
- ///
- partial class Main : Form
- {
- ///
- /// Create the control panel. Requires the has had it's connection info setup
- ///
- public Main()
- {
- InitializeComponent();
- if (Interface.VersionMismatch(out string error) && MessageBox.Show(error, "Warning", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
- {
- Close();
- return;
- }
- Panels.SelectedIndexChanged += Panels_SelectedIndexChanged;
- Panels.SelectedIndex += Math.Min(Properties.Settings.Default.LastPageIndex, Panels.TabCount - 1);
- InitRepoPage();
- InitBYONDPage();
- InitServerPage();
- LoadChatPage();
- InitStaticPage();
- }
-
- private void Main_Resize(object sender, EventArgs e)
- {
- Panels.Location = new Point(10, 10);
- Panels.Width = ClientSize.Width - 20;
- Panels.Height = ClientSize.Height - 20;
- }
-
- private void Panels_SelectedIndexChanged(object sender, EventArgs e)
- {
- switch (Panels.SelectedIndex)
- {
- case 0: //repo
- PopulateRepoFields();
- break;
- case 1: //byond
- UpdateBYONDButtons();
- break;
- case 2: //scp
- LoadServerPage();
- break;
- case 3: //chat
- LoadChatPage();
- break;
- }
- Properties.Settings.Default.LastPageIndex = Panels.SelectedIndex;
- }
- }
-}
+using System;
+using System.Drawing;
+using System.Windows.Forms;
+using TGServiceInterface;
+
+namespace TGControlPanel
+{
+ ///
+ /// The main form
+ ///
+ partial class ControlPanel : Form
+ {
+ ///
+ /// The instance for this
+ ///
+ readonly Interface Interface;
+
+ ///
+ /// Constructs a
+ ///
+ /// The for the
+ public ControlPanel(Interface I)
+ {
+ Interface = I;
+ InitializeComponent();
+ if (Interface.VersionMismatch(out string error) && MessageBox.Show(error, "Warning", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
+ {
+ Close();
+ return;
+ }
+ Panels.SelectedIndexChanged += Panels_SelectedIndexChanged;
+ Panels.SelectedIndex += Math.Min(Properties.Settings.Default.LastPageIndex, Panels.TabCount - 1);
+ InitRepoPage();
+ InitBYONDPage();
+ InitServerPage();
+ LoadChatPage();
+ InitStaticPage();
+ }
+
+ private void Main_Resize(object sender, EventArgs e)
+ {
+ Panels.Location = new Point(10, 10);
+ Panels.Width = ClientSize.Width - 20;
+ Panels.Height = ClientSize.Height - 20;
+ }
+
+ private void Panels_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (Panels.SelectedIndex)
+ {
+ case 0: //repo
+ PopulateRepoFields();
+ break;
+ case 1: //byond
+ UpdateBYONDButtons();
+ break;
+ case 2: //scp
+ LoadServerPage();
+ break;
+ case 3: //chat
+ LoadChatPage();
+ break;
+ }
+ Properties.Settings.Default.LastPageIndex = Panels.SelectedIndex;
+ }
+
+ bool CheckAdminWithWarning()
+ {
+ if (!Interface.AuthenticateAdmin())
+ {
+ MessageBox.Show("Only system administrators may use this command!");
+ return false;
+ }
+ return true;
+ }
+ }
+}
diff --git a/TGControlPanel/Main.resx b/TGControlPanel/ControlPanel.resx
similarity index 100%
rename from TGControlPanel/Main.resx
rename to TGControlPanel/ControlPanel.resx
diff --git a/TGControlPanel/Login.cs b/TGControlPanel/Login.cs
index 8c4b28437f..e75498e0d0 100644
--- a/TGControlPanel/Login.cs
+++ b/TGControlPanel/Login.cs
@@ -31,46 +31,50 @@ namespace TGControlPanel
{
IPTextBox.Text = IPTextBox.Text.Trim();
UsernameTextBox.Text = UsernameTextBox.Text.Trim();
- Interface.SetRemoteLoginInformation(IPTextBox.Text, (ushort)PortSelector.Value, UsernameTextBox.Text, PasswordTextBox.Text);
- var Config = Properties.Settings.Default;
- Config.RemoteIP = IPTextBox.Text;
- Config.RemoteUsername = UsernameTextBox.Text;
- if (SavePasswordCheckBox.Checked)
+ using (var I = new Interface(IPTextBox.Text, (ushort)PortSelector.Value, UsernameTextBox.Text, PasswordTextBox.Text))
{
- Config.RemotePassword = Helpers.EncryptData(PasswordTextBox.Text, out string entrop);
- Config.RemoteEntropy = entrop;
+ var Config = Properties.Settings.Default;
+ Config.RemoteIP = IPTextBox.Text;
+ Config.RemoteUsername = UsernameTextBox.Text;
+ if (SavePasswordCheckBox.Checked)
+ {
+ Config.RemotePassword = Helpers.EncryptData(PasswordTextBox.Text, out string entrop);
+ Config.RemoteEntropy = entrop;
+ }
+ else
+ {
+ Config.RemotePassword = null;
+ Config.RemoteEntropy = null;
+ }
+ Config.RemoteDefault = true;
+ VerifyAndConnect(I);
}
- else
- {
- Config.RemotePassword = null;
- Config.RemoteEntropy = null;
- }
- Config.RemoteDefault = true;
- VerifyAndConnect();
}
private void LocalLoginButton_Click(object sender, EventArgs e)
{
- Interface.MakeLocalConnection();
- Properties.Settings.Default.RemoteDefault = false;
- VerifyAndConnect();
+ using (var I = new Interface())
+ {
+ Properties.Settings.Default.RemoteDefault = false;
+ VerifyAndConnect(I);
+ }
}
- void VerifyAndConnect()
+ void VerifyAndConnect(Interface I)
{
- var res = Interface.VerifyConnection();
+ var res = I.VerifyConnection();
if (res != null)
{
MessageBox.Show("Unable to connect to service! Error: " + res);
return;
}
- if (!Interface.Authenticate())
+ if (!I.Authenticate())
{
MessageBox.Show("Authentication error: Username/password/windows identity is not authorized! Ensure you are a system administrator or in the correct Windows group on the service machine.");
return;
}
Hide();
- using (var M = new Main())
+ using (var M = new ControlPanel(I))
M.ShowDialog();
Close();
}
diff --git a/TGControlPanel/Program.cs b/TGControlPanel/Program.cs
index b4eec9afc3..0c012c7123 100644
--- a/TGControlPanel/Program.cs
+++ b/TGControlPanel/Program.cs
@@ -9,7 +9,6 @@ namespace TGControlPanel
[STAThread]
static void Main(string[] args)
{
- Interface.SetBadCertificateHandler(BadCertificateHandler);
try
{
if (Properties.Settings.Default.UpgradeRequired)
@@ -44,16 +43,6 @@ namespace TGControlPanel
return true;
}
- public static bool CheckAdminWithWarning()
- {
- if (!Interface.AuthenticateAdmin())
- {
- MessageBox.Show("Only system administrators may use this command!");
- return false;
- }
- return true;
- }
-
public static void ServiceDisconnectException(Exception e)
{
MessageBox.Show("An unhandled exception occurred. This usually means we lost connection to the service. Error" + e.ToString());
diff --git a/TGControlPanel/RepoPage.cs b/TGControlPanel/RepoPage.cs
index 076933a6b6..d6f6bc9bae 100644
--- a/TGControlPanel/RepoPage.cs
+++ b/TGControlPanel/RepoPage.cs
@@ -7,7 +7,7 @@ using TGServiceInterface.Components;
namespace TGControlPanel
{
- partial class Main
+ partial class ControlPanel
{
enum RepoAction {
Clone,
diff --git a/TGControlPanel/ServerPage.cs b/TGControlPanel/ServerPage.cs
index 75f7b63ce4..f8b4addcd7 100644
--- a/TGControlPanel/ServerPage.cs
+++ b/TGControlPanel/ServerPage.cs
@@ -6,7 +6,7 @@ using TGServiceInterface.Components;
namespace TGControlPanel
{
- partial class Main
+ partial class ControlPanel
{
enum FullUpdateAction
{
@@ -83,7 +83,7 @@ namespace TGControlPanel
void UpdateServerPath()
{
- if (!Program.CheckAdminWithWarning())
+ if (!CheckAdminWithWarning())
{
ServerPathTextbox.Enabled = false;
ServerPathTextbox.ReadOnly = true;
@@ -95,7 +95,7 @@ namespace TGControlPanel
if (DialogResult != DialogResult.Yes)
return;
- if (!Program.CheckAdminWithWarning())
+ if (!CheckAdminWithWarning())
{
ServerPathTextbox.Enabled = false;
ServerPathTextbox.ReadOnly = true;
diff --git a/TGControlPanel/StaticPage.cs b/TGControlPanel/StaticPage.cs
index e04eb02c38..61a3ca7155 100644
--- a/TGControlPanel/StaticPage.cs
+++ b/TGControlPanel/StaticPage.cs
@@ -7,7 +7,7 @@ using TGServiceInterface.Components;
namespace TGControlPanel
{
- partial class Main
+ partial class ControlPanel
{
IDictionary IndexesToPaths = new Dictionary();
IList EnumeratedPaths = new List() { "" };
@@ -325,14 +325,14 @@ namespace TGControlPanel
private void RecreateStaticButton_Click(object sender, EventArgs e)
{
- if (!Program.CheckAdminWithWarning())
+ if (!CheckAdminWithWarning())
{
RecreateStaticButton.Visible = false;
return;
}
if (MessageBox.Show("This will rename the current static directory to a backup and recreate it. Continue?", "Confirm", MessageBoxButtons.YesNo) != DialogResult.Yes)
return;
- if (!Program.CheckAdminWithWarning())
+ if (!CheckAdminWithWarning())
{
RecreateStaticButton.Visible = false;
return;
diff --git a/TGControlPanel/TGControlPanel.csproj b/TGControlPanel/TGControlPanel.csproj
index 87c59e1792..3d0d464ccd 100644
--- a/TGControlPanel/TGControlPanel.csproj
+++ b/TGControlPanel/TGControlPanel.csproj
@@ -61,11 +61,11 @@
Login.cs
-
+
Form
-
- Main.cs
+
+ ControlPanel.cs
@@ -87,8 +87,8 @@
Login.cs
-
- Main.cs
+
+ ControlPanel.cs
diff --git a/TGInstallerWrapper/Main.cs b/TGInstallerWrapper/Main.cs
index 1c6b6cea85..2d941c519a 100644
--- a/TGInstallerWrapper/Main.cs
+++ b/TGInstallerWrapper/Main.cs
@@ -26,6 +26,7 @@ namespace TGInstallerWrapper
const string InterfaceServiceInterfacePrepareForUpdate = "PrepareForUpdate";
Assembly InterfaceAssembly;
+ object InterfaceObject;
Type Server, ITGSService;
MethodInfo VerifyConnection, GetComponentITGSService, Version, PrepareForUpdate;
@@ -74,6 +75,7 @@ namespace TGInstallerWrapper
File.WriteAllBytes(tmppath, Properties.Resources.TGServiceInterface);
InterfaceAssembly = Assembly.LoadFrom(tmppath); //we can't link to it, or load the bytes directly because the thing will complain about mixing the DLLExport code and IL code
Server = InterfaceAssembly.GetType(InterfaceClass);
+ InterfaceObject = Activator.CreateInstance(Server);
ITGSService = InterfaceAssembly.GetType(InterfaceServiceInterface);
VerifyConnection = Server.GetMethod(InterfaceClassVerifyConnection);
GetComponentITGSService = Server.GetMethod(InterfaceClassGetComponent).MakeGenericMethod(ITGSService);
@@ -91,10 +93,10 @@ namespace TGInstallerWrapper
void CheckForExistingVersion() {
if (InterfaceAssembly == null)
return;
- var verifiedConnection = VerifyConnection.Invoke(null, null) == null;
+ var verifiedConnection = VerifyConnection.Invoke(InterfaceObject, null) == null;
try
{
- VersionLabel.Text = (string)Version.Invoke(GetComponentITGSService.Invoke(null, null), null);
+ VersionLabel.Text = (string)Version.Invoke(GetComponentITGSService.Invoke(InterfaceObject, null), null);
if (VersionLabel.Text.Contains("v3.0")) //OH GOD!!!!
MessageBox.Show("Warning! Upgrading from version 3.0 may trigger a bug that can delete /config and /data. IT IS STRONGLY RECCOMMENDED THAT YOU BACKUP THESE FOLDERS BEFORE UPDATING!");
}
@@ -114,10 +116,10 @@ namespace TGInstallerWrapper
{
if (InterfaceAssembly == null)
return ConfirmDangerousUpgrade();
- var connectionVerified = VerifyConnection.Invoke(null, null) == null;
+ var connectionVerified = VerifyConnection.Invoke(InterfaceObject, null) == null;
try
{
- PrepareForUpdate.Invoke(GetComponentITGSService.Invoke(null, null), null);
+ PrepareForUpdate.Invoke(GetComponentITGSService.Invoke(InterfaceObject, null), null);
Thread.Sleep(3000); //chat messages
return true;
}
diff --git a/TGServiceInterface/DreamDaemonBridge.cs b/TGServiceInterface/DreamDaemonBridge.cs
index a85ae6541b..e1652509e4 100644
--- a/TGServiceInterface/DreamDaemonBridge.cs
+++ b/TGServiceInterface/DreamDaemonBridge.cs
@@ -21,13 +21,8 @@ namespace TGServiceInterface
{
try
{
- var channel = Interface.CreateChannel();
- try
- {
- channel.CreateChannel().InteropMessage(String.Join(" ", args));
- }
- catch { }
- Interface.CloseChannel(channel);
+ using (var I = new Interface())
+ I.GetComponent().InteropMessage(String.Join(" ", args));
}
catch { }
return 0;
diff --git a/TGServiceInterface/Interface.cs b/TGServiceInterface/Interface.cs
index 7cbbd1f090..d788499b0f 100644
--- a/TGServiceInterface/Interface.cs
+++ b/TGServiceInterface/Interface.cs
@@ -14,7 +14,7 @@ namespace TGServiceInterface
///
/// Main inteface class for the service
///
- public class Interface
+ public class Interface : IDisposable
{
///
/// List of s that can be used with and
@@ -40,27 +40,27 @@ namespace TGServiceInterface
///
/// If this is set, we will try and connect to an HTTPS server running at this address
///
- static string HTTPSURL;
+ readonly string HTTPSURL;
///
/// The port used by the service
///
- static ushort HTTPSPort = 38607;
+ readonly ushort HTTPSPort;
///
/// Username for remote operations
///
- static string HTTPSUsername;
+ readonly string HTTPSUsername;
///
/// Password for remote operations
///
- static string HTTPSPassword;
+ readonly string HTTPSPassword;
///
/// Associated list of open s keyed by type. A in this list may close or fault at any time. Must be locked before being accessed
///
- static IDictionary ChannelFactoryCache = new Dictionary();
+ IDictionary ChannelFactoryCache = new Dictionary();
///
/// Returns a of s that can be used with the service
@@ -77,11 +77,31 @@ namespace TGServiceInterface
return query.ToList();
}
+ ///
+ /// Construct an for a local connection
+ ///
+ public Interface() { }
+
+ ///
+ /// Construct an for a remote connection
+ ///
+ /// The address of the remote server
+ /// The port the remote server runs on
+ /// Windows account username for the remote server
+ /// Windows account password for the remote server
+ public Interface(string address, ushort port, string username, string password)
+ {
+ HTTPSURL = address;
+ HTTPSPort = port;
+ HTTPSUsername = username;
+ HTTPSPassword = password;
+ }
+
///
/// Sets the function called when a remote login fails due to the server having an invalid SSL cert
///
/// The to be called when a remote login is attempted while the server posesses a bad certificate. Passed a of error information about the and should return if it the connection should be made anyway
- public static void SetBadCertificateHandler(Func handler)
+ public void SetBadCertificateHandler(Func handler)
{
ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) =>
{
@@ -108,20 +128,10 @@ namespace TGServiceInterface
};
}
- ///
- /// Set the interface to look for services on the current computer
- ///
- public static void MakeLocalConnection()
- {
- HTTPSURL = null;
- HTTPSPassword = null;
- ClearCachedChannels();
- }
-
///
/// Closes all s stored in and clears it
///
- static void ClearCachedChannels()
+ void ClearCachedChannels()
{
lock (ChannelFactoryCache)
{
@@ -136,9 +146,9 @@ namespace TGServiceInterface
///
/// An error message to display to the user should this function return
/// if the interface being used to connect to a service does not have the same release version as the service
- public static bool VersionMismatch(out string errorMessage)
+ public bool VersionMismatch(out string errorMessage)
{
- var splits = Interface.GetComponent().Version().Split(' ');
+ var splits = GetComponent().Version().Split(' ');
var theirs = new Version(splits[splits.Length - 1].Substring(1));
var ours = new Version(FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion);
if(theirs.Major != ours.Major || theirs.Minor != ours.Minor || theirs.Revision != ours.Revision) //don't care about the patch level
@@ -150,30 +160,15 @@ namespace TGServiceInterface
return false;
}
- ///
- /// Set the remote to connect to along with
- ///
- /// The address of the remote server
- /// The port the remote server runs on
- /// Windows account username for the remote server
- /// Windows account password for the remote server
- public static void SetRemoteLoginInformation(string address, ushort port, string username, string password)
- {
- HTTPSURL = address;
- HTTPSPort = port;
- HTTPSUsername = username;
- HTTPSPassword = password;
- ClearCachedChannels();
- }
-
///
/// Safely shuts down a single
///
/// The to shutdown
- public static void CloseChannel(ChannelFactory cf)
+ static void CloseChannel(ChannelFactory cf)
{
try
{
+ cf.Closed += ChannelFactory_Closed;
cf.Close();
}
catch
@@ -182,12 +177,22 @@ namespace TGServiceInterface
}
}
+ ///
+ /// Disposes a closed
+ ///
+ /// The channel factory that was closed
+ /// The event arguments
+ static void ChannelFactory_Closed(object sender, EventArgs e)
+ {
+ (sender as IDisposable).Dispose();
+ }
+
///
/// Returns the requested component . This does not guarantee a successful connection. s created this way are recycled for minimum latency and bandwidth usage
///
/// The component to retrieve
/// The correct component
- public static T GetComponent()
+ public T GetComponent()
{
var tot = typeof(T);
ChannelFactory cf;
@@ -219,7 +224,7 @@ namespace TGServiceInterface
/// The component of the channel to be created
/// The correct
/// Thrown if isn't a valid component
- public static ChannelFactory CreateChannel()
+ public ChannelFactory CreateChannel()
{
var ToT = typeof(T);
if (!ValidInterfaces.Contains(ToT))
@@ -257,7 +262,7 @@ namespace TGServiceInterface
/// Used to test if the service is avaiable on the machine. Note that state can technically change at any time and any call to the service may throw an exception because it failed
///
/// on successful connection, error message on failure
- public static string VerifyConnection()
+ public string VerifyConnection()
{
try
{
@@ -274,7 +279,7 @@ namespace TGServiceInterface
/// Checks if the supplied user's credentials have permission to use the service. Requires a successful prior call to
///
/// if credentials are valid, otherwise
- public static bool Authenticate()
+ public bool Authenticate()
{
try
{
@@ -291,7 +296,7 @@ namespace TGServiceInterface
/// Checks if the current login can use . Requires a successful prior call to
///
/// if the connection may use , otherwise
- public static bool AuthenticateAdmin()
+ public bool AuthenticateAdmin()
{
try
{
@@ -303,5 +308,49 @@ namespace TGServiceInterface
return false;
}
}
+
+ #region IDisposable Support
+ ///
+ /// To detect redundant calls
+ ///
+ private bool disposedValue = false;
+
+ ///
+ /// Implements the pattern. Calls
+ ///
+ /// if was called manually, if it was from the finalizer
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!disposedValue)
+ {
+ if (disposing)
+ {
+ ClearCachedChannels();
+ }
+
+ // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
+ // TODO: set large fields to null.
+
+ disposedValue = true;
+ }
+ }
+
+ // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources.
+ // ~Interface() {
+ // // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
+ // Dispose(false);
+ // }
+
+ ///
+ /// Implements the pattern
+ ///
+ public void Dispose()
+ {
+ // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
+ Dispose(true);
+ // TODO: uncomment the following line if the finalizer is overridden above.
+ // GC.SuppressFinalize(this);
+ }
+ #endregion
}
}