source: binary-improvements2/MapRendering/Web/API/GetHostileLocation.cs@ 384

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