source: binary-improvements/MapRendering/Web/API/GetAllowedCommands.cs@ 420

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

A21 preparations.
NOT COMPATIBLE WITH A20 ANYMORE!

File size: 1.1 KB
RevLine 
[325]1using System.Net;
[279]2using AllocsFixes.JSON;
3
[325]4namespace AllocsFixes.NetConnections.Servers.Web.API {
[279]5 public class GetAllowedCommands : WebAPI {
[351]6 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user,
7 int _permissionLevel) {
[279]8 JSONObject result = new JSONObject ();
9 JSONArray entries = new JSONArray ();
10 foreach (IConsoleCommand cc in SdtdConsole.Instance.GetCommands ()) {
[420]11 int commandPermissionLevel = GameManager.Instance.adminTools.Commands.GetCommandPermissionLevel (cc.GetCommands ());
[360]12 if (_permissionLevel <= commandPermissionLevel) {
[279]13 string cmd = string.Empty;
14 foreach (string s in cc.GetCommands ()) {
15 if (s.Length > cmd.Length) {
16 cmd = s;
17 }
18 }
[325]19
[279]20 JSONObject cmdObj = new JSONObject ();
21 cmdObj.Add ("command", new JSONString (cmd));
22 cmdObj.Add ("description", new JSONString (cc.GetDescription ()));
23 cmdObj.Add ("help", new JSONString (cc.GetHelp ()));
24 entries.Add (cmdObj);
25 }
26 }
27
28 result.Add ("commands", entries);
29
[351]30 WriteJSON (_resp, result);
[279]31 }
32
33 public override int DefaultPermissionLevel () {
34 return 2000;
35 }
36 }
[325]37}
Note: See TracBrowser for help on using the repository browser.