source: binary-improvements2/WebServer/src/WebAPI/GetAllowedCommands.cs@ 401

Last change on this file since 401 was 401, checked in by alloc, 2 years ago

GetAllowedCommands: Also report all overloads

File size: 1.2 KB
RevLine 
[391]1using AllocsFixes.JSON;
2using JetBrains.Annotations;
3
4namespace Webserver.WebAPI {
5 [UsedImplicitly]
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.GetCommandPermissionLevel (cc.GetCommands ());
12 if (_context.PermissionLevel > commandPermissionLevel) {
13 continue;
14 }
15
[401]16 JsonArray cmdOverloads = new JsonArray ();
17
[391]18 string cmd = string.Empty;
19 foreach (string s in cc.GetCommands ()) {
[401]20 cmdOverloads.Add (new JsonString (s));
[391]21 if (s.Length > cmd.Length) {
22 cmd = s;
23 }
24 }
25
26 JsonObject cmdObj = new JsonObject ();
27 cmdObj.Add ("command", new JsonString (cmd));
[401]28 cmdObj.Add ("overloads", cmdOverloads);
[391]29 cmdObj.Add ("description", new JsonString (cc.GetDescription ()));
30 cmdObj.Add ("help", new JsonString (cc.GetHelp ()));
31 entries.Add (cmdObj);
32 }
33
34 result.Add ("commands", entries);
35
36 WebUtils.WriteJson (_context.Response, result);
37 }
38
39 public override int DefaultPermissionLevel () {
40 return 2000;
41 }
42 }
43}
Note: See TracBrowser for help on using the repository browser.