[279] | 1 | using System;
|
---|
[325] | 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 {
|
---|
| 7 | public class GetServerInfo : WebAPI {
|
---|
[351] | 8 | public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user,
|
---|
| 9 | int _permissionLevel) {
|
---|
[279] | 10 | JSONObject serverInfo = new JSONObject ();
|
---|
| 11 |
|
---|
[360] | 12 | GameServerInfo gsi = ConnectionManager.Instance.LocalServerInfo;
|
---|
[279] | 13 |
|
---|
[325] | 14 | foreach (string stringGamePref in Enum.GetNames (typeof (GameInfoString))) {
|
---|
| 15 | string value = gsi.GetValue ((GameInfoString) Enum.Parse (typeof (GameInfoString), stringGamePref));
|
---|
[279] | 16 |
|
---|
| 17 | JSONObject singleStat = new JSONObject ();
|
---|
| 18 | singleStat.Add ("type", new JSONString ("string"));
|
---|
| 19 | singleStat.Add ("value", new JSONString (value));
|
---|
| 20 |
|
---|
| 21 | serverInfo.Add (stringGamePref, singleStat);
|
---|
| 22 | }
|
---|
| 23 |
|
---|
[325] | 24 | foreach (string intGamePref in Enum.GetNames (typeof (GameInfoInt))) {
|
---|
| 25 | int value = gsi.GetValue ((GameInfoInt) Enum.Parse (typeof (GameInfoInt), intGamePref));
|
---|
[279] | 26 |
|
---|
| 27 | JSONObject singleStat = new JSONObject ();
|
---|
| 28 | singleStat.Add ("type", new JSONString ("int"));
|
---|
| 29 | singleStat.Add ("value", new JSONNumber (value));
|
---|
| 30 |
|
---|
| 31 | serverInfo.Add (intGamePref, singleStat);
|
---|
| 32 | }
|
---|
| 33 |
|
---|
[325] | 34 | foreach (string boolGamePref in Enum.GetNames (typeof (GameInfoBool))) {
|
---|
| 35 | bool value = gsi.GetValue ((GameInfoBool) Enum.Parse (typeof (GameInfoBool), boolGamePref));
|
---|
[279] | 36 |
|
---|
| 37 | JSONObject singleStat = new JSONObject ();
|
---|
| 38 | singleStat.Add ("type", new JSONString ("bool"));
|
---|
| 39 | singleStat.Add ("value", new JSONBoolean (value));
|
---|
| 40 |
|
---|
| 41 | serverInfo.Add (boolGamePref, singleStat);
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 |
|
---|
[351] | 45 | WriteJSON (_resp, serverInfo);
|
---|
[279] | 46 | }
|
---|
| 47 | }
|
---|
[325] | 48 | }
|
---|