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