source: binary-improvements2/MapRendering/Web/API/GetWebUIUpdates.cs@ 383

Last change on this file since 383 was 383, checked in by alloc, 3 years ago

Fixed a bunch of warnings

File size: 1.5 KB
Line 
1using AllocsFixes.JSON;
2using AllocsFixes.LiveData;
3using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;
4using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;
5
6namespace AllocsFixes.NetConnections.Servers.Web.API {
7 public class GetWebUIUpdates : WebAPI {
8 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user,
9 int _permissionLevel) {
10 int latestLine;
11 if (_req.QueryString ["latestLine"] == null ||
12 !int.TryParse (_req.QueryString ["latestLine"], out latestLine)) {
13 latestLine = 0;
14 }
15
16 JSONObject result = new JSONObject ();
17
18 JSONObject time = new JSONObject ();
19 time.Add ("days", new JSONNumber (GameUtils.WorldTimeToDays (GameManager.Instance.World.worldTime)));
20 time.Add ("hours", new JSONNumber (GameUtils.WorldTimeToHours (GameManager.Instance.World.worldTime)));
21 time.Add ("minutes", new JSONNumber (GameUtils.WorldTimeToMinutes (GameManager.Instance.World.worldTime)));
22 result.Add ("gametime", time);
23
24 result.Add ("players", new JSONNumber (GameManager.Instance.World.Players.Count));
25 result.Add ("hostiles", new JSONNumber (Hostiles.Instance.GetCount ()));
26 result.Add ("animals", new JSONNumber (Animals.Instance.GetCount ()));
27
28 result.Add ("newlogs", new JSONNumber (LogBuffer.Instance.LatestLine - latestLine));
29
30 WriteJSON (_resp, result);
31 }
32
33 public override int DefaultPermissionLevel () {
34 return 2000;
35 }
36 }
37}
Note: See TracBrowser for help on using the repository browser.