1 | using AllocsFixes.JSON;
|
---|
2 | using AllocsFixes.LiveData;
|
---|
3 | using System;
|
---|
4 | using System.Collections.Generic;
|
---|
5 | using System.Net;
|
---|
6 |
|
---|
7 | namespace AllocsFixes.NetConnections.Servers.Web.API
|
---|
8 | {
|
---|
9 | class GetHostileLocation : WebAPI
|
---|
10 | {
|
---|
11 | private List<EntityEnemy> enemies = new List<EntityEnemy> ();
|
---|
12 |
|
---|
13 | public override void HandleRequest(HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel)
|
---|
14 | {
|
---|
15 | JSONArray hostilesJsResult = new JSONArray();
|
---|
16 |
|
---|
17 | Hostiles.Get (enemies);
|
---|
18 | for (int i = 0; i < enemies.Count; i++)
|
---|
19 | {
|
---|
20 | EntityEnemy entity = enemies [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("enemy class #" + entity.entityClass.ToString()));
|
---|
35 |
|
---|
36 | pJson.Add("position", jsonPOS);
|
---|
37 |
|
---|
38 | hostilesJsResult.Add(pJson);
|
---|
39 | }
|
---|
40 |
|
---|
41 | WriteJSON(resp, hostilesJsResult);
|
---|
42 | }
|
---|
43 | }
|
---|
44 | }
|
---|