using AllocsFixes.JSON; using AllocsFixes.PersistentData; using System; using System.Collections.Generic; using System.Net; namespace AllocsFixes.NetConnections.Servers.Web.API { public class GetServerInfo : WebAPI { public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { JSONObject serverInfo = new JSONObject (); GameServerInfo gsi = Steam.Masterserver.Server.LocalGameInfo; foreach (string stringGamePref in Enum.GetNames(typeof(GameInfoString))) { string value = gsi.GetValue ( (GameInfoString)Enum.Parse (typeof(GameInfoString), stringGamePref) ); JSONObject singleStat = new JSONObject (); singleStat.Add ("type", new JSONString ("string")); singleStat.Add ("value", new JSONString (value)); serverInfo.Add (stringGamePref, singleStat); } foreach (string intGamePref in Enum.GetNames(typeof(GameInfoInt))) { int value = gsi.GetValue ( (GameInfoInt)Enum.Parse (typeof(GameInfoInt), intGamePref) ); JSONObject singleStat = new JSONObject (); singleStat.Add ("type", new JSONString ("int")); singleStat.Add ("value", new JSONNumber (value)); serverInfo.Add (intGamePref, singleStat); } foreach (string boolGamePref in Enum.GetNames(typeof(GameInfoBool))) { bool value = gsi.GetValue ( (GameInfoBool)Enum.Parse (typeof(GameInfoBool), boolGamePref) ); JSONObject singleStat = new JSONObject (); singleStat.Add ("type", new JSONString ("bool")); singleStat.Add ("value", new JSONBoolean (value)); serverInfo.Add (boolGamePref, singleStat); } WriteJSON(resp, serverInfo); } } }