[391] | 1 | using AllocsFixes.JSON;
|
---|
| 2 | using AllocsFixes.LiveData;
|
---|
| 3 | using JetBrains.Annotations;
|
---|
| 4 |
|
---|
| 5 | namespace Webserver.WebAPI {
|
---|
| 6 | [UsedImplicitly]
|
---|
| 7 | public class GetWebUIUpdates : AbsWebAPI {
|
---|
| 8 | public override void HandleRequest (RequestContext _context) {
|
---|
| 9 | if (_context.Request.QueryString ["latestLine"] == null ||
|
---|
| 10 | !int.TryParse (_context.Request.QueryString ["latestLine"], out int latestLine)) {
|
---|
| 11 | latestLine = 0;
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | JsonObject result = new JsonObject ();
|
---|
| 15 |
|
---|
| 16 | JsonObject time = new JsonObject ();
|
---|
| 17 | time.Add ("days", new JsonNumber (GameUtils.WorldTimeToDays (GameManager.Instance.World.worldTime)));
|
---|
| 18 | time.Add ("hours", new JsonNumber (GameUtils.WorldTimeToHours (GameManager.Instance.World.worldTime)));
|
---|
| 19 | time.Add ("minutes", new JsonNumber (GameUtils.WorldTimeToMinutes (GameManager.Instance.World.worldTime)));
|
---|
| 20 | result.Add ("gametime", time);
|
---|
| 21 |
|
---|
| 22 | result.Add ("players", new JsonNumber (GameManager.Instance.World.Players.Count));
|
---|
| 23 | result.Add ("hostiles", new JsonNumber (Hostiles.Instance.GetCount ()));
|
---|
| 24 | result.Add ("animals", new JsonNumber (Animals.Instance.GetCount ()));
|
---|
| 25 |
|
---|
| 26 | result.Add ("newlogs", new JsonNumber (LogBuffer.Instance.LatestLine - latestLine));
|
---|
| 27 |
|
---|
| 28 | WebUtils.WriteJson (_context.Response, result);
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | public override int DefaultPermissionLevel () {
|
---|
| 32 | return 2000;
|
---|
| 33 | }
|
---|
| 34 | }
|
---|
| 35 | }
|
---|