using AllocsFixes.JSON; using AllocsFixes.PersistentData; using System; using System.Collections.Generic; using System.Net; namespace AllocsFixes.NetConnections.Servers.Web.API { public class ExecuteConsoleCommand : WebAPI { public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { if (string.IsNullOrEmpty (req.QueryString ["command"])) { resp.StatusCode = (int)HttpStatusCode.BadRequest; Web.SetResponseTextContent (resp, "No command given"); return; } string commandline = req.QueryString ["command"]; string commandPart = commandline.Split (' ') [0]; string argumentsPart = commandline.Substring (Math.Min (commandline.Length, commandPart.Length + 1)); IConsoleCommand command = SdtdConsole.Instance.GetCommand (commandline); if (command == null) { resp.StatusCode = (int)HttpStatusCode.NotImplemented; Web.SetResponseTextContent (resp, "Unknown command"); return; } AdminToolsCommandPermissions atcp = GameManager.Instance.adminTools.GetAdminToolsCommandPermission (command.GetCommands ()); if (permissionLevel > atcp.PermissionLevel) { resp.StatusCode = (int)HttpStatusCode.Forbidden; Web.SetResponseTextContent (resp, "You are not allowed to execute this command"); return; } // TODO: Execute command (store resp as IConsoleConnection instance to deliver response to the single client?) resp.SendChunked = true; WebCommandResult wcr = new WebCommandResult (commandPart, argumentsPart, resp); SdtdConsole.Instance.ExecuteAsync (commandline, wcr); } public override int DefaultPermissionLevel () { return 2000; } } }