source: binary-improvements/MapRendering/Web/API/GetRawEntitiesList.cs@ 252

Last change on this file since 252 was 251, checked in by peter.souza, 10 years ago

Enemies (zombies and hostile animal entities) are now shown on the map as Hostiles and require permission level 'webapi.gethostilelocation' for web viewers to see.

Animals (non-hostile entities) are now shown on the map as Animals and require permission level 'webapi.getanimalslocation' for web viewers to see.

Permission level for 'webapi.viewallclaims' is now required for a viewer to see all claims, otherwise the permission level for 'webapi.getlandclaims' will only show viewer-owned claims. A viewer requires both 'webapi.getlandclaims' and 'webapi.viewallclaims' to be set for all claims to show (you can't just set 'webapi.viewallclaims').
https://7daystodie.com/forums/showthread.php?12837-Improvements-for-the-dedicated-server&p=317405&viewfull=1#post317405

Permission level for 'webapi.viewallplayers' is now required for a viewer to see all players, otherwise the permission level for 'webapi.getplayerslocation' will only show the player for the currently-authenticated viewer. A viewer requires both 'webapi.getplayerslocation' and 'webapi.viewallplayers' to be set for all players to show (you can't just set 'webapi.viewallplayers').
https://7daystodie.com/forums/showthread.php?12837-Improvements-for-the-dedicated-server&p=317405&viewfull=1#post317405

Banned players are now hidden from the web map.
https://7daystodie.com/forums/showthread.php?12837-Improvements-for-the-dedicated-server&p=320702&viewfull=1#post320702

Items using 'CustomIcon' and 'CustomIconTint' are now supported (although the exact tinting may not be perfectly the same as the game).
https://7daystodie.com/forums/showthread.php?12837-Improvements-for-the-dedicated-server&p=317117&viewfull=1#post317117
https://7daystodie.com/forums/showthread.php?12837-Improvements-for-the-dedicated-server&p=317679&viewfull=1#post317679

Map marker icons for players, hostiles, and animals have been updated.

File size: 9.5 KB
Line 
1using AllocsFixes.JSON;
2using System;
3using System.Collections.Generic;
4using System.Net;
5
6namespace AllocsFixes.NetConnections.Servers.Web.API
7{
8 class GetRawEntitiesList : WebAPI
9 {
10 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel)
11 {
12 JSONArray entitiesJsResult = new JSONArray ();
13
14 // Yes: hardcoded... even hacking the web interface won't show this data. You -must- be an admin.
15 if (permissionLevel != 0) {
16 try {
17 foreach (object base_entity in GameManager.Instance.World.Entities.list) {
18 try {
19 Entity entity = (Entity)base_entity;
20
21 if ((entity.entityType == EntityType.Animal) || (base_entity.GetType () == typeof(EntityAnimal)) || (base_entity.GetType ().ToString ().ToLower ().Contains ("animal")))
22 {
23 EntityAnimal ea = (EntityAnimal)entity;
24
25 Vector3i position = new Vector3i (entity.GetPosition ());
26
27 JSONObject jsonPOS = new JSONObject ();
28 jsonPOS.Add("x", new JSONNumber (position.x));
29 jsonPOS.Add("y", new JSONNumber (position.y));
30 jsonPOS.Add("z", new JSONNumber (position.z));
31
32 JSONObject pJson = new JSONObject ();
33 pJson.Add ("id", new JSONNumber (entity.entityId));
34 pJson.Add ("type", new JSONString ("animal"));
35 pJson.Add ("tag", new JSONString (entity.tag ?? ""));
36 pJson.Add ("model", new JSONString ((entity.emodel == null) ? "?" : entity.emodel.name ?? "?"));
37 pJson.Add ("alive", new JSONBoolean (ea.IsAlive ()));
38 pJson.Add ("health", new JSONNumber (ea.Health));
39
40 if (PetesUtils.ValidText (ea.EntityName))
41 pJson.Add ("name", new JSONString (ea.EntityName));
42 else
43 pJson.Add ("name", new JSONString ("animal class #" + entity.entityClass.ToString ()));
44
45 pJson.Add ("position", jsonPOS);
46
47 entitiesJsResult.Add (pJson);
48 }
49 else if ((entity.entityType == EntityType.Zombie) || (base_entity.GetType () == typeof(EntityEnemy))) {
50 EntityEnemy ee = (EntityEnemy)entity;
51
52 Vector3i position = new Vector3i (entity.GetPosition ());
53
54 JSONObject jsonPOS = new JSONObject ();
55 jsonPOS.Add ("x", new JSONNumber (position.x));
56 jsonPOS.Add ("y", new JSONNumber (position.y));
57 jsonPOS.Add ("z", new JSONNumber (position.z));
58
59 JSONObject pJson = new JSONObject ();
60 pJson.Add ("id", new JSONNumber (entity.entityId));
61 pJson.Add ("type", new JSONString ("enemy"));
62 pJson.Add ("tag", new JSONString (entity.tag ?? ""));
63 pJson.Add ("model", new JSONString ((entity.emodel == null) ? "?" : entity.emodel.name ?? "?"));
64 pJson.Add ("alive", new JSONBoolean (ee.IsAlive ()));
65 pJson.Add ("health", new JSONNumber (ee.Health));
66
67 if (PetesUtils.ValidText (ee.EntityName))
68 pJson.Add ("name", new JSONString (ee.EntityName));
69 else
70 pJson.Add ("name", new JSONString ("enemy class #" + entity.entityClass.ToString ()));
71
72 pJson.Add ("position", jsonPOS);
73
74 entitiesJsResult.Add (pJson);
75 }
76 else if ((entity.entityType == EntityType.Player) || (base_entity.GetType () == typeof(EntityPlayer))) {
77 EntityPlayer ep = (EntityPlayer)entity;
78
79 Vector3i position = new Vector3i (entity.GetPosition ());
80
81 JSONObject jsonPOS = new JSONObject ();
82 jsonPOS.Add ("x", new JSONNumber (position.x));
83 jsonPOS.Add ("y", new JSONNumber (position.y));
84 jsonPOS.Add ("z", new JSONNumber (position.z));
85
86 JSONObject pJson = new JSONObject ();
87 pJson.Add ("id", new JSONNumber (entity.entityId));
88 pJson.Add ("type", new JSONString ("player"));
89 pJson.Add ("tag", new JSONString (entity.tag ?? ""));
90 pJson.Add ("model", new JSONString ((entity.emodel == null) ? "?" : entity.emodel.name ?? "?"));
91 pJson.Add ("alive", new JSONBoolean (ep.IsAlive ()));
92 pJson.Add ("score", new JSONNumber (ep.Score));
93 pJson.Add ("health", new JSONNumber (ep.Health));
94 pJson.Add ("zombiekills", new JSONNumber (ep.KilledZombies));
95 pJson.Add ("stamina", new JSONNumber (ep.Stamina));
96
97 if (PetesUtils.ValidText (ep.EntityName))
98 pJson.Add ("name", new JSONString (ep.EntityName));
99 else
100 pJson.Add ("name", new JSONString ("player class #" + entity.entityClass.ToString ()));
101
102 pJson.Add("position", jsonPOS);
103
104 entitiesJsResult.Add(pJson);
105 }
106 else { // note: animals are an EntityAnimal but are being generated with the wrong entityType ID, so get caught here
107 Vector3i position = new Vector3i (entity.GetPosition ());
108
109 JSONObject jsonPOS = new JSONObject ();
110 jsonPOS.Add ("x", new JSONNumber (position.x));
111 jsonPOS.Add ("y", new JSONNumber (position.y));
112 jsonPOS.Add ("z", new JSONNumber (position.z));
113
114 JSONObject pJson = new JSONObject ();
115 pJson.Add ("id", new JSONNumber (entity.entityId));
116 pJson.Add ("type", new JSONString ("unknown #" + ((int)entity.entityType).ToString ()));
117 pJson.Add ("tag", new JSONString (entity.tag ?? ""));
118
119 string true_name = entity.name;
120
121 try {
122 int iTries = 0;
123 UnityEngine.GameObject go = entity.gameObject;
124
125 while (true_name == "GameObject") {
126 true_name = go.name;
127 go = go.gameObject;
128
129 if (++iTries > 10)
130 break;
131 }
132 }
133 catch { }
134
135 string true_emodel = (entity.emodel == null) ? "?" : entity.emodel.name;
136
137 try {
138 int iTries = 0;
139 UnityEngine.GameObject go = entity.emodel.gameObject;
140
141 while (true_emodel == "GameObject") {
142 true_emodel = go.name;
143 go = go.gameObject;
144
145 if (++iTries > 10)
146 break;
147 }
148 }
149 catch { }
150
151 pJson.Add ("model", new JSONString (true_emodel));
152
153 if (PetesUtils.ValidText (true_name))
154 pJson.Add("name", new JSONString (base_entity.GetType ().ToString () + ": " + true_name));
155 else
156 pJson.Add("name", new JSONString (base_entity.GetType ().ToString () + " class #" + entity.entityClass.ToString ()));
157
158 pJson.Add ("position", jsonPOS);
159
160 entitiesJsResult.Add (pJson);
161 }
162 }
163 catch { }
164 }
165 }
166 catch (Exception ex) {
167 entitiesJsResult.Add (new JSONString ("Error: " + ex.GetType ().ToString () + " - " + ex.Message + "\r\n" + ex.StackTrace));
168 }
169 }
170
171 WriteJSON (resp, entitiesJsResult);
172 }
173 }
174}
Note: See TracBrowser for help on using the repository browser.