1 | using System;
|
---|
2 | using AllocsFixes.JSON;
|
---|
3 | using Webserver;
|
---|
4 | using Webserver.WebAPI;
|
---|
5 |
|
---|
6 | namespace AllocsFixes.WebAPIs {
|
---|
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 | LegacyApiHelper.WriteJSON (_context.Response, serverInfo);
|
---|
45 | }
|
---|
46 | }
|
---|
47 | }
|
---|