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
RevLine 
[325]1using System.Collections.Generic;
2using AllocsFixes.JSON;
[251]3using AllocsFixes.LiveData;
[382]4using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;
5using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;
[251]6
[325]7namespace AllocsFixes.NetConnections.Servers.Web.API {
8 internal class GetHostileLocation : WebAPI {
9 private readonly List<EntityEnemy> enemies = new List<EntityEnemy> ();
[306]10
[351]11 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user,
12 int _permissionLevel) {
[325]13 JSONArray hostilesJsResult = new JSONArray ();
[251]14
[313]15 Hostiles.Instance.Get (enemies);
[325]16 for (int i = 0; i < enemies.Count; i++) {
[306]17 EntityEnemy entity = enemies [i];
[325]18 Vector3i position = new Vector3i (entity.GetPosition ());
[251]19
[325]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));
[251]24
[325]25 JSONObject pJson = new JSONObject ();
26 pJson.Add ("id", new JSONNumber (entity.entityId));
[251]27
[325]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 }
[251]33
[325]34 pJson.Add ("position", jsonPOS);
[251]35
[325]36 hostilesJsResult.Add (pJson);
37 }
[251]38
[351]39 WriteJSON (_resp, hostilesJsResult);
[325]40 }
41 }
42}
Note: See TracBrowser for help on using the repository browser.