1 | using System;
|
---|
2 | using System.Net;
|
---|
3 | using AllocsFixes.JSON;
|
---|
4 | using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;
|
---|
5 | using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;
|
---|
6 |
|
---|
7 | namespace AllocsFixes.NetConnections.Servers.Web.API {
|
---|
8 | public class GetServerInfo : WebAPI {
|
---|
9 | public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user,
|
---|
10 | int _permissionLevel) {
|
---|
11 | JSONObject serverInfo = new JSONObject ();
|
---|
12 |
|
---|
13 | GameServerInfo gsi = ConnectionManager.Instance.LocalServerInfo;
|
---|
14 |
|
---|
15 | foreach (string stringGamePref in Enum.GetNames (typeof (GameInfoString))) {
|
---|
16 | string value = gsi.GetValue ((GameInfoString) Enum.Parse (typeof (GameInfoString), stringGamePref));
|
---|
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 |
|
---|
25 | foreach (string intGamePref in Enum.GetNames (typeof (GameInfoInt))) {
|
---|
26 | int value = gsi.GetValue ((GameInfoInt) Enum.Parse (typeof (GameInfoInt), intGamePref));
|
---|
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 |
|
---|
35 | foreach (string boolGamePref in Enum.GetNames (typeof (GameInfoBool))) {
|
---|
36 | bool value = gsi.GetValue ((GameInfoBool) Enum.Parse (typeof (GameInfoBool), boolGamePref));
|
---|
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 |
|
---|
46 | WriteJSON (_resp, serverInfo);
|
---|
47 | }
|
---|
48 | }
|
---|
49 | }
|
---|