source: binary-improvements2/WebServer/src/WebAPI/GetServerInfo.cs@ 392

Last change on this file since 392 was 391, checked in by alloc, 2 years ago

Major refactoring/cleanup

File size: 1.5 KB
RevLine 
[391]1using System;
2using AllocsFixes.JSON;
3using JetBrains.Annotations;
4
5namespace Webserver.WebAPI {
6 [UsedImplicitly]
7 public class GetServerInfo : AbsWebAPI {
8 public override void HandleRequest (RequestContext _context) {
9 JsonObject serverInfo = new JsonObject ();
10
11 GameServerInfo gsi = ConnectionManager.Instance.LocalServerInfo;
12
13 foreach (string stringGamePref in Enum.GetNames (typeof (GameInfoString))) {
14 string value = gsi.GetValue ((GameInfoString) Enum.Parse (typeof (GameInfoString), stringGamePref));
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
23 foreach (string intGamePref in Enum.GetNames (typeof (GameInfoInt))) {
24 int value = gsi.GetValue ((GameInfoInt) Enum.Parse (typeof (GameInfoInt), intGamePref));
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
33 foreach (string boolGamePref in Enum.GetNames (typeof (GameInfoBool))) {
34 bool value = gsi.GetValue ((GameInfoBool) Enum.Parse (typeof (GameInfoBool), boolGamePref));
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
44 WebUtils.WriteJson (_context.Response, serverInfo);
45 }
46 }
47}
Note: See TracBrowser for help on using the repository browser.