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

Last change on this file since 454 was 454, checked in by alloc, 16 months ago

24_29_43
Switched over to vanilla Web infrastructure

File size: 1.1 KB
Line 
1using AllocsFixes.JSON;
2using Webserver;
3using Webserver.WebAPI;
4
5namespace AllocsFixes.WebAPIs {
6 public class GetAllowedCommands : AbsWebAPI {
7 public override void HandleRequest (RequestContext _context) {
8 JSONObject result = new JSONObject ();
9 JSONArray entries = new JSONArray ();
10 foreach (IConsoleCommand cc in SdtdConsole.Instance.GetCommands ()) {
11 int commandPermissionLevel = GameManager.Instance.adminTools.Commands.GetCommandPermissionLevel (cc.GetCommands ());
12 if (_context.PermissionLevel <= commandPermissionLevel) {
13 string cmd = string.Empty;
14 foreach (string s in cc.GetCommands ()) {
15 if (s.Length > cmd.Length) {
16 cmd = s;
17 }
18 }
19
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
30 LegacyApiHelper.WriteJSON (_context.Response, result);
31 }
32
33 public override int DefaultPermissionLevel () {
34 return 2000;
35 }
36 }
37}
Note: See TracBrowser for help on using the repository browser.