source: binary-improvements/MapRendering/Web/API/GetLandClaims.cs@ 251

Last change on this file since 251 was 251, checked in by peter.souza, 9 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: 3.9 KB
Line 
1using AllocsFixes.JSON;
2using AllocsFixes.PersistentData;
3using System;
4using System.Collections.Generic;
5using System.Net;
6
7namespace AllocsFixes.NetConnections.Servers.Web.API
8{
9 public class GetLandClaims : WebAPI
10 {
11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel)
12 {
13 string ViewersSteamID = string.Empty;
14 ulong lViewersSteamID = 0L;
15
16 if (req.QueryString ["steamid"] != null) {
17 ViewersSteamID = req.QueryString ["steamid"];
18 if (ViewersSteamID.Length != 17 || !ulong.TryParse (ViewersSteamID, out lViewersSteamID)) {
19 resp.StatusCode = (int)HttpStatusCode.BadRequest;
20 Web.SetResponseTextContent (resp, "Invalid SteamID given");
21 return;
22 }
23 }
24
25 // default user, cheap way to avoid 'null reference exception'
26 try { user = user ?? new WebConnection ("", "", 0L); } catch { }
27
28 bool bViewAll = false; try { bViewAll = user.CanViewAllClaims (permissionLevel); } catch { }
29
30 JSONObject result = new JSONObject ();
31 result.Add ("claimsize", new JSONNumber (GamePrefs.GetInt (EnumGamePrefs.LandClaimSize)));
32
33 JSONArray claimOwners = new JSONArray ();
34 result.Add ("claimowners", claimOwners);
35
36 Dictionary<Vector3i, PersistentPlayerData> d = GameManager.Instance.GetPersistentPlayerList ().m_lpBlockMap;
37 if (d != null) {
38 World w = GameManager.Instance.World;
39 Dictionary<PersistentPlayerData, List<Vector3i>> owners = new Dictionary<PersistentPlayerData, List<Vector3i>> ();
40
41 // Add all owners to this temporary list regardless of permissions
42 foreach (KeyValuePair<Vector3i, PersistentPlayerData> kvp in d) {
43 if (kvp.Value.PlayerId.Equals (ViewersSteamID)) {
44 if (!owners.ContainsKey (kvp.Value)) {
45 owners.Add (kvp.Value, new List<Vector3i> ());
46 }
47 owners [kvp.Value].Add (kvp.Key);
48 }
49 }
50
51 // Loop through all claim owners...
52 foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) {
53 try
54 {
55 // ... but only show us claims that are from the current web user or if the current web user can see all claims regardless of ownership
56 if (kvp.Key.PlayerId.Equals (ViewersSteamID) || bViewAll)
57 {
58 string currentSteamID = kvp.Key.PlayerId;
59 bool isActive = w.IsLandProtectionValidForPlayer (kvp.Key);
60
61 JSONObject owner = new JSONObject ();
62 claimOwners.Add (owner);
63
64 owner.Add("steamid", new JSONString (currentSteamID));
65 owner.Add("claimactive", new JSONBoolean (isActive));
66
67 if (PersistentContainer.Instance.Players [currentSteamID, false] != null) {
68 owner.Add("playername", new JSONString (PersistentContainer.Instance.Players [currentSteamID, false].Name));
69 } else {
70 owner.Add("playername", new JSONNull ());
71 }
72
73 JSONArray claims = new JSONArray ();
74 owner.Add ("claims", claims);
75
76 foreach (Vector3i v in kvp.Value) {
77 JSONObject claim = new JSONObject ();
78 claim.Add ("x", new JSONNumber (v.x));
79 claim.Add ("y", new JSONNumber (v.y));
80 claim.Add ("z", new JSONNumber (v.z));
81
82 claims.Add (claim);
83 }
84 }
85 }
86 catch { }
87 }
88 }
89
90 WriteJSON (resp, result);
91 }
92 }
93}
94
Note: See TracBrowser for help on using the repository browser.