source: binary-improvements/MapRendering/Web/API/GetServerInfo.cs@ 403

Last change on this file since 403 was 360, checked in by alloc, 4 years ago

A19 code

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