source: binary-improvements/MapRendering/Web/API/GetHostileLocation.cs@ 360

Last change on this file since 360 was 351, checked in by alloc, 6 years ago

Fixed game version compatibility of GamePrefs
Code style cleanup (mostly argument names)

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