- Timestamp:
- Jul 26, 2015, 4:47:49 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/API/GetPlayerInventory.cs
r244 r245 7 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 8 { 9 public class GetPlayerInventory : WebAPI 10 { 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 12 { 9 public class GetPlayerInventory : WebAPI { 10 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { 13 11 if (req.QueryString ["steamid"] == null) { 14 12 resp.StatusCode = (int)HttpStatusCode.InternalServerError; … … 31 29 JSONArray bag = new JSONArray (); 32 30 JSONArray belt = new JSONArray (); 31 JSONObject equipment = new JSONObject (); 32 result.Add ("playername", new JSONString (p.Name)); 33 33 result.Add ("bag", bag); 34 34 result.Add ("belt", belt); 35 result.Add ("equipment", equipment); 35 36 36 37 for (int i = 0; i < inv.belt.Count; i++) { 37 JSONObject item = new JSONObject ();38 JSONObject item = new JSONObject (); 38 39 if (inv.belt [i] != null) { 39 item.Add ("count", new JSONNumber (inv.belt[i].count));40 item.Add ("name", new JSONString (inv.belt[i].itemName));40 item.Add ("count", new JSONNumber (inv.belt [i].count)); 41 item.Add ("name", new JSONString (inv.belt [i].itemName)); 41 42 } else { 42 item.Add ("count", new JSONNumber (0));43 item.Add ("name", new JSONString (string.Empty));43 item.Add ("count", new JSONNumber (0)); 44 item.Add ("name", new JSONString (string.Empty)); 44 45 } 45 belt.Add (item);46 belt.Add (item); 46 47 } 47 48 for (int i = 0; i < inv.bag.Count; i++) { 48 JSONObject item = new JSONObject ();49 JSONObject item = new JSONObject (); 49 50 if (inv.bag [i] != null) { 50 item.Add ("count", new JSONNumber (inv.bag[i].count));51 item.Add ("name", new JSONString (inv.bag[i].itemName));51 item.Add ("count", new JSONNumber (inv.bag [i].count)); 52 item.Add ("name", new JSONString (inv.bag [i].itemName)); 52 53 } else { 53 item.Add ("count", new JSONNumber (0));54 item.Add ("name", new JSONString (string.Empty));54 item.Add ("count", new JSONNumber (0)); 55 item.Add ("name", new JSONString (string.Empty)); 55 56 } 56 bag.Add (item);57 bag.Add (item); 57 58 } 59 60 AddEquipment (equipment, "head", inv.equipment, XMLData.Item.EnumEquipmentSlot.Head, NGuiInvGridEquipment.EnumClothingLayer.Middle); 61 AddEquipment (equipment, "eyes", inv.equipment, XMLData.Item.EnumEquipmentSlot.Eyes, NGuiInvGridEquipment.EnumClothingLayer.Middle); 62 AddEquipment (equipment, "face", inv.equipment, XMLData.Item.EnumEquipmentSlot.Face, NGuiInvGridEquipment.EnumClothingLayer.Middle); 63 64 AddEquipment (equipment, "armor", inv.equipment, XMLData.Item.EnumEquipmentSlot.Chest, NGuiInvGridEquipment.EnumClothingLayer.Outer); 65 AddEquipment (equipment, "jacket", inv.equipment, XMLData.Item.EnumEquipmentSlot.Chest, NGuiInvGridEquipment.EnumClothingLayer.Middle); 66 AddEquipment (equipment, "shirt", inv.equipment, XMLData.Item.EnumEquipmentSlot.Chest, NGuiInvGridEquipment.EnumClothingLayer.Inner); 67 68 AddEquipment (equipment, "legarmor", inv.equipment, XMLData.Item.EnumEquipmentSlot.Legs, NGuiInvGridEquipment.EnumClothingLayer.Outer); 69 AddEquipment (equipment, "pants", inv.equipment, XMLData.Item.EnumEquipmentSlot.Legs, NGuiInvGridEquipment.EnumClothingLayer.Inner); 70 AddEquipment (equipment, "boots", inv.equipment, XMLData.Item.EnumEquipmentSlot.Feet, NGuiInvGridEquipment.EnumClothingLayer.Inner); 71 72 AddEquipment (equipment, "gloves", inv.equipment, XMLData.Item.EnumEquipmentSlot.Hands, NGuiInvGridEquipment.EnumClothingLayer.Inner); 73 AddEquipment (equipment, "backpack", inv.equipment, XMLData.Item.EnumEquipmentSlot.Back, NGuiInvGridEquipment.EnumClothingLayer.Outer); 58 74 59 75 WriteJSON (resp, result); 60 76 } 77 78 private void AddEquipment (JSONObject _eq, string _slotname, InvItem[] _items, XMLData.Item.EnumEquipmentSlot _slot, NGuiInvGridEquipment.EnumClothingLayer _layer) { 79 int index = (int)_slot + (int)_layer * (int)XMLData.Item.EnumEquipmentSlot.Count; 80 if (_items != null && _items [index] != null) { 81 _eq.Add (_slotname, new JSONString (_items [index].itemName)); 82 } else { 83 _eq.Add (_slotname, new JSONBoolean (false)); 84 } 85 } 86 61 87 } 62 88 }
Note:
See TracChangeset
for help on using the changeset viewer.