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

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

Major refactoring/cleanup

File size: 1.1 KB
Line 
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
16 string cmd = string.Empty;
17 foreach (string s in cc.GetCommands ()) {
18 if (s.Length > cmd.Length) {
19 cmd = s;
20 }
21 }
22
23 JsonObject cmdObj = new JsonObject ();
24 cmdObj.Add ("command", new JsonString (cmd));
25 cmdObj.Add ("description", new JsonString (cc.GetDescription ()));
26 cmdObj.Add ("help", new JsonString (cc.GetHelp ()));
27 entries.Add (cmdObj);
28 }
29
30 result.Add ("commands", entries);
31
32 WebUtils.WriteJson (_context.Response, result);
33 }
34
35 public override int DefaultPermissionLevel () {
36 return 2000;
37 }
38 }
39}
Note: See TracBrowser for help on using the repository browser.