From 68957d8802a9bd792eb37757020d26fd42df1835 Mon Sep 17 00:00:00 2001 From: Jamie Hankins Date: Sat, 9 Sep 2017 05:28:31 +0100 Subject: [PATCH 01/13] Adds a preaction framework so we can run a .bat file before or after compiling the code --- README.md | 3 ++ TGServerService/Compiler.cs | 15 +++++- TGServerService/PreactionHandler.cs | 65 ++++++++++++++++++++++++++ TGServerService/ServerService.cs | 2 + TGServerService/TGServerService.csproj | 1 + 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 TGServerService/PreactionHandler.cs diff --git a/README.md b/README.md index 0a9b038383..5d8314202a 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,9 @@ The process to update the server while DD is running is a functioning work in pr * `RepoKey/` * This contains ssh key information for automatic changelog pushing. +* `EventHandlers/` + * This contains batch files that run after certain events, currently only precompile and postcompile events are implemented. + * `BYOND/` * This contains the actual BYOND installation the server uses diff --git a/TGServerService/Compiler.cs b/TGServerService/Compiler.cs index 631a7e12a4..83a225f719 100644 --- a/TGServerService/Compiler.cs +++ b/TGServerService/Compiler.cs @@ -378,6 +378,13 @@ namespace TGServerService } } + if (!PrecompileHook()) + { + lastCompilerError = "The precompile hook failed"; + compilerCurrentStatus = TGCompilerStatus.Initialized; //still fairly valid + return; + } + using (var DM = new Process()) //will kill the process if the thread is terminated { DM.StartInfo.FileName = ByondDirectory + "/bin/dm.exe"; @@ -468,7 +475,13 @@ namespace TGServerService } } var staged = DaemonStatus() != TGDreamDaemonStatus.Offline; - var msg = String.Format("Compile complete!{0}", !staged ? "" : " Server will update next round."); + if (!PostcompileHook()) + { + lastCompilerError = "The postcompile hook failed"; + compilerCurrentStatus = TGCompilerStatus.Initialized; //still fairly valid + return; + } + var msg = String.Format("Compile complete!{0}", !staged ? "" : " Server will update next round."); SendMessage("DM: " + msg, ChatMessageType.DeveloperInfo); TGServerService.WriteInfo(msg, TGServerService.EventID.DMCompileSuccess); lock (CompilerLock) diff --git a/TGServerService/PreactionHandler.cs b/TGServerService/PreactionHandler.cs new file mode 100644 index 0000000000..ac71129f24 --- /dev/null +++ b/TGServerService/PreactionHandler.cs @@ -0,0 +1,65 @@ +using System; +using System.Diagnostics; +using System.IO; + +namespace TGServerService +{ + // Some useful functions for triggering pre action events + partial class TGStationServer + { + const string EventFolder = "EventHandlers/"; + + string GetPath(string eventName) + { + return string.Format("{}{}.bat", EventFolder, eventName); + } + + bool EventHandlerExists(string eventName) + { + return File.Exists(GetPath(eventName)); + } + + bool HandleEvent(string eventName) + { + if (!EventHandlerExists(eventName)) + { + // We don't need a handler, so let's just fail silently. + return true; + } + + var process = new Process + { + StartInfo = new ProcessStartInfo + { + FileName = GetPath(eventName), + UseShellExecute = false, + RedirectStandardOutput = true, + RedirectStandardError = true, + CreateNoWindow = true + } + }; + process.Start(); + process.WaitForExit(); + + var stdout = process.StandardOutput.ReadToEnd(); + var stderr = process.StandardError.ReadToEnd(); + + TGServerService.WriteInfo( + String.Format("Preaction Event ran. Stdout:\n{}\nStderr:\n{}", stdout, stderr), + process.ExitCode == 0 ? TGServerService.EventID.PreactionEvent : TGServerService.EventID.PreactionFail + ); + + return process.ExitCode == 0 ? true : false; + } + + public bool PrecompileHook() + { + return HandleEvent("precompile"); + } + + public bool PostcompileHook() + { + return HandleEvent("postcompile"); + } + } +} diff --git a/TGServerService/ServerService.cs b/TGServerService/ServerService.cs index 7cbc5fb224..4824a5ad38 100644 --- a/TGServerService/ServerService.cs +++ b/TGServerService/ServerService.cs @@ -75,6 +75,8 @@ namespace TGServerService ServerUpdateApplied = 6300, ChatBroadcastFail = 6400, IRCLogModes = 6500, + PreactionEvent = 6600, + PreactionFail = 6700 } static TGServerService ActiveService; //So everyone else can write to our eventlog diff --git a/TGServerService/TGServerService.csproj b/TGServerService/TGServerService.csproj index 5bd5b49e98..adebbc8836 100644 --- a/TGServerService/TGServerService.csproj +++ b/TGServerService/TGServerService.csproj @@ -93,6 +93,7 @@ + True From 63added211a1d77e73ed1983f27ba1410a7ff559 Mon Sep 17 00:00:00 2001 From: Jamie Hankins Date: Sun, 10 Sep 2017 01:41:11 +0100 Subject: [PATCH 02/13] Spaces to Tabs --- TGServerService/Compiler.cs | 12 ++-- TGServerService/PreactionHandler.cs | 98 ++++++++++++++--------------- TGServerService/ServerService.cs | 2 +- 3 files changed, 56 insertions(+), 56 deletions(-) diff --git a/TGServerService/Compiler.cs b/TGServerService/Compiler.cs index 05f580af7b..352c99db7c 100644 --- a/TGServerService/Compiler.cs +++ b/TGServerService/Compiler.cs @@ -383,12 +383,12 @@ namespace TGServerService } } - if (!PrecompileHook()) - { - lastCompilerError = "The precompile hook failed"; - compilerCurrentStatus = TGCompilerStatus.Initialized; //still fairly valid - return; - } + if (!PrecompileHook()) + { + lastCompilerError = "The precompile hook failed"; + compilerCurrentStatus = TGCompilerStatus.Initialized; //still fairly valid + return; + } using (var DM = new Process()) //will kill the process if the thread is terminated { diff --git a/TGServerService/PreactionHandler.cs b/TGServerService/PreactionHandler.cs index ac71129f24..9b7ef88da0 100644 --- a/TGServerService/PreactionHandler.cs +++ b/TGServerService/PreactionHandler.cs @@ -4,62 +4,62 @@ using System.IO; namespace TGServerService { - // Some useful functions for triggering pre action events - partial class TGStationServer - { - const string EventFolder = "EventHandlers/"; + // Some useful functions for triggering pre action events + partial class TGStationServer + { + const string EventFolder = "EventHandlers/"; - string GetPath(string eventName) - { - return string.Format("{}{}.bat", EventFolder, eventName); - } + string GetPath(string eventName) + { + return string.Format("{}{}.bat", EventFolder, eventName); + } - bool EventHandlerExists(string eventName) - { - return File.Exists(GetPath(eventName)); - } + bool EventHandlerExists(string eventName) + { + return File.Exists(GetPath(eventName)); + } - bool HandleEvent(string eventName) - { - if (!EventHandlerExists(eventName)) - { - // We don't need a handler, so let's just fail silently. - return true; - } + bool HandleEvent(string eventName) + { + if (!EventHandlerExists(eventName)) + { + // We don't need a handler, so let's just fail silently. + return true; + } - var process = new Process - { - StartInfo = new ProcessStartInfo - { - FileName = GetPath(eventName), - UseShellExecute = false, - RedirectStandardOutput = true, - RedirectStandardError = true, - CreateNoWindow = true - } - }; - process.Start(); - process.WaitForExit(); + var process = new Process + { + StartInfo = new ProcessStartInfo + { + FileName = GetPath(eventName), + UseShellExecute = false, + RedirectStandardOutput = true, + RedirectStandardError = true, + CreateNoWindow = true + } + }; + process.Start(); + process.WaitForExit(); - var stdout = process.StandardOutput.ReadToEnd(); - var stderr = process.StandardError.ReadToEnd(); + var stdout = process.StandardOutput.ReadToEnd(); + var stderr = process.StandardError.ReadToEnd(); - TGServerService.WriteInfo( - String.Format("Preaction Event ran. Stdout:\n{}\nStderr:\n{}", stdout, stderr), - process.ExitCode == 0 ? TGServerService.EventID.PreactionEvent : TGServerService.EventID.PreactionFail - ); + TGServerService.WriteInfo( + String.Format("Preaction Event ran. Stdout:\n{}\nStderr:\n{}", stdout, stderr), + process.ExitCode == 0 ? TGServerService.EventID.PreactionEvent : TGServerService.EventID.PreactionFail + ); - return process.ExitCode == 0 ? true : false; - } + return process.ExitCode == 0 ? true : false; + } - public bool PrecompileHook() - { - return HandleEvent("precompile"); - } + public bool PrecompileHook() + { + return HandleEvent("precompile"); + } - public bool PostcompileHook() - { - return HandleEvent("postcompile"); - } - } + public bool PostcompileHook() + { + return HandleEvent("postcompile"); + } + } } diff --git a/TGServerService/ServerService.cs b/TGServerService/ServerService.cs index 0a74f09c92..68efab2c10 100644 --- a/TGServerService/ServerService.cs +++ b/TGServerService/ServerService.cs @@ -77,7 +77,7 @@ namespace TGServerService IRCLogModes = 6500, SubmoduleReclone = 6600, PreactionEvent = 6700, - PreactionFail = 6800 + PreactionFail = 6800 } static TGServerService ActiveService; //So everyone else can write to our eventlog From 6bd485e5bfb4ac801cc9d7004abbc617460a402b Mon Sep 17 00:00:00 2001 From: Jamie Hankins Date: Sun, 10 Sep 2017 03:02:00 +0100 Subject: [PATCH 03/13] Oops more spaces --- TGServerService/Compiler.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/TGServerService/Compiler.cs b/TGServerService/Compiler.cs index 352c99db7c..6b3bf3a984 100644 --- a/TGServerService/Compiler.cs +++ b/TGServerService/Compiler.cs @@ -480,13 +480,13 @@ namespace TGServerService } } var staged = DaemonStatus() != TGDreamDaemonStatus.Offline; - if (!PostcompileHook()) - { - lastCompilerError = "The postcompile hook failed"; - compilerCurrentStatus = TGCompilerStatus.Initialized; //still fairly valid - return; - } - var msg = String.Format("Compile complete!{0}", !staged ? "" : " Server will update next round."); + if (!PostcompileHook()) + { + lastCompilerError = "The postcompile hook failed"; + compilerCurrentStatus = TGCompilerStatus.Initialized; //still fairly valid + return; + } + var msg = String.Format("Compile complete!{0}", !staged ? "" : " Server will update next round."); SendMessage("DM: " + msg, ChatMessageType.DeveloperInfo); TGServerService.WriteInfo(msg, TGServerService.EventID.DMCompileSuccess); lock (CompilerLock) From 2125054478cac7441d07f39502030c0a918476c2 Mon Sep 17 00:00:00 2001 From: Jamie Hankins Date: Sun, 10 Sep 2017 03:05:57 +0100 Subject: [PATCH 04/13] Minor version bump because it's not working? --- Version.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Version.cs b/Version.cs index 2fdd65b7fb..becc04b6bc 100644 --- a/Version.cs +++ b/Version.cs @@ -12,6 +12,6 @@ using System.Reflection; // [assembly: AssemblyVersion("1.0.*")] //It's impossible to make these a define, don't say I didn't warn you -[assembly: AssemblyVersion("3.0.90.2")] -[assembly: AssemblyFileVersion("3.0.90.2")] -[assembly: AssemblyInformationalVersion("3.0.90.2")] +[assembly: AssemblyVersion("3.0.90.3")] +[assembly: AssemblyFileVersion("3.0.90.3")] +[assembly: AssemblyInformationalVersion("3.0.90.3")] From b44d102546ad45ab1a01fe65bb0159f698f4a00c Mon Sep 17 00:00:00 2001 From: Jamie Hankins Date: Sun, 10 Sep 2017 03:10:46 +0100 Subject: [PATCH 05/13] Raise a warning when we don't run an event handler --- TGServerService/PreactionHandler.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/TGServerService/PreactionHandler.cs b/TGServerService/PreactionHandler.cs index 9b7ef88da0..e1594d5023 100644 --- a/TGServerService/PreactionHandler.cs +++ b/TGServerService/PreactionHandler.cs @@ -23,7 +23,8 @@ namespace TGServerService { if (!EventHandlerExists(eventName)) { - // We don't need a handler, so let's just fail silently. + // We don't need a handler, so let's just fail semi-silently. + TGServerService.WriteWarning(String.Format("Preaction Event not running due to missing event handler: {}.", GetPath(eventName)), TGServerService.EventID.PreactionFail); return true; } From 3491d80b5652938f2b4e643d22913280d5f26138 Mon Sep 17 00:00:00 2001 From: Jamie Hankins Date: Sun, 10 Sep 2017 03:11:28 +0100 Subject: [PATCH 06/13] . --- TGServerService/PreactionHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TGServerService/PreactionHandler.cs b/TGServerService/PreactionHandler.cs index e1594d5023..768333f8bb 100644 --- a/TGServerService/PreactionHandler.cs +++ b/TGServerService/PreactionHandler.cs @@ -24,7 +24,7 @@ namespace TGServerService if (!EventHandlerExists(eventName)) { // We don't need a handler, so let's just fail semi-silently. - TGServerService.WriteWarning(String.Format("Preaction Event not running due to missing event handler: {}.", GetPath(eventName)), TGServerService.EventID.PreactionFail); + TGServerService.WriteWarning(String.Format("Preaction Event not running due to missing event handler: {}", GetPath(eventName)), TGServerService.EventID.PreactionFail); return true; } From eb3822ce21df79cb829507aa2f510b0a9f52e5de Mon Sep 17 00:00:00 2001 From: Jamie Hankins Date: Sun, 10 Sep 2017 06:57:33 +0100 Subject: [PATCH 07/13] I know how these work, honestly... --- TGServerService/PreactionHandler.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TGServerService/PreactionHandler.cs b/TGServerService/PreactionHandler.cs index 768333f8bb..510d7d606f 100644 --- a/TGServerService/PreactionHandler.cs +++ b/TGServerService/PreactionHandler.cs @@ -11,7 +11,7 @@ namespace TGServerService string GetPath(string eventName) { - return string.Format("{}{}.bat", EventFolder, eventName); + return string.Format("{0}{1}.bat", EventFolder, eventName); } bool EventHandlerExists(string eventName) @@ -24,7 +24,7 @@ namespace TGServerService if (!EventHandlerExists(eventName)) { // We don't need a handler, so let's just fail semi-silently. - TGServerService.WriteWarning(String.Format("Preaction Event not running due to missing event handler: {}", GetPath(eventName)), TGServerService.EventID.PreactionFail); + TGServerService.WriteWarning(String.Format("Preaction Event not running due to missing event handler: {0}", GetPath(eventName)), TGServerService.EventID.PreactionFail); return true; } @@ -46,7 +46,7 @@ namespace TGServerService var stderr = process.StandardError.ReadToEnd(); TGServerService.WriteInfo( - String.Format("Preaction Event ran. Stdout:\n{}\nStderr:\n{}", stdout, stderr), + String.Format("Preaction Event ran. Stdout:\n{0}\nStderr:\n{1}", stdout, stderr), process.ExitCode == 0 ? TGServerService.EventID.PreactionEvent : TGServerService.EventID.PreactionFail ); From 9e0e6a717c025e95aa6453e578d19bbcdad86a25 Mon Sep 17 00:00:00 2001 From: Jamie Hankins Date: Sun, 10 Sep 2017 07:31:21 +0100 Subject: [PATCH 08/13] Verson bump --- Version.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Version.cs b/Version.cs index becc04b6bc..5643d82a20 100644 --- a/Version.cs +++ b/Version.cs @@ -12,6 +12,6 @@ using System.Reflection; // [assembly: AssemblyVersion("1.0.*")] //It's impossible to make these a define, don't say I didn't warn you -[assembly: AssemblyVersion("3.0.90.3")] -[assembly: AssemblyFileVersion("3.0.90.3")] -[assembly: AssemblyInformationalVersion("3.0.90.3")] +[assembly: AssemblyVersion("3.0.90.4")] +[assembly: AssemblyFileVersion("3.0.90.4")] +[assembly: AssemblyInformationalVersion("3.0.90.4")] From fa7ab1cfe16fc50fef71185153ff005ecf59441d Mon Sep 17 00:00:00 2001 From: Jamie Hankins Date: Mon, 11 Sep 2017 01:00:33 +0100 Subject: [PATCH 09/13] Downgrade version for @Cyberboss --- Version.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Version.cs b/Version.cs index 5643d82a20..2fdd65b7fb 100644 --- a/Version.cs +++ b/Version.cs @@ -12,6 +12,6 @@ using System.Reflection; // [assembly: AssemblyVersion("1.0.*")] //It's impossible to make these a define, don't say I didn't warn you -[assembly: AssemblyVersion("3.0.90.4")] -[assembly: AssemblyFileVersion("3.0.90.4")] -[assembly: AssemblyInformationalVersion("3.0.90.4")] +[assembly: AssemblyVersion("3.0.90.2")] +[assembly: AssemblyFileVersion("3.0.90.2")] +[assembly: AssemblyInformationalVersion("3.0.90.2")] From b6b3ef3eb592d8a5fba06882285ffe6b60cfe359 Mon Sep 17 00:00:00 2001 From: JamieH Date: Fri, 15 Sep 2017 10:01:33 +0100 Subject: [PATCH 10/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d8314202a..1e6f2d16dd 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ The process to update the server while DD is running is a functioning work in pr * This contains ssh key information for automatic changelog pushing. * `EventHandlers/` - * This contains batch files that run after certain events, currently only precompile and postcompile events are implemented. + * This contains batch files that run after certain events, currently only precompile and postcompile events are implemented. If you'd like an event handler you should create a file in this folder with the following name: `{event_name}.bat` for example: if I want an event handler for precompile, I would name it `precompile.bat`. * `BYOND/` * This contains the actual BYOND installation the server uses From 4b4f2e7afc0b7092169fb7b3c748db41147ff43c Mon Sep 17 00:00:00 2001 From: JamieH Date: Sun, 17 Sep 2017 23:16:53 +0100 Subject: [PATCH 11/13] Update ServerService.cs --- TGServerService/ServerService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TGServerService/ServerService.cs b/TGServerService/ServerService.cs index 762d768fd2..f02ce445d0 100644 --- a/TGServerService/ServerService.cs +++ b/TGServerService/ServerService.cs @@ -78,7 +78,7 @@ namespace TGServerService IRCLogModes = 6500, SubmoduleReclone = 6600, Authentication = 6700, - PreactionEvent = 6800, + PreactionEvent = 6800, PreactionFail = 6900 } From e4d1a235cd78d2578e9f5a13e09b4bf87ad734d5 Mon Sep 17 00:00:00 2001 From: JamieH Date: Sun, 17 Sep 2017 23:18:30 +0100 Subject: [PATCH 12/13] Update PreactionHandler.cs --- TGServerService/PreactionHandler.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TGServerService/PreactionHandler.cs b/TGServerService/PreactionHandler.cs index 510d7d606f..0cf3432ca3 100644 --- a/TGServerService/PreactionHandler.cs +++ b/TGServerService/PreactionHandler.cs @@ -24,7 +24,7 @@ namespace TGServerService if (!EventHandlerExists(eventName)) { // We don't need a handler, so let's just fail semi-silently. - TGServerService.WriteWarning(String.Format("Preaction Event not running due to missing event handler: {0}", GetPath(eventName)), TGServerService.EventID.PreactionFail); + TGServerService.WriteWarning(String.Format("Preaction Event: {0} not running due to missing event handler: {1}", eventName, GetPath(eventName)), TGServerService.EventID.PreactionFail); return true; } @@ -46,7 +46,7 @@ namespace TGServerService var stderr = process.StandardError.ReadToEnd(); TGServerService.WriteInfo( - String.Format("Preaction Event ran. Stdout:\n{0}\nStderr:\n{1}", stdout, stderr), + String.Format("Preaction Event: {0} @ {1} ran. Stdout:\n{2}\nStderr:\n{3}", eventName, GetPath(eventName), stdout, stderr), process.ExitCode == 0 ? TGServerService.EventID.PreactionEvent : TGServerService.EventID.PreactionFail ); From 8b5ff10f4842f4c88716604f7839503797f315ca Mon Sep 17 00:00:00 2001 From: JamieH Date: Sun, 17 Sep 2017 23:19:25 +0100 Subject: [PATCH 13/13] Update Compiler.cs --- TGServerService/Compiler.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TGServerService/Compiler.cs b/TGServerService/Compiler.cs index 6b3bf3a984..5768508be1 100644 --- a/TGServerService/Compiler.cs +++ b/TGServerService/Compiler.cs @@ -387,6 +387,7 @@ namespace TGServerService { lastCompilerError = "The precompile hook failed"; compilerCurrentStatus = TGCompilerStatus.Initialized; //still fairly valid + TGServerService.WriteWarning("Precompile hook failed!", TGServerService.EventID.DMCompileError); return; } @@ -484,6 +485,7 @@ namespace TGServerService { lastCompilerError = "The postcompile hook failed"; compilerCurrentStatus = TGCompilerStatus.Initialized; //still fairly valid + TGServerService.WriteWarning("Postcompile hook failed!", TGServerService.EventID.DMCompileError); return; } var msg = String.Format("Compile complete!{0}", !staged ? "" : " Server will update next round.");