source: binary-improvements/MapRendering/Web/API/ExecuteConsoleCommand.cs@ 346

Last change on this file since 346 was 325, checked in by alloc, 6 years ago

Code style cleanup (mostly whitespace changes, enforcing braces, using cleanup)

File size: 1.7 KB
RevLine 
[245]1using System;
2using System.Net;
3
[325]4namespace AllocsFixes.NetConnections.Servers.Web.API {
5 public class ExecuteConsoleCommand : WebAPI {
6 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user,
7 int permissionLevel) {
[245]8 if (string.IsNullOrEmpty (req.QueryString ["command"])) {
[325]9 resp.StatusCode = (int) HttpStatusCode.BadRequest;
[245]10 Web.SetResponseTextContent (resp, "No command given");
11 return;
12 }
13
[306]14 WebCommandResult.ResultType responseType =
[325]15 req.QueryString ["raw"] != null
16 ? WebCommandResult.ResultType.Raw
17 : (req.QueryString ["simple"] != null
18 ? WebCommandResult.ResultType.ResultOnly
19 : WebCommandResult.ResultType.Full);
[306]20
[279]21 string commandline = req.QueryString ["command"];
22 string commandPart = commandline.Split (' ') [0];
23 string argumentsPart = commandline.Substring (Math.Min (commandline.Length, commandPart.Length + 1));
[245]24
[279]25 IConsoleCommand command = SdtdConsole.Instance.GetCommand (commandline);
[245]26
27 if (command == null) {
[325]28 resp.StatusCode = (int) HttpStatusCode.NotImplemented;
[245]29 Web.SetResponseTextContent (resp, "Unknown command");
30 return;
31 }
32
[325]33 AdminToolsCommandPermissions atcp =
34 GameManager.Instance.adminTools.GetAdminToolsCommandPermission (command.GetCommands ());
[245]35
36 if (permissionLevel > atcp.PermissionLevel) {
[325]37 resp.StatusCode = (int) HttpStatusCode.Forbidden;
[245]38 Web.SetResponseTextContent (resp, "You are not allowed to execute this command");
39 return;
40 }
41
[279]42 resp.SendChunked = true;
[306]43 WebCommandResult wcr = new WebCommandResult (commandPart, argumentsPart, responseType, resp);
[279]44 SdtdConsole.Instance.ExecuteAsync (commandline, wcr);
[245]45 }
[279]46
47 public override int DefaultPermissionLevel () {
48 return 2000;
49 }
[245]50 }
[325]51}
Note: See TracBrowser for help on using the repository browser.