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