Changeset 245
- Timestamp:
- Jul 26, 2015, 4:47:49 PM (9 years ago)
- Location:
- binary-improvements
- Files:
-
- 7 added
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/PersistentData/Inventory.cs
r238 r245 7 7 { 8 8 [Serializable] 9 public class Inventory 10 { 9 public class Inventory { 11 10 public List<InvItem> bag; 12 11 public List<InvItem> belt; 12 public InvItem[] equipment; 13 13 14 public Inventory () 15 { 14 public Inventory () { 16 15 bag = new List<InvItem> (); 17 16 belt = new List<InvItem> (); 17 equipment = null; 18 18 } 19 19 20 public void Update (PlayerDataFile pdf) 21 { 22 //Log.Out ("Updating player inventory - player id: " + pdf.id); 23 ProcessInv (bag, pdf.bag, pdf.id); 24 ProcessInv (belt, pdf.inventory, pdf.id); 20 public void Update (PlayerDataFile pdf) { 21 lock (this) { 22 //Log.Out ("Updating player inventory - player id: " + pdf.id); 23 ProcessInv (bag, pdf.bag, pdf.id); 24 ProcessInv (belt, pdf.inventory, pdf.id); 25 ProcessEqu (pdf.equipment); 26 } 25 27 } 26 28 27 private void ProcessInv (List<InvItem> target, ItemStack[] sourceFields, int id) 28 { 29 lock (target) { 30 target.Clear (); 31 for (int i = 0; i < sourceFields.Length; i++) { 32 if (sourceFields [i].count > 0) { 33 int count = sourceFields [i].count; 34 int maxAllowed = ItemClass.list [sourceFields [i].itemValue.type].Stacknumber.Value; 35 string name = ItemClass.list [sourceFields [i].itemValue.type].GetItemName (); 29 private void ProcessInv (List<InvItem> target, ItemStack[] sourceFields, int id) { 30 target.Clear (); 31 for (int i = 0; i < sourceFields.Length; i++) { 32 if (sourceFields [i].count > 0) { 33 int count = sourceFields [i].count; 34 int maxAllowed = ItemClass.list [sourceFields [i].itemValue.type].Stacknumber.Value; 35 string name = ItemClass.list [sourceFields [i].itemValue.type].GetItemName (); 36 36 37 if (count > maxAllowed) 38 Log.Out ("Player with ID " + id + " has stack for \"" + name + "\" greater than allowed (" + count + " > " + maxAllowed + ")"); 39 target.Add (new InvItem (name, count)); 40 } else { 41 target.Add (null); 37 if (count > maxAllowed) { 38 Log.Out ("Player with ID " + id + " has stack for \"" + name + "\" greater than allowed (" + count + " > " + maxAllowed + ")"); 42 39 } 40 target.Add (new InvItem (name, count)); 41 } else { 42 target.Add (null); 43 } 44 } 45 } 46 47 private void ProcessEqu (Equipment sourceEquipment) { 48 equipment = new InvItem[sourceEquipment.GetSlotCount ()]; 49 for (int i = 0; i < sourceEquipment.GetSlotCount (); i++) { 50 if (sourceEquipment.GetSlotItem (i) != null && !sourceEquipment.GetSlotItem (i).Equals (ItemValue.None)) { 51 int count = 1; 52 string name = ItemClass.list [sourceEquipment.GetSlotItem (i).type].GetItemName (); 53 54 equipment [i] = new InvItem (name, count); 55 } else { 56 equipment [i] = null; 43 57 } 44 58 } -
binary-improvements/MapRendering/ModInfo.xml
r243 r245 5 5 <Description value="Render the game map to image map tiles as it is uncovered" /> 6 6 <Author value="Christian 'Alloc' Illy" /> 7 <Version value=" 6" />7 <Version value="7" /> 8 8 <Website value="http://7dtd.illy.bz" /> 9 9 </ModInfo> -
binary-improvements/MapRendering/Web/API/GetLandClaims.cs
r244 r245 53 53 owner.Add ("claimactive", new JSONBoolean (isActive)); 54 54 55 if (PersistentContainer.Instance.Players [curID, false] != null) { 56 owner.Add ("playername", new JSONString (PersistentContainer.Instance.Players [curID, false].Name)); 57 } else { 58 owner.Add ("playername", new JSONNull ()); 59 } 60 55 61 JSONArray claims = new JSONArray (); 56 62 owner.Add ("claims", claims); -
binary-improvements/MapRendering/Web/API/GetPlayerInventory.cs
r244 r245 7 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 8 { 9 public class GetPlayerInventory : WebAPI 10 { 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 12 { 9 public class GetPlayerInventory : WebAPI { 10 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { 13 11 if (req.QueryString ["steamid"] == null) { 14 12 resp.StatusCode = (int)HttpStatusCode.InternalServerError; … … 31 29 JSONArray bag = new JSONArray (); 32 30 JSONArray belt = new JSONArray (); 31 JSONObject equipment = new JSONObject (); 32 result.Add ("playername", new JSONString (p.Name)); 33 33 result.Add ("bag", bag); 34 34 result.Add ("belt", belt); 35 result.Add ("equipment", equipment); 35 36 36 37 for (int i = 0; i < inv.belt.Count; i++) { 37 JSONObject item = new JSONObject ();38 JSONObject item = new JSONObject (); 38 39 if (inv.belt [i] != null) { 39 item.Add ("count", new JSONNumber (inv.belt[i].count));40 item.Add ("name", new JSONString (inv.belt[i].itemName));40 item.Add ("count", new JSONNumber (inv.belt [i].count)); 41 item.Add ("name", new JSONString (inv.belt [i].itemName)); 41 42 } else { 42 item.Add ("count", new JSONNumber (0));43 item.Add ("name", new JSONString (string.Empty));43 item.Add ("count", new JSONNumber (0)); 44 item.Add ("name", new JSONString (string.Empty)); 44 45 } 45 belt.Add (item);46 belt.Add (item); 46 47 } 47 48 for (int i = 0; i < inv.bag.Count; i++) { 48 JSONObject item = new JSONObject ();49 JSONObject item = new JSONObject (); 49 50 if (inv.bag [i] != null) { 50 item.Add ("count", new JSONNumber (inv.bag[i].count));51 item.Add ("name", new JSONString (inv.bag[i].itemName));51 item.Add ("count", new JSONNumber (inv.bag [i].count)); 52 item.Add ("name", new JSONString (inv.bag [i].itemName)); 52 53 } else { 53 item.Add ("count", new JSONNumber (0));54 item.Add ("name", new JSONString (string.Empty));54 item.Add ("count", new JSONNumber (0)); 55 item.Add ("name", new JSONString (string.Empty)); 55 56 } 56 bag.Add (item);57 bag.Add (item); 57 58 } 59 60 AddEquipment (equipment, "head", inv.equipment, XMLData.Item.EnumEquipmentSlot.Head, NGuiInvGridEquipment.EnumClothingLayer.Middle); 61 AddEquipment (equipment, "eyes", inv.equipment, XMLData.Item.EnumEquipmentSlot.Eyes, NGuiInvGridEquipment.EnumClothingLayer.Middle); 62 AddEquipment (equipment, "face", inv.equipment, XMLData.Item.EnumEquipmentSlot.Face, NGuiInvGridEquipment.EnumClothingLayer.Middle); 63 64 AddEquipment (equipment, "armor", inv.equipment, XMLData.Item.EnumEquipmentSlot.Chest, NGuiInvGridEquipment.EnumClothingLayer.Outer); 65 AddEquipment (equipment, "jacket", inv.equipment, XMLData.Item.EnumEquipmentSlot.Chest, NGuiInvGridEquipment.EnumClothingLayer.Middle); 66 AddEquipment (equipment, "shirt", inv.equipment, XMLData.Item.EnumEquipmentSlot.Chest, NGuiInvGridEquipment.EnumClothingLayer.Inner); 67 68 AddEquipment (equipment, "legarmor", inv.equipment, XMLData.Item.EnumEquipmentSlot.Legs, NGuiInvGridEquipment.EnumClothingLayer.Outer); 69 AddEquipment (equipment, "pants", inv.equipment, XMLData.Item.EnumEquipmentSlot.Legs, NGuiInvGridEquipment.EnumClothingLayer.Inner); 70 AddEquipment (equipment, "boots", inv.equipment, XMLData.Item.EnumEquipmentSlot.Feet, NGuiInvGridEquipment.EnumClothingLayer.Inner); 71 72 AddEquipment (equipment, "gloves", inv.equipment, XMLData.Item.EnumEquipmentSlot.Hands, NGuiInvGridEquipment.EnumClothingLayer.Inner); 73 AddEquipment (equipment, "backpack", inv.equipment, XMLData.Item.EnumEquipmentSlot.Back, NGuiInvGridEquipment.EnumClothingLayer.Outer); 58 74 59 75 WriteJSON (resp, result); 60 76 } 77 78 private void AddEquipment (JSONObject _eq, string _slotname, InvItem[] _items, XMLData.Item.EnumEquipmentSlot _slot, NGuiInvGridEquipment.EnumClothingLayer _layer) { 79 int index = (int)_slot + (int)_layer * (int)XMLData.Item.EnumEquipmentSlot.Count; 80 if (_items != null && _items [index] != null) { 81 _eq.Add (_slotname, new JSONString (_items [index].itemName)); 82 } else { 83 _eq.Add (_slotname, new JSONBoolean (false)); 84 } 85 } 86 61 87 } 62 88 } -
binary-improvements/MapRendering/Web/API/GetStats.cs
r244 r245 19 19 result.Add ("gametime", time); 20 20 21 result.Add ("players", new JSONNumber (GameManager.Instance.World.Players.Count)); 22 21 23 WriteJSON (resp, result); 22 24 } -
binary-improvements/server-fixes.userprefs
r244 r245 1 1 <Properties> 2 2 <MonoDevelop.Ide.Workspace ActiveConfiguration="Release_Version" /> 3 <MonoDevelop.Ide.Workbench ActiveDocument=" 7dtd-server-fixes/src/AssemblyInfo.cs">3 <MonoDevelop.Ide.Workbench ActiveDocument="MapRendering/Web/API/GetLandClaims.cs"> 4 4 <Files> 5 5 <File FileName="MapRendering/MapRendering/Constants.cs" Line="1" Column="1" /> 6 <File FileName="7dtd-server-fixes/src/AssemblyInfo.cs" Line="20" Column="35" />7 6 <File FileName="7dtd-server-fixes/ModInfo.xml" Line="2" Column="6" /> 8 7 <File FileName="AllocsCommands/ModInfo.xml" Line="7" Column="20" /> 9 8 <File FileName="MapRendering/ModInfo.xml" Line="7" Column="20" /> 10 <File FileName="MapRendering/Web/Web.cs" Line="245" Column="3" /> 11 <File FileName="MapRendering/Web/WebPermissions.cs" Line="156" Column="25" /> 12 <File FileName="MapRendering/Web/Handlers/SessionHandler.cs" Line="16" Column="123" /> 13 <File FileName="MapRendering/Web/Handlers/ApiHandler.cs" Line="34" Column="1" /> 9 <File FileName="MapRendering/Web/Web.cs" Line="69" Column="19" /> 14 10 <File FileName="MapRendering/Web/API/ExecuteConsoleCommand.cs" Line="36" Column="114" /> 11 <File FileName="MapRendering/Web/API/GetStats.cs" Line="21" Column="84" /> 12 <File FileName="MapRendering/Web/API/GetLandClaims.cs" Line="59" Column="8" /> 15 13 </Files> 16 14 <Pads> -
binary-improvements/webserver/css/style.css
r244 r245 1 /* Generic page layout */ 1 /*======================================== 2 - Generic page layout 3 */ 2 4 3 5 body { … … 12 14 } 13 15 14 .admin menu,16 .adminnavbar, 15 17 .admincontent { 16 18 position: absolute; … … 19 21 } 20 22 21 .adminmenu { 23 24 /*======================================== 25 - Menu bar 26 */ 27 28 .adminnavbar { 22 29 width: 200px; 23 30 left: 0; … … 25 32 } 26 33 27 .adminmenu .current_tab { 34 .adminnavbar > div { 35 margin: 5px; 36 } 37 38 /*---------------------------------------- 39 - Menu entries 40 */ 41 42 .adminnavbar ul { 43 margin-top: 5px; 44 } 45 46 .adminnavbar #adminmenu .menu_button { 47 display: none; 48 } 49 50 .adminnavbar #adminmenu .menu_button.allowed { 51 display: inline; 52 } 53 54 .adminnavbar #adminmenu .menu_button a { 55 color: #000; 56 text-decoration: none; 57 } 58 59 .adminnavbar #adminmenu .current_tab { 28 60 font-weight: bold; 29 61 text-transform: uppercase; 30 62 } 31 63 32 .adminmenu .menu_button a { 64 /*---------------------------------------- 65 - Server stats 66 */ 67 68 .adminnavbar #serverstats { 69 margin-bottom: 20px; 70 display: none; 33 71 color: #000; 34 } 35 36 .adminmenu #userstate { 37 position: absolute; 38 bottom: 5px; 39 left: 5px; 40 right: 5px; 72 text-decoration: none; 73 } 74 75 .adminnavbar #serverstats #stats_time { 76 white-space: nowrap; 77 } 78 79 /*---------------------------------------- 80 - Session state box 81 */ 82 83 .adminnavbar #userstate { 84 position: absolute; 85 bottom: 0px; 86 left: 0px; 87 right: 0px; 41 88 background-color: green; 42 89 } 43 90 44 .admin menu#userstate #username {91 .adminnavbar #userstate #username { 45 92 padding-left: 10px; 46 93 } 47 94 48 .adminmenu #userstate > div { 49 display: none; 50 } 95 .adminnavbar #userstate > div { 96 display: none; 97 } 98 99 100 /*======================================== 101 - Content area 102 */ 51 103 52 104 .admincontent { … … 54 106 right: 0; 55 107 left: 200px; 56 background-color: #fff; 108 background-color: #a04; 109 } 110 111 .admincontent #nopermissionwarning { 112 margin: 20px 50px; 57 113 } 58 114 … … 78 134 79 135 80 /* Inventory dialog overlay */ 136 /*======================================== 137 - Inventory dialog 138 */ 81 139 82 140 #info { … … 91 149 margin: 0px; 92 150 border-collapse: collapse; 93 background-color: #303030;94 151 } 95 152 .invField { … … 99 156 margin: 0px; 100 157 border: 1px solid gray; 158 background-color: #303030; 101 159 background-size: 58px; 102 160 background-repeat: no-repeat; … … 112 170 1px 1px 0 #000; 113 171 } 172 173 #equipmentTable .invFieldText { 174 display: none; 175 } 176 114 177 .inventoryButton { 115 178 color: #00ff00; … … 126 189 z-index:1010 !important; 127 190 } 191 128 192 129 193 -
binary-improvements/webserver/index.html
r244 r245 33 33 <script type="text/javascript" src="js/leaflet.control.coordinates.js"></script> 34 34 <script type="text/javascript" src="js/leaflet.control.reloadtiles.js"></script> 35 <script type="text/javascript" src="js/leaflet.control.gametime.js"></script> 35 <script type="text/javascript" src="js/leaflet.layer.landclaims.js"></script> 36 <script type="text/javascript" src="js/inventory_dialog.js"></script> 36 37 <script type="text/javascript" src="js/util.js"></script> 38 <script type="text/javascript" src="js/stats.js"></script> 39 <script type="text/javascript" src="js/tabs.js"></script> 40 <script type="text/javascript" src="js/permissions.js"></script> 41 <script type="text/javascript" src="js/map.js"></script> 37 42 38 43 <!-- Own stylesheet --> … … 44 49 45 50 <div class="adminwrapper"> 46 <div class="adminmenu"> 47 <ul> 48 <li><a href="#tab_map" data-permission="web.map">Map</a></li> 49 <li><a href="#tab_log" data-permission="web.log">Log</a></li> 50 </ul> 51 <div class="adminnavbar"> 52 <div id="serverstats"> 53 <span id="stats_time">-</span><br/> 54 <span id="stats_players">-</span> Players 55 </div> 56 57 <div id="adminmenu"> 58 Menu 59 <ul> 60 <li><a href="#tab_map" data-permission="web.map">Map</a></li> 61 <li><a href="#tab_log" data-permission="web.log">Log</a></li> 62 </ul> 63 </div> 51 64 52 65 <div id="userstate"> … … 67 80 </div> 68 81 <div class="admincontent"> 82 <h1 id="nopermissionwarning" style="display:none">An error occured or you do not have any permissions on this WebPanel. Log in with the link on the lower left!</h1> 69 83 <div id="tab_map" class="adminmap"></div> 70 84 <div id="tab_log" class="adminlog"></div> … … 74 88 75 89 <div id="playerInventoryDialog" title="Player inventory"> 76 Player: <span id="invPlayerName"></span> 77 <table class="invTable" id="bagTable"> 90 Player: <span id="invPlayerName"></span><br/> 91 <table> 92 <tr> 93 <td> 94 Inventory:<br/> 95 <table class="invTable" id="bagTable"> 96 </table> 97 </td> 98 <td rowspan="2"> 99 Equipment:<br/> 100 <table class="invTable" id="equipmentTable"> 101 </table> 102 </td> 103 </tr> 104 <tr> 105 <td> 106 Belt:<br/> 107 <table class="invTable" id="beltTable"> 108 </table> 109 </td> 110 </tr> 78 111 </table> 79 <br/> 80 <table class="invTable" id="beltTable"> 81 </table> 112 82 113 </div> 83 114 -
binary-improvements/webserver/js/index.js
r244 r245 1 // =============================================================================================== 2 // Constants 1 InitializeTabs (); 2 SetupInventoryDialog (); 3 InitPermissions (); 3 4 4 var mapinfo = {5 regionsize: 512,6 chunksize: 16,7 tilesize: 128,8 maxzoom: 49 }10 11 var BAG_COLS = 8;12 var BAG_ROWS = 4;13 var BELT_COLS = 8;14 var INV_ITEM_WIDTH = 58;15 var INV_ITEM_HEIGHT = 40;16 17 var userdata = false;18 19 20 function initMap() {21 // ===============================================================================================22 // 7dtd coordinate transformations23 24 SDTD_Projection = {25 project: function (latlng) {26 return new L.Point(27 (latlng.lat) / Math.pow(2, mapinfo.maxzoom),28 (latlng.lng) / Math.pow(2, mapinfo.maxzoom) );29 },30 31 unproject: function (point) {32 return new L.LatLng(33 point.x * Math.pow(2, mapinfo.maxzoom),34 point.y * Math.pow(2, mapinfo.maxzoom) );35 }36 };37 38 SDTD_CRS = L.extend({}, L.CRS.Simple, {39 projection: SDTD_Projection,40 transformation: new L.Transformation(1, 0, -1, 0),41 42 scale: function (zoom) {43 return Math.pow(2, zoom);44 }45 });46 47 48 49 50 // ===============================================================================================51 // Map and basic tile layers52 53 var initTime = new Date().getTime();54 55 map = L.map('tab_map', {56 zoomControl: false, // Added by Zoomslider57 zoomsliderControl: true,58 attributionControl: false,59 crs: SDTD_CRS60 }).setView([0, 0], Math.max(0, mapinfo.maxzoom - 5));61 62 var tileLayer = L.tileLayer('../map/{z}/{x}/{y}.png?t={time}', {63 maxZoom: mapinfo.maxzoom + 1,64 minZoom: Math.max(0, mapinfo.maxzoom - 5),65 maxNativeZoom: mapinfo.maxzoom,66 tileSize: mapinfo.tilesize,67 continuousWorld: true,68 tms: true,69 unloadInvisibleTiles: false,70 time: initTime71 });72 73 // TileLayer w/ TMS=true fix for zoomlevel >= 874 tileLayer._getWrapTileNum = function () {75 return L.point(0, 0);76 };77 78 var tileLayerMiniMap = L.tileLayer('../map/{z}/{x}/{y}.png?t={time}', {79 maxZoom: mapinfo.maxzoom,80 minZoom: 0,81 maxNativeZoom: mapinfo.maxzoom,82 tileSize: mapinfo.tilesize,83 continuousWorld: true,84 tms: true,85 unloadInvisibleTiles: false,86 time: initTime87 });88 89 90 91 92 93 94 95 // ===============================================================================================96 // Overlays and controls97 98 var playersOnlineMarkerGroup = L.layerGroup();99 var playersOfflineMarkerGroup = L.markerClusterGroup({100 maxClusterRadius: function(zoom) { return zoom == mapinfo.maxzoom ? 10 : 50; }101 });102 103 104 var landClaimsGroup = L.layerGroup();105 var landClaimsClusterGroup = L.markerClusterGroup({106 disableClusteringAtZoom: mapinfo.maxzoom,107 singleMarkerMode: true,108 maxClusterRadius: 50109 });110 var landClaimsRectGroup = L.layerGroup();111 landClaimsGroup.addLayer(landClaimsClusterGroup);112 landClaimsGroup.addLayer(landClaimsRectGroup);113 var maxZoomForCluster = 4;114 115 var baseLayers = {116 //"Map": tileLayer117 };118 119 var layerControl = L.control.layers(baseLayers, null, {120 collapsed: false121 });122 123 var layerCount = 0;124 125 126 if (hasPermission ("web.map")) {127 tileLayer.addTo(map);128 new L.Control.Coordinates({}).addTo(map);129 new L.Control.ReloadTiles({layers: [tileLayer, tileLayerMiniMap]}).addTo(map);130 layerControl.addOverlay (GetRegionLayer (mapinfo), "Region files");131 var miniMap = new L.Control.MiniMap(tileLayerMiniMap, {132 zoomLevelOffset: -6,133 toggleDisplay: true134 }).addTo(map);135 136 if (hasPermission ("webapi.getstats")) {137 new L.Control.GameTime({}).addTo(map);138 }139 }140 if (hasPermission ("webapi.getlandclaims")) {141 layerControl.addOverlay (landClaimsGroup, "Land claims");142 layerCount++;143 }144 if (hasPermission ("webapi.getplayerslocation")) {145 layerControl.addOverlay (playersOfflineMarkerGroup, "Players (offline) (<span id='mapControlOfflineCount'>0</span>)");146 layerControl.addOverlay (playersOnlineMarkerGroup, "Players (online) (<span id='mapControlOnlineCount'>0</span>)");147 layerCount++;148 }149 150 if (layerCount > 0) {151 layerControl.addTo(map);152 }153 154 155 var playersMappingList = {};156 157 158 159 // ===============================================================================================160 // Inventory dialog161 162 var showInv = function(steamid) {163 $.getJSON( "../api/getplayerinventory", { steamid: steamid })164 .done(function(data) {165 $("#invPlayerName").text(playersMappingList[steamid].name);166 for (var y = 0; y < BAG_ROWS; y++) {167 for (var x = 0; x < BAG_COLS; x++) {168 if (data.bag[y*BAG_COLS+x].count > 0) {169 $("#bagField"+x+"_"+y).attr("style", "background-image: url(../itemicons/" + data.bag[y*BAG_COLS+x].name + ".png);").attr("title", data.bag[y*BAG_COLS+x].name);170 $("#bagFieldText"+x+"_"+y).text(data.bag[y*BAG_COLS+x].count);171 } else {172 $("#bagField"+x+"_"+y).attr("style", "background-image: none;");173 $("#bagFieldText"+x+"_"+y).text("");174 }175 }176 }177 178 for (var x = 0; x < BELT_COLS; x++) {179 if (data.belt[x].count > 0) {180 $("#beltField"+x).attr("style", "background-image: url(../itemicons/" + data.belt[x].name + ".png);").attr("title", data.belt[x].name);181 $("#beltFieldText"+x).text(data.belt[x].count);182 } else {183 $("#beltField"+x).attr("style", "background-image: none;");184 $("#beltFieldText"+x).text("");185 }186 }187 188 $( "#playerInventoryDialog" ).css("z-index", "1010").dialog({189 modal: true,190 width: BAG_COLS*(INV_ITEM_WIDTH+14) + 20,191 buttons: {192 Ok: function() {193 $( this ).dialog( "close" );194 }195 }196 });197 })198 .fail(function(jqxhr, textStatus, error) {199 console.log("Error fetching player inventory");200 })201 .always(function() {202 });203 };204 205 for (var y = 0; y < BAG_ROWS; y++) {206 $("#bagTable").append("<tr id=\"bagRow"+y+"\"></tr>");207 for (var x = 0; x < BAG_COLS; x++) {208 $("#bagRow"+y).append(209 "<td class=\"invField\" id=\"bagField"+x+"_"+y+"\">" +210 "<span class=\"invFieldText\" id=\"bagFieldText"+x+"_"+y+"\"></span>" +211 "</td>");212 }213 }214 215 $("#beltTable").append("<tr id=\"beltRow0\"></tr>");216 for (var x = 0; x < BELT_COLS; x++) {217 $("#beltRow0").append(218 "<td class=\"invField\" id=\"beltField"+x+"\">" +219 "<span class=\"invFieldText\" id=\"beltFieldText"+x+"\"></span>" +220 "</td>");221 }222 223 224 225 // ===============================================================================================226 // Player markers227 228 $(".leaflet-popup-pane").on('click.action', '.inventoryButton', function(event) {229 showInv($(this).data('steamid'));230 });231 232 var setPlayerMarkers = function(data) {233 var online = 0;234 var offline = 0;235 $.each( data, function( key, val ) {236 var marker;237 if (playersMappingList.hasOwnProperty(val.steamid)) {238 marker = playersMappingList[val.steamid].currentPosMarker;239 marker.setLatLng([val.position.x, val.position.z]);240 } else {241 marker = L.marker([val.position.x, val.position.z]).bindPopup(242 "Player: " + val.name +243 (hasPermission ("webapi.getplayerinventory") ?244 "<br/><a class='inventoryButton' data-steamid='"+val.steamid+"'>Show inventory</a>"245 : "")246 );247 playersMappingList[val.steamid] = { online: !val.online };248 }249 if (playersMappingList[val.steamid].online != val.online) {250 if (val.online) {251 marker.setOpacity(1.0);252 playersOfflineMarkerGroup.removeLayer(marker);253 playersOnlineMarkerGroup.addLayer(marker);254 } else {255 marker.setOpacity(0.5);256 playersOnlineMarkerGroup.removeLayer(marker);257 playersOfflineMarkerGroup.addLayer(marker);258 }259 }260 val.currentPosMarker = marker;261 playersMappingList[val.steamid] = val;262 263 if (val.online)264 online++;265 else266 offline++;267 });268 $( "#mapControlOnlineCount" ).text( online );269 $( "#mapControlOfflineCount" ).text( offline );270 }271 272 var updatePlayerEvent = function() {273 $.getJSON( "../api/getplayerslocation")274 .done(setPlayerMarkers)275 .fail(function(jqxhr, textStatus, error) {276 console.log("Error fetching players list");277 })278 .always(function() {279 window.setTimeout(updatePlayerEvent, 2000);280 });281 }282 283 if (hasPermission ("webapi.getplayerslocation")) {284 window.setTimeout(updatePlayerEvent, 0);285 }286 287 288 289 // ===============================================================================================290 // Land claim markers291 292 var setLandClaims = function(data) {293 landClaimsClusterGroup.clearLayers();294 landClaimsRectGroup.clearLayers();295 296 var claimPower = Math.floor(Math.log(data.claimsize) / Math.LN2);297 var maxClusterZoomUnlimited = mapinfo.maxzoom - (claimPower - 3);298 var maxClusterZoomLimitedMax = Math.min(maxClusterZoomUnlimited, mapinfo.maxzoom+1);299 maxZoomForCluster = Math.max(maxClusterZoomLimitedMax, 0);300 301 checkClaimClustering({target: map});302 303 var sizeHalf = Math.floor(data.claimsize / 2);304 305 $.each( data.claimowners, function( key, val ) {306 var steamid = val.steamid;307 var active = val.claimactive;308 var color = active ? "#55ff55" : "#ff0000";309 310 $.each( val.claims, function( key, val ) {311 var pos = L.latLng(val.x, val.z);312 var bounds = L.latLngBounds(L.latLng(val.x - sizeHalf, val.z - sizeHalf), L.latLng(val.x + sizeHalf, val.z + sizeHalf));313 var r = L.rectangle(bounds, {color: color, weight: 1, opacity: 0.8, fillOpacity: 0.15});314 var m = L.marker(pos, { clickable: false, keyboard: false, zIndexOffset:-1000, iconSize: [0,0], icon: L.divIcon({className: 'invisIcon', iconSize:[0,0]}) });315 if (playersMappingList.hasOwnProperty(steamid)) {316 var name = playersMappingList[steamid].name;317 } else {318 var name = "unknown"319 }320 r.bindPopup("Owner: " + name + " ("+steamid+")<br/>Position: " + val.x + " / " + val.y + " / " + val.z);321 landClaimsRectGroup.addLayer(r);322 landClaimsClusterGroup.addLayer(m);323 });324 });325 }326 327 var updateClaimsEvent = function() {328 $.getJSON( "../api/getlandclaims")329 .done(setLandClaims)330 .fail(function(jqxhr, textStatus, error) {331 console.log("Error fetching land claim list");332 })333 .always(function() {334 //updateClaimTimer = window.setTimeout(updateClaimsEvent, 3000);335 });336 }337 338 339 340 // ===============================================================================================341 // Layer events342 343 var updateClaimTimer;344 map.on('overlayadd', function(e) {345 if (e.layer == landClaimsGroup) {346 updateClaimsEvent();347 }348 });349 350 map.on('overlayremove', function(e) {351 if (e.layer == landClaimsGroup) {352 //window.clearTimeout(updateClaimTimer);353 }354 });355 356 var checkClaimClustering = function(e) {357 if (e.target._zoom >= maxZoomForCluster) {358 landClaimsGroup.removeLayer(landClaimsClusterGroup);359 } else {360 landClaimsGroup.addLayer(landClaimsClusterGroup);361 }362 };363 364 map.on('zoomend', checkClaimClustering);365 366 }367 368 369 370 371 function doTabs () {372 $(".adminmenu > ul > li").addClass ("menu_button");373 $(".admincontent > div").addClass ("contenttab");374 $(".adminmenu .menu_button").first ().addClass ("current_tab");375 $(".menu_button").on ('click.action', null, function (event) {376 var menuElement = $(this);377 var linkElement = menuElement.children ("a");378 var linkName = linkElement.attr ("href");379 380 $("*").removeClass ("current_tab");381 menuElement.addClass ("current_tab");382 $(linkName).addClass ("current_tab");383 });384 385 $(".adminmenu .menu_button").first ().click ();386 }387 388 function initMapInfo () {389 $.getJSON( "../map/mapinfo.json")390 .done(function(data) {391 mapinfo.tilesize = data.blockSize;392 mapinfo.maxzoom = data.maxZoom;393 })394 .fail(function(jqxhr, textStatus, error) {395 console.log("Error fetching map information");396 })397 .always(function() {398 initMap();399 });400 }401 402 function initUser () {403 $.getJSON( "../userstatus")404 .done(function(data) {405 userdata = data;406 407 var userdataDiv = $("#userstate");408 if (userdata.loggedin == true) {409 var data = userdataDiv.children ("#userstate_loggedin");410 data.attr ("style", "display: block");411 data.children ("#username").attr ("href", "http://steamcommunity.com/profiles/" + userdata.username);412 data.children ("#username").html (userdata.username);413 } else {414 var data = userdataDiv.children ("#userstate_loggedout");415 data.attr ("style", "display: block");416 }417 418 initMapInfo ();419 })420 .fail(function(jqxhr, textStatus, error) {421 console.log("Error fetching user data");422 })423 }424 425 doTabs ();426 initUser (); -
binary-improvements/webserver/js/util.js
r244 r245 11 11 } 12 12 13 function hasPermission (modulename) {14 for (var i = 0; i < userdata.permissions.length; i++) {15 if (userdata.permissions [i].module == modulename) {16 return userdata.permissions [i].allowed;17 }18 }19 return false;20 }21
Note:
See TracChangeset
for help on using the changeset viewer.