source: binary-improvements/MapRendering/Web/API/GetPlayerInventories.cs@ 325

Last change on this file since 325 was 325, checked in by alloc, 6 years ago

Code style cleanup (mostly whitespace changes, enforcing braces, using cleanup)

File size: 2.2 KB
RevLine 
[325]1using System.Net;
[321]2using AllocsFixes.JSON;
3using AllocsFixes.PersistentData;
4
5namespace AllocsFixes.NetConnections.Servers.Web.API {
6 public class GetPlayerInventories : WebAPI {
[325]7 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user,
8 int permissionLevel) {
9 JSONArray AllInventoriesResult = new JSONArray ();
[321]10
[325]11 foreach (string sid in PersistentContainer.Instance.Players.SteamIDs) {
[321]12 Player p = PersistentContainer.Instance.Players [sid, false];
[325]13
[321]14 if (p == null) {
15 continue;
16 }
[325]17
18 if (p.IsOnline) {
19 PersistentData.Inventory inv = p.Inventory;
20
21 JSONObject result = new JSONObject ();
22 JSONArray bag = new JSONArray ();
23 JSONArray belt = new JSONArray ();
[321]24 JSONObject equipment = new JSONObject ();
[325]25 result.Add ("steamid", new JSONString (sid));
[321]26 result.Add ("entityid", new JSONNumber (p.EntityID));
[325]27 result.Add ("playername", new JSONString (p.Name));
28 result.Add ("bag", bag);
29 result.Add ("belt", belt);
30 result.Add ("equipment", equipment);
31
32 GetPlayerInventory.DoInventory (belt, inv.belt);
33 GetPlayerInventory.DoInventory (bag, inv.bag);
34
35 GetPlayerInventory.AddEquipment (equipment, "head", inv.equipment, EquipmentSlots.Headgear);
36 GetPlayerInventory.AddEquipment (equipment, "eyes", inv.equipment, EquipmentSlots.Eyewear);
37 GetPlayerInventory.AddEquipment (equipment, "face", inv.equipment, EquipmentSlots.Face);
38
39 GetPlayerInventory.AddEquipment (equipment, "armor", inv.equipment, EquipmentSlots.ChestArmor);
40 GetPlayerInventory.AddEquipment (equipment, "jacket", inv.equipment, EquipmentSlots.Jacket);
41 GetPlayerInventory.AddEquipment (equipment, "shirt", inv.equipment, EquipmentSlots.Shirt);
42
43 GetPlayerInventory.AddEquipment (equipment, "legarmor", inv.equipment, EquipmentSlots.LegArmor);
44 GetPlayerInventory.AddEquipment (equipment, "pants", inv.equipment, EquipmentSlots.Legs);
45 GetPlayerInventory.AddEquipment (equipment, "boots", inv.equipment, EquipmentSlots.Feet);
46
47 GetPlayerInventory.AddEquipment (equipment, "gloves", inv.equipment, EquipmentSlots.Hands);
48
49 AllInventoriesResult.Add (result);
50 }
[321]51 }
52
53 WriteJSON (resp, AllInventoriesResult);
54 }
55 }
[325]56}
Note: See TracBrowser for help on using the repository browser.