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