- Timestamp:
- Aug 6, 2022, 11:32:32 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/MapRendering/Web/API/ExecuteConsoleCommand.cs
r382 r387 1 1 using System; 2 2 using System.Net; 3 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;4 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;5 3 6 4 namespace AllocsFixes.NetConnections.Servers.Web.API { 7 public class ExecuteConsoleCommand : WebAPI { 8 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 9 int _permissionLevel) { 10 if (string.IsNullOrEmpty (_req.QueryString ["command"])) { 11 _resp.StatusCode = (int) HttpStatusCode.BadRequest; 12 Web.SetResponseTextContent (_resp, "No command given"); 5 public class ExecuteConsoleCommand : AbsWebAPI { 6 public override void HandleRequest (RequestContext _context) { 7 if (string.IsNullOrEmpty (_context.Request.QueryString ["command"])) { 8 WebUtils.WriteText (_context.Response, "No command given", HttpStatusCode.BadRequest); 13 9 return; 14 10 } 15 11 16 12 WebCommandResult.ResultType responseType = 17 _ req.QueryString ["raw"] != null13 _context.Request.QueryString ["raw"] != null 18 14 ? WebCommandResult.ResultType.Raw 19 : (_ req.QueryString ["simple"] != null15 : (_context.Request.QueryString ["simple"] != null 20 16 ? WebCommandResult.ResultType.ResultOnly 21 17 : WebCommandResult.ResultType.Full); 22 18 23 string commandline = _ req.QueryString ["command"];19 string commandline = _context.Request.QueryString ["command"]; 24 20 string commandPart = commandline.Split (' ') [0]; 25 21 string argumentsPart = commandline.Substring (Math.Min (commandline.Length, commandPart.Length + 1)); … … 28 24 29 25 if (command == null) { 30 _resp.StatusCode = (int) HttpStatusCode.NotFound; 31 Web.SetResponseTextContent (_resp, "Unknown command"); 26 WebUtils.WriteText (_context.Response, "Unknown command", HttpStatusCode.NotFound); 32 27 return; 33 28 } … … 35 30 int commandPermissionLevel = GameManager.Instance.adminTools.GetCommandPermissionLevel (command.GetCommands ()); 36 31 37 if (_permissionLevel > commandPermissionLevel) { 38 _resp.StatusCode = (int) HttpStatusCode.Forbidden; 39 Web.SetResponseTextContent (_resp, "You are not allowed to execute this command"); 32 if (_context.PermissionLevel > commandPermissionLevel) { 33 WebUtils.WriteText (_context.Response, "You are not allowed to execute this command", HttpStatusCode.Forbidden); 40 34 return; 41 35 } 42 36 43 _ resp.SendChunked = true;44 WebCommandResult wcr = new WebCommandResult (commandPart, argumentsPart, responseType, _ resp);37 _context.Response.SendChunked = true; 38 WebCommandResult wcr = new WebCommandResult (commandPart, argumentsPart, responseType, _context.Response); 45 39 SdtdConsole.Instance.ExecuteAsync (commandline, wcr); 46 40 }
Note:
See TracChangeset
for help on using the changeset viewer.