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