source: binary-improvements/MapRendering/Web/API/GetAllowedCommands.cs@ 359

Last change on this file since 359 was 351, checked in by alloc, 6 years ago

Fixed game version compatibility of GamePrefs
Code style cleanup (mostly argument names)

File size: 1.1 KB
RevLine 
[325]1using System.Net;
[279]2using AllocsFixes.JSON;
3
[325]4namespace AllocsFixes.NetConnections.Servers.Web.API {
[279]5 public class GetAllowedCommands : WebAPI {
[351]6 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user,
7 int _permissionLevel) {
[279]8 JSONObject result = new JSONObject ();
9 JSONArray entries = new JSONArray ();
10 foreach (IConsoleCommand cc in SdtdConsole.Instance.GetCommands ()) {
[325]11 AdminToolsCommandPermissions atcp =
12 GameManager.Instance.adminTools.GetAdminToolsCommandPermission (cc.GetCommands ());
[351]13 if (_permissionLevel <= atcp.PermissionLevel) {
[279]14 string cmd = string.Empty;
15 foreach (string s in cc.GetCommands ()) {
16 if (s.Length > cmd.Length) {
17 cmd = s;
18 }
19 }
[325]20
[279]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
[351]31 WriteJSON (_resp, result);
[279]32 }
33
34 public override int DefaultPermissionLevel () {
35 return 2000;
36 }
37 }
[325]38}
Note: See TracBrowser for help on using the repository browser.