source: binary-improvements2/MapRendering/Web/API/GetHostileLocation.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 GetHostileLocation : WebAPI {
10 private readonly List<EntityEnemy> enemies = new List<EntityEnemy> ();
11
12 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user,
13 int _permissionLevel) {
14 JSONArray hostilesJsResult = new JSONArray ();
15
16 Hostiles.Instance.Get (enemies);
17 for (int i = 0; i < enemies.Count; i++) {
18 EntityEnemy entity = enemies [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 ("enemy class #" + entity.entityClass));
33 }
34
35 pJson.Add ("position", jsonPOS);
36
37 hostilesJsResult.Add (pJson);
38 }
39
40 WriteJSON (_resp, hostilesJsResult);
41 }
42 }
43}
Note: See TracBrowser for help on using the repository browser.