source: binary-improvements2/MapRendering/Web/API/GetServerInfo.cs@ 389

Last change on this file since 389 was 387, checked in by alloc, 2 years ago

Big refactoring in Web to pass around a Context instead of a bunch of individual arguments all the time

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