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