mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-25 14:06:41 +01:00
Merge pull request #148 from Cyberboss/FormalAPI
Implement server chat commands
This commit is contained in:
@@ -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
|
||||
|
||||
+35
-112
@@ -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,42 @@ namespace TGServerService
|
||||
return base.DoRun(parameters);
|
||||
}
|
||||
}
|
||||
|
||||
class ServerChatCommand : ChatCommand
|
||||
{
|
||||
readonly string HelpText;
|
||||
public ServerChatCommand(string name, string helpText, bool adminOnly, int requiredParameters)
|
||||
{
|
||||
Keyword = name;
|
||||
RequiresAdmin = adminOnly;
|
||||
HelpText = helpText;
|
||||
RequiredParameters = requiredParameters;
|
||||
}
|
||||
|
||||
public override string GetHelpText()
|
||||
{
|
||||
return HelpText;
|
||||
}
|
||||
|
||||
protected override ExitCode Run(IList<string> 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;
|
||||
}
|
||||
}
|
||||
|
||||
class RootChatCommand : RootCommand
|
||||
{
|
||||
public RootChatCommand()
|
||||
public RootChatCommand(List<Command> serverCommands)
|
||||
{
|
||||
var tmp = new List<Command> { new PRsCommand(), new VersionCommand(), new RevisionCommand(), new ByondCommand(), new KekCommand() };
|
||||
if (serverCommands != null)
|
||||
tmp.AddRange(serverCommands);
|
||||
Children = tmp.ToArray();
|
||||
serverCommands = new List<Command>();
|
||||
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() };
|
||||
}
|
||||
}
|
||||
class RevisionCommand : ChatCommand
|
||||
@@ -61,51 +91,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<string> 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 "<target>";
|
||||
}
|
||||
}
|
||||
class AdminWhoCommand : ChatCommand
|
||||
{
|
||||
public AdminWhoCommand()
|
||||
{
|
||||
Keyword = "adminwho";
|
||||
RequiresAdmin = true;
|
||||
}
|
||||
protected override ExitCode Run(IList<string> 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 "<target>";
|
||||
}
|
||||
}
|
||||
|
||||
class ByondCommand : ChatCommand
|
||||
{
|
||||
@@ -134,42 +119,6 @@ namespace TGServerService
|
||||
return "[--staged|--latest]";
|
||||
}
|
||||
}
|
||||
class CheckCommand : ChatCommand
|
||||
{
|
||||
public CheckCommand()
|
||||
{
|
||||
Keyword = "check";
|
||||
}
|
||||
protected override ExitCode Run(IList<string> 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<string> 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 +184,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<string> 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 "<ckey> <message|ticket <close|resolve|icissue|reject|reopen <ticket #>|list>>";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -463,7 +463,7 @@ namespace TGServerService
|
||||
res = "REBOOTING";
|
||||
break;
|
||||
case TGDreamDaemonStatus.Online:
|
||||
res = SendCommand(SCIRCCheck);
|
||||
res = "ONLINE";
|
||||
if (includeMetaInfo)
|
||||
{
|
||||
string secandvis;
|
||||
|
||||
+27
-17
@@ -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,36 @@ 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";
|
||||
|
||||
const string CCPHelpText = "help_text";
|
||||
const string CCPAdminOnly = "admin_only";
|
||||
const string CCPRequiredParameters = "required_parameters";
|
||||
|
||||
List<Command> ServerChatCommands;
|
||||
|
||||
void LoadServerChatCommands()
|
||||
{
|
||||
if (DaemonStatus() != TGDreamDaemonStatus.Online)
|
||||
return;
|
||||
var json = SendCommand(SCListCustomCommands);
|
||||
if (String.IsNullOrWhiteSpace(json))
|
||||
return;
|
||||
List<Command> tmp = new List<Command>();
|
||||
try
|
||||
{
|
||||
foreach(var I in new JavaScriptSerializer().Deserialize<IDictionary<string, IDictionary<string, object>>>(json))
|
||||
tmp.Add(new ServerChatCommand(I.Key, (string)I.Value[CCPHelpText], ((int)I.Value[CCPAdminOnly]) == 1, (int)I.Value[CCPRequiredParameters]));
|
||||
ServerChatCommands = tmp;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
//raw command string sent here via world.ExportService
|
||||
void HandleCommand(string cmd)
|
||||
{
|
||||
@@ -55,6 +74,7 @@ namespace TGServerService
|
||||
break;
|
||||
case SRWorldReboot:
|
||||
TGServerService.WriteInfo("World Rebooted", TGServerService.EventID.WorldReboot);
|
||||
ServerChatCommands = null;
|
||||
lock (CompilerLock)
|
||||
{
|
||||
if (UpdateStaged)
|
||||
@@ -77,16 +97,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)
|
||||
{
|
||||
@@ -118,7 +128,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)
|
||||
|
||||
Reference in New Issue
Block a user