Changeset 253 for binary-improvements/MapRendering/Web/API
- Timestamp:
- Dec 12, 2015, 4:08:53 PM (9 years ago)
- Location:
- binary-improvements/MapRendering/Web/API
- Files:
-
- 1 deleted
- 4 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 } -
binary-improvements/MapRendering/Web/API/GetLog.cs
r250 r253 15 15 } 16 16 17 if (req.QueryString ["lastLine"] == null || !int.TryParse (req.QueryString ["lastLine"], out lastLine)) {18 lastLine = -1;19 }20 21 17 JSONObject result = new JSONObject (); 22 18 23 List<LogBuffer.LogEntry> logEntries = LogBuffer.Instance.GetRange (ref firstLine, reflastLine);19 List<LogBuffer.LogEntry> logEntries = LogBuffer.Instance.GetRange (ref firstLine, 50, out lastLine); 24 20 25 21 JSONArray entries = new JSONArray (); -
binary-improvements/MapRendering/Web/API/GetPlayerInventory.cs
r251 r253 8 8 { 9 9 public class GetPlayerInventory : WebAPI { 10 10 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { 11 12 if (req.QueryString ["steamid"] == null) { … … 38 39 DoInventory (bag, inv.bag); 39 40 40 AddEquipment (equipment, "head", inv.equipment, XMLData.Item.EnumEquipmentSlot.Head, NGuiInvGridEquipment.EnumClothingLayer.Middle);41 AddEquipment (equipment, "eyes", inv.equipment, XMLData.Item.EnumEquipmentSlot.Eyes, NGuiInvGridEquipment.EnumClothingLayer.Middle);42 AddEquipment (equipment, "face", inv.equipment, XMLData.Item.EnumEquipmentSlot.Face, NGuiInvGridEquipment.EnumClothingLayer.Middle);41 AddEquipment (equipment, "head", inv.equipment, EquipmentSlots.Headgear); 42 AddEquipment (equipment, "eyes", inv.equipment, EquipmentSlots.Eyewear); 43 AddEquipment (equipment, "face", inv.equipment, EquipmentSlots.Face); 43 44 44 AddEquipment (equipment, "armor", inv.equipment, XMLData.Item.EnumEquipmentSlot.Chest, NGuiInvGridEquipment.EnumClothingLayer.Outer);45 AddEquipment (equipment, "jacket", inv.equipment, XMLData.Item.EnumEquipmentSlot.Chest, NGuiInvGridEquipment.EnumClothingLayer.Middle);46 AddEquipment (equipment, "shirt", inv.equipment, XMLData.Item.EnumEquipmentSlot.Chest, NGuiInvGridEquipment.EnumClothingLayer.Inner);45 AddEquipment (equipment, "armor", inv.equipment, EquipmentSlots.ChestArmor); 46 AddEquipment (equipment, "jacket", inv.equipment, EquipmentSlots.Jacket); 47 AddEquipment (equipment, "shirt", inv.equipment, EquipmentSlots.Shirt); 47 48 48 AddEquipment (equipment, "legarmor", inv.equipment, XMLData.Item.EnumEquipmentSlot.Legs, NGuiInvGridEquipment.EnumClothingLayer.Outer);49 AddEquipment (equipment, "pants", inv.equipment, XMLData.Item.EnumEquipmentSlot.Legs, NGuiInvGridEquipment.EnumClothingLayer.Inner);50 AddEquipment (equipment, "boots", inv.equipment, XMLData.Item.EnumEquipmentSlot.Feet, NGuiInvGridEquipment.EnumClothingLayer.Inner);49 AddEquipment (equipment, "legarmor", inv.equipment, EquipmentSlots.LegArmor); 50 AddEquipment (equipment, "pants", inv.equipment, EquipmentSlots.Legs); 51 AddEquipment (equipment, "boots", inv.equipment, EquipmentSlots.Feet); 51 52 52 AddEquipment (equipment, "gloves", inv.equipment, XMLData.Item.EnumEquipmentSlot.Hands, NGuiInvGridEquipment.EnumClothingLayer.Inner); 53 AddEquipment (equipment, "backpack", inv.equipment, XMLData.Item.EnumEquipmentSlot.Back, NGuiInvGridEquipment.EnumClothingLayer.Outer); 53 AddEquipment (equipment, "gloves", inv.equipment, EquipmentSlots.Hands); 54 54 55 55 WriteJSON (resp, result); … … 62 62 } 63 63 64 private void AddEquipment (JSONObject _eq, string _slotname, InvItem[] _items, XMLData.Item.EnumEquipmentSlot _slot, NGuiInvGridEquipment.EnumClothingLayer _layer) { 65 int index = (int)_slot + (int)_layer * (int)XMLData.Item.EnumEquipmentSlot.Count; 66 if (_items != null) { 67 _eq.Add (_slotname, GetJsonForItem (_items [index])); 68 } else { 69 _eq.Add (_slotname, new JSONNull ()); 64 private void AddEquipment (JSONObject _eq, string _slotname, InvItem[] _items, EquipmentSlots _slot) { 65 int[] slotindices = XUiM_PlayerEquipment.GetSlotIndicesByEquipmentSlot (_slot); 66 67 for (int i = 0; i < slotindices.Length; i++) { 68 if (_items != null && _items [slotindices [i]] != null) { 69 InvItem item = _items [slotindices [i]]; 70 _eq.Add (_slotname, GetJsonForItem (item)); 71 return; 72 } 70 73 } 74 75 _eq.Add (_slotname, new JSONNull ()); 71 76 } 72 77 … … 75 80 JSONObject jsonItem = new JSONObject (); 76 81 jsonItem.Add ("count", new JSONNumber (_item.count)); 77 78 79 jsonItem.Add ("iconcolor", new JSONString ((string.IsNullOrEmpty (_item.iconcolor) || _item.iconcolor == "FFFFFF" ? "" : _item.iconcolor)));80 jsonItem.Add ("quality", new JSONNumber(_item.quality));82 jsonItem.Add ("name", new JSONString (_item.itemName)); 83 jsonItem.Add ("icon", new JSONString (_item.icon)); 84 jsonItem.Add ("iconcolor", new JSONString (_item.iconcolor)); 85 jsonItem.Add ("quality", new JSONNumber (_item.quality)); 81 86 if (_item.quality >= 0) { 82 87 jsonItem.Add ("qualitycolor", new JSONString (QualityInfo.GetQualityColorHex (_item.quality))); -
binary-improvements/MapRendering/Web/API/GetPlayersLocation.cs
r251 r253 11 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 12 12 { 13 AdminTools admTools = null; 13 AdminTools admTools = GameManager.Instance.adminTools; 14 user = user ?? new WebConnection ("", "", 0L); 14 15 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 { } 16 bool bViewAll = WebConnection.CanViewAllPlayers (permissionLevel); 19 17 20 18 JSONArray playersJsResult = new JSONArray (); … … 23 21 24 22 foreach (string sid in playersList.SteamIDs) { 25 try { 26 if ((admTools != null) && (PetesUtils.ValidText (sid))) 27 if (admTools.IsBanned (sid)) 28 continue; 23 if (admTools != null) 24 if (admTools.IsBanned (sid)) 25 continue; 26 27 Player p = playersList [sid, false]; 28 29 ulong player_steam_ID = 0L; 30 if (!ulong.TryParse (sid, out player_steam_ID)) 31 player_steam_ID = 0L; 32 33 if ((player_steam_ID == user.SteamID) || bViewAll) { 34 JSONObject pos = new JSONObject (); 35 pos.Add("x", new JSONNumber (p.LastPosition.x)); 36 pos.Add("y", new JSONNumber (p.LastPosition.y)); 37 pos.Add("z", new JSONNumber (p.LastPosition.z)); 38 39 JSONObject pJson = new JSONObject (); 40 pJson.Add("steamid", new JSONString (sid)); 41 pJson.Add("ip", new JSONString (p.IP)); 42 pJson.Add("name", new JSONString (p.Name)); 43 pJson.Add("online", new JSONBoolean (p.IsOnline)); 44 pJson.Add("position", pos); 45 46 playersJsResult.Add (pJson); 29 47 } 30 catch { }31 32 try33 {34 Player p = playersList [sid, false];35 36 ulong player_steam_ID = 0L;37 if (!ulong.TryParse (sid, out player_steam_ID))38 player_steam_ID = 0L;39 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));45 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 48 } 58 49
Note:
See TracChangeset
for help on using the changeset viewer.