1 | using System.Collections.Generic;
|
---|
2 | using AllocsFixes.JSON;
|
---|
3 | using AllocsFixes.LiveData;
|
---|
4 | using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;
|
---|
5 | using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;
|
---|
6 |
|
---|
7 | namespace AllocsFixes.NetConnections.Servers.Web.API {
|
---|
8 | internal class GetAnimalsLocation : WebAPI {
|
---|
9 | private readonly List<EntityAnimal> animals = new List<EntityAnimal> ();
|
---|
10 |
|
---|
11 | public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user,
|
---|
12 | int _permissionLevel) {
|
---|
13 | JSONArray animalsJsResult = new JSONArray ();
|
---|
14 |
|
---|
15 | Animals.Instance.Get (animals);
|
---|
16 | for (int i = 0; i < animals.Count; i++) {
|
---|
17 | EntityAnimal entity = animals [i];
|
---|
18 | Vector3i position = new Vector3i (entity.GetPosition ());
|
---|
19 |
|
---|
20 | JSONObject jsonPOS = new JSONObject ();
|
---|
21 | jsonPOS.Add ("x", new JSONNumber (position.x));
|
---|
22 | jsonPOS.Add ("y", new JSONNumber (position.y));
|
---|
23 | jsonPOS.Add ("z", new JSONNumber (position.z));
|
---|
24 |
|
---|
25 | JSONObject pJson = new JSONObject ();
|
---|
26 | pJson.Add ("id", new JSONNumber (entity.entityId));
|
---|
27 |
|
---|
28 | if (!string.IsNullOrEmpty (entity.EntityName)) {
|
---|
29 | pJson.Add ("name", new JSONString (entity.EntityName));
|
---|
30 | } else {
|
---|
31 | pJson.Add ("name", new JSONString ("animal class #" + entity.entityClass));
|
---|
32 | }
|
---|
33 |
|
---|
34 | pJson.Add ("position", jsonPOS);
|
---|
35 |
|
---|
36 | animalsJsResult.Add (pJson);
|
---|
37 | }
|
---|
38 |
|
---|
39 | WriteJSON (_resp, animalsJsResult);
|
---|
40 | }
|
---|
41 | }
|
---|
42 | }
|
---|