Changeset 253 for binary-improvements/MapRendering/Web/API/GetLandClaims.cs
- Timestamp:
- Dec 12, 2015, 4:08:53 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/API/GetLandClaims.cs
r251 r253 7 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 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; 9 public class GetLandClaims : WebAPI { 10 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { 11 string requestedSteamID = string.Empty; 15 12 16 13 if (req.QueryString ["steamid"] != null) { 17 ViewersSteamID = req.QueryString ["steamid"]; 18 if (ViewersSteamID.Length != 17 || !ulong.TryParse (ViewersSteamID, out lViewersSteamID)) { 14 ulong lViewersSteamID; 15 requestedSteamID = req.QueryString ["steamid"]; 16 if (requestedSteamID.Length != 17 || !ulong.TryParse (requestedSteamID, out lViewersSteamID)) { 19 17 resp.StatusCode = (int)HttpStatusCode.BadRequest; 20 18 Web.SetResponseTextContent (resp, "Invalid SteamID given"); … … 23 21 } 24 22 25 26 try { user = user ?? new WebConnection ("", "", 0L); } catch { } 23 // default user, cheap way to avoid 'null reference exception' 24 user = user ?? new WebConnection ("", "", 0L); 27 25 28 bool bViewAll = false; try { bViewAll = user.CanViewAllClaims (permissionLevel); } catch { } 26 bool bViewAll = WebConnection.CanViewAllClaims (permissionLevel); 29 27 30 28 JSONObject result = new JSONObject (); … … 34 32 result.Add ("claimowners", claimOwners); 35 33 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>> (); 34 LandClaimList.OwnerFilter[] ownerFilters = null; 35 if (!string.IsNullOrEmpty (requestedSteamID) || !bViewAll) { 36 if (!string.IsNullOrEmpty (requestedSteamID) && !bViewAll) { 37 ownerFilters = new LandClaimList.OwnerFilter[] { 38 LandClaimList.SteamIdFilter (user.SteamID.ToString ()), 39 LandClaimList.SteamIdFilter (requestedSteamID) 40 }; 41 } else if (!bViewAll) { 42 ownerFilters = new LandClaimList.OwnerFilter[] { LandClaimList.SteamIdFilter (user.SteamID.ToString ()) }; 43 } else { 44 ownerFilters = new LandClaimList.OwnerFilter[] { LandClaimList.SteamIdFilter (requestedSteamID) }; 45 } 46 } 47 LandClaimList.PositionFilter[] posFilters = null; 40 48 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); 49 Dictionary<PersistentData.Player, List<Vector3i>> claims = LandClaimList.GetLandClaims (ownerFilters, posFilters); 50 51 foreach (KeyValuePair<PersistentData.Player, List<Vector3i>> kvp in claims) { 52 53 try { 54 JSONObject owner = new JSONObject (); 55 claimOwners.Add (owner); 56 57 owner.Add ("steamid", new JSONString (kvp.Key.SteamID)); 58 owner.Add ("claimactive", new JSONBoolean (kvp.Key.LandProtectionActive)); 59 60 if (kvp.Key.Name.Length > 0) { 61 owner.Add ("playername", new JSONString (kvp.Key.Name)); 62 } else { 63 owner.Add ("playername", new JSONNull ()); 48 64 } 49 }50 65 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); 66 JSONArray claimsJson = new JSONArray (); 67 owner.Add ("claims", claimsJson); 60 68 61 JSONObject owner = new JSONObject (); 62 claimOwners.Add (owner); 69 foreach (Vector3i v in kvp.Value) { 70 JSONObject claim = new JSONObject (); 71 claim.Add ("x", new JSONNumber (v.x)); 72 claim.Add ("y", new JSONNumber (v.y)); 73 claim.Add ("z", new JSONNumber (v.z)); 63 74 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 { } 75 claimsJson.Add (claim); 76 } 77 } catch { 87 78 } 88 79 }
Note:
See TracChangeset
for help on using the changeset viewer.