| [251] | 1 | using AllocsFixes.JSON;
|
|---|
| 2 | using AllocsFixes.LiveData;
|
|---|
| 3 | using AllocsFixes.PersistentData;
|
|---|
| 4 | using System;
|
|---|
| 5 | using System.Collections.Generic;
|
|---|
| 6 | using System.Net;
|
|---|
| 7 |
|
|---|
| 8 | namespace AllocsFixes.NetConnections.Servers.Web.API
|
|---|
| 9 | {
|
|---|
| 10 | public class GetWebUIUpdates : WebAPI {
|
|---|
| 11 | public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) {
|
|---|
| 12 | int latestLine;
|
|---|
| 13 | if (req.QueryString ["latestLine"] == null || !int.TryParse (req.QueryString ["latestLine"], out latestLine)) {
|
|---|
| 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));
|
|---|
| 26 | result.Add ("hostiles", new JSONNumber (Hostiles.Count));
|
|---|
| 27 | result.Add ("animals", new JSONNumber (Animals.Count));
|
|---|
| 28 |
|
|---|
| 29 | result.Add ("newlogs", new JSONNumber (LogBuffer.Instance.LatestLine - latestLine));
|
|---|
| 30 |
|
|---|
| 31 | WriteJSON (resp, result);
|
|---|
| 32 | }
|
|---|
| [279] | 33 |
|
|---|
| 34 | public override int DefaultPermissionLevel () {
|
|---|
| 35 | return 2000;
|
|---|
| 36 | }
|
|---|
| [251] | 37 | }
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|