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) {