[279] | 1 | using System;
|
---|
[325] | 2 | using AllocsFixes.JSON;
|
---|
[279] | 3 |
|
---|
[325] | 4 | namespace 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 | }
|
---|