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

Last change on this file since 296 was 279, checked in by alloc, 8 years ago

Mod stuff

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