Changeset 250
- Timestamp:
- Aug 12, 2015, 6:10:28 PM (9 years ago)
- Location:
- binary-improvements
- Files:
-
- 4 added
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/ModInfo.xml
r246 r250 5 5 <Description value="Common functions" /> 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/7dtd-server-fixes/src/PersistentData/InvItem.cs
r145 r250 9 9 public string itemName; 10 10 public int count; 11 public int quality; 12 public InvItem[] parts; 11 13 12 public InvItem (string itemName, int count )14 public InvItem (string itemName, int count, int quality = -1) 13 15 { 14 16 this.itemName = itemName; 15 17 this.count = count; 18 this.quality = quality; 16 19 } 17 20 } -
binary-improvements/7dtd-server-fixes/src/PersistentData/Inventory.cs
r245 r250 23 23 ProcessInv (bag, pdf.bag, pdf.id); 24 24 ProcessInv (belt, pdf.inventory, pdf.id); 25 ProcessEqu (pdf.equipment );25 ProcessEqu (pdf.equipment, pdf.id); 26 26 } 27 27 } … … 30 30 target.Clear (); 31 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 37 if (count > maxAllowed) { 38 Log.Out ("Player with ID " + id + " has stack for \"" + name + "\" greater than allowed (" + count + " > " + maxAllowed + ")"); 39 } 40 target.Add (new InvItem (name, count)); 41 } else { 42 target.Add (null); 32 InvItem item = CreateInvItem (sourceFields [i].itemValue, sourceFields [i].count, id); 33 if (item != null && sourceFields [i].itemValue.Parts != null) { 34 ProcessParts (sourceFields [i].itemValue.Parts, item, id); 43 35 } 36 target.Add (item); 44 37 } 45 38 } 46 39 47 private void ProcessEqu (Equipment sourceEquipment ) {40 private void ProcessEqu (Equipment sourceEquipment, int _playerId) { 48 41 equipment = new InvItem[sourceEquipment.GetSlotCount ()]; 49 42 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 ();43 equipment [i] = CreateInvItem (sourceEquipment.GetSlotItem (i), 1, _playerId); 44 } 45 } 53 46 54 equipment [i] = new InvItem (name, count); 47 private void ProcessParts (ItemValue[] _parts, InvItem _item, int _playerId) { 48 InvItem[] itemParts = new InvItem[_parts.Length]; 49 for (int i = 0; i < _parts.Length; i++) { 50 InvItem partItem = CreateInvItem (_parts [i], 1, _playerId); 51 if (partItem != null && _parts [i].Parts != null) { 52 ProcessParts (_parts [i].Parts, partItem, _playerId); 53 } 54 itemParts [i] = partItem; 55 } 56 _item.parts = itemParts; 57 } 58 59 private InvItem CreateInvItem (ItemValue _itemValue, int _count, int _playerId) { 60 if (_count > 0 && _itemValue != null && !_itemValue.Equals (ItemValue.None)) { 61 int maxAllowed = ItemClass.list [_itemValue.type].Stacknumber.Value; 62 string name = ItemClass.list [_itemValue.type].GetItemName (); 63 64 if (_count > maxAllowed) { 65 Log.Out ("Player with ID " + _playerId + " has stack for \"" + name + "\" greater than allowed (" + _count + " > " + maxAllowed + ")"); 66 } 67 68 InvItem item = null; 69 if (_itemValue.HasQuality) { 70 item = new InvItem (name, _count, _itemValue.Quality); 55 71 } else { 56 equipment [i] = null;72 item = new InvItem (name, _count); 57 73 } 74 return item; 75 } else { 76 return null; 58 77 } 59 78 } -
binary-improvements/AllocsCommands/Commands/Give.cs
r238 r250 5 5 namespace AllocsFixes.CustomCommands 6 6 { 7 public class Give : ConsoleCmdAbstract 8 { 9 public override string GetDescription () 10 { 7 public class Give : ConsoleCmdAbstract { 8 public override string GetDescription () { 11 9 return "give an item to a player (entity id or name)"; 12 10 } … … 14 12 public override string GetHelp () { 15 13 return "Give an item to a player by dropping it in front of that player\n" + 16 "Usage:\n" + 17 " give <name / entity id> <item name> <amount>\n" + 18 "Either pass the full name of a player or his entity id (given by e.g. \"lpi\").\n" + 19 "Item name has to be the exact name of an item as listed by \"listitems\".\n" + 20 "Amount is the number of instances of this item to drop (as a single stack)."; 14 "Usage:\n" + 15 " give <name / entity id> <item name> <amount>\n" + 16 " give <name / entity id> <item name> <amount> <quality>\n" + 17 "Either pass the full name of a player or his entity id (given by e.g. \"lpi\").\n" + 18 "Item name has to be the exact name of an item as listed by \"listitems\".\n" + 19 "Amount is the number of instances of this item to drop (as a single stack).\n" + 20 "Quality is the quality of the dropped items for items that have a quality."; 21 21 } 22 22 23 public override string[] GetCommands () 24 { 23 public override string[] GetCommands () { 25 24 return new string[] { "give", string.Empty }; 26 25 } 27 26 28 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) 29 { 27 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) { 30 28 try { 31 if (_params.Count != 3 ) {32 SdtdConsole.Instance.Output ("Wrong number of arguments, expected 3 , found " + _params.Count + ".");29 if (_params.Count != 3 && _params.Count != 4) { 30 SdtdConsole.Instance.Output ("Wrong number of arguments, expected 3 or 4, found " + _params.Count + "."); 33 31 return; 34 32 } … … 41 39 } 42 40 43 ItemValue iv = ItemList.Instance.GetItemValue (_params [1]);41 ItemValue iv = ItemList.Instance.GetItemValue (_params [1]); 44 42 if (iv == null) { 45 43 SdtdConsole.Instance.Output ("Item not found."); … … 51 49 SdtdConsole.Instance.Output ("Amount is not an integer or not greater than zero."); 52 50 return; 51 } 52 53 if (_params.Count == 4) { 54 if (!iv.HasQuality) { 55 SdtdConsole.Instance.Output ("Item " + _params [1] + " does not support quality."); 56 return; 57 } 58 59 int quality = int.MinValue; 60 if (!int.TryParse (_params [3], out quality) || quality <= 0) { 61 SdtdConsole.Instance.Output ("Quality is not an integer or not greater than zero."); 62 return; 63 } 64 iv.Quality = quality; 53 65 } 54 66 -
binary-improvements/AllocsCommands/Commands/ShowInventory.cs
r238 r250 5 5 namespace AllocsFixes.CustomCommands 6 6 { 7 public class ShowInventory : ConsoleCmdAbstract 8 { 9 public override string GetDescription () 10 { 7 public class ShowInventory : ConsoleCmdAbstract { 8 public override string GetDescription () { 11 9 return "list inventory of a given player"; 12 10 } … … 14 12 public override string GetHelp () { 15 13 return "Usage:\n" + 16 17 18 19 20 14 " showinventory <steam id / player name / entity id>\n" + 15 "Show the inventory of the player given by his SteamID, player name or\n" + 16 "entity id (as given by e.g. \"lpi\")." + 17 "Note: This only shows the player's inventory after it was first sent to\n" + 18 "the server which happens at least every 30 seconds."; 21 19 } 22 20 23 public override string[] GetCommands () 24 { 21 public override string[] GetCommands () { 25 22 return new string[] { "showinventory", "si" }; 26 23 } 27 24 28 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) 29 { 25 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) { 30 26 try { 31 27 if (_params.Count < 1) { … … 44 40 45 41 SdtdConsole.Instance.Output ("Belt of player " + p.Name + ":"); 46 for (int i = 0; i < inv.belt.Count; i++) { 47 if (inv.belt [i] != null) 48 SdtdConsole.Instance.Output (string.Format (" Slot {0}: {1:000} * {2}", i, inv.belt [i].count, inv.belt [i].itemName)); 49 } 42 PrintInv (inv.belt); 50 43 SdtdConsole.Instance.Output (string.Empty); 44 51 45 SdtdConsole.Instance.Output ("Bagpack of player " + p.Name + ":"); 52 for (int i = 0; i < inv.bag.Count; i++) { 53 if (inv.bag [i] != null) 54 SdtdConsole.Instance.Output (string.Format (" Slot {0}: {1:000} * {2}", i, inv.bag [i].count, inv.bag [i].itemName)); 55 } 46 PrintInv (inv.bag); 56 47 SdtdConsole.Instance.Output (string.Empty); 48 49 SdtdConsole.Instance.Output ("Equipment of player " + p.Name + ":"); 50 PrintEquipment (inv.equipment); 51 57 52 } catch (Exception e) { 58 53 Log.Out ("Error in ShowInventory.Run: " + e); 59 54 } 60 55 } 56 57 private void PrintInv (List<InvItem> _inv) { 58 for (int i = 0; i < _inv.Count; i++) { 59 if (_inv [i] != null) { 60 if (_inv [i].quality < 0) { 61 SdtdConsole.Instance.Output (string.Format (" Slot {0}: {1:000} * {2}", i, _inv [i].count, _inv [i].itemName)); 62 } else { 63 SdtdConsole.Instance.Output (string.Format (" Slot {0}: {1:000} * {2} - quality: {3}", i, _inv [i].count, _inv [i].itemName, _inv [i].quality)); 64 } 65 DoParts (_inv [i].parts, 1); 66 } 67 } 68 } 69 70 private void PrintEquipment (InvItem[] _equipment) { 71 AddEquipment ("head", _equipment, XMLData.Item.EnumEquipmentSlot.Head, NGuiInvGridEquipment.EnumClothingLayer.Middle); 72 AddEquipment ("eyes", _equipment, XMLData.Item.EnumEquipmentSlot.Eyes, NGuiInvGridEquipment.EnumClothingLayer.Middle); 73 AddEquipment ("face", _equipment, XMLData.Item.EnumEquipmentSlot.Face, NGuiInvGridEquipment.EnumClothingLayer.Middle); 74 75 AddEquipment ("armor", _equipment, XMLData.Item.EnumEquipmentSlot.Chest, NGuiInvGridEquipment.EnumClothingLayer.Outer); 76 AddEquipment ("jacket", _equipment, XMLData.Item.EnumEquipmentSlot.Chest, NGuiInvGridEquipment.EnumClothingLayer.Middle); 77 AddEquipment ("shirt", _equipment, XMLData.Item.EnumEquipmentSlot.Chest, NGuiInvGridEquipment.EnumClothingLayer.Inner); 78 79 AddEquipment ("legarmor", _equipment, XMLData.Item.EnumEquipmentSlot.Legs, NGuiInvGridEquipment.EnumClothingLayer.Outer); 80 AddEquipment ("pants", _equipment, XMLData.Item.EnumEquipmentSlot.Legs, NGuiInvGridEquipment.EnumClothingLayer.Inner); 81 AddEquipment ("boots", _equipment, XMLData.Item.EnumEquipmentSlot.Feet, NGuiInvGridEquipment.EnumClothingLayer.Inner); 82 83 AddEquipment ("gloves", _equipment, XMLData.Item.EnumEquipmentSlot.Hands, NGuiInvGridEquipment.EnumClothingLayer.Inner); 84 AddEquipment ("backpack", _equipment, XMLData.Item.EnumEquipmentSlot.Back, NGuiInvGridEquipment.EnumClothingLayer.Outer); 85 } 86 87 private void AddEquipment (string _slotname, InvItem[] _items, XMLData.Item.EnumEquipmentSlot _slot, NGuiInvGridEquipment.EnumClothingLayer _layer) { 88 int index = (int)_slot + (int)_layer * (int)XMLData.Item.EnumEquipmentSlot.Count; 89 if (_items != null && _items [index] != null) { 90 if (_items [index].quality < 0) { 91 SdtdConsole.Instance.Output (string.Format (" Slot {0:8}: {1:000}", _slotname, _items [index].itemName)); 92 } else { 93 SdtdConsole.Instance.Output (string.Format (" Slot {0:8}: {1:000} - quality: {2}", _slotname, _items [index].itemName, _items [index].quality)); 94 } 95 DoParts (_items [index].parts, 1); 96 } 97 } 98 99 private void DoParts (InvItem[] _parts, int _indent) { 100 if (_parts != null && _parts.Length > 0) { 101 string indenter = new string (' ', _indent * 4); 102 for (int i = 0; i < _parts.Length; i++) { 103 if (_parts [i] != null) { 104 if (_parts [i].quality < 0) { 105 SdtdConsole.Instance.Output (string.Format ("{0} - {1}", indenter, _parts [i].itemName)); 106 } else { 107 SdtdConsole.Instance.Output (string.Format ("{0} - {1} - quality: {2}", indenter, _parts [i].itemName, _parts [i].quality)); 108 } 109 DoParts (_parts [i].parts, _indent + 1); 110 } 111 } 112 } 113 } 114 61 115 } 62 116 } -
binary-improvements/AllocsCommands/Commands/TeleportPlayer.cs
r238 r250 5 5 namespace AllocsFixes.CustomCommands 6 6 { 7 public class TeleportPlayer : ConsoleCmdAbstract 8 { 9 public override string GetDescription () 10 { 7 public class TeleportPlayer : ConsoleCmdAbstract { 8 public override string GetDescription () { 11 9 return "teleport a player to a given location"; 12 10 } … … 14 12 public override string GetHelp () { 15 13 return "Usage:\n" + 16 " 1. teleportplayer <steam id / player name / entity id> <x> <y> <z>\n" + 17 " 2. teleportplayer <steam id / player name / entity id> <target steam id / player name / entity id>\n" + 18 "1. Teleports the player given by his SteamID, player name or entity id (as given by e.g. \"lpi\")\n" + 19 " to the specified location\n" + 20 "2. As 1, but destination given by another player which has to be online"; 14 " 1. teleportplayer <steam id / player name / entity id> <x> <y> <z>\n" + 15 " 2. teleportplayer <steam id / player name / entity id> <target steam id / player name / entity id>\n" + 16 " 3. teleportplayer <inc x> <inc y> <inc z>\n" + 17 "1. Teleports the player given by his SteamID, player name or entity id (as given by e.g. \"lpi\")\n" + 18 " to the specified location\n" + 19 "2. As 1, but destination given by another player which has to be online\n" + 20 "3. Teleport the local player to the position calculated by his current position and the given offsets"; 21 21 } 22 22 23 public override string[] GetCommands () 24 { 23 public override string[] GetCommands () { 25 24 return new string[] { "teleportplayer", "tele" }; 26 25 } 27 26 28 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) 29 { 27 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) { 30 28 try { 31 if (_params.Count != 4 && _params.Count != 2) {32 SdtdConsole.Instance.Output (" Usage: teleportplayer <entityid|playername|steamid> <x> <y> <z>");33 SdtdConsole.Instance.Output (" or: teleportplayer <entityid|playername|steamid> <target entityid|playername|steamid>");29 if (_params.Count < 2 || _params.Count > 4) { 30 SdtdConsole.Instance.Output ("Wrong number of arguments, expected 2 to 4, found " + _params.Count + "."); 31 return; 34 32 } else { 35 ClientInfo ci1 = ConsoleHelper.ParseParamIdOrName (_params [0]); 36 if (ci1 == null) { 37 SdtdConsole.Instance.Output ("Playername or entity/steamid id not found."); 38 return; 39 } 40 EntityPlayer ep1 = GameManager.Instance.World.Players.dict [ci1.entityId]; 33 ClientInfo ci1 = null; 34 EntityPlayer ep1 = null; 35 36 if (_params.Count == 2 || _params.Count == 4) { 37 ci1 = ConsoleHelper.ParseParamIdOrName (_params [0]); 38 if (ci1 == null) { 39 SdtdConsole.Instance.Output ("Playername or entity/steamid id not found."); 40 return; 41 } 42 ep1 = GameManager.Instance.World.Players.dict [ci1.entityId]; 41 43 42 if (_params.Count == 4) { 44 if (_params.Count == 4) { 45 int x = int.MinValue; 46 int y = int.MinValue; 47 int z = int.MinValue; 48 49 int.TryParse (_params [1], out x); 50 int.TryParse (_params [2], out y); 51 int.TryParse (_params [3], out z); 52 53 if (x == int.MinValue || y == int.MinValue || z == int.MinValue) { 54 SdtdConsole.Instance.Output ("At least one of the given coordinates is not a valid integer"); 55 return; 56 } 57 58 ep1.position.x = x; 59 ep1.position.y = y; 60 ep1.position.z = z; 61 } else if (_params.Count == 2) { 62 ClientInfo ci2 = ConsoleHelper.ParseParamIdOrName (_params [1]); 63 if (ci2 == null) { 64 SdtdConsole.Instance.Output ("Target playername or entity/steamid id not found."); 65 return; 66 } 67 EntityPlayer ep2 = GameManager.Instance.World.Players.dict [ci2.entityId]; 68 69 ep1.position = ep2.GetPosition (); 70 ep1.position.y += 1; 71 ep1.position.z += 1; 72 } 73 } else if (_params.Count == 3) { 74 if (_senderInfo.RemoteClientInfo == null) { 75 SdtdConsole.Instance.Output ("This command can only be executed on the in-game console."); 76 return; 77 } 78 79 ci1 = _senderInfo.RemoteClientInfo; 80 ep1 = GameManager.Instance.World.Players.dict [ci1.entityId]; 81 43 82 int x = int.MinValue; 44 83 int y = int.MinValue; 45 84 int z = int.MinValue; 46 85 47 int.TryParse (_params [ 1], out x);48 int.TryParse (_params [ 2], out y);49 int.TryParse (_params [ 3], out z);86 int.TryParse (_params [0], out x); 87 int.TryParse (_params [1], out y); 88 int.TryParse (_params [2], out z); 50 89 51 90 if (x == int.MinValue || y == int.MinValue || z == int.MinValue) { … … 54 93 } 55 94 56 ep1.position.x = x; 57 ep1.position.y = y; 58 ep1.position.z = z; 59 } else { 60 ClientInfo ci2 = ConsoleHelper.ParseParamIdOrName (_params [1]); 61 if (ci2 == null) { 62 SdtdConsole.Instance.Output ("Target playername or entity/steamid id not found."); 63 return; 64 } 65 EntityPlayer ep2 = GameManager.Instance.World.Players.dict [ci2.entityId]; 66 67 ep1.position = ep2.GetPosition(); 68 ep1.position.y += 1; 69 ep1.position.z += 1; 95 ep1.position.x = ep1.position.x + x; 96 ep1.position.y = ep1.position.y + y; 97 ep1.position.z = ep1.position.z + z; 70 98 } 71 99 -
binary-improvements/AllocsCommands/ModInfo.xml
r238 r250 5 5 <Description value="Additional commands for server operation" /> 6 6 <Author value="Christian 'Alloc' Illy" /> 7 <Version value=" 4" />7 <Version value="5" /> 8 8 <Website value="http://7dtd.illy.bz" /> 9 9 </ModInfo> -
binary-improvements/MapRendering/API.cs
r230 r250 7 7 public override void GameAwake () { 8 8 new AllocsFixes.NetConnections.Servers.Web.Web (); 9 AllocsFixes.NetConnections.Servers.Web.LogBuffer.Instance.GetType (); 9 10 } 10 11 -
binary-improvements/MapRendering/ModInfo.xml
r249 r250 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=" 8" />7 <Version value="9" /> 8 8 <Website value="http://7dtd.illy.bz" /> 9 9 </ModInfo> -
binary-improvements/MapRendering/Web/API/GetPlayerInventory.cs
r245 r250 35 35 result.Add ("equipment", equipment); 36 36 37 for (int i = 0; i < inv.belt.Count; i++) { 38 JSONObject item = new JSONObject (); 39 if (inv.belt [i] != null) { 40 item.Add ("count", new JSONNumber (inv.belt [i].count)); 41 item.Add ("name", new JSONString (inv.belt [i].itemName)); 42 } else { 43 item.Add ("count", new JSONNumber (0)); 44 item.Add ("name", new JSONString (string.Empty)); 45 } 46 belt.Add (item); 47 } 48 for (int i = 0; i < inv.bag.Count; i++) { 49 JSONObject item = new JSONObject (); 50 if (inv.bag [i] != null) { 51 item.Add ("count", new JSONNumber (inv.bag [i].count)); 52 item.Add ("name", new JSONString (inv.bag [i].itemName)); 53 } else { 54 item.Add ("count", new JSONNumber (0)); 55 item.Add ("name", new JSONString (string.Empty)); 56 } 57 bag.Add (item); 58 } 37 DoInventory (belt, inv.belt); 38 DoInventory (bag, inv.bag); 59 39 60 40 AddEquipment (equipment, "head", inv.equipment, XMLData.Item.EnumEquipmentSlot.Head, NGuiInvGridEquipment.EnumClothingLayer.Middle); … … 76 56 } 77 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 78 64 private void AddEquipment (JSONObject _eq, string _slotname, InvItem[] _items, XMLData.Item.EnumEquipmentSlot _slot, NGuiInvGridEquipment.EnumClothingLayer _layer) { 79 65 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));66 if (_items != null) { 67 _eq.Add (_slotname, GetJsonForItem (_items [index])); 82 68 } else { 83 _eq.Add (_slotname, new JSONBoolean (false)); 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 ("quality", new JSONNumber (_item.quality)); 79 if (_item.quality >= 0) { 80 jsonItem.Add ("qualitycolor", new JSONString (QualityInfo.GetQualityColorHex (_item.quality))); 81 } 82 return jsonItem; 83 } else { 84 return new JSONNull (); 84 85 } 85 86 } -
binary-improvements/MapRendering/Web/ConnectionHandler.cs
r244 r250 50 50 } 51 51 52 public void SendLog (string text, string trace, UnityEngine.LogType type) {53 foreach (WebConnection wc in connections.Values) {54 wc.SendLog (text, trace, type);55 }56 }57 58 52 } 59 53 } -
binary-improvements/MapRendering/Web/Handlers/ApiHandler.cs
r247 r250 4 4 using System.IO; 5 5 using System.Net; 6 using System.Reflection; 6 7 using System.Threading; 7 8 … … 14 15 public ApiHandler (string staticPart, string moduleName = null) : base(moduleName) { 15 16 this.staticPart = staticPart; 16 addApi ("getlandclaims", new GetLandClaims ()); 17 addApi ("getplayersonline", new GetPlayersOnline ()); 18 addApi ("getplayerslocation", new GetPlayersLocation ()); 19 addApi ("getplayerinventory", new GetPlayerInventory ()); 20 addApi ("getstats", new GetStats ()); 17 18 foreach (Type t in Assembly.GetExecutingAssembly ().GetTypes ()) { 19 if (!t.IsAbstract && t.IsSubclassOf (typeof(WebAPI))) { 20 ConstructorInfo ctor = t.GetConstructor (new Type[0]); 21 if (ctor != null) { 22 WebAPI apiInstance = (WebAPI)ctor.Invoke (new object[0]); 23 addApi (t.Name.ToLower (), apiInstance); 24 } 25 } 26 } 21 27 } 22 28 … … 38 44 } else { 39 45 foreach (KeyValuePair<string, WebAPI> kvp in apis) { 40 try{41 if (apiName.StartsWith (kvp.Key)){46 if (apiName.StartsWith (kvp.Key)) { 47 try { 42 48 kvp.Value.HandleRequest (req, resp, user, permissionLevel); 43 49 return; 50 } catch (Exception e) { 51 Log.Error ("Error in ApiHandler.HandleRequest(): Handler {0} threw an exception:", kvp.Key); 52 Log.Exception (e); 53 resp.StatusCode = (int)HttpStatusCode.InternalServerError; 54 return; 44 55 } 45 } catch (Exception e) {46 Log.Out ("Error in ApiHandler.HandleRequest(): Handler threw an exception: " + e);47 resp.StatusCode = (int)HttpStatusCode.InternalServerError;48 return;49 56 } 50 57 } -
binary-improvements/MapRendering/Web/Web.cs
r249 r250 250 250 251 251 public void SendLog (string text, string trace, UnityEngine.LogType type) { 252 connectionHandler.SendLog (text, trace, type);252 // Do nothing, handled by LogBuffer internally 253 253 } 254 254 -
binary-improvements/MapRendering/Web/WebConnection.cs
r244 r250 12 12 private DateTime login; 13 13 private DateTime lastAction; 14 15 14 private List<string> outputLines = new List<string> (); 16 private List<LogLine> logLines = new List<LogLine> ();17 15 18 16 public string SessionID { … … 57 55 58 56 public override void SendLog (string _msg, string _trace, LogType _type) { 59 LogLine ll = new LogLine (); 60 ll.message = _msg; 61 ll.trace = _trace; 62 ll.type = _type; 63 logLines.Add (ll); 57 // Do nothing, handled by LogBuffer 64 58 } 65 59 66 private struct LogLine {67 public string message;68 public string trace;69 public LogType type;70 }71 60 } 72 61 } -
binary-improvements/MapRendering/WebAndMapRendering.csproj
r244 r250 75 75 <Compile Include="Commands\WebTokens.cs" /> 76 76 <Compile Include="Commands\WebPermissionsCmd.cs" /> 77 <Compile Include="Web\LogBuffer.cs" /> 78 <Compile Include="Web\API\GetLog.cs" /> 79 <Compile Include="Web\API\GetWebUIUpdates.cs" /> 77 80 </ItemGroup> 78 81 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> -
binary-improvements/webserver/css/style.css
r249 r250 14 14 15 15 a { 16 color: #ff6000;16 color: orangered; 17 17 text-decoration: none; 18 18 } 19 19 20 20 a:visited { 21 color: #ff6000;21 color: orangered; 22 22 text-decoration: none; 23 23 } … … 30 30 31 31 .adminnavbar, 32 .admincontent {32 #admincontent { 33 33 position: absolute; 34 34 top: 0; … … 50 50 border-right: 1px solid rgba(0,0,0,0.3); 51 51 box-shadow: 3px 0px 14px rgba(0,0,0,0.9); 52 position: fixed; 52 53 } 53 54 … … 69 70 70 71 .adminnavbar #adminmenu .menu_button.allowed { 71 display: inline;72 display: list-item; 72 73 } 73 74 … … 80 81 font-weight: bold; 81 82 text-transform: uppercase; 83 } 84 85 #newlogcount { 86 font-size: 70%; 87 border-radius: 2px; 88 background-color: #f00; 89 color: #fff; 90 padding: 0px 2px 0px 2px; 91 display: none; 92 } 93 94 #newlogcount.visible { 95 display: inline; 82 96 } 83 97 … … 122 136 */ 123 137 124 .admincontent {138 #admincontent { 125 139 position: absolute; 126 140 right: 0; … … 129 143 } 130 144 131 .admincontent #nopermissionwarning {145 #admincontent #nopermissionwarning { 132 146 margin: 20px 50px; 133 147 } 134 148 135 .admincontent .contenttab {149 #admincontent .contenttab { 136 150 position: absolute; 137 151 top: 0; … … 141 155 } 142 156 143 .admincontent .current_tab {157 #admincontent .current_tab { 144 158 display: block; 145 159 } … … 199 213 border-collapse: collapse; 200 214 } 201 #equipmentTable .invFieldText { 202 display: none; 203 } 215 204 216 .playerInventoryDialog td.invField { 205 217 width: 58px; … … 222 234 } 223 235 236 #equipmentTable .invFieldText { 237 display: none; 238 } 239 .playerInventoryDialog .invFieldText { 240 display: none; 241 } 242 .playerInventoryDialog .invFieldText.visible { 243 display: inline; 244 } 245 .playerInventoryDialog .invFieldQuality { 246 bottom: 0px; 247 height: 5px; 248 left: 0px; 249 position: relative; 250 right: 0px; 251 display: none; 252 } 253 .playerInventoryDialog .invFieldQuality.visible { 254 display: block; 255 } 224 256 225 257 … … 246 278 .adminmap .leaflet-container a:hover { 247 279 text-decoration: none; 248 color: #ff6000;280 color: orangered; 249 281 } 250 282 … … 261 293 } 262 294 295 296 297 298 /*======================================== 299 - Log 300 */ 301 302 .adminlog { 303 padding: 10px; 304 } 305 306 .adminlog table { 307 width: 100%; 308 } 309 310 .adminlog table td { 311 vertical-align: top; 312 } 313 314 .adminlog table tr.readmark td { 315 border-bottom-width: 2px; 316 border-bottom-color: red; 317 border-bottom-style: dotted; 318 } 319 320 .adminlog table tr.Log td { 321 color: limegreen; 322 } 323 .adminlog table tr.Warning td { 324 color: orange; 325 } 326 .adminlog table tr.Error td { 327 color: red; 328 } 329 .adminlog table tr.Exception td { 330 color: red; 331 } 332 333 334 .adminlog .logcol_datetime, 335 .adminlog .logcol_uptime { 336 white-space: nowrap; 337 text-align: right; 338 } 339 .adminlog .logcol_type { 340 white-space: nowrap; 341 } 342 .adminlog .logcol_msg { 343 width: 100%; 344 } 345 346 .adminlog .logcol_missed { 347 text-align: center; 348 border-width: 1px 0px; 349 border-style: dashed; 350 border-color: orange; 351 } 352 353 .adminlog .tracebtn { 354 cursor: pointer; 355 } 356 .adminlog .tracebtn:after { 357 content: "Show trace..."; 358 } 359 .adminlog .tracebtn.visible:after { 360 content: "Hide trace..."; 361 } 362 363 .adminlog .trace { 364 display: none; 365 } 366 367 .adminlog .trace.visible { 368 display: block; 369 } 370 371 .adminlog .trace span { 372 display: block; 373 margin-left: 30px; 374 text-indent: -30px; 375 } 376 377 .adminlog #markasread { 378 cursor: pointer; 379 border-radius: 5px; 380 background-color: #444; 381 color: orangered; 382 display: inline-block; 383 margin-top: 10px; 384 padding: 3px 5px 3px 5px; 385 } 386 387 -
binary-improvements/webserver/index.html
r249 r250 46 46 <script type="text/javascript" src="js/permissions.js"></script> 47 47 <script type="text/javascript" src="js/map.js"></script> 48 <script type="text/javascript" src="js/log.js"></script> 48 49 49 50 <!-- Own stylesheet --> … … 65 66 <ul> 66 67 <li><a href="#tab_map" data-permission="web.map">Map</a></li> 67 <li><a href="#tab_log" data-permission="web .log">Log</a></li>68 <li><a href="#tab_log" data-permission="webapi.getlog">Log <span id="newlogcount"></span></a></li> 68 69 </ul> 69 70 </div> … … 85 86 </div> 86 87 </div> 87 <div class="admincontent">88 <div id="admincontent"> 88 89 <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> 89 90 <div id="tab_map" class="adminmap"></div> 90 <div id="tab_log" class="adminlog"></div> 91 <div id="tab_log" class="adminlog"> 92 <table> 93 <tr> 94 <th>Date/Time</th> 95 <th>Uptime</th> 96 <th>Severity</th> 97 <th>Message</th> 98 </tr> 99 </table> 100 <a id="markasread">Mark as read</a> 101 </div> 91 102 </div> 92 103 </div> -
binary-improvements/webserver/js/index.js
r245 r250 1 InitializeTabs (); 1 //InitializeTabs (); 2 var tabs = $("#adminmenu").tabbedContent ({ 3 contentdiv: $("#admincontent"), 4 }); 2 5 SetupInventoryDialog (); 3 6 InitPermissions (); -
binary-improvements/webserver/js/inventory_dialog.js
r249 r250 11 11 var cell = $("#" + containerTypeName + "Field"+cellIdent); 12 12 var text = $("#" + containerTypeName + "FieldText"+cellIdent); 13 if (itemdata.count > 0) { 13 var qual = $("#" + containerTypeName + "FieldQuality"+cellIdent); 14 15 cell.attr("style", "background-image: none;"); 16 cell.removeAttr("title"); 17 text.removeClass ("visible"); 18 qual.removeClass ("visible"); 19 20 if (itemdata !== null) { 14 21 cell.attr("style", "background-image: url(" + ITEMICONBASEURL + itemdata.name + ".png);"); 15 cell.attr("title", itemdata.name); 16 text.text(itemdata.count); 17 } else { 18 cell.attr("style", "background-image: none;"); 19 cell.removeAttr("title"); 20 text.text(""); 22 if (itemdata.quality >= 0) { 23 cell.attr("title", itemdata.name + " (quality: " + itemdata.quality + ")"); 24 qual.attr("style", "background-color: #"+ itemdata.qualitycolor); 25 qual.addClass ("visible"); 26 } else { 27 cell.attr("title", itemdata.name); 28 text.text(itemdata.count); 29 text.addClass ("visible"); 30 } 21 31 } 22 32 } … … 24 34 var SetEquipmentItem = function (data, name, cellIdent) { 25 35 if (data.equipment [name] == false) { 26 SetCellItem ("equipment", cellIdent, { count: 0, name: "" });36 SetCellItem ("equipment", cellIdent, null); 27 37 } else { 28 SetCellItem ("equipment", cellIdent, { count: 1, name: data.equipment [name] });38 SetCellItem ("equipment", cellIdent, data.equipment [name] ); 29 39 } 30 40 } … … 77 87 var CreateInvCell = function (containerTypeName, cellIdent) { 78 88 return "<td class=\"invField\" id=\"" + containerTypeName + "Field"+cellIdent+"\">" + 89 "<div class=\"invFieldQuality\" id=\"" + containerTypeName + "FieldQuality" + cellIdent + "\"></div>" + 79 90 "<span class=\"invFieldText\" id=\"" + containerTypeName + "FieldText"+cellIdent+"\"></span>" + 80 91 "</td>"; -
binary-improvements/webserver/js/map.js
r249 r250 131 131 }); 132 132 133 var openedPopup = null; 134 var updatingMarkers = false; 135 136 map.on ("popupopen", function (event) { 137 console.log ("open"); 138 console.log (event.popup._source); 139 openedPopup = event.popup._source; 140 }); 141 map.on ("popupclose", function (event) { 142 if (!updatingMarkers) { 143 console.log ("close"); 144 openedPopup = null; 145 } 146 }); 147 133 148 var setPlayerMarkers = function(data) { 134 149 var online = 0; 135 150 var offline = 0; 151 updatingMarkers = true; 136 152 $.each( data, function( key, val ) { 137 153 var marker; … … 147 163 playersMappingList[val.steamid] = { online: !val.online }; 148 164 } 149 if (playersMappingList[val.steamid].online) { 150 playersOnlineMarkerGroup.removeLayer(marker); 151 } else { 152 playersOfflineMarkerGroup.removeLayer(marker); 153 } 154 marker.setLatLng([val.position.x, val.position.z]); 155 if (val.online) { 156 marker.setOpacity(1.0); 157 playersOnlineMarkerGroup.addLayer(marker); 158 } else { 159 marker.setOpacity(0.5); 160 playersOfflineMarkerGroup.addLayer(marker); 165 166 oldpos = marker.getLatLng (); 167 if ( playersMappingList[val.steamid].online != val.online || oldpos.lat != val.position.x || oldpos.lng != val.position.z ) { 168 if (playersMappingList[val.steamid].online) { 169 playersOnlineMarkerGroup.removeLayer(marker); 170 } else { 171 playersOfflineMarkerGroup.removeLayer(marker); 172 } 173 marker.setLatLng([val.position.x, val.position.z]); 174 if (val.online) { 175 marker.setOpacity(1.0); 176 playersOnlineMarkerGroup.addLayer(marker); 177 } else { 178 marker.setOpacity(0.5); 179 playersOfflineMarkerGroup.addLayer(marker); 180 } 161 181 } 162 182 … … 169 189 offline++; 170 190 }); 191 updatingMarkers = false; 192 if (openedPopup != null) { 193 openedPopup.openPopup (); 194 } 171 195 $( "#mapControlOnlineCount" ).text( online ); 172 196 $( "#mapControlOfflineCount" ).text( offline ); 173 197 } 174 198 199 var updatePlayerTimeout; 175 200 var updatePlayerEvent = function() { 176 201 $.getJSON( "../api/getplayerslocation") … … 180 205 }) 181 206 .always(function() { 182 window.setTimeout(updatePlayerEvent, 2000);207 updatePlayerTimeout = window.setTimeout(updatePlayerEvent, 4000); 183 208 }); 184 209 } 185 210 186 if (HasPermission ("webapi.getplayerslocation")) { 187 window.setTimeout(updatePlayerEvent, 0); 211 tabs.on ("tabbedcontenttabopened", function (event, data) { 212 if (data.newTab === "#tab_map") { 213 if (HasPermission ("webapi.getplayerslocation")) { 214 updatePlayerEvent (); 215 } 216 } else { 217 window.clearTimeout (updatePlayerTimeout); 218 } 219 }); 220 221 if (tabs.tabbedContent ("isTabOpen", "tab_map")) { 222 if (HasPermission ("webapi.getplayerslocation")) { 223 updatePlayerEvent (); 224 } 188 225 } 189 226 -
binary-improvements/webserver/js/permissions.js
r249 r250 21 21 } 22 22 23 ApplyTabPermissions ();24 25 23 if (HasPermission ("web.map")) { 26 24 StartMapModule (); 27 25 } 26 if (HasPermission ("webapi.getlog")) { 27 StartLogModule (); 28 } 28 29 29 if (HasPermission ("webapi.getstats")) { 30 if (HasPermission ("webapi.getwebuiupdates")) { 31 StartUIUpdatesModule (); 32 } else if (HasPermission ("webapi.getstats")) { 30 33 StartStatsModule (); 31 34 } 35 36 tabs.tabbedContent ("applyPermissions"); 32 37 33 38 }) -
binary-improvements/webserver/js/stats.js
r245 r250 25 25 } 26 26 27 function StartUIUpdatesModule () { 28 var updateGameTimeEvent = function() { 29 $.getJSON( "../api/getwebuiupdates?latestLine=" + lastLogLine) 30 .done(function(data) { 31 var time = "Day " + data.gametime.days + ", "; 32 if (data.gametime.hours < 10) 33 time += "0"; 34 time += data.gametime.hours; 35 time += ":"; 36 if (data.gametime.minutes < 10) 37 time += "0"; 38 time += data.gametime.minutes; 39 40 $("#stats_time").html (time); 41 $("#stats_players").html (data.players); 42 $("#newlogcount").html (data.newlogs); 43 if (data.newlogs > 0) { 44 $("#newlogcount").addClass ("visible"); 45 } else { 46 $("#newlogcount").removeClass ("visible"); 47 } 48 }) 49 .fail(function(jqxhr, textStatus, error) { 50 console.log("Error fetching ui updates"); 51 }) 52 .always(function() { 53 }); 54 window.setTimeout(updateGameTimeEvent, 2000); 55 }; 56 updateGameTimeEvent(); 57 } 58 -
binary-improvements/webserver/js/tabs.js
r249 r250 1 var tabElements = {}; 2 var currentTabClass = "current_tab"; 1 $.widget( "7dtd.tabbedContent", { 2 options: { 3 contentdiv: null, 4 currentTabClass: "current_tab", 5 menuButtonClass: "menu_button", 6 allowedMenuButtonClass: "allowed", 7 contentDivClass: "contenttab", 8 }, 9 10 _create: function () { 11 var options = this.options; 12 var self = this; 13 14 if (options.contentdiv == null) { 15 console.log ("contentdiv has to be set!"); 16 } 17 18 this.element.find ("ul > li").addClass (options.menuButtonClass); 3 19 4 function OpenTab () { 5 var menuElement = $(this); 6 var linkElement = menuElement.children ("a"); 7 var linkName = linkElement.attr ("href"); 20 options.contentdiv.children ("div").addClass (options.contentDivClass); 21 this.element.on ('click.action', "ul > li", function (event) { 22 var menuElement = $(this); 23 var linkElement = menuElement.children ("a"); 24 var linkName = linkElement.attr ("href"); 25 self.openTab (linkName); 26 }); 8 27 9 $("*").removeClass (currentTabClass); 10 menuElement.addClass (currentTabClass); 11 $(linkName).addClass (currentTabClass); 12 } 28 self.tabs = {}; 29 this.element.find (".menu_button").each (function () { 30 self.tabs [$(this).children ("a").attr ("href")] = $(this); 31 }); 32 }, 33 34 applyPermissions: function () { 35 var self = this; 36 this.element.find (".menu_button").each (function () { 37 if ($(this).children ("a").data ("permission")) { 38 var perm = $(this).children ("a").data ("permission"); 39 if (HasPermission (perm)) { 40 $(this).addClass (self.options.allowedMenuButtonClass); 41 } 42 } else { 43 $(this).addClass (self.options.allowedMenuButtonClass); 44 } 45 }); 13 46 14 function InitializeTabs () { 15 $("#adminmenu > ul > li").addClass ("menu_button"); 16 $(".admincontent > div").addClass ("contenttab"); 17 $(".menu_button").on ('click.action', null, function (event) { 18 var menuElement = $(this); 19 var linkElement = menuElement.children ("a"); 20 var linkName = linkElement.attr ("href"); 47 this.element.find ("." + self.options.allowedMenuButtonClass).first ().click (); 48 }, 49 50 openTab: function (name) { 51 if (name.indexOf ("#") != 0) 52 name = "#" + name; 21 53 22 $("*").removeClass ("current_tab"); 23 menuElement.addClass ("current_tab"); 24 $(linkName).addClass ("current_tab"); 25 }); 26 } 54 if (!this.tabs.hasOwnProperty(name)) { 55 console.log ("no tab named " + name + " in " + this); 56 return; 57 } 27 58 28 function ApplyTabPermissions () { 29 $("#adminmenu .menu_button").each (function () { 30 if ($(this).children ("a").data ("permission")) { 31 var perm = $(this).children ("a").data ("permission"); 32 if (HasPermission (perm)) { 33 $(this).addClass ("allowed"); 34 } 59 var menuElement = $(".menu_button > a[href=" + name + "]").parent (); 60 61 $("*").removeClass (this.options.currentTabClass); 62 menuElement.addClass (this.options.currentTabClass); 63 $(name).addClass (this.options.currentTabClass); 64 var oldTab = this.currentTab; 65 this.currentTab = name; 66 67 if (oldTab != name) { 68 this._trigger ("tabopened", null, { oldTab: oldTab, newTab: name } ); 35 69 } 36 }); 70 }, 71 72 currentOpenTab: function () { 73 return this.currentTab; 74 }, 75 76 isTabOpen: function (name) { 77 if (name.indexOf ("#") != 0) 78 name = "#" + name; 37 79 38 $("#adminmenu .allowed").first ().click ();39 } 80 return this.currentTab == name; 81 }, 40 82 83 /* 84 value: function (value) { 85 if ( value === undefined ) { 86 return this.options.value; 87 } else { 88 this.options.value = this._constrain( value ); 89 var progress = this.options.value + "%"; 90 this.element.text( progress ); 91 } 92 }, 93 */ 94 });
Note:
See TracChangeset
for help on using the changeset viewer.