source: binary-improvements2/MapRendering/Web/API/GetAllowedCommands.cs@ 386

Last change on this file since 386 was 383, checked in by alloc, 3 years ago

Fixed a bunch of warnings

File size: 1.3 KB
Line 
1using AllocsFixes.JSON;
2using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;
3using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;
4
5namespace AllocsFixes.NetConnections.Servers.Web.API {
6 public class GetAllowedCommands : WebAPI {
7 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user,
8 int _permissionLevel) {
9 JSONObject result = new JSONObject ();
10 JSONArray entries = new JSONArray ();
11 foreach (IConsoleCommand cc in SdtdConsole.Instance.GetCommands ()) {
12 int commandPermissionLevel = GameManager.Instance.adminTools.GetCommandPermissionLevel (cc.GetCommands ());
13 if (_permissionLevel <= commandPermissionLevel) {
14 string cmd = string.Empty;
15 foreach (string s in cc.GetCommands ()) {
16 if (s.Length > cmd.Length) {
17 cmd = s;
18 }
19 }
20
21 JSONObject cmdObj = new JSONObject ();
22 cmdObj.Add ("command", new JSONString (cmd));
23 cmdObj.Add ("description", new JSONString (cc.GetDescription ()));
24 cmdObj.Add ("help", new JSONString (cc.GetHelp ()));
25 entries.Add (cmdObj);
26 }
27 }
28
29 result.Add ("commands", entries);
30
31 WriteJSON (_resp, result);
32 }
33
34 public override int DefaultPermissionLevel () {
35 return 2000;
36 }
37 }
38}
Note: See TracBrowser for help on using the repository browser.