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