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

Last change on this file since 434 was 420, checked in by alloc, 20 months ago

A21 preparations.
NOT COMPATIBLE WITH A20 ANYMORE!

File size: 1.7 KB
Line 
1using System;
2using System.Net;
3
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) {
8 if (string.IsNullOrEmpty (_req.QueryString ["command"])) {
9 _resp.StatusCode = (int) HttpStatusCode.BadRequest;
10 Web.SetResponseTextContent (_resp, "No command given");
11 return;
12 }
13
14 WebCommandResult.ResultType responseType =
15 _req.QueryString ["raw"] != null
16 ? WebCommandResult.ResultType.Raw
17 : (_req.QueryString ["simple"] != null
18 ? WebCommandResult.ResultType.ResultOnly
19 : WebCommandResult.ResultType.Full);
20
21 string commandline = _req.QueryString ["command"];
22 string commandPart = commandline.Split (' ') [0];
23 string argumentsPart = commandline.Substring (Math.Min (commandline.Length, commandPart.Length + 1));
24
25 IConsoleCommand command = SdtdConsole.Instance.GetCommand (commandline);
26
27 if (command == null) {
28 _resp.StatusCode = (int) HttpStatusCode.NotFound;
29 Web.SetResponseTextContent (_resp, "Unknown command");
30 return;
31 }
32
33 int commandPermissionLevel = GameManager.Instance.adminTools.Commands.GetCommandPermissionLevel (command.GetCommands ());
34
35 if (_permissionLevel > commandPermissionLevel) {
36 _resp.StatusCode = (int) HttpStatusCode.Forbidden;
37 Web.SetResponseTextContent (_resp, "You are not allowed to execute this command");
38 return;
39 }
40
41 _resp.SendChunked = true;
42 WebCommandResult wcr = new WebCommandResult (commandPart, argumentsPart, responseType, _resp);
43 SdtdConsole.Instance.ExecuteAsync (commandline, wcr);
44 }
45
46 public override int DefaultPermissionLevel () {
47 return 2000;
48 }
49 }
50}
Note: See TracBrowser for help on using the repository browser.