source: binary-improvements/MapRendering/Web/API/GetServerInfo.cs@ 300

Last change on this file since 300 was 279, checked in by alloc, 8 years ago

Mod stuff

File size: 1.6 KB
RevLine 
[279]1using AllocsFixes.JSON;
2using AllocsFixes.PersistentData;
3using System;
4using System.Collections.Generic;
5using System.Net;
6
7namespace AllocsFixes.NetConnections.Servers.Web.API
8{
9 public class GetServerInfo : WebAPI
10 {
11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel)
12 {
13 JSONObject serverInfo = new JSONObject ();
14
15 GameServerInfo gsi = Steam.Masterserver.Server.LocalGameInfo;
16
17 foreach (string stringGamePref in Enum.GetNames(typeof(GameInfoString))) {
18 string value = gsi.GetValue ( (GameInfoString)Enum.Parse (typeof(GameInfoString), stringGamePref) );
19
20 JSONObject singleStat = new JSONObject ();
21 singleStat.Add ("type", new JSONString ("string"));
22 singleStat.Add ("value", new JSONString (value));
23
24 serverInfo.Add (stringGamePref, singleStat);
25 }
26
27 foreach (string intGamePref in Enum.GetNames(typeof(GameInfoInt))) {
28 int value = gsi.GetValue ( (GameInfoInt)Enum.Parse (typeof(GameInfoInt), intGamePref) );
29
30 JSONObject singleStat = new JSONObject ();
31 singleStat.Add ("type", new JSONString ("int"));
32 singleStat.Add ("value", new JSONNumber (value));
33
34 serverInfo.Add (intGamePref, singleStat);
35 }
36
37 foreach (string boolGamePref in Enum.GetNames(typeof(GameInfoBool))) {
38 bool value = gsi.GetValue ( (GameInfoBool)Enum.Parse (typeof(GameInfoBool), boolGamePref) );
39
40 JSONObject singleStat = new JSONObject ();
41 singleStat.Add ("type", new JSONString ("bool"));
42 singleStat.Add ("value", new JSONBoolean (value));
43
44 serverInfo.Add (boolGamePref, singleStat);
45 }
46
47
48 WriteJSON(resp, serverInfo);
49 }
50 }
51}
52
Note: See TracBrowser for help on using the repository browser.