From 2fba2898042d49588f0433cbae28f1c7bbb14c19 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 20 Oct 2017 14:12:46 -0400 Subject: [PATCH] Server => Interface --- TGCommandLine/AdminCommands.cs | 14 +- TGCommandLine/BYONDCommands.cs | 6 +- TGCommandLine/ChatCommands.cs | 34 +- TGCommandLine/ConfigCommands.cs | 10 +- TGCommandLine/DDCommands.cs | 18 +- TGCommandLine/DMCommands.cs | 14 +- TGCommandLine/Program.cs | 28 +- TGCommandLine/RepoCommands.cs | 28 +- TGCommandLine/RootCommands.cs | 14 +- TGControlPanel/ByondPage.cs | 10 +- TGControlPanel/ChatPage.cs | 8 +- TGControlPanel/Login.cs | 8 +- TGControlPanel/Main.cs | 4 +- TGControlPanel/Program.cs | 4 +- TGControlPanel/RepoPage.cs | 12 +- TGControlPanel/ServerPage.cs | 54 +- TGControlPanel/StaticPage.cs | 18 +- TGServerService/Service.cs | 8 +- TGServiceInterface/DreamDaemonBridge.cs | 4 +- .../{Server.cs => Interface.cs} | 614 +++++++++--------- TGServiceInterface/TGServiceInterface.csproj | 2 +- 21 files changed, 456 insertions(+), 456 deletions(-) rename TGServiceInterface/{Server.cs => Interface.cs} (90%) diff --git a/TGCommandLine/AdminCommands.cs b/TGCommandLine/AdminCommands.cs index 611abd756d..b50ef3201f 100644 --- a/TGCommandLine/AdminCommands.cs +++ b/TGCommandLine/AdminCommands.cs @@ -28,7 +28,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { - var res = Server.GetComponent().MoveServer(parameters[0]); + var res = Interface.GetComponent().MoveServer(parameters[0]); OutputProc(res ?? "Success"); return res == null ? ExitCode.Normal : ExitCode.ServerError; } @@ -52,7 +52,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { - var res = Server.GetComponent().RecreateStaticFolder(); + var res = Interface.GetComponent().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().SetRemoteAccessPort(port); + var res = Interface.GetComponent().SetRemoteAccessPort(port); OutputProc(res ?? "Success!"); return ExitCode.Normal; } @@ -110,7 +110,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { - var port = Server.GetComponent().RemoteAccessPort(); + var port = Interface.GetComponent().RemoteAccessPort(); OutputProc(String.Format("{0}", port)); return ExitCode.Normal; } @@ -129,7 +129,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { - var group = Server.GetComponent().GetCurrentAuthorizedGroup(); + var group = Interface.GetComponent().GetCurrentAuthorizedGroup(); OutputProc(group ?? "ERROR"); return group != null ? ExitCode.Normal : ExitCode.ServerError; } @@ -154,7 +154,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - var result = Server.GetComponent().SetAuthorizedGroup(parameters[0]); + var result = Interface.GetComponent().SetAuthorizedGroup(parameters[0]); if(result != null) { OutputProc("Group set to: " + result); @@ -182,7 +182,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { - var res = Server.GetComponent().SetAuthorizedGroup(null); + var res = Interface.GetComponent().SetAuthorizedGroup(null); if(res != "ADMIN") { OutputProc("Failed to clear the group??? We are currently set to: " + res); diff --git a/TGCommandLine/BYONDCommands.cs b/TGCommandLine/BYONDCommands.cs index 3fed8adc7d..12b0c1a420 100644 --- a/TGCommandLine/BYONDCommands.cs +++ b/TGCommandLine/BYONDCommands.cs @@ -33,7 +33,7 @@ namespace TGCommandLine type = ByondVersion.Staged; else if (parameters[0].ToLower() == "--latest") type = ByondVersion.Latest; - OutputProc(Server.GetComponent().GetVersion(type) ?? "Unistalled"); + OutputProc(Interface.GetComponent().GetVersion(type) ?? "Unistalled"); return ExitCode.Normal; } public override string GetArgumentString() @@ -56,7 +56,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - switch (Server.GetComponent().CurrentStatus()) + switch (Interface.GetComponent().CurrentStatus()) { case ByondStatus.Downloading: OutputProc("Downloading update..."); @@ -109,7 +109,7 @@ namespace TGCommandLine return ExitCode.BadCommand; } - var BYOND = Server.GetComponent(); + var BYOND = Interface.GetComponent(); if (!BYOND.UpdateToVersion(Major, Minor)) { diff --git a/TGCommandLine/ChatCommands.cs b/TGCommandLine/ChatCommands.cs index 9d53af175d..b5b8ee41e4 100644 --- a/TGCommandLine/ChatCommands.cs +++ b/TGCommandLine/ChatCommands.cs @@ -48,7 +48,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { - var Chat = Server.GetComponent(); + var Chat = Interface.GetComponent(); Chat.SetProviderInfo(new IRCSetupInfo(Chat.ProviderInfos()[(int)ChatProvider.IRC]) { Nickname = parameters[0], @@ -78,7 +78,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { - var IRC = Server.GetComponent(); + var IRC = Interface.GetComponent(); var info = IRC.ProviderInfos()[providerIndex]; IList channels; @@ -156,7 +156,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - var IRC = Server.GetComponent(); + var IRC = Interface.GetComponent(); var info = IRC.ProviderInfos()[providerIndex]; IList channels; @@ -222,7 +222,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { - var info = Server.GetComponent().ProviderInfos()[providerIndex]; + var info = Interface.GetComponent().ProviderInfos()[providerIndex]; string authType; switch ((ChatProvider)providerIndex) { @@ -281,7 +281,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { - var res = Server.GetComponent().Reconnect(providerIndex); + var res = Interface.GetComponent().Reconnect(providerIndex); if (res != null) { OutputProc("Error: " + res); @@ -310,7 +310,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - var IRC = Server.GetComponent(); + var IRC = Interface.GetComponent(); var info = IRC.ProviderInfos()[providerIndex]; var newmin = parameters[0].ToLower(); @@ -355,7 +355,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - var IRC = Server.GetComponent(); + var IRC = Interface.GetComponent(); 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 parameters) { - var IRC = Server.GetComponent(); + var IRC = Interface.GetComponent(); 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 parameters) { - var IRC = Server.GetComponent(); + var IRC = Interface.GetComponent(); var info = new IRCSetupInfo(IRC.ProviderInfos()[(int)ChatProvider.IRC]); switch (parameters[0]) { @@ -482,7 +482,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - var IRC = Server.GetComponent(); + var IRC = Interface.GetComponent(); var info = IRC.ProviderInfos()[providerIndex]; var newmin = parameters[0].ToLower(); @@ -529,7 +529,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - var IRC = Server.GetComponent(); + var IRC = Interface.GetComponent(); IRC.SetProviderInfo(new IRCSetupInfo(IRC.ProviderInfos()[(int)ChatProvider.IRC]) { AuthTarget = parameters[0], @@ -551,7 +551,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - var IRC = Server.GetComponent(); + var IRC = Interface.GetComponent(); IRC.SetProviderInfo(new IRCSetupInfo(IRC.ProviderInfos()[(int)ChatProvider.IRC]) { AuthTarget = null, @@ -575,7 +575,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - var IRC = Server.GetComponent(); + var IRC = Interface.GetComponent(); var info = IRC.ProviderInfos()[providerIndex]; OutputProc("Currently configured channels:"); OutputProc("Admin:"); @@ -610,7 +610,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { - var Chat = Server.GetComponent(); + var Chat = Interface.GetComponent(); var info = Chat.ProviderInfos()[providerIndex]; info.Enabled = true; var res = Chat.SetProviderInfo(info); @@ -638,7 +638,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { - var Chat = Server.GetComponent(); + var Chat = Interface.GetComponent(); 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(); + var Chat = Interface.GetComponent(); var PI = new IRCSetupInfo(Chat.ProviderInfos()[(int)ChatProvider.IRC]) { URL = splits[0] @@ -713,7 +713,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - var Chat = Server.GetComponent(); + var Chat = Interface.GetComponent(); var res = Chat.SetProviderInfo(new DiscordSetupInfo(Chat.ProviderInfos()[(int)ChatProvider.Discord]) { BotToken = parameters[0] }); OutputProc(res ?? "Success"); return res == null ? ExitCode.Normal : ExitCode.ServerError; diff --git a/TGCommandLine/ConfigCommands.cs b/TGCommandLine/ConfigCommands.cs index 6e4b3dd47f..16192311e4 100644 --- a/TGCommandLine/ConfigCommands.cs +++ b/TGCommandLine/ConfigCommands.cs @@ -28,7 +28,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { - var res = Server.GetComponent().DeleteFile(parameters[0], out bool unauthorized); + var res = Interface.GetComponent().DeleteFile(parameters[0], out bool unauthorized); if (res != null) { OutputProc(res); @@ -64,7 +64,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - var list = Server.GetComponent().ListStaticDirectory(parameters.Count > 0 ? parameters[0] : null, out string error, out bool unauthorized); + var list = Interface.GetComponent().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 parameters) { - OutputProc(Server.GetComponent().ServerDirectory()); + OutputProc(Interface.GetComponent().ServerDirectory()); return ExitCode.Normal; } @@ -108,7 +108,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { - var bytes = Server.GetComponent().ReadText(parameters[0], parameters.Count > 2 && parameters[2].ToLower() == "--repo", out string error, out bool unauthorized); + var bytes = Interface.GetComponent().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().WriteText(parameters[0], File.ReadAllText(parameters[1]), out bool unauthorized); + var res = Interface.GetComponent().WriteText(parameters[0], File.ReadAllText(parameters[1]), out bool unauthorized); if (res != null) { OutputProc("Error: " + res); diff --git a/TGCommandLine/DDCommands.cs b/TGCommandLine/DDCommands.cs index 6c754ed9a4..e14f763eae 100644 --- a/TGCommandLine/DDCommands.cs +++ b/TGCommandLine/DDCommands.cs @@ -38,7 +38,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { - var res = Server.GetComponent().WorldAnnounce(String.Join(" ", parameters)); + var res = Interface.GetComponent().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 parameters) { - var res = Server.GetComponent().Start(); + var res = Interface.GetComponent().Start(); OutputProc(res ?? "Success!"); return res == null ? ExitCode.Normal : ExitCode.ServerError; } @@ -82,7 +82,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { - var DD = Server.GetComponent(); + var DD = Interface.GetComponent(); if (parameters.Count > 0 && parameters[0].ToLower() == "--graceful") { if (DD.DaemonStatus() != DreamDaemonStatus.Online) @@ -111,7 +111,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - var DD = Server.GetComponent(); + var DD = Interface.GetComponent(); if (parameters.Count > 0 && parameters[0].ToLower() == "--graceful") { if (DD.DaemonStatus() != DreamDaemonStatus.Online) @@ -146,7 +146,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { - var DD = Server.GetComponent(); + var DD = Interface.GetComponent(); 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 parameters) { - var DD = Server.GetComponent(); + var DD = Interface.GetComponent(); switch (parameters[0].ToLower()) { case "on": @@ -205,7 +205,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { - var DD = Server.GetComponent(); + var DD = Interface.GetComponent(); switch (parameters[0].ToLower()) { case "on": @@ -255,7 +255,7 @@ namespace TGCommandLine return ExitCode.BadCommand; } - Server.GetComponent().SetPort(port); + Interface.GetComponent().SetPort(port); return ExitCode.Normal; } @@ -298,7 +298,7 @@ namespace TGCommandLine OutputProc("Invalid security word!"); return ExitCode.BadCommand; } - Server.GetComponent().SetSecurityLevel(sec); + Interface.GetComponent().SetSecurityLevel(sec); return ExitCode.Normal; } diff --git a/TGCommandLine/DMCommands.cs b/TGCommandLine/DMCommands.cs index ca0c365448..4a61f9e13d 100644 --- a/TGCommandLine/DMCommands.cs +++ b/TGCommandLine/DMCommands.cs @@ -28,7 +28,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { - var DM = Server.GetComponent(); + var DM = Interface.GetComponent(); var stat = DM.GetStatus(); if (stat != CompilerStatus.Initialized) { @@ -36,7 +36,7 @@ namespace TGCommandLine return ExitCode.ServerError; } - if (Server.GetComponent().GetVersion(ByondVersion.Installed) == null) + if (Interface.GetComponent().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().CompileError(); + var error = Interface.GetComponent().CompileError(); if (error != null) OutputProc("Last error: " + error); } protected override ExitCode Run(IList parameters) { - var DM = Server.GetComponent(); + var DM = Interface.GetComponent(); 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 parameters) { - Server.GetComponent().SetProjectName(parameters[0]); + Interface.GetComponent().SetProjectName(parameters[0]); return ExitCode.Normal; } } @@ -166,7 +166,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { - var DM = Server.GetComponent(); + var DM = Interface.GetComponent(); var stat = DM.GetStatus(); if (stat == CompilerStatus.Compiling || stat == CompilerStatus.Initializing) { @@ -206,7 +206,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { - var res = Server.GetComponent().Cancel(); + var res = Interface.GetComponent().Cancel(); OutputProc(res ?? "Success!"); return ExitCode.Normal; //because failing cancellation implys it's already cancelled } diff --git a/TGCommandLine/Program.cs b/TGCommandLine/Program.cs index adf4dcd154..1cc910a9cd 100644 --- a/TGCommandLine/Program.cs +++ b/TGCommandLine/Program.cs @@ -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(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().PrepareForUpdate(); + Interface.GetComponent().PrepareForUpdate(); return (int)Command.ExitCode.Normal; #endif default: diff --git a/TGCommandLine/RepoCommands.cs b/TGCommandLine/RepoCommands.cs index e6c19d5930..04d646e8f2 100644 --- a/TGCommandLine/RepoCommands.cs +++ b/TGCommandLine/RepoCommands.cs @@ -32,7 +32,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { - var res = Server.GetComponent().UpdateTGS3Json(); + var res = Interface.GetComponent().UpdateTGS3Json(); if (res != null) { OutputProc(res); @@ -51,7 +51,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - var res = Server.GetComponent().Setup(parameters[0], parameters.Count > 1 ? parameters[1] : "master"); + var res = Interface.GetComponent().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 parameters) { - var Repo = Server.GetComponent(); + var Repo = Interface.GetComponent(); var busy = Repo.OperationInProgress(); if (!busy) { @@ -131,7 +131,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - var result = Server.GetComponent().Reset(parameters.Count > 0 && parameters[0].ToLower() == "--origin"); + var result = Interface.GetComponent().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().Update(hard); + var res = Interface.GetComponent().Update(hard); OutputProc(res ?? "Success"); return res == null ? ExitCode.Normal : ExitCode.ServerError; } @@ -188,7 +188,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - var result = Server.GetComponent().GenerateChangelog(out string error); + var result = Interface.GetComponent().GenerateChangelog(out string error); OutputProc(error ?? "Success!"); if (result != null) OutputProc(result); @@ -208,7 +208,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - var result = Server.GetComponent().SynchronizePush(); + var result = Interface.GetComponent().SynchronizePush(); if(result != null) OutputProc(result); return result == null ? ExitCode.Normal : ExitCode.ServerError; @@ -228,7 +228,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - Server.GetComponent().SetCommitterEmail(parameters[0]); + Interface.GetComponent().SetCommitterEmail(parameters[0]); return ExitCode.Normal; } @@ -250,7 +250,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - Server.GetComponent().SetCommitterName(parameters[0]); + Interface.GetComponent().SetCommitterName(parameters[0]); return ExitCode.Normal; } public override string GetArgumentString() @@ -271,7 +271,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - Server.GetComponent().SetPythonPath(parameters[0]); + Interface.GetComponent().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().MergePullRequest(PR); + var res = Interface.GetComponent().MergePullRequest(PR); OutputProc(res ?? "Success"); return res == null ? ExitCode.Normal : ExitCode.ServerError; } @@ -331,7 +331,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - var data = Server.GetComponent().MergedPullRequests(out string error); + var data = Interface.GetComponent().MergedPullRequests(out string error); if (data == null) { OutputProc(error); @@ -358,7 +358,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - var data = Server.GetComponent().ListBackups(out string error); + var data = Interface.GetComponent().ListBackups(out string error); if (data == null) { OutputProc(error); @@ -385,7 +385,7 @@ namespace TGCommandLine } protected override ExitCode Run(IList parameters) { - var res = Server.GetComponent().Checkout(parameters[0]); + var res = Interface.GetComponent().Checkout(parameters[0]); OutputProc(res ?? "Success"); return res == null ? ExitCode.Normal : ExitCode.ServerError; } diff --git a/TGCommandLine/RootCommands.cs b/TGCommandLine/RootCommands.cs index 5d7894d8db..e78740e7e0 100644 --- a/TGCommandLine/RootCommands.cs +++ b/TGCommandLine/RootCommands.cs @@ -10,7 +10,7 @@ namespace TGCommandLine public CLICommand() { var tmp = new List { new UpdateCommand(), new TestmergeCommand(), new RepoCommand(), new BYONDCommand(), new DMCommand(), new DDCommand(), new ConfigCommand(), new IRCCommand(), new DiscordCommand(), new AutoUpdateCommand(), new SetAutoUpdateCommand() }; - if (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 parameters) { - var res = Server.GetComponent().AutoUpdateInterval(); + var res = Interface.GetComponent().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().SetAutoUpdateInterval(NewInterval); + Interface.GetComponent().SetAutoUpdateInterval(NewInterval); return ExitCode.Normal; } @@ -89,7 +89,7 @@ namespace TGCommandLine protected override ExitCode Run(IList parameters) { var gen_cl = parameters.Count > 1 && parameters[1].ToLower() == "--cl"; - var Repo = Server.GetComponent(); + var Repo = Interface.GetComponent(); switch (parameters[0].ToLower()) { case "hard": @@ -124,7 +124,7 @@ namespace TGCommandLine OutputProc(res); } } - var resu = Server.GetComponent().Compile(true); + var resu = Interface.GetComponent().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(); + var Repo = Interface.GetComponent(); var res = Repo.MergePullRequest(tm); if (res != null) { @@ -174,7 +174,7 @@ namespace TGCommandLine OutputProc(res); return ExitCode.ServerError; } - var resu = Server.GetComponent().Compile(true); + var resu = Interface.GetComponent().Compile(true); OutputProc(resu ? "Compilation started!" : "Compilation could not be started!"); return resu ? ExitCode.Normal : ExitCode.ServerError; } diff --git a/TGControlPanel/ByondPage.cs b/TGControlPanel/ByondPage.cs index 3108172ef7..7f120c3705 100644 --- a/TGControlPanel/ByondPage.cs +++ b/TGControlPanel/ByondPage.cs @@ -10,7 +10,7 @@ namespace TGControlPanel string lastReadError = null; void InitBYONDPage() { - var BYOND = Server.GetComponent(); + var BYOND = Interface.GetComponent(); var CV = BYOND.GetVersion(ByondVersion.Installed); if (CV == null) CV = BYOND.GetVersion(ByondVersion.Staged); @@ -30,7 +30,7 @@ namespace TGControlPanel } } - var latestVer = Server.GetComponent().GetVersion(ByondVersion.Latest); + var latestVer = Interface.GetComponent().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().UpdateToVersion((int)MajorVersionNumeric.Value, (int)MinorVersionNumeric.Value)) + if (!Interface.GetComponent().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(); + var BYOND = Interface.GetComponent(); VersionLabel.Text = BYOND.GetVersion(ByondVersion.Installed) ?? "Not Installed"; @@ -90,7 +90,7 @@ namespace TGControlPanel UpdateButton.Enabled = false; break; } - var error = Server.GetComponent().GetError(); + var error = Interface.GetComponent().GetError(); if (error != lastReadError) { lastReadError = error; diff --git a/TGControlPanel/ChatPage.cs b/TGControlPanel/ChatPage.cs index f4f43c2229..1bf6460e54 100644 --- a/TGControlPanel/ChatPage.cs +++ b/TGControlPanel/ChatPage.cs @@ -19,7 +19,7 @@ namespace TGControlPanel void LoadChatPage() { updatingChat = true; - var Chat = Server.GetComponent(); + var Chat = Interface.GetComponent(); 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().Reconnect(ModifyingProvider); + Interface.GetComponent().Reconnect(ModifyingProvider); LoadChatPage(); } @@ -149,7 +149,7 @@ namespace TGControlPanel } void SetAdminsAreSpecial(bool value) { - var Chat = Server.GetComponent(); + var Chat = Interface.GetComponent(); 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().SetProviderInfo(wip); + res = Interface.GetComponent().SetProviderInfo(wip); } if (res != null) MessageBox.Show(res); diff --git a/TGControlPanel/Login.cs b/TGControlPanel/Login.cs index e7ff2e1f53..8c4b28437f 100644 --- a/TGControlPanel/Login.cs +++ b/TGControlPanel/Login.cs @@ -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; diff --git a/TGControlPanel/Main.cs b/TGControlPanel/Main.cs index d6bb808270..4c1e9af2e7 100644 --- a/TGControlPanel/Main.cs +++ b/TGControlPanel/Main.cs @@ -11,12 +11,12 @@ namespace TGControlPanel partial class Main : Form { /// - /// Create the control panel. Requires the has had it's connection info setup + /// Create the control panel. Requires the has had it's connection info setup /// 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; diff --git a/TGControlPanel/Program.cs b/TGControlPanel/Program.cs index 12753f1962..b4eec9afc3 100644 --- a/TGControlPanel/Program.cs +++ b/TGControlPanel/Program.cs @@ -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; diff --git a/TGControlPanel/RepoPage.cs b/TGControlPanel/RepoPage.cs index 1191bc68da..076933a6b6 100644 --- a/TGControlPanel/RepoPage.cs +++ b/TGControlPanel/RepoPage.cs @@ -77,7 +77,7 @@ namespace TGControlPanel if (RepoBusyCheck()) return; - var Repo = Server.GetComponent(); + var Repo = Interface.GetComponent(); RepoProgressBar.Style = ProgressBarStyle.Marquee; RepoProgressBar.Visible = false; @@ -150,7 +150,7 @@ namespace TGControlPanel bool RepoBusyCheck() { - if (Server.GetComponent().OperationInProgress()) + if (Interface.GetComponent().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(); + var Repo = Interface.GetComponent(); switch (action) { case RepoAction.Clone: @@ -213,7 +213,7 @@ namespace TGControlPanel } void UpdatePythonPath() { - if (!Server.GetComponent().SetPythonPath(PythonPathText.Text)) + if (!Interface.GetComponent().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(); + var Repo = Interface.GetComponent(); 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().UpdateTGS3Json(); + var res = Interface.GetComponent().UpdateTGS3Json(); if (res != null) MessageBox.Show(res); } diff --git a/TGControlPanel/ServerPage.cs b/TGControlPanel/ServerPage.cs index acb9f0172a..75f7b63ce4 100644 --- a/TGControlPanel/ServerPage.cs +++ b/TGControlPanel/ServerPage.cs @@ -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().Cancel(); + var res = Interface.GetComponent().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().ServerDirectory()) + if (updatingFields || ServerPathTextbox.Text.Trim() == Interface.GetComponent().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().MoveServer(ServerPathTextbox.Text) ?? "Success!"); + MessageBox.Show(Interface.GetComponent().MoveServer(ServerPathTextbox.Text) ?? "Success!"); } void LoadServerPage() { - var RepoExists = Server.GetComponent().Exists(); + var RepoExists = Interface.GetComponent().Exists(); compileButton.Visible = RepoExists; AutoUpdateCheckbox.Visible = RepoExists; initializeButton.Visible = RepoExists; @@ -138,10 +138,10 @@ namespace TGControlPanel if (updatingFields) return; - var DM = Server.GetComponent(); - var DD = Server.GetComponent(); - var Config = Server.GetComponent(); - var Repo = Server.GetComponent(); + var DM = Interface.GetComponent(); + var DD = Interface.GetComponent(); + var Config = Interface.GetComponent(); + var Repo = Interface.GetComponent(); try { @@ -247,13 +247,13 @@ namespace TGControlPanel void UpdateProjectName() { if (!updatingFields) - Server.GetComponent().SetProjectName(projectNameText.Text); + Interface.GetComponent().SetProjectName(projectNameText.Text); } private void PortSelector_ValueChanged(object sender, EventArgs e) { if (!updatingFields) - Server.GetComponent().SetPort((ushort)PortSelector.Value); + Interface.GetComponent().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().Initialize()) + if (!Interface.GetComponent().Initialize()) MessageBox.Show("Unable to start initialization!"); LoadServerPage(); } private void CompileButton_Click(object sender, EventArgs e) { - if (!Server.GetComponent().Compile()) + if (!Interface.GetComponent().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().SetAutostart(AutostartCheckbox.Checked); + Interface.GetComponent().SetAutostart(AutostartCheckbox.Checked); } private void ServerStartButton_Click(object sender, System.EventArgs e) { @@ -319,7 +319,7 @@ namespace TGControlPanel { try { - e.Result = Server.GetComponent().Start(); + e.Result = Interface.GetComponent().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().Stop(); + var res = Interface.GetComponent().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().Restart(); + var res = Interface.GetComponent().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().RequestStop(); + Interface.GetComponent().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().RequestRestart(); + Interface.GetComponent().RequestRestart(); } @@ -371,8 +371,8 @@ namespace TGControlPanel { try { - var Repo = Server.GetComponent(); - var DM = Server.GetComponent(); + var Repo = Interface.GetComponent(); + var DM = Interface.GetComponent(); switch (fuAction) { case FullUpdateAction.Testmerge: @@ -460,7 +460,7 @@ namespace TGControlPanel private void SecuritySelector_SelectedIndexChanged(object sender, EventArgs e) { if (!updatingFields) - if (!Server.GetComponent().SetSecurityLevel((DreamDaemonSecurity)SecuritySelector.SelectedIndex)) + if (!Interface.GetComponent().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().WorldAnnounce(msg); + var res = Interface.GetComponent().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().SetWebclient(WebclientCheckBox.Checked); + Interface.GetComponent().SetWebclient(WebclientCheckBox.Checked); } private void AutoUpdateInterval_ValueChanged(object sender, EventArgs e) { if (!updatingFields) - Server.GetComponent().SetAutoUpdateInterval((ulong)AutoUpdateInterval.Value); + Interface.GetComponent().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().SetAutoUpdateInterval(0); + Interface.GetComponent().SetAutoUpdateInterval(0); else - Server.GetComponent().SetAutoUpdateInterval((ulong)AutoUpdateInterval.Value); + Interface.GetComponent().SetAutoUpdateInterval((ulong)AutoUpdateInterval.Value); } } } diff --git a/TGControlPanel/StaticPage.cs b/TGControlPanel/StaticPage.cs index e3b0003a2e..e04eb02c38 100644 --- a/TGControlPanel/StaticPage.cs +++ b/TGControlPanel/StaticPage.cs @@ -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(), 1) == EnumResult.Unauthorized) + if (EnumeratePath("", Interface.GetComponent(), 1) == EnumResult.Unauthorized) { StaticFileListBox.Items[0] += " (UNAUTHORIZED)"; IndexesToPaths[0] = null; @@ -140,7 +140,7 @@ namespace TGControlPanel if (error == null) try { - error = Server.GetComponent().WriteText(FileName, fileContents, out bool unauthorized); + error = Interface.GetComponent().WriteText(FileName, fileContents, out bool unauthorized); } catch (Exception ex) { @@ -164,7 +164,7 @@ namespace TGControlPanel string text, error; try { - text = Server.GetComponent().ReadText(remotePath, false, out error, out bool unauthorized); + text = Interface.GetComponent().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().DeleteFile(IndexesToPaths[StaticFileListBox.SelectedIndex], out bool unauthorized); + var res = Interface.GetComponent().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(); + var config = Interface.GetComponent(); 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().WriteText(IndexesToPaths[index], StaticFileEditTextbox.Text, out unauthorized); + res = Interface.GetComponent().WriteText(IndexesToPaths[index], StaticFileEditTextbox.Text, out unauthorized); } catch (Exception ex) { @@ -300,7 +300,7 @@ namespace TGControlPanel bool unauthorized; try { - entry = Server.GetComponent().ReadText(path, false, out error, out unauthorized); + entry = Interface.GetComponent().ReadText(path, false, out error, out unauthorized); } catch(Exception e) { @@ -337,7 +337,7 @@ namespace TGControlPanel RecreateStaticButton.Visible = false; return; } - var res = Server.GetComponent().RecreateStaticFolder(); + var res = Interface.GetComponent().RecreateStaticFolder(); if (res != null) MessageBox.Show(res); BuildFileList(); diff --git a/TGServerService/Service.cs b/TGServerService/Service.cs index 2603e49c8c..6804b3f40d 100644 --- a/TGServerService/Service.cs +++ b/TGServerService/Service.cs @@ -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; diff --git a/TGServiceInterface/DreamDaemonBridge.cs b/TGServiceInterface/DreamDaemonBridge.cs index cd807d822a..a85ae6541b 100644 --- a/TGServiceInterface/DreamDaemonBridge.cs +++ b/TGServiceInterface/DreamDaemonBridge.cs @@ -21,13 +21,13 @@ namespace TGServiceInterface { try { - var channel = Server.CreateChannel(); + var channel = Interface.CreateChannel(); try { channel.CreateChannel().InteropMessage(String.Join(" ", args)); } catch { } - Server.CloseChannel(channel); + Interface.CloseChannel(channel); } catch { } return 0; diff --git a/TGServiceInterface/Server.cs b/TGServiceInterface/Interface.cs similarity index 90% rename from TGServiceInterface/Server.cs rename to TGServiceInterface/Interface.cs index 592a774fcd..0398a4b404 100644 --- a/TGServiceInterface/Server.cs +++ b/TGServiceInterface/Interface.cs @@ -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 -{ - /// - /// Main inteface class for the service - /// - public class Server - { - /// - /// List of s that can be used with and - /// - public static readonly IList ValidInterfaces = CollectComponents(); - - /// - /// The maximum message size to and from a local server - /// - public static readonly long TransferLimitLocal = Int32.MaxValue; //2GB can't go higher - - /// - /// The maximum message size to and from a remote server - /// - public static readonly long TransferLimitRemote = 10485760; //10 MB - - /// - /// Base name of the communication pipe - /// they are formatted as MasterPipeName/ComponentName - /// - public static string MasterInterfaceName = "TGStationServerService"; - - /// - /// If this is set, we will try and connect to an HTTPS server running at this address - /// - static string HTTPSURL; - - /// - /// The port used by the service - /// - static ushort HTTPSPort = 38607; - - /// - /// Username for remote operations - /// - static string HTTPSUsername; - - /// - /// Password for remote operations - /// - static string HTTPSPassword; - - /// - /// Associated list of open s keyed by type. A in this list may close or fault at any time. Must be locked before being accessed - /// - static IDictionary ChannelFactoryCache = new Dictionary(); - - /// - /// Returns a of s that can be used with the service - /// - /// A of s that can be used with the service - static IList 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(); - } - - /// - /// Sets the function called when a remote login fails due to the server having an invalid SSL cert - /// - /// The to be called when a remote login is attempted while the server posesses a bad certificate. Passed a of error information about the and should return if it the connection should be made anyway - public static void SetBadCertificateHandler(Func handler) - { - 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); - }; - } - - /// - /// Set the interface to look for services on the current computer - /// - public static void MakeLocalConnection() - { - HTTPSURL = null; - HTTPSPassword = null; - ClearCachedChannels(); - } - - /// - /// Closes all s stored in and clears it - /// - static void ClearCachedChannels() - { - lock (ChannelFactoryCache) - { - foreach (var I in ChannelFactoryCache) - CloseChannel(I.Value); - ChannelFactoryCache.Clear(); - } - } - - /// - /// Returns if the interface being used to connect to a service does not have the same release version as the service - /// - /// An error message to display to the user should this function return - /// if the interface being used to connect to a service does not have the same release version as the service - public static bool VersionMismatch(out string errorMessage) - { - var splits = Server.GetComponent().Version().Split(' '); - var theirs = new Version(splits[splits.Length - 1].Substring(1)); - var ours = new Version(FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion); - if(theirs != 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; - } - - /// - /// Set the remote to connect to along with - /// - /// The address of the remote server - /// The port the remote server runs on - /// Windows account username for the remote server - /// Windows account password for the remote server - public static void SetRemoteLoginInformation(string address, ushort port, string username, string password) - { - HTTPSURL = address; - HTTPSPort = port; - HTTPSUsername = username; - HTTPSPassword = password; - ClearCachedChannels(); - } - - /// - /// Safely shuts down a single - /// - /// The to shutdown - public static void CloseChannel(ChannelFactory cf) - { - try - { - cf.Close(); - } - catch - { - cf.Abort(); - } - } - - /// - /// Returns the requested component . This does not guarantee a successful connection. s created this way are recycled for minimum latency and bandwidth usage - /// - /// The component to retrieve - /// The correct component - public static T GetComponent() - { - var tot = typeof(T); - ChannelFactory cf; - - lock (ChannelFactoryCache) - { - if (ChannelFactoryCache.ContainsKey(tot)) - try - { - cf = ((ChannelFactory)ChannelFactoryCache[tot]); - if (cf.State != CommunicationState.Opened) - throw new Exception(); - return cf.CreateChannel(); - } - catch - { - ChannelFactoryCache[tot].Abort(); - ChannelFactoryCache.Remove(tot); - } - cf = CreateChannel(); - ChannelFactoryCache[tot] = cf; - } - return cf.CreateChannel(); - } - - /// - /// Directly creates a for without caching. This should be eventually closed by the caller - /// - /// The component of the channel to be created - /// The correct - /// Thrown if isn't a valid component - public static ChannelFactory CreateChannel() - { - 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( - 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(binding, address); - if (requireAuth) - { - res.Credentials.UserName.UserName = HTTPSUsername; - res.Credentials.UserName.Password = HTTPSPassword; - } - return res; - } - - /// - /// Used to test if the service is avaiable on the machine. Note that state can technically change at any time and any call to the service may throw an exception because it failed - /// - /// on successful connection, error message on failure - public static string VerifyConnection() - { - try - { - GetComponent().VerifyConnection(); - return null; - } - catch (Exception e) - { - return e.ToString(); - } - } - - /// - /// Checks if the supplied user's credentials have permission to use the service. Requires a successful prior call to - /// - /// if credentials are valid, otherwise - public static bool Authenticate() - { - try - { - GetComponent().Version(); - return true; - } - catch - { - return false; - } - } - - /// - /// Checks if the current login can use . Requires a successful prior call to - /// - /// if the connection may use , otherwise - public static bool AuthenticateAdmin() - { - try - { - GetComponent().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 +{ + /// + /// Main inteface class for the service + /// + public class Interface + { + /// + /// List of s that can be used with and + /// + public static readonly IList ValidInterfaces = CollectComponents(); + + /// + /// The maximum message size to and from a local server + /// + public static readonly long TransferLimitLocal = Int32.MaxValue; //2GB can't go higher + + /// + /// The maximum message size to and from a remote server + /// + public static readonly long TransferLimitRemote = 10485760; //10 MB + + /// + /// Base name of the communication pipe + /// they are formatted as MasterPipeName/ComponentName + /// + public static string MasterInterfaceName = "TGStationServerService"; + + /// + /// If this is set, we will try and connect to an HTTPS server running at this address + /// + static string HTTPSURL; + + /// + /// The port used by the service + /// + static ushort HTTPSPort = 38607; + + /// + /// Username for remote operations + /// + static string HTTPSUsername; + + /// + /// Password for remote operations + /// + static string HTTPSPassword; + + /// + /// Associated list of open s keyed by type. A in this list may close or fault at any time. Must be locked before being accessed + /// + static IDictionary ChannelFactoryCache = new Dictionary(); + + /// + /// Returns a of s that can be used with the service + /// + /// A of s that can be used with the service + static IList 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(); + } + + /// + /// Sets the function called when a remote login fails due to the server having an invalid SSL cert + /// + /// The to be called when a remote login is attempted while the server posesses a bad certificate. Passed a of error information about the and should return if it the connection should be made anyway + public static void SetBadCertificateHandler(Func handler) + { + 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); + }; + } + + /// + /// Set the interface to look for services on the current computer + /// + public static void MakeLocalConnection() + { + HTTPSURL = null; + HTTPSPassword = null; + ClearCachedChannels(); + } + + /// + /// Closes all s stored in and clears it + /// + static void ClearCachedChannels() + { + lock (ChannelFactoryCache) + { + foreach (var I in ChannelFactoryCache) + CloseChannel(I.Value); + ChannelFactoryCache.Clear(); + } + } + + /// + /// Returns if the interface being used to connect to a service does not have the same release version as the service + /// + /// An error message to display to the user should this function return + /// if the interface being used to connect to a service does not have the same release version as the service + public static bool VersionMismatch(out string errorMessage) + { + var splits = Interface.GetComponent().Version().Split(' '); + var theirs = new Version(splits[splits.Length - 1].Substring(1)); + var ours = new Version(FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion); + if(theirs != 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; + } + + /// + /// Set the remote to connect to along with + /// + /// The address of the remote server + /// The port the remote server runs on + /// Windows account username for the remote server + /// Windows account password for the remote server + public static void SetRemoteLoginInformation(string address, ushort port, string username, string password) + { + HTTPSURL = address; + HTTPSPort = port; + HTTPSUsername = username; + HTTPSPassword = password; + ClearCachedChannels(); + } + + /// + /// Safely shuts down a single + /// + /// The to shutdown + public static void CloseChannel(ChannelFactory cf) + { + try + { + cf.Close(); + } + catch + { + cf.Abort(); + } + } + + /// + /// Returns the requested component . This does not guarantee a successful connection. s created this way are recycled for minimum latency and bandwidth usage + /// + /// The component to retrieve + /// The correct component + public static T GetComponent() + { + var tot = typeof(T); + ChannelFactory cf; + + lock (ChannelFactoryCache) + { + if (ChannelFactoryCache.ContainsKey(tot)) + try + { + cf = ((ChannelFactory)ChannelFactoryCache[tot]); + if (cf.State != CommunicationState.Opened) + throw new Exception(); + return cf.CreateChannel(); + } + catch + { + ChannelFactoryCache[tot].Abort(); + ChannelFactoryCache.Remove(tot); + } + cf = CreateChannel(); + ChannelFactoryCache[tot] = cf; + } + return cf.CreateChannel(); + } + + /// + /// Directly creates a for without caching. This should be eventually closed by the caller + /// + /// The component of the channel to be created + /// The correct + /// Thrown if isn't a valid component + public static ChannelFactory CreateChannel() + { + 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( + 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(binding, address); + if (requireAuth) + { + res.Credentials.UserName.UserName = HTTPSUsername; + res.Credentials.UserName.Password = HTTPSPassword; + } + return res; + } + + /// + /// Used to test if the service is avaiable on the machine. Note that state can technically change at any time and any call to the service may throw an exception because it failed + /// + /// on successful connection, error message on failure + public static string VerifyConnection() + { + try + { + GetComponent().VerifyConnection(); + return null; + } + catch (Exception e) + { + return e.ToString(); + } + } + + /// + /// Checks if the supplied user's credentials have permission to use the service. Requires a successful prior call to + /// + /// if credentials are valid, otherwise + public static bool Authenticate() + { + try + { + GetComponent().Version(); + return true; + } + catch + { + return false; + } + } + + /// + /// Checks if the current login can use . Requires a successful prior call to + /// + /// if the connection may use , otherwise + public static bool AuthenticateAdmin() + { + try + { + GetComponent().GetCurrentAuthorizedGroup(); + return true; + } + catch + { + return false; + } + } + } +} diff --git a/TGServiceInterface/TGServiceInterface.csproj b/TGServiceInterface/TGServiceInterface.csproj index 75c5de13ff..ea546a5b8a 100644 --- a/TGServiceInterface/TGServiceInterface.csproj +++ b/TGServiceInterface/TGServiceInterface.csproj @@ -63,7 +63,7 @@ - +