| 1 | using System;
|
|---|
| 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 GetServerInfo : WebAPI {
|
|---|
| 8 | public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user,
|
|---|
| 9 | int _permissionLevel) {
|
|---|
| 10 | JSONObject serverInfo = new JSONObject ();
|
|---|
| 11 |
|
|---|
| 12 | GameServerInfo gsi = ConnectionManager.Instance.LocalServerInfo;
|
|---|
| 13 |
|
|---|
| 14 | foreach (string stringGamePref in Enum.GetNames (typeof (GameInfoString))) {
|
|---|
| 15 | string value = gsi.GetValue ((GameInfoString) Enum.Parse (typeof (GameInfoString), stringGamePref));
|
|---|
| 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 |
|
|---|
| 24 | foreach (string intGamePref in Enum.GetNames (typeof (GameInfoInt))) {
|
|---|
| 25 | int value = gsi.GetValue ((GameInfoInt) Enum.Parse (typeof (GameInfoInt), intGamePref));
|
|---|
| 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 |
|
|---|
| 34 | foreach (string boolGamePref in Enum.GetNames (typeof (GameInfoBool))) {
|
|---|
| 35 | bool value = gsi.GetValue ((GameInfoBool) Enum.Parse (typeof (GameInfoBool), boolGamePref));
|
|---|
| 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 |
|
|---|
| 45 | WriteJSON (_resp, serverInfo);
|
|---|
| 46 | }
|
|---|
| 47 | }
|
|---|
| 48 | }
|
|---|