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

Last change on this file since 387 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
Line 
1using System;
2using AllocsFixes.JSON;
3
4namespace AllocsFixes.NetConnections.Servers.Web.API {
5 public class GetServerInfo : AbsWebAPI {
6 public override void HandleRequest (RequestContext _context) {
7 JSONObject serverInfo = new JSONObject ();
8
9 GameServerInfo gsi = ConnectionManager.Instance.LocalServerInfo;
10
11 foreach (string stringGamePref in Enum.GetNames (typeof (GameInfoString))) {
12 string value = gsi.GetValue ((GameInfoString) Enum.Parse (typeof (GameInfoString), stringGamePref));
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
21 foreach (string intGamePref in Enum.GetNames (typeof (GameInfoInt))) {
22 int value = gsi.GetValue ((GameInfoInt) Enum.Parse (typeof (GameInfoInt), intGamePref));
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
31 foreach (string boolGamePref in Enum.GetNames (typeof (GameInfoBool))) {
32 bool value = gsi.GetValue ((GameInfoBool) Enum.Parse (typeof (GameInfoBool), boolGamePref));
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
42 WebUtils.WriteJson (_context.Response, serverInfo);
43 }
44 }
45}
Note: See TracBrowser for help on using the repository browser.