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