- Timestamp:
- Jul 31, 2023, 4:06:13 PM (16 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/API/GetAllowedCommands.cs
r454 r455 1 using AllocsFixes.JSON; 1 using JetBrains.Annotations; 2 using Utf8Json; 2 3 using Webserver; 3 4 using Webserver.WebAPI; 4 5 5 6 namespace AllocsFixes.WebAPIs { 7 [UsedImplicitly] 6 8 public class GetAllowedCommands : AbsWebAPI { 9 private static readonly byte[] jsonKeyCommands = JsonWriter.GetEncodedPropertyNameWithBeginObject ("commands"); 10 11 private static readonly byte[] jsonKeyCommand = JsonWriter.GetEncodedPropertyNameWithBeginObject ("command"); 12 private static readonly byte[] jsonKeyDescription = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("description"); 13 private static readonly byte[] jsonKeyHelp = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("help"); 14 7 15 public override void HandleRequest (RequestContext _context) { 8 JSONObject result = new JSONObject (); 9 JSONArray entries = new JSONArray (); 16 JsonWriter writer = new JsonWriter (); 17 18 writer.WriteRaw (jsonKeyCommands); 19 writer.WriteBeginArray (); 20 21 bool first = true; 22 10 23 foreach (IConsoleCommand cc in SdtdConsole.Instance.GetCommands ()) { 11 24 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 } 25 if (_context.PermissionLevel > commandPermissionLevel) { 26 continue; 27 } 28 29 string cmd = string.Empty; 30 foreach (string s in cc.GetCommands ()) { 31 if (s.Length > cmd.Length) { 32 cmd = s; 18 33 } 34 } 19 35 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); 36 if (!first) { 37 writer.WriteValueSeparator (); 25 38 } 39 40 first = false; 41 42 writer.WriteRaw (jsonKeyCommand); 43 writer.WriteString (cmd); 44 45 writer.WriteRaw (jsonKeyDescription); 46 writer.WriteString (cc.GetDescription ()); 47 48 writer.WriteRaw (jsonKeyHelp); 49 if (cc.GetHelp () == null) { 50 writer.WriteString (""); 51 } else { 52 writer.WriteString (cc.GetHelp ()); 53 } 54 55 writer.WriteEndObject (); 26 56 } 27 57 28 result.Add ("commands", entries); 29 30 LegacyApiHelper.WriteJSON (_context.Response, result); 58 writer.WriteEndArray (); 59 writer.WriteEndObject (); 60 61 WebUtils.WriteJsonData (_context.Response, ref writer); 31 62 } 32 63
Note:
See TracChangeset
for help on using the changeset viewer.