source: binary-improvements/MapRendering/Web/API/GetAnimalsLocation.cs@ 323

Last change on this file since 323 was 313, checked in by alloc, 7 years ago

Common func: Rebased Animals and Hostiles to common base

File size: 1.5 KB
Line 
1using AllocsFixes.JSON;
2using AllocsFixes.LiveData;
3using System;
4using System.Collections.Generic;
5using System.Net;
6
7namespace AllocsFixes.NetConnections.Servers.Web.API
8{
9 class GetAnimalsLocation : WebAPI
10 {
11 private List<EntityAnimal> animals = new List<EntityAnimal> ();
12
13 public override void HandleRequest(HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel)
14 {
15 JSONArray animalsJsResult = new JSONArray();
16
17 Animals.Instance.Get (animals);
18 for (int i = 0; i < animals.Count; i++)
19 {
20 EntityAnimal entity = animals [i];
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}
Note: See TracBrowser for help on using the repository browser.