Changeset 251 for binary-improvements/MapRendering/Web/API/GetLandClaims.cs
- Timestamp:
- Oct 28, 2015, 7:51:20 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/API/GetLandClaims.cs
r245 r251 11 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 12 12 { 13 string steamid = string.Empty; 13 string ViewersSteamID = string.Empty; 14 ulong lViewersSteamID = 0L; 14 15 15 16 if (req.QueryString ["steamid"] != null) { 16 long tempLong; 17 steamid = req.QueryString ["steamid"]; 18 if (steamid.Length != 17 || !long.TryParse (steamid, out tempLong)) { 17 ViewersSteamID = req.QueryString ["steamid"]; 18 if (ViewersSteamID.Length != 17 || !ulong.TryParse (ViewersSteamID, out lViewersSteamID)) { 19 19 resp.StatusCode = (int)HttpStatusCode.BadRequest; 20 20 Web.SetResponseTextContent (resp, "Invalid SteamID given"); … … 23 23 } 24 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 25 30 JSONObject result = new JSONObject (); 26 31 result.Add ("claimsize", new JSONNumber (GamePrefs.GetInt (EnumGamePrefs.LandClaimSize))); … … 33 38 World w = GameManager.Instance.World; 34 39 Dictionary<PersistentPlayerData, List<Vector3i>> owners = new Dictionary<PersistentPlayerData, List<Vector3i>> (); 40 41 // Add all owners to this temporary list regardless of permissions 35 42 foreach (KeyValuePair<Vector3i, PersistentPlayerData> kvp in d) { 36 if ( steamid.Length == 0 || kvp.Value.PlayerId.Equals (steamid)) {43 if (kvp.Value.PlayerId.Equals (ViewersSteamID)) { 37 44 if (!owners.ContainsKey (kvp.Value)) { 38 45 owners.Add (kvp.Value, new List<Vector3i> ()); … … 42 49 } 43 50 51 // Loop through all claim owners... 44 52 foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) { 45 if (steamid.Length == 0 || kvp.Key.PlayerId.Equals (steamid)) { 46 string curID = kvp.Key.PlayerId; 47 bool isActive = w.IsLandProtectionValidForPlayer (kvp.Key); 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); 48 60 49 50 61 JSONObject owner = new JSONObject (); 62 claimOwners.Add (owner); 51 63 52 owner.Add ("steamid", new JSONString (curID));53 owner.Add("claimactive", new JSONBoolean (isActive));64 owner.Add("steamid", new JSONString (currentSteamID)); 65 owner.Add("claimactive", new JSONBoolean (isActive)); 54 66 55 if (PersistentContainer.Instance.Players [curID, false] != null) {56 owner.Add ("playername", new JSONString (PersistentContainer.Instance.Players [curID, false].Name));57 58 owner.Add("playername", new JSONNull ());59 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 } 60 72 61 62 73 JSONArray claims = new JSONArray (); 74 owner.Add ("claims", claims); 63 75 64 65 66 67 68 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)); 69 81 70 claims.Add (claim); 71 } 72 } 82 claims.Add (claim); 83 } 84 } 85 } 86 catch { } 73 87 } 74 88 }
Note:
See TracChangeset
for help on using the changeset viewer.