source: binary-improvements2/MapRendering/Web/API/GetAnimalsLocation.cs@ 386

Last change on this file since 386 was 383, checked in by alloc, 2 years ago

Fixed a bunch of warnings

File size: 1.4 KB
Line 
1using System.Collections.Generic;
2using AllocsFixes.JSON;
3using AllocsFixes.LiveData;
4using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;
5using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;
6
7namespace 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}
Note: See TracBrowser for help on using the repository browser.