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

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

*Latest optimizations

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