source: binary-improvements/MapRendering/Web/API/GetPlayerInventory.cs@ 251

Last change on this file since 251 was 251, checked in by peter.souza, 9 years ago

Enemies (zombies and hostile animal entities) are now shown on the map as Hostiles and require permission level 'webapi.gethostilelocation' for web viewers to see.

Animals (non-hostile entities) are now shown on the map as Animals and require permission level 'webapi.getanimalslocation' for web viewers to see.

Permission level for 'webapi.viewallclaims' is now required for a viewer to see all claims, otherwise the permission level for 'webapi.getlandclaims' will only show viewer-owned claims. A viewer requires both 'webapi.getlandclaims' and 'webapi.viewallclaims' to be set for all claims to show (you can't just set 'webapi.viewallclaims').
https://7daystodie.com/forums/showthread.php?12837-Improvements-for-the-dedicated-server&p=317405&viewfull=1#post317405

Permission level for 'webapi.viewallplayers' is now required for a viewer to see all players, otherwise the permission level for 'webapi.getplayerslocation' will only show the player for the currently-authenticated viewer. A viewer requires both 'webapi.getplayerslocation' and 'webapi.viewallplayers' to be set for all players to show (you can't just set 'webapi.viewallplayers').
https://7daystodie.com/forums/showthread.php?12837-Improvements-for-the-dedicated-server&p=317405&viewfull=1#post317405

Banned players are now hidden from the web map.
https://7daystodie.com/forums/showthread.php?12837-Improvements-for-the-dedicated-server&p=320702&viewfull=1#post320702

Items using 'CustomIcon' and 'CustomIconTint' are now supported (although the exact tinting may not be perfectly the same as the game).
https://7daystodie.com/forums/showthread.php?12837-Improvements-for-the-dedicated-server&p=317117&viewfull=1#post317117
https://7daystodie.com/forums/showthread.php?12837-Improvements-for-the-dedicated-server&p=317679&viewfull=1#post317679

Map marker icons for players, hostiles, and animals have been updated.

File size: 4.1 KB
Line 
1using AllocsFixes.JSON;
2using AllocsFixes.PersistentData;
3using System;
4using System.Collections.Generic;
5using System.Net;
6
7namespace AllocsFixes.NetConnections.Servers.Web.API
8{
9 public class GetPlayerInventory : WebAPI {
10 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) {
11 if (req.QueryString ["steamid"] == null) {
12 resp.StatusCode = (int)HttpStatusCode.InternalServerError;
13 Web.SetResponseTextContent (resp, "No SteamID given");
14 return;
15 }
16
17 Player p = PersistentContainer.Instance.Players [req.QueryString ["steamid"], false];
18 if (p == null) {
19 resp.StatusCode = (int)HttpStatusCode.InternalServerError;
20 Web.SetResponseTextContent (resp, "Invalid or unknown SteamID given");
21 return;
22 }
23
24 PersistentData.Inventory inv = p.Inventory;
25
26
27 JSONObject result = new JSONObject ();
28
29 JSONArray bag = new JSONArray ();
30 JSONArray belt = new JSONArray ();
31 JSONObject equipment = new JSONObject ();
32 result.Add ("playername", new JSONString (p.Name));
33 result.Add ("bag", bag);
34 result.Add ("belt", belt);
35 result.Add ("equipment", equipment);
36
37 DoInventory (belt, inv.belt);
38 DoInventory (bag, inv.bag);
39
40 AddEquipment (equipment, "head", inv.equipment, XMLData.Item.EnumEquipmentSlot.Head, NGuiInvGridEquipment.EnumClothingLayer.Middle);
41 AddEquipment (equipment, "eyes", inv.equipment, XMLData.Item.EnumEquipmentSlot.Eyes, NGuiInvGridEquipment.EnumClothingLayer.Middle);
42 AddEquipment (equipment, "face", inv.equipment, XMLData.Item.EnumEquipmentSlot.Face, NGuiInvGridEquipment.EnumClothingLayer.Middle);
43
44 AddEquipment (equipment, "armor", inv.equipment, XMLData.Item.EnumEquipmentSlot.Chest, NGuiInvGridEquipment.EnumClothingLayer.Outer);
45 AddEquipment (equipment, "jacket", inv.equipment, XMLData.Item.EnumEquipmentSlot.Chest, NGuiInvGridEquipment.EnumClothingLayer.Middle);
46 AddEquipment (equipment, "shirt", inv.equipment, XMLData.Item.EnumEquipmentSlot.Chest, NGuiInvGridEquipment.EnumClothingLayer.Inner);
47
48 AddEquipment (equipment, "legarmor", inv.equipment, XMLData.Item.EnumEquipmentSlot.Legs, NGuiInvGridEquipment.EnumClothingLayer.Outer);
49 AddEquipment (equipment, "pants", inv.equipment, XMLData.Item.EnumEquipmentSlot.Legs, NGuiInvGridEquipment.EnumClothingLayer.Inner);
50 AddEquipment (equipment, "boots", inv.equipment, XMLData.Item.EnumEquipmentSlot.Feet, NGuiInvGridEquipment.EnumClothingLayer.Inner);
51
52 AddEquipment (equipment, "gloves", inv.equipment, XMLData.Item.EnumEquipmentSlot.Hands, NGuiInvGridEquipment.EnumClothingLayer.Inner);
53 AddEquipment (equipment, "backpack", inv.equipment, XMLData.Item.EnumEquipmentSlot.Back, NGuiInvGridEquipment.EnumClothingLayer.Outer);
54
55 WriteJSON (resp, result);
56 }
57
58 private void DoInventory (JSONArray _jsonRes, List<InvItem> _inv) {
59 for (int i = 0; i < _inv.Count; i++) {
60 _jsonRes.Add (GetJsonForItem (_inv [i]));
61 }
62 }
63
64 private void AddEquipment (JSONObject _eq, string _slotname, InvItem[] _items, XMLData.Item.EnumEquipmentSlot _slot, NGuiInvGridEquipment.EnumClothingLayer _layer) {
65 int index = (int)_slot + (int)_layer * (int)XMLData.Item.EnumEquipmentSlot.Count;
66 if (_items != null) {
67 _eq.Add (_slotname, GetJsonForItem (_items [index]));
68 } else {
69 _eq.Add (_slotname, new JSONNull ());
70 }
71 }
72
73 private JSONNode GetJsonForItem (InvItem _item) {
74 if (_item != null) {
75 JSONObject jsonItem = new JSONObject ();
76 jsonItem.Add ("count", new JSONNumber (_item.count));
77 jsonItem.Add ("name", new JSONString (_item.itemName));
78 jsonItem.Add ("icon", new JSONString (_item.icon));
79 jsonItem.Add ("iconcolor", new JSONString ((string.IsNullOrEmpty (_item.iconcolor) || _item.iconcolor == "FFFFFF" ? "" : _item.iconcolor)));
80 jsonItem.Add ("quality", new JSONNumber(_item.quality));
81 if (_item.quality >= 0) {
82 jsonItem.Add ("qualitycolor", new JSONString (QualityInfo.GetQualityColorHex (_item.quality)));
83 }
84 return jsonItem;
85 } else {
86 return new JSONNull ();
87 }
88 }
89
90 }
91}
92
Note: See TracBrowser for help on using the repository browser.