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

Last change on this file since 355 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
Line 
1using System.Net;
2using AllocsFixes.JSON;
3
4namespace AllocsFixes.NetConnections.Servers.Web.API {
5 public class GetAllowedCommands : WebAPI {
6 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user,
7 int _permissionLevel) {
8 JSONObject result = new JSONObject ();
9 JSONArray entries = new JSONArray ();
10 foreach (IConsoleCommand cc in SdtdConsole.Instance.GetCommands ()) {
11 AdminToolsCommandPermissions atcp =
12 GameManager.Instance.adminTools.GetAdminToolsCommandPermission (cc.GetCommands ());
13 if (_permissionLevel <= atcp.PermissionLevel) {
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.