[391] | 1 | using AllocsFixes.JSON;
|
---|
| 2 | using JetBrains.Annotations;
|
---|
| 3 |
|
---|
| 4 | namespace 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 | }
|
---|