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