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

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

Switched to use SpaceWizards.HttpListener

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