Changeset 251 for binary-improvements/MapRendering/Web/API
- Timestamp:
- Oct 28, 2015, 7:51:20 PM (9 years ago)
- Location:
- binary-improvements/MapRendering/Web/API
- Files:
-
- 4 added
- 5 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 } -
binary-improvements/MapRendering/Web/API/GetPlayerInventory.cs
r250 r251 75 75 JSONObject jsonItem = new JSONObject (); 76 76 jsonItem.Add ("count", new JSONNumber (_item.count)); 77 jsonItem.Add ("name", new JSONString (_item.itemName)); 78 jsonItem.Add ("quality", new JSONNumber (_item.quality)); 77 jsonItem.Add ("name", new JSONString (_item.itemName)); 78 jsonItem.Add ("icon", new JSONString (_item.icon)); 79 jsonItem.Add ("iconcolor", new JSONString ((string.IsNullOrEmpty (_item.iconcolor) || _item.iconcolor == "FFFFFF" ? "" : _item.iconcolor))); 80 jsonItem.Add ("quality", new JSONNumber(_item.quality)); 79 81 if (_item.quality >= 0) { 80 82 jsonItem.Add ("qualitycolor", new JSONString (QualityInfo.GetQualityColorHex (_item.quality))); -
binary-improvements/MapRendering/Web/API/GetPlayersLocation.cs
r244 r251 11 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 12 12 { 13 JSONArray playersJsResult = new JSONArray (); 13 AdminTools admTools = null; 14 15 try { admTools = GameManager.Instance.adminTools; } catch { } 16 try { user = user ?? new WebConnection ("", "", 0L); } catch { } // default user, cheap way to avoid 'null reference exception' 17 18 bool bViewAll = false; try { bViewAll = user.CanViewAllPlayers (permissionLevel); } catch { } 19 20 JSONArray playersJsResult = new JSONArray (); 14 21 15 22 Players playersList = PersistentContainer.Instance.Players; 16 23 17 24 foreach (string sid in playersList.SteamIDs) { 18 Player p = playersList[sid, false]; 25 try { 26 if ((admTools != null) && (PetesUtils.ValidText (sid))) 27 if (admTools.IsBanned (sid)) 28 continue; 29 } 30 catch { } 19 31 20 JSONObject pos = new JSONObject(); 21 pos.Add("x", new JSONNumber(p.LastPosition.x)); 22 pos.Add("y", new JSONNumber(p.LastPosition.y)); 23 pos.Add("z", new JSONNumber(p.LastPosition.z)); 32 try 33 { 34 Player p = playersList [sid, false]; 24 35 25 JSONObject pJson = new JSONObject(); 26 pJson.Add("steamid", new JSONString(sid)); 27 pJson.Add("ip", new JSONString(p.IP)); 28 pJson.Add("name", new JSONString(p.Name)); 29 pJson.Add("online", new JSONBoolean(p.IsOnline)); 30 pJson.Add("position", pos); 36 ulong player_steam_ID = 0L; 37 if (!ulong.TryParse (sid, out player_steam_ID)) 38 player_steam_ID = 0L; 31 39 32 playersJsResult.Add(pJson); 33 } 40 if ((player_steam_ID == user.SteamID) || bViewAll) { 41 JSONObject pos = new JSONObject (); 42 pos.Add("x", new JSONNumber (p.LastPosition.x)); 43 pos.Add("y", new JSONNumber (p.LastPosition.y)); 44 pos.Add("z", new JSONNumber (p.LastPosition.z)); 34 45 35 WriteJSON(resp, playersJsResult); 46 JSONObject pJson = new JSONObject (); 47 pJson.Add("steamid", new JSONString (sid)); 48 pJson.Add("ip", new JSONString (p.IP)); 49 pJson.Add("name", new JSONString (p.Name)); 50 pJson.Add("online", new JSONBoolean (p.IsOnline)); 51 pJson.Add("position", pos); 52 53 playersJsResult.Add (pJson); 54 } 55 } 56 catch { } 57 } 58 59 WriteJSON (resp, playersJsResult); 36 60 } 37 61 } -
binary-improvements/MapRendering/Web/API/GetStats.cs
r245 r251 1 1 using AllocsFixes.JSON; 2 using AllocsFixes.LiveData; 2 3 using AllocsFixes.PersistentData; 3 4 using System; … … 20 21 21 22 result.Add ("players", new JSONNumber (GameManager.Instance.World.Players.Count)); 23 result.Add ("hostiles", new JSONNumber (Hostiles.Count)); 24 result.Add ("animals", new JSONNumber (Animals.Count)); 22 25 23 26 WriteJSON (resp, result); -
binary-improvements/MapRendering/Web/API/GetWebUIUpdates.cs
r250 r251 1 1 using AllocsFixes.JSON; 2 using AllocsFixes.LiveData; 2 3 using AllocsFixes.PersistentData; 3 4 using System; … … 23 24 24 25 result.Add ("players", new JSONNumber (GameManager.Instance.World.Players.Count)); 26 result.Add ("hostiles", new JSONNumber (Hostiles.Count)); 27 result.Add ("animals", new JSONNumber (Animals.Count)); 25 28 26 29 result.Add ("newlogs", new JSONNumber (LogBuffer.Instance.LatestLine - latestLine));
Note:
See TracChangeset
for help on using the changeset viewer.