mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-25 05:56:58 +01:00
Server => Interface
This commit is contained in:
@@ -28,7 +28,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var res = Server.GetComponent<ITGAdministration>().MoveServer(parameters[0]);
|
||||
var res = Interface.GetComponent<ITGAdministration>().MoveServer(parameters[0]);
|
||||
OutputProc(res ?? "Success");
|
||||
return res == null ? ExitCode.Normal : ExitCode.ServerError;
|
||||
}
|
||||
@@ -52,7 +52,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var res = Server.GetComponent<ITGAdministration>().RecreateStaticFolder();
|
||||
var res = Interface.GetComponent<ITGAdministration>().RecreateStaticFolder();
|
||||
OutputProc(res ?? "Success");
|
||||
return res == null ? ExitCode.Normal : ExitCode.ServerError;
|
||||
}
|
||||
@@ -92,7 +92,7 @@ namespace TGCommandLine
|
||||
OutputProc("Invalid port number!");
|
||||
return ExitCode.BadCommand;
|
||||
}
|
||||
var res = Server.GetComponent<ITGAdministration>().SetRemoteAccessPort(port);
|
||||
var res = Interface.GetComponent<ITGAdministration>().SetRemoteAccessPort(port);
|
||||
OutputProc(res ?? "Success!");
|
||||
return ExitCode.Normal;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var port = Server.GetComponent<ITGAdministration>().RemoteAccessPort();
|
||||
var port = Interface.GetComponent<ITGAdministration>().RemoteAccessPort();
|
||||
OutputProc(String.Format("{0}", port));
|
||||
return ExitCode.Normal;
|
||||
}
|
||||
@@ -129,7 +129,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var group = Server.GetComponent<ITGAdministration>().GetCurrentAuthorizedGroup();
|
||||
var group = Interface.GetComponent<ITGAdministration>().GetCurrentAuthorizedGroup();
|
||||
OutputProc(group ?? "ERROR");
|
||||
return group != null ? ExitCode.Normal : ExitCode.ServerError;
|
||||
}
|
||||
@@ -154,7 +154,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var result = Server.GetComponent<ITGAdministration>().SetAuthorizedGroup(parameters[0]);
|
||||
var result = Interface.GetComponent<ITGAdministration>().SetAuthorizedGroup(parameters[0]);
|
||||
if(result != null)
|
||||
{
|
||||
OutputProc("Group set to: " + result);
|
||||
@@ -182,7 +182,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var res = Server.GetComponent<ITGAdministration>().SetAuthorizedGroup(null);
|
||||
var res = Interface.GetComponent<ITGAdministration>().SetAuthorizedGroup(null);
|
||||
if(res != "ADMIN")
|
||||
{
|
||||
OutputProc("Failed to clear the group??? We are currently set to: " + res);
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace TGCommandLine
|
||||
type = ByondVersion.Staged;
|
||||
else if (parameters[0].ToLower() == "--latest")
|
||||
type = ByondVersion.Latest;
|
||||
OutputProc(Server.GetComponent<ITGByond>().GetVersion(type) ?? "Unistalled");
|
||||
OutputProc(Interface.GetComponent<ITGByond>().GetVersion(type) ?? "Unistalled");
|
||||
return ExitCode.Normal;
|
||||
}
|
||||
public override string GetArgumentString()
|
||||
@@ -56,7 +56,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
switch (Server.GetComponent<ITGByond>().CurrentStatus())
|
||||
switch (Interface.GetComponent<ITGByond>().CurrentStatus())
|
||||
{
|
||||
case ByondStatus.Downloading:
|
||||
OutputProc("Downloading update...");
|
||||
@@ -109,7 +109,7 @@ namespace TGCommandLine
|
||||
return ExitCode.BadCommand;
|
||||
}
|
||||
|
||||
var BYOND = Server.GetComponent<ITGByond>();
|
||||
var BYOND = Interface.GetComponent<ITGByond>();
|
||||
if (!BYOND.UpdateToVersion(Major, Minor))
|
||||
|
||||
{
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var Chat = Server.GetComponent<ITGChat>();
|
||||
var Chat = Interface.GetComponent<ITGChat>();
|
||||
Chat.SetProviderInfo(new IRCSetupInfo(Chat.ProviderInfos()[(int)ChatProvider.IRC])
|
||||
{
|
||||
Nickname = parameters[0],
|
||||
@@ -78,7 +78,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var IRC = Server.GetComponent<ITGChat>();
|
||||
var IRC = Interface.GetComponent<ITGChat>();
|
||||
var info = IRC.ProviderInfos()[providerIndex];
|
||||
IList<string> channels;
|
||||
|
||||
@@ -156,7 +156,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var IRC = Server.GetComponent<ITGChat>();
|
||||
var IRC = Interface.GetComponent<ITGChat>();
|
||||
var info = IRC.ProviderInfos()[providerIndex];
|
||||
IList<string> channels;
|
||||
|
||||
@@ -222,7 +222,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var info = Server.GetComponent<ITGChat>().ProviderInfos()[providerIndex];
|
||||
var info = Interface.GetComponent<ITGChat>().ProviderInfos()[providerIndex];
|
||||
string authType;
|
||||
switch ((ChatProvider)providerIndex)
|
||||
{
|
||||
@@ -281,7 +281,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var res = Server.GetComponent<ITGChat>().Reconnect(providerIndex);
|
||||
var res = Interface.GetComponent<ITGChat>().Reconnect(providerIndex);
|
||||
if (res != null)
|
||||
{
|
||||
OutputProc("Error: " + res);
|
||||
@@ -310,7 +310,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var IRC = Server.GetComponent<ITGChat>();
|
||||
var IRC = Interface.GetComponent<ITGChat>();
|
||||
var info = IRC.ProviderInfos()[providerIndex];
|
||||
var newmin = parameters[0].ToLower();
|
||||
|
||||
@@ -355,7 +355,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var IRC = Server.GetComponent<ITGChat>();
|
||||
var IRC = Interface.GetComponent<ITGChat>();
|
||||
var info = IRC.ProviderInfos()[(int)ChatProvider.IRC];
|
||||
var lowerparam = parameters[0].ToLower();
|
||||
if (lowerparam == "channel-mode")
|
||||
@@ -394,7 +394,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var IRC = Server.GetComponent<ITGChat>();
|
||||
var IRC = Interface.GetComponent<ITGChat>();
|
||||
var info = IRC.ProviderInfos()[(int)ChatProvider.Discord];
|
||||
var lowerparam = parameters[0].ToLower();
|
||||
if (lowerparam == "role-id")
|
||||
@@ -433,7 +433,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var IRC = Server.GetComponent<ITGChat>();
|
||||
var IRC = Interface.GetComponent<ITGChat>();
|
||||
var info = new IRCSetupInfo(IRC.ProviderInfos()[(int)ChatProvider.IRC]);
|
||||
switch (parameters[0])
|
||||
{
|
||||
@@ -482,7 +482,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var IRC = Server.GetComponent<ITGChat>();
|
||||
var IRC = Interface.GetComponent<ITGChat>();
|
||||
var info = IRC.ProviderInfos()[providerIndex];
|
||||
var newmin = parameters[0].ToLower();
|
||||
|
||||
@@ -529,7 +529,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var IRC = Server.GetComponent<ITGChat>();
|
||||
var IRC = Interface.GetComponent<ITGChat>();
|
||||
IRC.SetProviderInfo(new IRCSetupInfo(IRC.ProviderInfos()[(int)ChatProvider.IRC])
|
||||
{
|
||||
AuthTarget = parameters[0],
|
||||
@@ -551,7 +551,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var IRC = Server.GetComponent<ITGChat>();
|
||||
var IRC = Interface.GetComponent<ITGChat>();
|
||||
IRC.SetProviderInfo(new IRCSetupInfo(IRC.ProviderInfos()[(int)ChatProvider.IRC])
|
||||
{
|
||||
AuthTarget = null,
|
||||
@@ -575,7 +575,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var IRC = Server.GetComponent<ITGChat>();
|
||||
var IRC = Interface.GetComponent<ITGChat>();
|
||||
var info = IRC.ProviderInfos()[providerIndex];
|
||||
OutputProc("Currently configured channels:");
|
||||
OutputProc("Admin:");
|
||||
@@ -610,7 +610,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var Chat = Server.GetComponent<ITGChat>();
|
||||
var Chat = Interface.GetComponent<ITGChat>();
|
||||
var info = Chat.ProviderInfos()[providerIndex];
|
||||
info.Enabled = true;
|
||||
var res = Chat.SetProviderInfo(info);
|
||||
@@ -638,7 +638,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var Chat = Server.GetComponent<ITGChat>();
|
||||
var Chat = Interface.GetComponent<ITGChat>();
|
||||
var info = Chat.ProviderInfos()[providerIndex];
|
||||
info.Enabled = false;
|
||||
var res = Chat.SetProviderInfo(info);
|
||||
@@ -675,7 +675,7 @@ namespace TGCommandLine
|
||||
OutputProc("Invalid parameter!");
|
||||
return ExitCode.BadCommand;
|
||||
}
|
||||
var Chat = Server.GetComponent<ITGChat>();
|
||||
var Chat = Interface.GetComponent<ITGChat>();
|
||||
var PI = new IRCSetupInfo(Chat.ProviderInfos()[(int)ChatProvider.IRC])
|
||||
{
|
||||
URL = splits[0]
|
||||
@@ -713,7 +713,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var Chat = Server.GetComponent<ITGChat>();
|
||||
var Chat = Interface.GetComponent<ITGChat>();
|
||||
var res = Chat.SetProviderInfo(new DiscordSetupInfo(Chat.ProviderInfos()[(int)ChatProvider.Discord]) { BotToken = parameters[0] });
|
||||
OutputProc(res ?? "Success");
|
||||
return res == null ? ExitCode.Normal : ExitCode.ServerError;
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var res = Server.GetComponent<ITGConfig>().DeleteFile(parameters[0], out bool unauthorized);
|
||||
var res = Interface.GetComponent<ITGConfig>().DeleteFile(parameters[0], out bool unauthorized);
|
||||
if (res != null)
|
||||
{
|
||||
OutputProc(res);
|
||||
@@ -64,7 +64,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var list = Server.GetComponent<ITGConfig>().ListStaticDirectory(parameters.Count > 0 ? parameters[0] : null, out string error, out bool unauthorized);
|
||||
var list = Interface.GetComponent<ITGConfig>().ListStaticDirectory(parameters.Count > 0 ? parameters[0] : null, out string error, out bool unauthorized);
|
||||
if(list == null)
|
||||
{
|
||||
OutputProc(error);
|
||||
@@ -88,7 +88,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
OutputProc(Server.GetComponent<ITGConfig>().ServerDirectory());
|
||||
OutputProc(Interface.GetComponent<ITGConfig>().ServerDirectory());
|
||||
return ExitCode.Normal;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var bytes = Server.GetComponent<ITGConfig>().ReadText(parameters[0], parameters.Count > 2 && parameters[2].ToLower() == "--repo", out string error, out bool unauthorized);
|
||||
var bytes = Interface.GetComponent<ITGConfig>().ReadText(parameters[0], parameters.Count > 2 && parameters[2].ToLower() == "--repo", out string error, out bool unauthorized);
|
||||
if(bytes == null)
|
||||
{
|
||||
OutputProc("Error: " + error);
|
||||
@@ -148,7 +148,7 @@ namespace TGCommandLine
|
||||
{
|
||||
try
|
||||
{
|
||||
var res = Server.GetComponent<ITGConfig>().WriteText(parameters[0], File.ReadAllText(parameters[1]), out bool unauthorized);
|
||||
var res = Interface.GetComponent<ITGConfig>().WriteText(parameters[0], File.ReadAllText(parameters[1]), out bool unauthorized);
|
||||
if (res != null)
|
||||
{
|
||||
OutputProc("Error: " + res);
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var res = Server.GetComponent<ITGDreamDaemon>().WorldAnnounce(String.Join(" ", parameters));
|
||||
var res = Interface.GetComponent<ITGDreamDaemon>().WorldAnnounce(String.Join(" ", parameters));
|
||||
OutputProc(res ?? "Success!");
|
||||
return res == null ? ExitCode.Normal : ExitCode.ServerError;
|
||||
}
|
||||
@@ -58,7 +58,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var res = Server.GetComponent<ITGDreamDaemon>().Start();
|
||||
var res = Interface.GetComponent<ITGDreamDaemon>().Start();
|
||||
OutputProc(res ?? "Success!");
|
||||
return res == null ? ExitCode.Normal : ExitCode.ServerError;
|
||||
}
|
||||
@@ -82,7 +82,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var DD = Server.GetComponent<ITGDreamDaemon>();
|
||||
var DD = Interface.GetComponent<ITGDreamDaemon>();
|
||||
if (parameters.Count > 0 && parameters[0].ToLower() == "--graceful")
|
||||
{
|
||||
if (DD.DaemonStatus() != DreamDaemonStatus.Online)
|
||||
@@ -111,7 +111,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var DD = Server.GetComponent<ITGDreamDaemon>();
|
||||
var DD = Interface.GetComponent<ITGDreamDaemon>();
|
||||
if (parameters.Count > 0 && parameters[0].ToLower() == "--graceful")
|
||||
{
|
||||
if (DD.DaemonStatus() != DreamDaemonStatus.Online)
|
||||
@@ -146,7 +146,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var DD = Server.GetComponent<ITGDreamDaemon>();
|
||||
var DD = Interface.GetComponent<ITGDreamDaemon>();
|
||||
OutputProc(DD.StatusString(true));
|
||||
if (DD.ShutdownInProgress())
|
||||
OutputProc("The server will shutdown once the current round completes.");
|
||||
@@ -167,7 +167,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var DD = Server.GetComponent<ITGDreamDaemon>();
|
||||
var DD = Interface.GetComponent<ITGDreamDaemon>();
|
||||
switch (parameters[0].ToLower())
|
||||
{
|
||||
case "on":
|
||||
@@ -205,7 +205,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var DD = Server.GetComponent<ITGDreamDaemon>();
|
||||
var DD = Interface.GetComponent<ITGDreamDaemon>();
|
||||
switch (parameters[0].ToLower())
|
||||
{
|
||||
case "on":
|
||||
@@ -255,7 +255,7 @@ namespace TGCommandLine
|
||||
return ExitCode.BadCommand;
|
||||
}
|
||||
|
||||
Server.GetComponent<ITGDreamDaemon>().SetPort(port);
|
||||
Interface.GetComponent<ITGDreamDaemon>().SetPort(port);
|
||||
return ExitCode.Normal;
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ namespace TGCommandLine
|
||||
OutputProc("Invalid security word!");
|
||||
return ExitCode.BadCommand;
|
||||
}
|
||||
Server.GetComponent<ITGDreamDaemon>().SetSecurityLevel(sec);
|
||||
Interface.GetComponent<ITGDreamDaemon>().SetSecurityLevel(sec);
|
||||
return ExitCode.Normal;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var DM = Server.GetComponent<ITGCompiler>();
|
||||
var DM = Interface.GetComponent<ITGCompiler>();
|
||||
var stat = DM.GetStatus();
|
||||
if (stat != CompilerStatus.Initialized)
|
||||
{
|
||||
@@ -36,7 +36,7 @@ namespace TGCommandLine
|
||||
return ExitCode.ServerError;
|
||||
}
|
||||
|
||||
if (Server.GetComponent<ITGByond>().GetVersion(ByondVersion.Installed) == null)
|
||||
if (Interface.GetComponent<ITGByond>().GetVersion(ByondVersion.Installed) == null)
|
||||
{
|
||||
Console.Write("Error: BYOND is not installed!");
|
||||
return ExitCode.ServerError;
|
||||
@@ -84,14 +84,14 @@ namespace TGCommandLine
|
||||
|
||||
void ShowError()
|
||||
{
|
||||
var error = Server.GetComponent<ITGCompiler>().CompileError();
|
||||
var error = Interface.GetComponent<ITGCompiler>().CompileError();
|
||||
if (error != null)
|
||||
OutputProc("Last error: " + error);
|
||||
}
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var DM = Server.GetComponent<ITGCompiler>();
|
||||
var DM = Interface.GetComponent<ITGCompiler>();
|
||||
OutputProc(String.Format("Target Project: /{0}.dme", DM.ProjectName()));
|
||||
Console.Write("Compilier is currently: ");
|
||||
switch (DM.GetStatus())
|
||||
@@ -142,7 +142,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
Server.GetComponent<ITGCompiler>().SetProjectName(parameters[0]);
|
||||
Interface.GetComponent<ITGCompiler>().SetProjectName(parameters[0]);
|
||||
return ExitCode.Normal;
|
||||
}
|
||||
}
|
||||
@@ -166,7 +166,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var DM = Server.GetComponent<ITGCompiler>();
|
||||
var DM = Interface.GetComponent<ITGCompiler>();
|
||||
var stat = DM.GetStatus();
|
||||
if (stat == CompilerStatus.Compiling || stat == CompilerStatus.Initializing)
|
||||
{
|
||||
@@ -206,7 +206,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var res = Server.GetComponent<ITGCompiler>().Cancel();
|
||||
var res = Interface.GetComponent<ITGCompiler>().Cancel();
|
||||
OutputProc(res ?? "Success!");
|
||||
return ExitCode.Normal; //because failing cancellation implys it's already cancelled
|
||||
}
|
||||
|
||||
+14
-14
@@ -51,7 +51,7 @@ namespace TGCommandLine
|
||||
}
|
||||
argsAsList.RemoveAt(I);
|
||||
argsAsList.RemoveAt(I);
|
||||
Server.SetRemoteLoginInformation(address, port, username, password);
|
||||
Interface.SetRemoteLoginInformation(address, port, username, password);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ namespace TGCommandLine
|
||||
return Command.ExitCode.BadCommand;
|
||||
}
|
||||
|
||||
var res = Server.VerifyConnection();
|
||||
var res = Interface.VerifyConnection();
|
||||
if (res != null)
|
||||
{
|
||||
Console.WriteLine("Unable to connect to service: " + res);
|
||||
@@ -70,13 +70,13 @@ namespace TGCommandLine
|
||||
return Command.ExitCode.ConnectionError;
|
||||
}
|
||||
|
||||
if (!Server.Authenticate())
|
||||
if (!Interface.Authenticate())
|
||||
{
|
||||
Console.WriteLine("Authentication error: Username/password/windows identity is not authorized!");
|
||||
return Command.ExitCode.ConnectionError;
|
||||
}
|
||||
|
||||
if (!SentVMMWarning && Server.VersionMismatch(out string error))
|
||||
if (!SentVMMWarning && Interface.VersionMismatch(out string error))
|
||||
{
|
||||
SentVMMWarning = true;
|
||||
Console.WriteLine(error);
|
||||
@@ -141,7 +141,7 @@ namespace TGCommandLine
|
||||
Command.OutputProcVar.Value = Console.WriteLine;
|
||||
if (args.Length != 0)
|
||||
{
|
||||
Server.SetBadCertificateHandler((message) => {
|
||||
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;
|
||||
@@ -151,7 +151,7 @@ namespace TGCommandLine
|
||||
return (int)RunCommandLine(new List<string>(args));
|
||||
}
|
||||
|
||||
Server.SetBadCertificateHandler(BadCertificateInteractive);
|
||||
Interface.SetBadCertificateHandler(BadCertificateInteractive);
|
||||
|
||||
Console.WriteLine("Type 'remote' to connect to a remote service");
|
||||
//interactive mode
|
||||
@@ -179,22 +179,22 @@ namespace TGCommandLine
|
||||
var username = Console.ReadLine();
|
||||
Console.Write("Enter password: ");
|
||||
var password = ReadLineSecure();
|
||||
Server.SetRemoteLoginInformation(address, port, username, password);
|
||||
var res = Server.VerifyConnection();
|
||||
Interface.SetRemoteLoginInformation(address, port, username, password);
|
||||
var res = Interface.VerifyConnection();
|
||||
if (res != null)
|
||||
{
|
||||
Console.WriteLine("Unable to connect: " + res);
|
||||
Server.MakeLocalConnection();
|
||||
Interface.MakeLocalConnection();
|
||||
}
|
||||
else if (!Server.Authenticate())
|
||||
else if (!Interface.Authenticate())
|
||||
{
|
||||
Console.WriteLine("Authentication error: Username/password/windows identity is not authorized! Returning to local mode...");
|
||||
Server.MakeLocalConnection();
|
||||
Interface.MakeLocalConnection();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Connected remotely");
|
||||
if (Server.VersionMismatch(out res))
|
||||
if (Interface.VersionMismatch(out res))
|
||||
{
|
||||
SentVMMWarning = true;
|
||||
Console.WriteLine(res);
|
||||
@@ -204,7 +204,7 @@ namespace TGCommandLine
|
||||
break;
|
||||
case "disconnect":
|
||||
SentVMMWarning = false;
|
||||
Server.MakeLocalConnection();
|
||||
Interface.MakeLocalConnection();
|
||||
Console.WriteLine("Switch to local mode");
|
||||
break;
|
||||
case "quit":
|
||||
@@ -212,7 +212,7 @@ namespace TGCommandLine
|
||||
return (int)Command.ExitCode.Normal;
|
||||
#if DEBUG
|
||||
case "debug-upgrade":
|
||||
Server.GetComponent<ITGSService>().PrepareForUpdate();
|
||||
Interface.GetComponent<ITGSService>().PrepareForUpdate();
|
||||
return (int)Command.ExitCode.Normal;
|
||||
#endif
|
||||
default:
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var res = Server.GetComponent<ITGRepository>().UpdateTGS3Json();
|
||||
var res = Interface.GetComponent<ITGRepository>().UpdateTGS3Json();
|
||||
if (res != null)
|
||||
{
|
||||
OutputProc(res);
|
||||
@@ -51,7 +51,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var res = Server.GetComponent<ITGRepository>().Setup(parameters[0], parameters.Count > 1 ? parameters[1] : "master");
|
||||
var res = Interface.GetComponent<ITGRepository>().Setup(parameters[0], parameters.Count > 1 ? parameters[1] : "master");
|
||||
if (res != null)
|
||||
{
|
||||
OutputProc("Error: " + res);
|
||||
@@ -78,7 +78,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var Repo = Server.GetComponent<ITGRepository>();
|
||||
var Repo = Interface.GetComponent<ITGRepository>();
|
||||
var busy = Repo.OperationInProgress();
|
||||
if (!busy)
|
||||
{
|
||||
@@ -131,7 +131,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var result = Server.GetComponent<ITGRepository>().Reset(parameters.Count > 0 && parameters[0].ToLower() == "--origin");
|
||||
var result = Interface.GetComponent<ITGRepository>().Reset(parameters.Count > 0 && parameters[0].ToLower() == "--origin");
|
||||
OutputProc(result ?? "Success!");
|
||||
return result == null ? ExitCode.Normal : ExitCode.ServerError;
|
||||
}
|
||||
@@ -167,7 +167,7 @@ namespace TGCommandLine
|
||||
OutputProc("Invalid parameter: " + parameters[0]);
|
||||
return ExitCode.BadCommand;
|
||||
}
|
||||
var res = Server.GetComponent<ITGRepository>().Update(hard);
|
||||
var res = Interface.GetComponent<ITGRepository>().Update(hard);
|
||||
OutputProc(res ?? "Success");
|
||||
return res == null ? ExitCode.Normal : ExitCode.ServerError;
|
||||
}
|
||||
@@ -188,7 +188,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var result = Server.GetComponent<ITGRepository>().GenerateChangelog(out string error);
|
||||
var result = Interface.GetComponent<ITGRepository>().GenerateChangelog(out string error);
|
||||
OutputProc(error ?? "Success!");
|
||||
if (result != null)
|
||||
OutputProc(result);
|
||||
@@ -208,7 +208,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var result = Server.GetComponent<ITGRepository>().SynchronizePush();
|
||||
var result = Interface.GetComponent<ITGRepository>().SynchronizePush();
|
||||
if(result != null)
|
||||
OutputProc(result);
|
||||
return result == null ? ExitCode.Normal : ExitCode.ServerError;
|
||||
@@ -228,7 +228,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
Server.GetComponent<ITGRepository>().SetCommitterEmail(parameters[0]);
|
||||
Interface.GetComponent<ITGRepository>().SetCommitterEmail(parameters[0]);
|
||||
return ExitCode.Normal;
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
Server.GetComponent<ITGRepository>().SetCommitterName(parameters[0]);
|
||||
Interface.GetComponent<ITGRepository>().SetCommitterName(parameters[0]);
|
||||
return ExitCode.Normal;
|
||||
}
|
||||
public override string GetArgumentString()
|
||||
@@ -271,7 +271,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
Server.GetComponent<ITGRepository>().SetPythonPath(parameters[0]);
|
||||
Interface.GetComponent<ITGRepository>().SetPythonPath(parameters[0]);
|
||||
return ExitCode.Normal;
|
||||
}
|
||||
public override string GetArgumentString()
|
||||
@@ -304,7 +304,7 @@ namespace TGCommandLine
|
||||
OutputProc("Invalid PR Number!");
|
||||
return ExitCode.BadCommand;
|
||||
}
|
||||
var res = Server.GetComponent<ITGRepository>().MergePullRequest(PR);
|
||||
var res = Interface.GetComponent<ITGRepository>().MergePullRequest(PR);
|
||||
OutputProc(res ?? "Success");
|
||||
return res == null ? ExitCode.Normal : ExitCode.ServerError;
|
||||
}
|
||||
@@ -331,7 +331,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var data = Server.GetComponent<ITGRepository>().MergedPullRequests(out string error);
|
||||
var data = Interface.GetComponent<ITGRepository>().MergedPullRequests(out string error);
|
||||
if (data == null)
|
||||
{
|
||||
OutputProc(error);
|
||||
@@ -358,7 +358,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var data = Server.GetComponent<ITGRepository>().ListBackups(out string error);
|
||||
var data = Interface.GetComponent<ITGRepository>().ListBackups(out string error);
|
||||
if (data == null)
|
||||
{
|
||||
OutputProc(error);
|
||||
@@ -385,7 +385,7 @@ namespace TGCommandLine
|
||||
}
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var res = Server.GetComponent<ITGRepository>().Checkout(parameters[0]);
|
||||
var res = Interface.GetComponent<ITGRepository>().Checkout(parameters[0]);
|
||||
OutputProc(res ?? "Success");
|
||||
return res == null ? ExitCode.Normal : ExitCode.ServerError;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace TGCommandLine
|
||||
public CLICommand()
|
||||
{
|
||||
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 (Server.VerifyConnection() == null && Server.Authenticate() && Server.AuthenticateAdmin())
|
||||
if (Interface.VerifyConnection() == null && Interface.Authenticate() && Interface.AuthenticateAdmin())
|
||||
tmp.Add(new AdminCommand());
|
||||
Children = tmp.ToArray();
|
||||
}
|
||||
@@ -35,7 +35,7 @@ namespace TGCommandLine
|
||||
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var res = Server.GetComponent<ITGRepository>().AutoUpdateInterval();
|
||||
var res = Interface.GetComponent<ITGRepository>().AutoUpdateInterval();
|
||||
OutputProc(res == 0 ? "OFF" : String.Format("Auto updating every {0} minutes", res));
|
||||
return ExitCode.Normal;
|
||||
}
|
||||
@@ -74,7 +74,7 @@ namespace TGCommandLine
|
||||
return ExitCode.BadCommand;
|
||||
}
|
||||
|
||||
Server.GetComponent<ITGRepository>().SetAutoUpdateInterval(NewInterval);
|
||||
Interface.GetComponent<ITGRepository>().SetAutoUpdateInterval(NewInterval);
|
||||
return ExitCode.Normal;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace TGCommandLine
|
||||
protected override ExitCode Run(IList<string> parameters)
|
||||
{
|
||||
var gen_cl = parameters.Count > 1 && parameters[1].ToLower() == "--cl";
|
||||
var Repo = Server.GetComponent<ITGRepository>();
|
||||
var Repo = Interface.GetComponent<ITGRepository>();
|
||||
switch (parameters[0].ToLower())
|
||||
{
|
||||
case "hard":
|
||||
@@ -124,7 +124,7 @@ namespace TGCommandLine
|
||||
OutputProc(res);
|
||||
}
|
||||
}
|
||||
var resu = Server.GetComponent<ITGCompiler>().Compile(true);
|
||||
var resu = Interface.GetComponent<ITGCompiler>().Compile(true);
|
||||
OutputProc(resu ? "Compilation started!" : "Compilation could not be started!");
|
||||
return resu ? ExitCode.Normal : ExitCode.ServerError;
|
||||
}
|
||||
@@ -161,7 +161,7 @@ namespace TGCommandLine
|
||||
OutputProc("Invalid tesmerge #: " + parameters[0]);
|
||||
return ExitCode.BadCommand;
|
||||
}
|
||||
var Repo = Server.GetComponent<ITGRepository>();
|
||||
var Repo = Interface.GetComponent<ITGRepository>();
|
||||
var res = Repo.MergePullRequest(tm);
|
||||
if (res != null)
|
||||
{
|
||||
@@ -174,7 +174,7 @@ namespace TGCommandLine
|
||||
OutputProc(res);
|
||||
return ExitCode.ServerError;
|
||||
}
|
||||
var resu = Server.GetComponent<ITGCompiler>().Compile(true);
|
||||
var resu = Interface.GetComponent<ITGCompiler>().Compile(true);
|
||||
OutputProc(resu ? "Compilation started!" : "Compilation could not be started!");
|
||||
return resu ? ExitCode.Normal : ExitCode.ServerError;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace TGControlPanel
|
||||
string lastReadError = null;
|
||||
void InitBYONDPage()
|
||||
{
|
||||
var BYOND = Server.GetComponent<ITGByond>();
|
||||
var BYOND = Interface.GetComponent<ITGByond>();
|
||||
var CV = BYOND.GetVersion(ByondVersion.Installed);
|
||||
if (CV == null)
|
||||
CV = BYOND.GetVersion(ByondVersion.Staged);
|
||||
@@ -30,7 +30,7 @@ namespace TGControlPanel
|
||||
}
|
||||
}
|
||||
|
||||
var latestVer = Server.GetComponent<ITGByond>().GetVersion(ByondVersion.Latest);
|
||||
var latestVer = Interface.GetComponent<ITGByond>().GetVersion(ByondVersion.Latest);
|
||||
LatestVersionLabel.Text = latestVer;
|
||||
|
||||
try
|
||||
@@ -47,7 +47,7 @@ namespace TGControlPanel
|
||||
private void UpdateButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
UpdateBYONDButtons();
|
||||
if (!Server.GetComponent<ITGByond>().UpdateToVersion((int)MajorVersionNumeric.Value, (int)MinorVersionNumeric.Value))
|
||||
if (!Interface.GetComponent<ITGByond>().UpdateToVersion((int)MajorVersionNumeric.Value, (int)MinorVersionNumeric.Value))
|
||||
MessageBox.Show("Unable to begin update, there is another operation in progress.");
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace TGControlPanel
|
||||
}
|
||||
void UpdateBYONDButtons()
|
||||
{
|
||||
var BYOND = Server.GetComponent<ITGByond>();
|
||||
var BYOND = Interface.GetComponent<ITGByond>();
|
||||
|
||||
VersionLabel.Text = BYOND.GetVersion(ByondVersion.Installed) ?? "Not Installed";
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace TGControlPanel
|
||||
UpdateButton.Enabled = false;
|
||||
break;
|
||||
}
|
||||
var error = Server.GetComponent<ITGByond>().GetError();
|
||||
var error = Interface.GetComponent<ITGByond>().GetError();
|
||||
if (error != lastReadError)
|
||||
{
|
||||
lastReadError = error;
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace TGControlPanel
|
||||
void LoadChatPage()
|
||||
{
|
||||
updatingChat = true;
|
||||
var Chat = Server.GetComponent<ITGChat>();
|
||||
var Chat = Interface.GetComponent<ITGChat>();
|
||||
var PI = Chat.ProviderInfos()[(int)ModifyingProvider];
|
||||
ChatAdminsTextBox.Visible = true;
|
||||
IRCModesComboBox.Visible = false;
|
||||
@@ -112,7 +112,7 @@ namespace TGControlPanel
|
||||
|
||||
private void ChatReconnectButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Server.GetComponent<ITGChat>().Reconnect(ModifyingProvider);
|
||||
Interface.GetComponent<ITGChat>().Reconnect(ModifyingProvider);
|
||||
LoadChatPage();
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ namespace TGControlPanel
|
||||
}
|
||||
void SetAdminsAreSpecial(bool value)
|
||||
{
|
||||
var Chat = Server.GetComponent<ITGChat>();
|
||||
var Chat = Interface.GetComponent<ITGChat>();
|
||||
var PI = Chat.ProviderInfos()[(int)ModifyingProvider];
|
||||
PI.AdminsAreSpecial = value;
|
||||
var res = Chat.SetProviderInfo(PI);
|
||||
@@ -208,7 +208,7 @@ namespace TGControlPanel
|
||||
wip.Enabled = ChatEnabledCheckbox.Checked;
|
||||
wip.AdminsAreSpecial = AdminModeSpecial.Checked;
|
||||
|
||||
res = Server.GetComponent<ITGChat>().SetProviderInfo(wip);
|
||||
res = Interface.GetComponent<ITGChat>().SetProviderInfo(wip);
|
||||
}
|
||||
if (res != null)
|
||||
MessageBox.Show(res);
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace TGControlPanel
|
||||
{
|
||||
IPTextBox.Text = IPTextBox.Text.Trim();
|
||||
UsernameTextBox.Text = UsernameTextBox.Text.Trim();
|
||||
Server.SetRemoteLoginInformation(IPTextBox.Text, (ushort)PortSelector.Value, UsernameTextBox.Text, PasswordTextBox.Text);
|
||||
Interface.SetRemoteLoginInformation(IPTextBox.Text, (ushort)PortSelector.Value, UsernameTextBox.Text, PasswordTextBox.Text);
|
||||
var Config = Properties.Settings.Default;
|
||||
Config.RemoteIP = IPTextBox.Text;
|
||||
Config.RemoteUsername = UsernameTextBox.Text;
|
||||
@@ -51,20 +51,20 @@ namespace TGControlPanel
|
||||
|
||||
private void LocalLoginButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Server.MakeLocalConnection();
|
||||
Interface.MakeLocalConnection();
|
||||
Properties.Settings.Default.RemoteDefault = false;
|
||||
VerifyAndConnect();
|
||||
}
|
||||
|
||||
void VerifyAndConnect()
|
||||
{
|
||||
var res = Server.VerifyConnection();
|
||||
var res = Interface.VerifyConnection();
|
||||
if (res != null)
|
||||
{
|
||||
MessageBox.Show("Unable to connect to service! Error: " + res);
|
||||
return;
|
||||
}
|
||||
if (!Server.Authenticate())
|
||||
if (!Interface.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;
|
||||
|
||||
@@ -11,12 +11,12 @@ namespace TGControlPanel
|
||||
partial class Main : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Create the control panel. Requires the <see cref="Server"/> has had it's connection info setup
|
||||
/// Create the control panel. Requires the <see cref="Interface"/> has had it's connection info setup
|
||||
/// </summary>
|
||||
public Main()
|
||||
{
|
||||
InitializeComponent();
|
||||
if (Server.VersionMismatch(out string error) && MessageBox.Show(error, "Warning", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
|
||||
if (Interface.VersionMismatch(out string error) && MessageBox.Show(error, "Warning", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
|
||||
{
|
||||
Close();
|
||||
return;
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace TGControlPanel
|
||||
[STAThread]
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Server.SetBadCertificateHandler(BadCertificateHandler);
|
||||
Interface.SetBadCertificateHandler(BadCertificateHandler);
|
||||
try
|
||||
{
|
||||
if (Properties.Settings.Default.UpgradeRequired)
|
||||
@@ -46,7 +46,7 @@ namespace TGControlPanel
|
||||
|
||||
public static bool CheckAdminWithWarning()
|
||||
{
|
||||
if (!Server.AuthenticateAdmin())
|
||||
if (!Interface.AuthenticateAdmin())
|
||||
{
|
||||
MessageBox.Show("Only system administrators may use this command!");
|
||||
return false;
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace TGControlPanel
|
||||
if (RepoBusyCheck())
|
||||
return;
|
||||
|
||||
var Repo = Server.GetComponent<ITGRepository>();
|
||||
var Repo = Interface.GetComponent<ITGRepository>();
|
||||
|
||||
RepoProgressBar.Style = ProgressBarStyle.Marquee;
|
||||
RepoProgressBar.Visible = false;
|
||||
@@ -150,7 +150,7 @@ namespace TGControlPanel
|
||||
|
||||
bool RepoBusyCheck()
|
||||
{
|
||||
if (Server.GetComponent<ITGRepository>().OperationInProgress())
|
||||
if (Interface.GetComponent<ITGRepository>().OperationInProgress())
|
||||
{
|
||||
DoAsyncOp(RepoAction.Wait, "Waiting for repository to finish another action...");
|
||||
return true;
|
||||
@@ -172,7 +172,7 @@ namespace TGControlPanel
|
||||
private void RepoBGW_DoWork(object sender, DoWorkEventArgs e)
|
||||
{
|
||||
//Only for clones
|
||||
var Repo = Server.GetComponent<ITGRepository>();
|
||||
var Repo = Interface.GetComponent<ITGRepository>();
|
||||
|
||||
switch (action) {
|
||||
case RepoAction.Clone:
|
||||
@@ -213,7 +213,7 @@ namespace TGControlPanel
|
||||
}
|
||||
void UpdatePythonPath()
|
||||
{
|
||||
if (!Server.GetComponent<ITGRepository>().SetPythonPath(PythonPathText.Text))
|
||||
if (!Interface.GetComponent<ITGRepository>().SetPythonPath(PythonPathText.Text))
|
||||
MessageBox.Show("Python could not be found in the selected location!");
|
||||
}
|
||||
private void CloneRepositoryButton_Click(object sender, EventArgs e)
|
||||
@@ -281,7 +281,7 @@ namespace TGControlPanel
|
||||
}
|
||||
private void RepoApplyButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var Repo = Server.GetComponent<ITGRepository>();
|
||||
var Repo = Interface.GetComponent<ITGRepository>();
|
||||
|
||||
if (RepoBusyCheck())
|
||||
return;
|
||||
@@ -353,7 +353,7 @@ namespace TGControlPanel
|
||||
{
|
||||
if (MessageBox.Show("This will update the cached TGS3.json to the current repository version, potentially redefining symlinks. Proceed?", "Json Update", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||
return;
|
||||
var res = Server.GetComponent<ITGRepository>().UpdateTGS3Json();
|
||||
var res = Interface.GetComponent<ITGRepository>().UpdateTGS3Json();
|
||||
if (res != null)
|
||||
MessageBox.Show(res);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace TGControlPanel
|
||||
void InitServerPage()
|
||||
{
|
||||
LoadServerPage();
|
||||
if (!Server.AuthenticateAdmin())
|
||||
if (!Interface.AuthenticateAdmin())
|
||||
{
|
||||
ServerPathTextbox.Enabled = false;
|
||||
ServerPathTextbox.ReadOnly = true;
|
||||
@@ -70,7 +70,7 @@ namespace TGControlPanel
|
||||
|
||||
private void CompileCancelButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var res = Server.GetComponent<ITGCompiler>().Cancel();
|
||||
var res = Interface.GetComponent<ITGCompiler>().Cancel();
|
||||
if (res != null)
|
||||
MessageBox.Show(res);
|
||||
LoadServerPage();
|
||||
@@ -89,7 +89,7 @@ namespace TGControlPanel
|
||||
ServerPathTextbox.ReadOnly = true;
|
||||
return;
|
||||
}
|
||||
if (updatingFields || ServerPathTextbox.Text.Trim() == Server.GetComponent<ITGConfig>().ServerDirectory())
|
||||
if (updatingFields || ServerPathTextbox.Text.Trim() == Interface.GetComponent<ITGConfig>().ServerDirectory())
|
||||
return;
|
||||
var DialogResult = MessageBox.Show("This will move the entire server installation.", "Confim", MessageBoxButtons.YesNo);
|
||||
if (DialogResult != DialogResult.Yes)
|
||||
@@ -101,12 +101,12 @@ namespace TGControlPanel
|
||||
ServerPathTextbox.ReadOnly = true;
|
||||
return;
|
||||
}
|
||||
MessageBox.Show(Server.GetComponent<ITGAdministration>().MoveServer(ServerPathTextbox.Text) ?? "Success!");
|
||||
MessageBox.Show(Interface.GetComponent<ITGAdministration>().MoveServer(ServerPathTextbox.Text) ?? "Success!");
|
||||
}
|
||||
|
||||
void LoadServerPage()
|
||||
{
|
||||
var RepoExists = Server.GetComponent<ITGRepository>().Exists();
|
||||
var RepoExists = Interface.GetComponent<ITGRepository>().Exists();
|
||||
compileButton.Visible = RepoExists;
|
||||
AutoUpdateCheckbox.Visible = RepoExists;
|
||||
initializeButton.Visible = RepoExists;
|
||||
@@ -138,10 +138,10 @@ namespace TGControlPanel
|
||||
if (updatingFields)
|
||||
return;
|
||||
|
||||
var DM = Server.GetComponent<ITGCompiler>();
|
||||
var DD = Server.GetComponent<ITGDreamDaemon>();
|
||||
var Config = Server.GetComponent<ITGConfig>();
|
||||
var Repo = Server.GetComponent<ITGRepository>();
|
||||
var DM = Interface.GetComponent<ITGCompiler>();
|
||||
var DD = Interface.GetComponent<ITGDreamDaemon>();
|
||||
var Config = Interface.GetComponent<ITGConfig>();
|
||||
var Repo = Interface.GetComponent<ITGRepository>();
|
||||
|
||||
try
|
||||
{
|
||||
@@ -247,13 +247,13 @@ namespace TGControlPanel
|
||||
void UpdateProjectName()
|
||||
{
|
||||
if (!updatingFields)
|
||||
Server.GetComponent<ITGCompiler>().SetProjectName(projectNameText.Text);
|
||||
Interface.GetComponent<ITGCompiler>().SetProjectName(projectNameText.Text);
|
||||
}
|
||||
|
||||
private void PortSelector_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!updatingFields)
|
||||
Server.GetComponent<ITGDreamDaemon>().SetPort((ushort)PortSelector.Value);
|
||||
Interface.GetComponent<ITGDreamDaemon>().SetPort((ushort)PortSelector.Value);
|
||||
}
|
||||
|
||||
private void RunServerUpdate(FullUpdateAction fua, ushort tm = 0)
|
||||
@@ -293,13 +293,13 @@ namespace TGControlPanel
|
||||
|
||||
private void InitializeButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!Server.GetComponent<ITGCompiler>().Initialize())
|
||||
if (!Interface.GetComponent<ITGCompiler>().Initialize())
|
||||
MessageBox.Show("Unable to start initialization!");
|
||||
LoadServerPage();
|
||||
}
|
||||
private void CompileButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!Server.GetComponent<ITGCompiler>().Compile())
|
||||
if (!Interface.GetComponent<ITGCompiler>().Compile())
|
||||
MessageBox.Show("Unable to start compilation!");
|
||||
LoadServerPage();
|
||||
}
|
||||
@@ -307,7 +307,7 @@ namespace TGControlPanel
|
||||
private void AutostartCheckbox_CheckedChanged(object sender, System.EventArgs e)
|
||||
{
|
||||
if (!updatingFields)
|
||||
Server.GetComponent<ITGDreamDaemon>().SetAutostart(AutostartCheckbox.Checked);
|
||||
Interface.GetComponent<ITGDreamDaemon>().SetAutostart(AutostartCheckbox.Checked);
|
||||
}
|
||||
private void ServerStartButton_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
@@ -319,7 +319,7 @@ namespace TGControlPanel
|
||||
{
|
||||
try
|
||||
{
|
||||
e.Result = Server.GetComponent<ITGDreamDaemon>().Start();
|
||||
e.Result = Interface.GetComponent<ITGDreamDaemon>().Start();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -332,7 +332,7 @@ namespace TGControlPanel
|
||||
var DialogResult = MessageBox.Show("This will immediately shut down the server. Continue?", "Confim", MessageBoxButtons.YesNo);
|
||||
if (DialogResult == DialogResult.No)
|
||||
return;
|
||||
var res = Server.GetComponent<ITGDreamDaemon>().Stop();
|
||||
var res = Interface.GetComponent<ITGDreamDaemon>().Stop();
|
||||
if (res != null)
|
||||
MessageBox.Show(res);
|
||||
}
|
||||
@@ -342,7 +342,7 @@ namespace TGControlPanel
|
||||
var DialogResult = MessageBox.Show("This will immediately restart the server. Continue?", "Confim", MessageBoxButtons.YesNo);
|
||||
if (DialogResult == DialogResult.No)
|
||||
return;
|
||||
var res = Server.GetComponent<ITGDreamDaemon>().Restart();
|
||||
var res = Interface.GetComponent<ITGDreamDaemon>().Restart();
|
||||
if (res != null)
|
||||
MessageBox.Show(res);
|
||||
}
|
||||
@@ -354,7 +354,7 @@ namespace TGControlPanel
|
||||
var DialogResult = MessageBox.Show("This will shut down the server when the current round ends. Continue?", "Confim", MessageBoxButtons.YesNo);
|
||||
if (DialogResult == DialogResult.No)
|
||||
return;
|
||||
Server.GetComponent<ITGDreamDaemon>().RequestStop();
|
||||
Interface.GetComponent<ITGDreamDaemon>().RequestStop();
|
||||
LoadServerPage();
|
||||
}
|
||||
|
||||
@@ -363,7 +363,7 @@ namespace TGControlPanel
|
||||
var DialogResult = MessageBox.Show("This will restart the server when the current round ends. Continue?", "Confim", MessageBoxButtons.YesNo);
|
||||
if (DialogResult == DialogResult.No)
|
||||
return;
|
||||
Server.GetComponent<ITGDreamDaemon>().RequestRestart();
|
||||
Interface.GetComponent<ITGDreamDaemon>().RequestRestart();
|
||||
}
|
||||
|
||||
|
||||
@@ -371,8 +371,8 @@ namespace TGControlPanel
|
||||
{
|
||||
try
|
||||
{
|
||||
var Repo = Server.GetComponent<ITGRepository>();
|
||||
var DM = Server.GetComponent<ITGCompiler>();
|
||||
var Repo = Interface.GetComponent<ITGRepository>();
|
||||
var DM = Interface.GetComponent<ITGCompiler>();
|
||||
switch (fuAction)
|
||||
{
|
||||
case FullUpdateAction.Testmerge:
|
||||
@@ -460,7 +460,7 @@ namespace TGControlPanel
|
||||
private void SecuritySelector_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!updatingFields)
|
||||
if (!Server.GetComponent<ITGDreamDaemon>().SetSecurityLevel((DreamDaemonSecurity)SecuritySelector.SelectedIndex))
|
||||
if (!Interface.GetComponent<ITGDreamDaemon>().SetSecurityLevel((DreamDaemonSecurity)SecuritySelector.SelectedIndex))
|
||||
MessageBox.Show("Security change will be applied after next server reboot.");
|
||||
}
|
||||
|
||||
@@ -469,7 +469,7 @@ namespace TGControlPanel
|
||||
var msg = WorldAnnounceField.Text;
|
||||
if (!String.IsNullOrWhiteSpace(msg))
|
||||
{
|
||||
var res = Server.GetComponent<ITGDreamDaemon>().WorldAnnounce(msg);
|
||||
var res = Interface.GetComponent<ITGDreamDaemon>().WorldAnnounce(msg);
|
||||
if (res != null)
|
||||
{
|
||||
MessageBox.Show(res);
|
||||
@@ -482,13 +482,13 @@ namespace TGControlPanel
|
||||
private void WebclientCheckBox_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!updatingFields)
|
||||
Server.GetComponent<ITGDreamDaemon>().SetWebclient(WebclientCheckBox.Checked);
|
||||
Interface.GetComponent<ITGDreamDaemon>().SetWebclient(WebclientCheckBox.Checked);
|
||||
}
|
||||
|
||||
private void AutoUpdateInterval_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!updatingFields)
|
||||
Server.GetComponent<ITGRepository>().SetAutoUpdateInterval((ulong)AutoUpdateInterval.Value);
|
||||
Interface.GetComponent<ITGRepository>().SetAutoUpdateInterval((ulong)AutoUpdateInterval.Value);
|
||||
}
|
||||
|
||||
private void AutoUpdateCheckbox_CheckedChanged(object sender, EventArgs e)
|
||||
@@ -499,9 +499,9 @@ namespace TGControlPanel
|
||||
AutoUpdateInterval.Visible = on;
|
||||
AutoUpdateMLabel.Visible = on;
|
||||
if (!on)
|
||||
Server.GetComponent<ITGRepository>().SetAutoUpdateInterval(0);
|
||||
Interface.GetComponent<ITGRepository>().SetAutoUpdateInterval(0);
|
||||
else
|
||||
Server.GetComponent<ITGRepository>().SetAutoUpdateInterval((ulong)AutoUpdateInterval.Value);
|
||||
Interface.GetComponent<ITGRepository>().SetAutoUpdateInterval((ulong)AutoUpdateInterval.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace TGControlPanel
|
||||
|
||||
void InitStaticPage()
|
||||
{
|
||||
if(!Server.AuthenticateAdmin())
|
||||
if(!Interface.AuthenticateAdmin())
|
||||
RecreateStaticButton.Visible = false;
|
||||
BuildFileList();
|
||||
}
|
||||
@@ -34,7 +34,7 @@ namespace TGControlPanel
|
||||
IndexesToPaths.Clear();
|
||||
StaticFileListBox.Items.Clear();
|
||||
IndexesToPaths.Add(StaticFileListBox.Items.Add("/"), "/");
|
||||
if (EnumeratePath("", Server.GetComponent<ITGConfig>(), 1) == EnumResult.Unauthorized)
|
||||
if (EnumeratePath("", Interface.GetComponent<ITGConfig>(), 1) == EnumResult.Unauthorized)
|
||||
{
|
||||
StaticFileListBox.Items[0] += " (UNAUTHORIZED)";
|
||||
IndexesToPaths[0] = null;
|
||||
@@ -140,7 +140,7 @@ namespace TGControlPanel
|
||||
if (error == null)
|
||||
try
|
||||
{
|
||||
error = Server.GetComponent<ITGConfig>().WriteText(FileName, fileContents, out bool unauthorized);
|
||||
error = Interface.GetComponent<ITGConfig>().WriteText(FileName, fileContents, out bool unauthorized);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -164,7 +164,7 @@ namespace TGControlPanel
|
||||
string text, error;
|
||||
try
|
||||
{
|
||||
text = Server.GetComponent<ITGConfig>().ReadText(remotePath, false, out error, out bool unauthorized);
|
||||
text = Interface.GetComponent<ITGConfig>().ReadText(remotePath, false, out error, out bool unauthorized);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -206,7 +206,7 @@ namespace TGControlPanel
|
||||
{
|
||||
if (MessageBox.Show("Are you sure you want to delete " + ((string)StaticFileListBox.SelectedItem).Trim() + "?", "Confirm", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||
return;
|
||||
var res = Server.GetComponent<ITGConfig>().DeleteFile(IndexesToPaths[StaticFileListBox.SelectedIndex], out bool unauthorized);
|
||||
var res = Interface.GetComponent<ITGConfig>().DeleteFile(IndexesToPaths[StaticFileListBox.SelectedIndex], out bool unauthorized);
|
||||
if (res != null)
|
||||
MessageBox.Show(res);
|
||||
BuildFileList();
|
||||
@@ -229,7 +229,7 @@ namespace TGControlPanel
|
||||
var FullFileName = Path.Combine(IndexesToPaths[StaticFileListBox.SelectedIndex], FileName);
|
||||
if (resu == DialogResult.Yes)
|
||||
FullFileName = Path.Combine(FullFileName, "__TGS3_CP_DIRECTORY_CREATOR__");
|
||||
var config = Server.GetComponent<ITGConfig>();
|
||||
var config = Interface.GetComponent<ITGConfig>();
|
||||
var res = config.WriteText(FullFileName, "", out bool unauthorized);
|
||||
if (res != null)
|
||||
MessageBox.Show(res);
|
||||
@@ -248,7 +248,7 @@ namespace TGControlPanel
|
||||
bool unauthorized;
|
||||
try
|
||||
{
|
||||
res = Server.GetComponent<ITGConfig>().WriteText(IndexesToPaths[index], StaticFileEditTextbox.Text, out unauthorized);
|
||||
res = Interface.GetComponent<ITGConfig>().WriteText(IndexesToPaths[index], StaticFileEditTextbox.Text, out unauthorized);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -300,7 +300,7 @@ namespace TGControlPanel
|
||||
bool unauthorized;
|
||||
try
|
||||
{
|
||||
entry = Server.GetComponent<ITGConfig>().ReadText(path, false, out error, out unauthorized);
|
||||
entry = Interface.GetComponent<ITGConfig>().ReadText(path, false, out error, out unauthorized);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
@@ -337,7 +337,7 @@ namespace TGControlPanel
|
||||
RecreateStaticButton.Visible = false;
|
||||
return;
|
||||
}
|
||||
var res = Server.GetComponent<ITGAdministration>().RecreateStaticFolder();
|
||||
var res = Interface.GetComponent<ITGAdministration>().RecreateStaticFolder();
|
||||
if (res != null)
|
||||
MessageBox.Show(res);
|
||||
BuildFileList();
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace TGServerService
|
||||
CloseTimeout = new TimeSpan(0, 0, 5)
|
||||
};
|
||||
|
||||
foreach (var I in Server.ValidInterfaces)
|
||||
foreach (var I in Interface.ValidInterfaces)
|
||||
AddEndpoint(I);
|
||||
|
||||
host.Authorization.ServiceAuthorizationManager = instance;
|
||||
@@ -132,12 +132,12 @@ namespace TGServerService
|
||||
//shorthand for adding the WCF endpoint
|
||||
void AddEndpoint(Type typetype)
|
||||
{
|
||||
var bindingName = Server.MasterInterfaceName + "/" + typetype.Name;
|
||||
host.AddServiceEndpoint(typetype, new NetNamedPipeBinding() { SendTimeout = new TimeSpan(0, 0, 30), MaxReceivedMessageSize = Server.TransferLimitLocal }, bindingName);
|
||||
var bindingName = Interface.MasterInterfaceName + "/" + typetype.Name;
|
||||
host.AddServiceEndpoint(typetype, new NetNamedPipeBinding() { SendTimeout = new TimeSpan(0, 0, 30), MaxReceivedMessageSize = Interface.TransferLimitLocal }, bindingName);
|
||||
var httpsBinding = new WSHttpBinding()
|
||||
{
|
||||
SendTimeout = new TimeSpan(0, 0, 40),
|
||||
MaxReceivedMessageSize = Server.TransferLimitRemote
|
||||
MaxReceivedMessageSize = Interface.TransferLimitRemote
|
||||
};
|
||||
var requireAuth = typetype.Name != typeof(ITGConnectivity).Name;
|
||||
httpsBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
|
||||
|
||||
@@ -21,13 +21,13 @@ namespace TGServiceInterface
|
||||
{
|
||||
try
|
||||
{
|
||||
var channel = Server.CreateChannel<ITGInterop>();
|
||||
var channel = Interface.CreateChannel<ITGInterop>();
|
||||
try
|
||||
{
|
||||
channel.CreateChannel().InteropMessage(String.Join(" ", args));
|
||||
}
|
||||
catch { }
|
||||
Server.CloseChannel(channel);
|
||||
Interface.CloseChannel(channel);
|
||||
}
|
||||
catch { }
|
||||
return 0;
|
||||
|
||||
@@ -1,307 +1,307 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Reflection;
|
||||
using System.Security.Principal;
|
||||
using System.ServiceModel;
|
||||
using TGServiceInterface.Components;
|
||||
|
||||
namespace TGServiceInterface
|
||||
{
|
||||
/// <summary>
|
||||
/// Main inteface class for the service
|
||||
/// </summary>
|
||||
public class Server
|
||||
{
|
||||
/// <summary>
|
||||
/// List of <see langword="interface"/>s that can be used with <see cref="GetComponent{T}"/> and <see cref="CreateChannel{T}"/>
|
||||
/// </summary>
|
||||
public static readonly IList<Type> ValidInterfaces = CollectComponents();
|
||||
|
||||
/// <summary>
|
||||
/// The maximum message size to and from a local server
|
||||
/// </summary>
|
||||
public static readonly long TransferLimitLocal = Int32.MaxValue; //2GB can't go higher
|
||||
|
||||
/// <summary>
|
||||
/// The maximum message size to and from a remote server
|
||||
/// </summary>
|
||||
public static readonly long TransferLimitRemote = 10485760; //10 MB
|
||||
|
||||
/// <summary>
|
||||
/// Base name of the communication pipe
|
||||
/// they are formatted as MasterPipeName/ComponentName
|
||||
/// </summary>
|
||||
public static string MasterInterfaceName = "TGStationServerService";
|
||||
|
||||
/// <summary>
|
||||
/// If this is set, we will try and connect to an HTTPS server running at this address
|
||||
/// </summary>
|
||||
static string HTTPSURL;
|
||||
|
||||
/// <summary>
|
||||
/// The port used by the service
|
||||
/// </summary>
|
||||
static ushort HTTPSPort = 38607;
|
||||
|
||||
/// <summary>
|
||||
/// Username for remote operations
|
||||
/// </summary>
|
||||
static string HTTPSUsername;
|
||||
|
||||
/// <summary>
|
||||
/// Password for remote operations
|
||||
/// </summary>
|
||||
static 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>();
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="IList{T}"/> of <see langword="interface"/> <see cref="Type"/>s that can be used with the service
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="IList{T}"/> of <see langword="interface"/> <see cref="Type"/>s that can be used with the service</returns>
|
||||
static IList<Type> CollectComponents()
|
||||
{
|
||||
//find all interfaces in this assembly in this namespace that have the service contract attribute
|
||||
var query = from t in Assembly.GetExecutingAssembly().GetTypes()
|
||||
where t.IsInterface
|
||||
&& t.Namespace == typeof(ITGSService).Namespace
|
||||
&& t.GetCustomAttribute(typeof(ServiceContractAttribute)) != null
|
||||
select t;
|
||||
return query.ToList();
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) =>
|
||||
{
|
||||
string ErrorMessage;
|
||||
switch (error)
|
||||
{
|
||||
case SslPolicyErrors.None:
|
||||
return true;
|
||||
case SslPolicyErrors.RemoteCertificateChainErrors:
|
||||
ErrorMessage = "There are certificate chain errors.";
|
||||
break;
|
||||
case SslPolicyErrors.RemoteCertificateNameMismatch:
|
||||
ErrorMessage = "The certificate name does not match.";
|
||||
break;
|
||||
case SslPolicyErrors.RemoteCertificateNotAvailable:
|
||||
ErrorMessage = "The certificate doesn't exist in the trust store.";
|
||||
break;
|
||||
default:
|
||||
ErrorMessage = "An unknown error occurred.";
|
||||
break;
|
||||
}
|
||||
ErrorMessage = String.Format("The certificate failed to verify for {0}:{1}. {2} {3}", HTTPSURL, HTTPSPort, ErrorMessage, cert.ToString());
|
||||
return handler(ErrorMessage);
|
||||
};
|
||||
}
|
||||
|
||||
/// <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()
|
||||
{
|
||||
lock (ChannelFactoryCache)
|
||||
{
|
||||
foreach (var I in ChannelFactoryCache)
|
||||
CloseChannel(I.Value);
|
||||
ChannelFactoryCache.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns <see langword="true"/> if the <see cref="Server"/> interface being used to connect to a service does not have the same release version as the service
|
||||
/// </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="Server"/> 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)
|
||||
{
|
||||
var splits = Server.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 != ours)
|
||||
{
|
||||
errorMessage = String.Format("Version mismatch between interface version ({0}) and service version ({1}). Some functionality may crash this program.", ours, theirs);
|
||||
return true;
|
||||
}
|
||||
errorMessage = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the remote <see cref="Server"/> 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)
|
||||
{
|
||||
try
|
||||
{
|
||||
cf.Close();
|
||||
}
|
||||
catch
|
||||
{
|
||||
cf.Abort();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the requested <see cref="Server"/> 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>()
|
||||
{
|
||||
var tot = typeof(T);
|
||||
ChannelFactory<T> cf;
|
||||
|
||||
lock (ChannelFactoryCache)
|
||||
{
|
||||
if (ChannelFactoryCache.ContainsKey(tot))
|
||||
try
|
||||
{
|
||||
cf = ((ChannelFactory<T>)ChannelFactoryCache[tot]);
|
||||
if (cf.State != CommunicationState.Opened)
|
||||
throw new Exception();
|
||||
return cf.CreateChannel();
|
||||
}
|
||||
catch
|
||||
{
|
||||
ChannelFactoryCache[tot].Abort();
|
||||
ChannelFactoryCache.Remove(tot);
|
||||
}
|
||||
cf = CreateChannel<T>();
|
||||
ChannelFactoryCache[tot] = cf;
|
||||
}
|
||||
return cf.CreateChannel();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Directly creates a <see cref="ChannelFactory{TChannel}"/> for <typeparamref name="T"/> without caching. This should be eventually closed by the caller
|
||||
/// </summary>
|
||||
/// <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>()
|
||||
{
|
||||
var ToT = typeof(T);
|
||||
if (!ValidInterfaces.Contains(ToT))
|
||||
throw new Exception("Invalid type!");
|
||||
var InterfaceName = typeof(T).Name;
|
||||
if (HTTPSURL == null)
|
||||
{
|
||||
var res2 = new ChannelFactory<T>(
|
||||
new NetNamedPipeBinding { SendTimeout = new TimeSpan(0, 0, 30), MaxReceivedMessageSize = TransferLimitLocal }, new EndpointAddress(String.Format("net.pipe://localhost/{0}/{1}", MasterInterfaceName, InterfaceName))); //10 megs
|
||||
res2.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
|
||||
return res2;
|
||||
}
|
||||
|
||||
//okay we're going over
|
||||
var binding = new WSHttpBinding()
|
||||
{
|
||||
SendTimeout = new TimeSpan(0, 0, 40),
|
||||
MaxReceivedMessageSize = TransferLimitRemote
|
||||
};
|
||||
var requireAuth = InterfaceName != typeof(ITGConnectivity).Name;
|
||||
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
|
||||
binding.Security.Mode = requireAuth ? SecurityMode.TransportWithMessageCredential : SecurityMode.Transport; //do not require auth for a connectivity check
|
||||
binding.Security.Message.ClientCredentialType = requireAuth ? MessageCredentialType.UserName : MessageCredentialType.None;
|
||||
var address = new EndpointAddress(String.Format("https://{0}:{1}/{2}/{3}", HTTPSURL, HTTPSPort, MasterInterfaceName, InterfaceName));
|
||||
var res = new ChannelFactory<T>(binding, address);
|
||||
if (requireAuth)
|
||||
{
|
||||
res.Credentials.UserName.UserName = HTTPSUsername;
|
||||
res.Credentials.UserName.Password = HTTPSPassword;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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()
|
||||
{
|
||||
try
|
||||
{
|
||||
GetComponent<ITGConnectivity>().VerifyConnection();
|
||||
return null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return e.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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()
|
||||
{
|
||||
try
|
||||
{
|
||||
GetComponent<ITGSService>().Version();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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()
|
||||
{
|
||||
try
|
||||
{
|
||||
GetComponent<ITGAdministration>().GetCurrentAuthorizedGroup();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Reflection;
|
||||
using System.Security.Principal;
|
||||
using System.ServiceModel;
|
||||
using TGServiceInterface.Components;
|
||||
|
||||
namespace TGServiceInterface
|
||||
{
|
||||
/// <summary>
|
||||
/// Main inteface class for the service
|
||||
/// </summary>
|
||||
public class Interface
|
||||
{
|
||||
/// <summary>
|
||||
/// List of <see langword="interface"/>s that can be used with <see cref="GetComponent{T}"/> and <see cref="CreateChannel{T}"/>
|
||||
/// </summary>
|
||||
public static readonly IList<Type> ValidInterfaces = CollectComponents();
|
||||
|
||||
/// <summary>
|
||||
/// The maximum message size to and from a local server
|
||||
/// </summary>
|
||||
public static readonly long TransferLimitLocal = Int32.MaxValue; //2GB can't go higher
|
||||
|
||||
/// <summary>
|
||||
/// The maximum message size to and from a remote server
|
||||
/// </summary>
|
||||
public static readonly long TransferLimitRemote = 10485760; //10 MB
|
||||
|
||||
/// <summary>
|
||||
/// Base name of the communication pipe
|
||||
/// they are formatted as MasterPipeName/ComponentName
|
||||
/// </summary>
|
||||
public static string MasterInterfaceName = "TGStationServerService";
|
||||
|
||||
/// <summary>
|
||||
/// If this is set, we will try and connect to an HTTPS server running at this address
|
||||
/// </summary>
|
||||
static string HTTPSURL;
|
||||
|
||||
/// <summary>
|
||||
/// The port used by the service
|
||||
/// </summary>
|
||||
static ushort HTTPSPort = 38607;
|
||||
|
||||
/// <summary>
|
||||
/// Username for remote operations
|
||||
/// </summary>
|
||||
static string HTTPSUsername;
|
||||
|
||||
/// <summary>
|
||||
/// Password for remote operations
|
||||
/// </summary>
|
||||
static 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>();
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="IList{T}"/> of <see langword="interface"/> <see cref="Type"/>s that can be used with the service
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="IList{T}"/> of <see langword="interface"/> <see cref="Type"/>s that can be used with the service</returns>
|
||||
static IList<Type> CollectComponents()
|
||||
{
|
||||
//find all interfaces in this assembly in this namespace that have the service contract attribute
|
||||
var query = from t in Assembly.GetExecutingAssembly().GetTypes()
|
||||
where t.IsInterface
|
||||
&& t.Namespace == typeof(ITGSService).Namespace
|
||||
&& t.GetCustomAttribute(typeof(ServiceContractAttribute)) != null
|
||||
select t;
|
||||
return query.ToList();
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) =>
|
||||
{
|
||||
string ErrorMessage;
|
||||
switch (error)
|
||||
{
|
||||
case SslPolicyErrors.None:
|
||||
return true;
|
||||
case SslPolicyErrors.RemoteCertificateChainErrors:
|
||||
ErrorMessage = "There are certificate chain errors.";
|
||||
break;
|
||||
case SslPolicyErrors.RemoteCertificateNameMismatch:
|
||||
ErrorMessage = "The certificate name does not match.";
|
||||
break;
|
||||
case SslPolicyErrors.RemoteCertificateNotAvailable:
|
||||
ErrorMessage = "The certificate doesn't exist in the trust store.";
|
||||
break;
|
||||
default:
|
||||
ErrorMessage = "An unknown error occurred.";
|
||||
break;
|
||||
}
|
||||
ErrorMessage = String.Format("The certificate failed to verify for {0}:{1}. {2} {3}", HTTPSURL, HTTPSPort, ErrorMessage, cert.ToString());
|
||||
return handler(ErrorMessage);
|
||||
};
|
||||
}
|
||||
|
||||
/// <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()
|
||||
{
|
||||
lock (ChannelFactoryCache)
|
||||
{
|
||||
foreach (var I in ChannelFactoryCache)
|
||||
CloseChannel(I.Value);
|
||||
ChannelFactoryCache.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </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)
|
||||
{
|
||||
var splits = Interface.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 != ours)
|
||||
{
|
||||
errorMessage = String.Format("Version mismatch between interface version ({0}) and service version ({1}). Some functionality may crash this program.", ours, theirs);
|
||||
return true;
|
||||
}
|
||||
errorMessage = null;
|
||||
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)
|
||||
{
|
||||
try
|
||||
{
|
||||
cf.Close();
|
||||
}
|
||||
catch
|
||||
{
|
||||
cf.Abort();
|
||||
}
|
||||
}
|
||||
|
||||
/// <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>()
|
||||
{
|
||||
var tot = typeof(T);
|
||||
ChannelFactory<T> cf;
|
||||
|
||||
lock (ChannelFactoryCache)
|
||||
{
|
||||
if (ChannelFactoryCache.ContainsKey(tot))
|
||||
try
|
||||
{
|
||||
cf = ((ChannelFactory<T>)ChannelFactoryCache[tot]);
|
||||
if (cf.State != CommunicationState.Opened)
|
||||
throw new Exception();
|
||||
return cf.CreateChannel();
|
||||
}
|
||||
catch
|
||||
{
|
||||
ChannelFactoryCache[tot].Abort();
|
||||
ChannelFactoryCache.Remove(tot);
|
||||
}
|
||||
cf = CreateChannel<T>();
|
||||
ChannelFactoryCache[tot] = cf;
|
||||
}
|
||||
return cf.CreateChannel();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Directly creates a <see cref="ChannelFactory{TChannel}"/> for <typeparamref name="T"/> without caching. This should be eventually closed by the caller
|
||||
/// </summary>
|
||||
/// <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>()
|
||||
{
|
||||
var ToT = typeof(T);
|
||||
if (!ValidInterfaces.Contains(ToT))
|
||||
throw new Exception("Invalid type!");
|
||||
var InterfaceName = typeof(T).Name;
|
||||
if (HTTPSURL == null)
|
||||
{
|
||||
var res2 = new ChannelFactory<T>(
|
||||
new NetNamedPipeBinding { SendTimeout = new TimeSpan(0, 0, 30), MaxReceivedMessageSize = TransferLimitLocal }, new EndpointAddress(String.Format("net.pipe://localhost/{0}/{1}", MasterInterfaceName, InterfaceName))); //10 megs
|
||||
res2.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
|
||||
return res2;
|
||||
}
|
||||
|
||||
//okay we're going over
|
||||
var binding = new WSHttpBinding()
|
||||
{
|
||||
SendTimeout = new TimeSpan(0, 0, 40),
|
||||
MaxReceivedMessageSize = TransferLimitRemote
|
||||
};
|
||||
var requireAuth = InterfaceName != typeof(ITGConnectivity).Name;
|
||||
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
|
||||
binding.Security.Mode = requireAuth ? SecurityMode.TransportWithMessageCredential : SecurityMode.Transport; //do not require auth for a connectivity check
|
||||
binding.Security.Message.ClientCredentialType = requireAuth ? MessageCredentialType.UserName : MessageCredentialType.None;
|
||||
var address = new EndpointAddress(String.Format("https://{0}:{1}/{2}/{3}", HTTPSURL, HTTPSPort, MasterInterfaceName, InterfaceName));
|
||||
var res = new ChannelFactory<T>(binding, address);
|
||||
if (requireAuth)
|
||||
{
|
||||
res.Credentials.UserName.UserName = HTTPSUsername;
|
||||
res.Credentials.UserName.Password = HTTPSPassword;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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()
|
||||
{
|
||||
try
|
||||
{
|
||||
GetComponent<ITGConnectivity>().VerifyConnection();
|
||||
return null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return e.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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()
|
||||
{
|
||||
try
|
||||
{
|
||||
GetComponent<ITGSService>().Version();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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()
|
||||
{
|
||||
try
|
||||
{
|
||||
GetComponent<ITGAdministration>().GetCurrentAuthorizedGroup();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@
|
||||
<Compile Include="Components\Repository.cs" />
|
||||
<Compile Include="PullRequestInfo.cs" />
|
||||
<Compile Include="RootCommand.cs" />
|
||||
<Compile Include="Server.cs" />
|
||||
<Compile Include="Interface.cs" />
|
||||
<Compile Include="..\Version.cs" />
|
||||
<Compile Include="Components\Service.cs" />
|
||||
<Compile Include="Components\Interop.cs" />
|
||||
|
||||
Reference in New Issue
Block a user