Changeset 348 for binary-improvements/MapRendering
- Timestamp:
- Jan 19, 2019, 5:13:47 PM (6 years ago)
- Location:
- binary-improvements/MapRendering/Web/API
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/API/GetPlayerInventories.cs
r332 r348 6 6 namespace AllocsFixes.NetConnections.Servers.Web.API { 7 7 public class GetPlayerInventories : WebAPI { 8 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 9 int permissionLevel) { 8 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 9 int _permissionLevel) { 10 11 bool showIconColor, showIconName; 12 GetPlayerInventory.GetInventoryArguments (_req, out showIconColor, out showIconName); 13 10 14 JSONArray AllInventoriesResult = new JSONArray (); 11 15 … … 18 22 19 23 if (p.IsOnline) { 20 PersistentData.Inventory inv = p.Inventory; 21 22 JSONObject result = new JSONObject (); 23 JSONArray bag = new JSONArray (); 24 JSONArray belt = new JSONArray (); 25 JSONObject equipment = new JSONObject (); 26 result.Add ("steamid", new JSONString (kvp.Key)); 27 result.Add ("entityid", new JSONNumber (p.EntityID)); 28 result.Add ("playername", new JSONString (p.Name)); 29 result.Add ("bag", bag); 30 result.Add ("belt", belt); 31 result.Add ("equipment", equipment); 32 33 GetPlayerInventory.DoInventory (belt, inv.belt); 34 GetPlayerInventory.DoInventory (bag, inv.bag); 35 36 GetPlayerInventory.AddEquipment (equipment, "head", inv.equipment, EquipmentSlots.Headgear); 37 GetPlayerInventory.AddEquipment (equipment, "eyes", inv.equipment, EquipmentSlots.Eyewear); 38 GetPlayerInventory.AddEquipment (equipment, "face", inv.equipment, EquipmentSlots.Face); 39 40 GetPlayerInventory.AddEquipment (equipment, "armor", inv.equipment, EquipmentSlots.ChestArmor); 41 GetPlayerInventory.AddEquipment (equipment, "jacket", inv.equipment, EquipmentSlots.Jacket); 42 GetPlayerInventory.AddEquipment (equipment, "shirt", inv.equipment, EquipmentSlots.Shirt); 43 44 GetPlayerInventory.AddEquipment (equipment, "legarmor", inv.equipment, EquipmentSlots.LegArmor); 45 GetPlayerInventory.AddEquipment (equipment, "pants", inv.equipment, EquipmentSlots.Legs); 46 GetPlayerInventory.AddEquipment (equipment, "boots", inv.equipment, EquipmentSlots.Feet); 47 48 GetPlayerInventory.AddEquipment (equipment, "gloves", inv.equipment, EquipmentSlots.Hands); 49 50 AllInventoriesResult.Add (result); 24 AllInventoriesResult.Add (GetPlayerInventory.DoPlayer (kvp.Key, p, showIconName, showIconName)); 51 25 } 52 26 } 53 27 54 WriteJSON ( resp, AllInventoriesResult);28 WriteJSON (_resp, AllInventoriesResult); 55 29 } 56 30 } -
binary-improvements/MapRendering/Web/API/GetPlayerInventory.cs
r326 r348 6 6 namespace AllocsFixes.NetConnections.Servers.Web.API { 7 7 public class GetPlayerInventory : WebAPI { 8 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnectionuser,9 int permissionLevel) {10 if ( req.QueryString ["steamid"] == null) {11 resp.StatusCode = (int) HttpStatusCode.InternalServerError;12 Web.SetResponseTextContent ( resp, "No SteamID given");8 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 9 int _permissionLevel) { 10 if (_req.QueryString ["steamid"] == null) { 11 _resp.StatusCode = (int) HttpStatusCode.BadRequest; 12 Web.SetResponseTextContent (_resp, "No SteamID given"); 13 13 return; 14 14 } 15 15 16 Player p = PersistentContainer.Instance.Players [req.QueryString ["steamid"], false]; 16 string steamId = _req.QueryString ["steamid"]; 17 18 Player p = PersistentContainer.Instance.Players [steamId, false]; 17 19 if (p == null) { 18 resp.StatusCode = (int) HttpStatusCode.InternalServerError;19 Web.SetResponseTextContent ( resp, "Invalid or unknown SteamID given");20 _resp.StatusCode = (int) HttpStatusCode.NotFound; 21 Web.SetResponseTextContent (_resp, "Invalid or unknown SteamID given"); 20 22 return; 21 23 } 22 24 23 PersistentData.Inventory inv = p.Inventory; 25 bool showIconColor, showIconName; 26 GetInventoryArguments (_req, out showIconColor, out showIconName); 24 27 28 JSONObject result = DoPlayer (steamId, p, showIconColor, showIconName); 29 30 WriteJSON (_resp, result); 31 } 32 33 internal static void GetInventoryArguments (HttpListenerRequest _req, out bool _showIconColor, out bool _showIconName) { 34 if (_req.QueryString ["showiconcolor"] == null || !bool.TryParse (_req.QueryString ["showiconcolor"], out _showIconColor)) { 35 _showIconColor = true; 36 } 37 38 if (_req.QueryString ["showiconname"] == null || !bool.TryParse (_req.QueryString ["showiconname"], out _showIconName)) { 39 _showIconName = true; 40 } 41 } 42 43 internal static JSONObject DoPlayer (string _steamId, Player _player, bool _showIconColor, bool _showIconName) { 44 PersistentData.Inventory inv = _player.Inventory; 25 45 26 46 JSONObject result = new JSONObject (); … … 29 49 JSONArray belt = new JSONArray (); 30 50 JSONObject equipment = new JSONObject (); 31 result.Add ("playername", new JSONString (p.Name)); 51 result.Add ("steamid", new JSONString (_steamId)); 52 result.Add ("entityid", new JSONNumber (_player.EntityID)); 53 result.Add ("playername", new JSONString (_player.Name)); 32 54 result.Add ("bag", bag); 33 55 result.Add ("belt", belt); 34 56 result.Add ("equipment", equipment); 35 57 36 DoInventory (belt, inv.belt );37 DoInventory (bag, inv.bag );58 DoInventory (belt, inv.belt, _showIconColor, _showIconName); 59 DoInventory (bag, inv.bag, _showIconColor, _showIconName); 38 60 39 AddEquipment (equipment, "head", inv.equipment, EquipmentSlots.Headgear );40 AddEquipment (equipment, "eyes", inv.equipment, EquipmentSlots.Eyewear );41 AddEquipment (equipment, "face", inv.equipment, EquipmentSlots.Face );61 AddEquipment (equipment, "head", inv.equipment, EquipmentSlots.Headgear, _showIconColor, _showIconName); 62 AddEquipment (equipment, "eyes", inv.equipment, EquipmentSlots.Eyewear, _showIconColor, _showIconName); 63 AddEquipment (equipment, "face", inv.equipment, EquipmentSlots.Face, _showIconColor, _showIconName); 42 64 43 AddEquipment (equipment, "armor", inv.equipment, EquipmentSlots.ChestArmor );44 AddEquipment (equipment, "jacket", inv.equipment, EquipmentSlots.Jacket );45 AddEquipment (equipment, "shirt", inv.equipment, EquipmentSlots.Shirt );65 AddEquipment (equipment, "armor", inv.equipment, EquipmentSlots.ChestArmor, _showIconColor, _showIconName); 66 AddEquipment (equipment, "jacket", inv.equipment, EquipmentSlots.Jacket, _showIconColor, _showIconName); 67 AddEquipment (equipment, "shirt", inv.equipment, EquipmentSlots.Shirt, _showIconColor, _showIconName); 46 68 47 AddEquipment (equipment, "legarmor", inv.equipment, EquipmentSlots.LegArmor );48 AddEquipment (equipment, "pants", inv.equipment, EquipmentSlots.Legs );49 AddEquipment (equipment, "boots", inv.equipment, EquipmentSlots.Feet );69 AddEquipment (equipment, "legarmor", inv.equipment, EquipmentSlots.LegArmor, _showIconColor, _showIconName); 70 AddEquipment (equipment, "pants", inv.equipment, EquipmentSlots.Legs, _showIconColor, _showIconName); 71 AddEquipment (equipment, "boots", inv.equipment, EquipmentSlots.Feet, _showIconColor, _showIconName); 50 72 51 AddEquipment (equipment, "gloves", inv.equipment, EquipmentSlots.Hands );73 AddEquipment (equipment, "gloves", inv.equipment, EquipmentSlots.Hands, _showIconColor, _showIconName); 52 74 53 WriteJSON (resp, result);75 return result; 54 76 } 55 77 56 internal static void DoInventory (JSONArray _jsonRes, List<InvItem> _inv) {78 private static void DoInventory (JSONArray _jsonRes, List<InvItem> _inv, bool _showIconColor, bool _showIconName) { 57 79 for (int i = 0; i < _inv.Count; i++) { 58 _jsonRes.Add (GetJsonForItem (_inv [i] ));80 _jsonRes.Add (GetJsonForItem (_inv [i], _showIconColor, _showIconName)); 59 81 } 60 82 } 61 83 62 internal static void AddEquipment (JSONObject _eq, string _slotname, InvItem[] _items, EquipmentSlots _slot) {84 private static void AddEquipment (JSONObject _eq, string _slotname, InvItem[] _items, EquipmentSlots _slot, bool _showIconColor, bool _showIconName) { 63 85 int[] slotindices = XUiM_PlayerEquipment.GetSlotIndicesByEquipmentSlot (_slot); 64 86 … … 66 88 if (_items != null && _items [slotindices [i]] != null) { 67 89 InvItem item = _items [slotindices [i]]; 68 _eq.Add (_slotname, GetJsonForItem (item ));90 _eq.Add (_slotname, GetJsonForItem (item, _showIconColor, _showIconName)); 69 91 return; 70 92 } … … 74 96 } 75 97 76 internal static JSONNode GetJsonForItem (InvItem _item) {98 private static JSONNode GetJsonForItem (InvItem _item, bool _showIconColor, bool _showIconName) { 77 99 if (_item == null) { 78 100 return new JSONNull (); … … 82 104 jsonItem.Add ("count", new JSONNumber (_item.count)); 83 105 jsonItem.Add ("name", new JSONString (_item.itemName)); 84 jsonItem.Add ("icon", new JSONString (_item.icon)); 85 jsonItem.Add ("iconcolor", new JSONString (_item.iconcolor)); 106 107 if (_showIconName) { 108 jsonItem.Add ("icon", new JSONString (_item.icon)); 109 } 110 111 if (_showIconColor) { 112 jsonItem.Add ("iconcolor", new JSONString (_item.iconcolor)); 113 } 114 86 115 jsonItem.Add ("quality", new JSONNumber (_item.quality)); 87 116 if (_item.quality >= 0) {
Note:
See TracChangeset
for help on using the changeset viewer.