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
Line 
1using System.Net;
2using AllocsFixes.JSON;
3using AllocsFixes.PersistentData;
4
5namespace AllocsFixes.NetConnections.Servers.Web.API {
6 public class GetPlayerInventories : WebAPI {
7 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user,
8 int permissionLevel) {
9 JSONArray AllInventoriesResult = new JSONArray ();
10
11 foreach (string sid in PersistentContainer.Instance.Players.SteamIDs) {
12 Player p = PersistentContainer.Instance.Players [sid, false];
13
14 if (p == null) {
15 continue;
16 }
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 ();
24 JSONObject equipment = new JSONObject ();
25 result.Add ("steamid", new JSONString (sid));
26 result.Add ("entityid", new JSONNumber (p.EntityID));
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 }
51 }
52
53 WriteJSON (resp, AllInventoriesResult);
54 }
55 }
56}
Note: See TracBrowser for help on using the repository browser.