[251] | 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 | public override void HandleRequest(HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel)
|
---|
| 12 | {
|
---|
| 13 | JSONArray hostilesJsResult = new JSONArray();
|
---|
| 14 |
|
---|
| 15 | foreach (EntityEnemy entity in Hostiles.List)
|
---|
| 16 | {
|
---|
| 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.ToString()));
|
---|
| 31 |
|
---|
| 32 | pJson.Add("position", jsonPOS);
|
---|
| 33 |
|
---|
| 34 | hostilesJsResult.Add(pJson);
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | WriteJSON(resp, hostilesJsResult);
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 | }
|
---|