From 71178d0851b6ee929ec4e9403a693b7f7d9fbd1e Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 1 Sep 2017 19:39:17 -0400 Subject: [PATCH 01/10] Implement server chat commands --- TGServerService/Chat.cs | 4 +- TGServerService/ChatCommands.cs | 145 ++++++++------------------------ TGServerService/DreamDaemon.cs | 2 +- TGServerService/Interop.cs | 37 ++++---- 4 files changed, 58 insertions(+), 130 deletions(-) diff --git a/TGServerService/Chat.cs b/TGServerService/Chat.cs index 7d3ab39b8b..cafc390697 100644 --- a/TGServerService/Chat.cs +++ b/TGServerService/Chat.cs @@ -147,7 +147,9 @@ namespace TGServerService Server = this, }; TGServerService.WriteInfo(String.Format("Chat Command from {0} ({2}): {1}", speaker, String.Join(" ", asList), channel), TGServerService.EventID.ChatCommand); - new RootChatCommand().DoRun(asList); + if (ServerChatCommands == null) + LoadServerChatCommands(); + new RootChatCommand(ServerChatCommands).DoRun(asList); } //cleanup and save diff --git a/TGServerService/ChatCommands.cs b/TGServerService/ChatCommands.cs index d60581d1e5..3ea26883d3 100644 --- a/TGServerService/ChatCommands.cs +++ b/TGServerService/ChatCommands.cs @@ -1,7 +1,7 @@ using TGServiceInterface; -using System.Threading; -using System.Collections.Generic; using System; +using System.Collections.Generic; +using System.Threading; namespace TGServerService { @@ -36,12 +36,40 @@ namespace TGServerService return base.DoRun(parameters); } } + + class ServerChatCommand : ChatCommand + { + readonly string HelpText; + public ServerChatCommand(string name, string helpText, bool adminOnly) + { + Keyword = name; + RequiresAdmin = adminOnly; + HelpText = helpText; + } + + public override string GetHelpText() + { + return HelpText; + } + + protected override ExitCode Run(IList parameters) + { + var res = Instance.SendCommand(String.Format("{0} {1}", Keyword, String.Join(" ", parameters))); + if (res != "SUCESS" && !String.IsNullOrWhiteSpace(res)) + OutputProc(res); + return ExitCode.Normal; + } + } + class RootChatCommand : RootCommand { - public RootChatCommand() + public RootChatCommand(List serverCommands) { + if (serverCommands == null) + serverCommands = new List(); PrintHelpList = true; - Children = new Command[] { new CheckCommand(), new StatusCommand(), new PRsCommand(), new VersionCommand(), new AHelpCommand(), new NameCheckCommand(), new RevisionCommand(), new AdminWhoCommand(), new ByondCommand(), new KekCommand() }; + serverCommands.AddRange(new Command[] { new PRsCommand(), new VersionCommand(), new RevisionCommand(), new ByondCommand(), new KekCommand() }); + Children = serverCommands.ToArray(); } } class RevisionCommand : ChatCommand @@ -61,51 +89,6 @@ namespace TGServerService return "Returns mob info of the specified target"; } } - class NameCheckCommand : ChatCommand - { - public NameCheckCommand() - { - Keyword = "namecheck"; - RequiredParameters = 1; - RequiresAdmin = true; - } - protected override ExitCode Run(IList parameters) - { - OutputProc(Instance.NameCheck(parameters[0], CommandInfo.Value.Speaker)); - return ExitCode.Normal; - } - - public override string GetHelpText() - { - return "Returns mob info of the specified target"; - } - public override string GetArgumentString() - { - return ""; - } - } - class AdminWhoCommand : ChatCommand - { - public AdminWhoCommand() - { - Keyword = "adminwho"; - RequiresAdmin = true; - } - protected override ExitCode Run(IList parameters) - { - OutputProc(Instance.SendCommand(TGStationServer.SCAdminWho)); - return ExitCode.Normal; - } - - public override string GetHelpText() - { - return "Returns mob info of the specified target"; - } - public override string GetArgumentString() - { - return ""; - } - } class ByondCommand : ChatCommand { @@ -134,42 +117,6 @@ namespace TGServerService return "[--staged|--latest]"; } } - class CheckCommand : ChatCommand - { - public CheckCommand() - { - Keyword = "check"; - } - protected override ExitCode Run(IList parameters) - { - OutputProc(Instance.StatusString(CommandInfo.Value.IsAdmin && CommandInfo.Value.IsAdminChannel)); - return ExitCode.Normal; - } - - public override string GetHelpText() - { - return "Gets the playercount, gamemode, and address of the server"; - } - } - - class StatusCommand : ChatCommand - { - public StatusCommand() - { - Keyword = "status"; - RequiresAdmin = true; - } - protected override ExitCode Run(IList parameters) - { - OutputProc(Instance.SendCommand(TGStationServer.SCIRCStatus)); - return ExitCode.Normal; - } - - public override string GetHelpText() - { - return "Gets the admincount, playercount, gamemode, and true game mode of the server"; - } - } class VersionCommand : ChatCommand { public VersionCommand() @@ -235,31 +182,5 @@ namespace TGServerService return "Gets the currently merged pull requests in the repository"; } } - - class AHelpCommand : ChatCommand - { - public AHelpCommand() - { - Keyword = "ahelp"; - RequiresAdmin = true; - RequiredParameters = 2; - } - protected override ExitCode Run(IList parameters) - { - var ckey = parameters[0]; - parameters.RemoveAt(0); - OutputProc(Instance.SendPM(ckey, CommandInfo.Value.Speaker, String.Join(" ", parameters))); - return ExitCode.Normal; - } - - public override string GetHelpText() - { - return "Respond to a relayed admin help request"; - } - - public override string GetArgumentString() - { - return " |list>>"; - } - } + } diff --git a/TGServerService/DreamDaemon.cs b/TGServerService/DreamDaemon.cs index 4d05e5a9a9..696125a7d3 100644 --- a/TGServerService/DreamDaemon.cs +++ b/TGServerService/DreamDaemon.cs @@ -463,7 +463,7 @@ namespace TGServerService res = "REBOOTING"; break; case TGDreamDaemonStatus.Online: - res = SendCommand(SCIRCCheck); + res = "ONLINE"; if (includeMetaInfo) { string secandvis; diff --git a/TGServerService/Interop.cs b/TGServerService/Interop.cs index 8dec4f1df1..072d6aebda 100644 --- a/TGServerService/Interop.cs +++ b/TGServerService/Interop.cs @@ -1,10 +1,10 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; +using System.Web.Script.Serialization; using System.Web.Security; using TGServiceInterface; @@ -24,17 +24,32 @@ namespace TGServerService const string SCHardReboot = "hard_reboot"; //requests that dreamdaemon restarts when the round ends const string SCGracefulShutdown = "graceful_shutdown"; //requests that dreamdaemon stops when the round ends const string SCWorldAnnounce = "world_announce"; //sends param 'message' to the world - public const string SCIRCCheck = "irc_check"; //returns game stats - public const string SCIRCStatus = "irc_status"; //returns admin stats - public const string SCNameCheck = "namecheck"; //returns keywords lookup - const string SCAdminPM = "adminmsg"; //pms a target ckey - public const string SCAdminWho = "adminwho"; //lists admins + const string SCListCustomCommands = "list_custom_commands"; //Get a list of commands supported by the server const string SRKillProcess = "killme"; const string SRIRCBroadcast = "irc"; const string SRIRCAdminChannelMessage = "send2irc"; const string SRWorldReboot = "worldreboot"; + List ServerChatCommands; + + void LoadServerChatCommands() + { + if (DaemonStatus() != TGDreamDaemonStatus.Online) + return; + var json = SendCommand(SCListCustomCommands); + if (String.IsNullOrWhiteSpace(json)) + return; + List tmp = new List(); + try + { + foreach(var I in new JavaScriptSerializer().Deserialize>>(json)) + tmp.Add(new ServerChatCommand(I.Key, (string)I.Value["help_text"], (bool)I.Value["adminOnly"])); + ServerChatCommands = tmp; + } + catch { } + } + //raw command string sent here via world.ExportService void HandleCommand(string cmd) { @@ -77,16 +92,6 @@ namespace TGServerService } } - public string SendPM(string targetCkey, string sender, string message) - { - return SendCommand(String.Format("{3};target={0};sender={1};message={2}", targetCkey, sender, message, SCAdminPM)); - } - - public string NameCheck(string targetCkey, string sender) - { - return SendCommand(String.Format("{2};target={0};sender={1}", targetCkey, sender, SCNameCheck)); - } - //Fuckery to diddle byond with the right packet to accept our girth string SendTopic(string topicdata, ushort port) { From f8a0f73e4428e68b0a17ed9b4e952c1511c5ca18 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 1 Sep 2017 19:46:15 -0400 Subject: [PATCH 02/10] Required parameters --- TGServerService/ChatCommands.cs | 3 ++- TGServerService/Interop.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/TGServerService/ChatCommands.cs b/TGServerService/ChatCommands.cs index 3ea26883d3..f0a8d42ec6 100644 --- a/TGServerService/ChatCommands.cs +++ b/TGServerService/ChatCommands.cs @@ -40,11 +40,12 @@ namespace TGServerService class ServerChatCommand : ChatCommand { readonly string HelpText; - public ServerChatCommand(string name, string helpText, bool adminOnly) + public ServerChatCommand(string name, string helpText, bool adminOnly, int requiredParameters) { Keyword = name; RequiresAdmin = adminOnly; HelpText = helpText; + RequiredParameters = requiredParameters; } public override string GetHelpText() diff --git a/TGServerService/Interop.cs b/TGServerService/Interop.cs index 072d6aebda..48b2d7953a 100644 --- a/TGServerService/Interop.cs +++ b/TGServerService/Interop.cs @@ -44,7 +44,7 @@ namespace TGServerService try { foreach(var I in new JavaScriptSerializer().Deserialize>>(json)) - tmp.Add(new ServerChatCommand(I.Key, (string)I.Value["help_text"], (bool)I.Value["adminOnly"])); + tmp.Add(new ServerChatCommand(I.Key, (string)I.Value["help_text"], (bool)I.Value["adminOnly"], (int)I.Value["required_parameters"])); ServerChatCommands = tmp; } catch { } From 6ed3ffabe237d73ed276d404c217025bfd765603 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 1 Sep 2017 20:36:25 -0400 Subject: [PATCH 03/10] Null out chat commands on restart --- TGServerService/Interop.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/TGServerService/Interop.cs b/TGServerService/Interop.cs index 48b2d7953a..c8f4b06fdc 100644 --- a/TGServerService/Interop.cs +++ b/TGServerService/Interop.cs @@ -70,6 +70,7 @@ namespace TGServerService break; case SRWorldReboot: TGServerService.WriteInfo("World Rebooted", TGServerService.EventID.WorldReboot); + ServerChatCommands = null; lock (CompilerLock) { if (UpdateStaged) From 32ee79121d245a45d6012eda593caf18f6a259c1 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Sat, 2 Sep 2017 21:56:42 -0400 Subject: [PATCH 04/10] Buff the topic recieve size --- TGServerService/Interop.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TGServerService/Interop.cs b/TGServerService/Interop.cs index c8f4b06fdc..e71b35a6a3 100644 --- a/TGServerService/Interop.cs +++ b/TGServerService/Interop.cs @@ -124,7 +124,7 @@ namespace TGServerService string returnedString = "NULL"; try { - var returnedData = new byte[512]; + var returnedData = new byte[UInt16.MaxValue]; topicSender.Receive(returnedData); var raw_string = Encoding.ASCII.GetString(returnedData).TrimEnd(new char[] { (char)0 }).Trim(); if (raw_string.Length > 6) From a17fd979223eb762b7636b23c4ed1b51dd94fde7 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Sat, 2 Sep 2017 22:17:39 -0400 Subject: [PATCH 05/10] The more defines the more better --- TGServerService/Interop.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/TGServerService/Interop.cs b/TGServerService/Interop.cs index e71b35a6a3..04d39d5052 100644 --- a/TGServerService/Interop.cs +++ b/TGServerService/Interop.cs @@ -29,7 +29,11 @@ namespace TGServerService const string SRKillProcess = "killme"; const string SRIRCBroadcast = "irc"; const string SRIRCAdminChannelMessage = "send2irc"; - const string SRWorldReboot = "worldreboot"; + const string SRWorldReboot = "worldreboot"; + + const string CCPHelpText = "help_text"; + const string CCPAdminOnly = "admin_only"; + const string CCPRequiredParameters = "required_parameters"; List ServerChatCommands; @@ -44,7 +48,7 @@ namespace TGServerService try { foreach(var I in new JavaScriptSerializer().Deserialize>>(json)) - tmp.Add(new ServerChatCommand(I.Key, (string)I.Value["help_text"], (bool)I.Value["adminOnly"], (int)I.Value["required_parameters"])); + tmp.Add(new ServerChatCommand(I.Key, (string)I.Value[CCPHelpText], (bool)I.Value[CCPAdminOnly], (int)I.Value[CCPRequiredParameters])); ServerChatCommands = tmp; } catch { } From 6f87fa6c18eb004e8b20aff0db579bddd0de4729 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Sat, 2 Sep 2017 22:38:12 -0400 Subject: [PATCH 06/10] Fix conversion --- TGServerService/Interop.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TGServerService/Interop.cs b/TGServerService/Interop.cs index 04d39d5052..9008416f31 100644 --- a/TGServerService/Interop.cs +++ b/TGServerService/Interop.cs @@ -48,7 +48,7 @@ namespace TGServerService try { foreach(var I in new JavaScriptSerializer().Deserialize>>(json)) - tmp.Add(new ServerChatCommand(I.Key, (string)I.Value[CCPHelpText], (bool)I.Value[CCPAdminOnly], (int)I.Value[CCPRequiredParameters])); + tmp.Add(new ServerChatCommand(I.Key, (string)I.Value[CCPHelpText], ((int)I.Value[CCPAdminOnly]) == 1, (int)I.Value[CCPRequiredParameters])); ServerChatCommands = tmp; } catch { } From 19c75976c61ffd2c0c56cfd8fb9e6a384ea24803 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Sat, 2 Sep 2017 22:40:13 -0400 Subject: [PATCH 07/10] Fix command format --- TGServerService/ChatCommands.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TGServerService/ChatCommands.cs b/TGServerService/ChatCommands.cs index f0a8d42ec6..55b92365f5 100644 --- a/TGServerService/ChatCommands.cs +++ b/TGServerService/ChatCommands.cs @@ -55,7 +55,7 @@ namespace TGServerService protected override ExitCode Run(IList parameters) { - var res = Instance.SendCommand(String.Format("{0} {1}", Keyword, String.Join(" ", parameters))); + var res = Instance.SendCommand(String.Format("{0};sender={1};custom=\"{2}\"", Keyword, CommandInfo.Value.Speaker, String.Join(" ", parameters))); if (res != "SUCESS" && !String.IsNullOrWhiteSpace(res)) OutputProc(res); return ExitCode.Normal; From 5bffe2e304a169a606b83c731909e5a71c2e758b Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Sat, 2 Sep 2017 22:44:16 -0400 Subject: [PATCH 08/10] Fix infinite listing --- TGServerService/ChatCommands.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/TGServerService/ChatCommands.cs b/TGServerService/ChatCommands.cs index 55b92365f5..1025066cc2 100644 --- a/TGServerService/ChatCommands.cs +++ b/TGServerService/ChatCommands.cs @@ -65,12 +65,12 @@ namespace TGServerService class RootChatCommand : RootCommand { public RootChatCommand(List serverCommands) - { - if (serverCommands == null) - serverCommands = new List(); + { + Children = new Command[] { new PRsCommand(), new VersionCommand(), new RevisionCommand(), new ByondCommand(), new KekCommand() }; + if (serverCommands != null) + serverCommands.CopyTo(Children); + serverCommands = new List(); PrintHelpList = true; - serverCommands.AddRange(new Command[] { new PRsCommand(), new VersionCommand(), new RevisionCommand(), new ByondCommand(), new KekCommand() }); - Children = serverCommands.ToArray(); } } class RevisionCommand : ChatCommand From 1be5f93d105af8ca0b016dd2a91b8578aba1cadc Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Sat, 2 Sep 2017 22:46:33 -0400 Subject: [PATCH 09/10] Actually fix it --- TGServerService/ChatCommands.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/TGServerService/ChatCommands.cs b/TGServerService/ChatCommands.cs index 1025066cc2..f0659c9c87 100644 --- a/TGServerService/ChatCommands.cs +++ b/TGServerService/ChatCommands.cs @@ -65,11 +65,12 @@ namespace TGServerService class RootChatCommand : RootCommand { public RootChatCommand(List serverCommands) - { - Children = new Command[] { new PRsCommand(), new VersionCommand(), new RevisionCommand(), new ByondCommand(), new KekCommand() }; - if (serverCommands != null) - serverCommands.CopyTo(Children); - serverCommands = new List(); + { + var tmp = new List { new PRsCommand(), new VersionCommand(), new RevisionCommand(), new ByondCommand(), new KekCommand() }; + if (serverCommands != null) + tmp.AddRange(serverCommands); + Children = tmp.ToArray(); + serverCommands = new List(); PrintHelpList = true; } } From c81cb5b8158e2842c22b222798adbc285213e58e Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Sat, 2 Sep 2017 22:51:40 -0400 Subject: [PATCH 10/10] Tabs --- TGServerService/Interop.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TGServerService/Interop.cs b/TGServerService/Interop.cs index 9008416f31..e30144b16b 100644 --- a/TGServerService/Interop.cs +++ b/TGServerService/Interop.cs @@ -29,11 +29,11 @@ namespace TGServerService const string SRKillProcess = "killme"; const string SRIRCBroadcast = "irc"; const string SRIRCAdminChannelMessage = "send2irc"; - const string SRWorldReboot = "worldreboot"; + const string SRWorldReboot = "worldreboot"; - const string CCPHelpText = "help_text"; - const string CCPAdminOnly = "admin_only"; - const string CCPRequiredParameters = "required_parameters"; + const string CCPHelpText = "help_text"; + const string CCPAdminOnly = "admin_only"; + const string CCPRequiredParameters = "required_parameters"; List ServerChatCommands;