Merge pull request #287 from Cyberboss/InterfaceInstancing

Renames Main form to ControlPanel. Interface now needs to be instantiated
This commit is contained in:
Jordan Brown
2017-10-31 12:30:18 -04:00
committed by GitHub
25 changed files with 332 additions and 251 deletions
+8 -7
View File
@@ -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()
{
+3 -3
View File
@@ -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()
{
+17 -17
View File
@@ -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()
{
+5 -5
View File
@@ -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()
{
+12
View File
@@ -0,0 +1,12 @@
using TGServiceInterface;
namespace TGCommandLine
{
abstract class ConsoleCommand : Command
{
/// <summary>
/// The <see cref="TGServiceInterface.Interface"/> currently in use by the <see cref="Program"/>
/// </summary>
public static Interface Interface;
}
}
+9 -9
View File
@@ -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()
{
+5 -5
View File
@@ -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()
{
+34 -24
View File
@@ -9,6 +9,8 @@ namespace TGCommandLine
class Program
{
static bool interactive = false;
static Interface currentInterface;
static Command.ExitCode RunCommandLine(IList<string> 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<string>(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<ITGSService>().PrepareForUpdate();
currentInterface.GetComponent<ITGSService>().PrepareForUpdate();
return (int)Command.ExitCode.Normal;
#endif
default:
+14 -14
View File
@@ -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 "<hard|merge>";
}
}
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()
{
+6 -6
View File
@@ -7,10 +7,10 @@ namespace TGCommandLine
{
class CLICommand : RootCommand
{
public CLICommand()
public CLICommand(Interface I)
{
var tmp = new List<Command> { 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()
{
+1
View File
@@ -44,6 +44,7 @@
<Compile Include="AdminCommands.cs" />
<Compile Include="BYONDCommands.cs" />
<Compile Include="ConfigCommands.cs" />
<Compile Include="ConsoleCommand.cs" />
<Compile Include="DDCommands.cs" />
<Compile Include="DMCommands.cs" />
<Compile Include="ChatCommands.cs" />
+1 -1
View File
@@ -5,7 +5,7 @@ using TGServiceInterface.Components;
namespace TGControlPanel
{
partial class Main
partial class ControlPanel
{
string lastReadError = null;
void InitBYONDPage()
+1 -1
View File
@@ -6,7 +6,7 @@ using TGServiceInterface.Components;
namespace TGControlPanel
{
partial class Main
partial class ControlPanel
{
bool updatingChat = false;
@@ -1,6 +1,6 @@
namespace TGControlPanel
{
partial class Main
partial class ControlPanel
{
/// <summary>
/// Required designer variable.
@@ -15,6 +15,7 @@
{
if (disposing && (components != null))
{
Interface.Dispose();
components.Dispose();
}
base.Dispose(disposing);
@@ -28,7 +29,7 @@
/// </summary>
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();
@@ -1,60 +1,77 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using TGServiceInterface;
namespace TGControlPanel
{
/// <summary>
/// The main <see cref="TGControlPanel"/> form
/// </summary>
partial class Main : Form
{
/// <summary>
/// Create the control panel. Requires the <see cref="Interface"/> has had it's connection info setup
/// </summary>
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
{
/// <summary>
/// The main <see cref="ControlPanel"/> form
/// </summary>
partial class ControlPanel : Form
{
/// <summary>
/// The <see cref="TGServiceInterface.Interface"/> instance for this <see cref="ControlPanel"/>
/// </summary>
readonly Interface Interface;
/// <summary>
/// Constructs a <see cref="ControlPanel"/>
/// </summary>
/// <param name="I">The <see cref="TGServiceInterface.Interface"/> for the <see cref="ControlPanel"/></param>
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;
}
}
}
+25 -21
View File
@@ -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();
}
-11
View File
@@ -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());
+1 -1
View File
@@ -7,7 +7,7 @@ using TGServiceInterface.Components;
namespace TGControlPanel
{
partial class Main
partial class ControlPanel
{
enum RepoAction {
Clone,
+3 -3
View File
@@ -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;
+3 -3
View File
@@ -7,7 +7,7 @@ using TGServiceInterface.Components;
namespace TGControlPanel
{
partial class Main
partial class ControlPanel
{
IDictionary<int, string> IndexesToPaths = new Dictionary<int, string>();
IList<string> EnumeratedPaths = new List<string>() { "" };
@@ -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;
+5 -5
View File
@@ -61,11 +61,11 @@
<Compile Include="Login.Designer.cs">
<DependentUpon>Login.cs</DependentUpon>
</Compile>
<Compile Include="Main.cs">
<Compile Include="ControlPanel.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Main.Designer.cs">
<DependentUpon>Main.cs</DependentUpon>
<Compile Include="ControlPanel.Designer.cs">
<DependentUpon>ControlPanel.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -87,8 +87,8 @@
<EmbeddedResource Include="Login.resx">
<DependentUpon>Login.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Main.resx">
<DependentUpon>Main.cs</DependentUpon>
<EmbeddedResource Include="ControlPanel.resx">
<DependentUpon>ControlPanel.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
+6 -4
View File
@@ -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;
}
+2 -7
View File
@@ -21,13 +21,8 @@ namespace TGServiceInterface
{
try
{
var channel = Interface.CreateChannel<ITGInterop>();
try
{
channel.CreateChannel().InteropMessage(String.Join(" ", args));
}
catch { }
Interface.CloseChannel(channel);
using (var I = new Interface())
I.GetComponent<ITGInterop>().InteropMessage(String.Join(" ", args));
}
catch { }
return 0;
+91 -42
View File
@@ -14,7 +14,7 @@ namespace TGServiceInterface
/// <summary>
/// Main inteface class for the service
/// </summary>
public class Interface
public class Interface : IDisposable
{
/// <summary>
/// List of <see langword="interface"/>s that can be used with <see cref="GetComponent{T}"/> and <see cref="CreateChannel{T}"/>
@@ -40,27 +40,27 @@ namespace TGServiceInterface
/// <summary>
/// If this is set, we will try and connect to an HTTPS server running at this address
/// </summary>
static string HTTPSURL;
readonly string HTTPSURL;
/// <summary>
/// The port used by the service
/// </summary>
static ushort HTTPSPort = 38607;
readonly ushort HTTPSPort;
/// <summary>
/// Username for remote operations
/// </summary>
static string HTTPSUsername;
readonly string HTTPSUsername;
/// <summary>
/// Password for remote operations
/// </summary>
static string HTTPSPassword;
readonly string HTTPSPassword;
/// <summary>
/// Associated list of open <see cref="ChannelFactory"/>s keyed by <see langword="interface"/> type. A <see cref="ChannelFactory"/> in this list may close or fault at any time. Must be locked before being accessed
/// </summary>
static IDictionary<Type, ChannelFactory> ChannelFactoryCache = new Dictionary<Type, ChannelFactory>();
IDictionary<Type, ChannelFactory> ChannelFactoryCache = new Dictionary<Type, ChannelFactory>();
/// <summary>
/// Returns a <see cref="IList{T}"/> of <see langword="interface"/> <see cref="Type"/>s that can be used with the service
@@ -77,11 +77,31 @@ namespace TGServiceInterface
return query.ToList();
}
/// <summary>
/// Construct an <see cref="Interface"/> for a local connection
/// </summary>
public Interface() { }
/// <summary>
/// Construct an <see cref="Interface"/> for a remote connection
/// </summary>
/// <param name="address">The address of the remote server</param>
/// <param name="port">The port the remote server runs on</param>
/// <param name="username">Windows account username for the remote server</param>
/// <param name="password">Windows account password for the remote server</param>
public Interface(string address, ushort port, string username, string password)
{
HTTPSURL = address;
HTTPSPort = port;
HTTPSUsername = username;
HTTPSPassword = password;
}
/// <summary>
/// Sets the function called when a remote login fails due to the server having an invalid SSL cert
/// </summary>
/// <param name="handler">The <see cref="Func{T, TResult}"/> to be called when a remote login is attempted while the server posesses a bad certificate. Passed a <see cref="string"/> of error information about the and should return <see langword="true"/> if it the connection should be made anyway</param>
public static void SetBadCertificateHandler(Func<string, bool> handler)
public void SetBadCertificateHandler(Func<string, bool> handler)
{
ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) =>
{
@@ -108,20 +128,10 @@ namespace TGServiceInterface
};
}
/// <summary>
/// Set the interface to look for services on the current computer
/// </summary>
public static void MakeLocalConnection()
{
HTTPSURL = null;
HTTPSPassword = null;
ClearCachedChannels();
}
/// <summary>
/// Closes all <see cref="ChannelFactory"/>s stored in <see cref="ChannelFactoryCache"/> and clears it
/// </summary>
static void ClearCachedChannels()
void ClearCachedChannels()
{
lock (ChannelFactoryCache)
{
@@ -136,9 +146,9 @@ namespace TGServiceInterface
/// </summary>
/// <param name="errorMessage">An error message to display to the user should this function return <see langword="true"/></param>
/// <returns><see langword="true"/> if the <see cref="Interface"/> interface being used to connect to a service does not have the same release version as the service</returns>
public static bool VersionMismatch(out string errorMessage)
public bool VersionMismatch(out string errorMessage)
{
var splits = Interface.GetComponent<ITGSService>().Version().Split(' ');
var splits = GetComponent<ITGSService>().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;
}
/// <summary>
/// Set the remote <see cref="Interface"/> to connect to along with
/// </summary>
/// <param name="address">The address of the remote server</param>
/// <param name="port">The port the remote server runs on</param>
/// <param name="username">Windows account username for the remote server</param>
/// <param name="password">Windows account password for the remote server</param>
public static void SetRemoteLoginInformation(string address, ushort port, string username, string password)
{
HTTPSURL = address;
HTTPSPort = port;
HTTPSUsername = username;
HTTPSPassword = password;
ClearCachedChannels();
}
/// <summary>
/// Safely shuts down a single <see cref="ChannelFactory"/>
/// </summary>
/// <param name="cf">The <see cref="ChannelFactory"/> to shutdown</param>
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
}
}
/// <summary>
/// Disposes a closed <see cref="ChannelFactory"/>
/// </summary>
/// <param name="sender">The channel factory that was closed</param>
/// <param name="e">The event arguments</param>
static void ChannelFactory_Closed(object sender, EventArgs e)
{
(sender as IDisposable).Dispose();
}
/// <summary>
/// Returns the requested <see cref="Interface"/> component <see langword="interface"/>. This does not guarantee a successful connection. <see cref="ChannelFactory{TChannel}"/>s created this way are recycled for minimum latency and bandwidth usage
/// </summary>
/// <typeparam name="T">The component <see langword="interface"/> to retrieve</typeparam>
/// <returns>The correct component <see langword="interface"/></returns>
public static T GetComponent<T>()
public T GetComponent<T>()
{
var tot = typeof(T);
ChannelFactory<T> cf;
@@ -219,7 +224,7 @@ namespace TGServiceInterface
/// <typeparam name="T">The component <see langword="interface"/> of the channel to be created</typeparam>
/// <returns>The correct <see cref="ChannelFactory{TChannel}"/></returns>
/// <exception cref="Exception">Thrown if <typeparamref name="T"/> isn't a valid component <see langword="interface"/></exception>
public static ChannelFactory<T> CreateChannel<T>()
public ChannelFactory<T> CreateChannel<T>()
{
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
/// </summary>
/// <returns><see langword="null"/> on successful connection, error message <see cref="string"/> on failure</returns>
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 <see cref="VerifyConnection"/>
/// </summary>
/// <returns><see langword="true"/> if credentials are valid, <see langword="false"/> otherwise</returns>
public static bool Authenticate()
public bool Authenticate()
{
try
{
@@ -291,7 +296,7 @@ namespace TGServiceInterface
/// Checks if the current login can use <see cref="ITGAdministration"/>. Requires a successful prior call to <see cref="Authenticate"/>
/// </summary>
/// <returns><see langword="true"/> if the connection may use <see cref="ITGAdministration"/>, <see langword="false"/> otherwise</returns>
public static bool AuthenticateAdmin()
public bool AuthenticateAdmin()
{
try
{
@@ -303,5 +308,49 @@ namespace TGServiceInterface
return false;
}
}
#region IDisposable Support
/// <summary>
/// To detect redundant <see cref="Dispose(bool)"/> calls
/// </summary>
private bool disposedValue = false;
/// <summary>
/// Implements the <see cref="IDisposable"/> pattern. Calls <see cref="ClearCachedChannels"/>
/// </summary>
/// <param name="disposing"><see langword="true"/> if <see cref="Dispose()"/> was called manually, <see langword="false"/> if it was from the finalizer</param>
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);
// }
/// <summary>
/// Implements the <see cref="IDisposable"/> pattern
/// </summary>
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
}
}