diff --git a/Plugins/LiveRadar/Configuration/LiveRadarConfiguration.cs b/Plugins/LiveRadar/Configuration/LiveRadarConfiguration.cs new file mode 100644 index 000000000..144d96158 --- /dev/null +++ b/Plugins/LiveRadar/Configuration/LiveRadarConfiguration.cs @@ -0,0 +1,107 @@ +using SharedLibraryCore.Configuration; +using SharedLibraryCore.Interfaces; +using System; +using System.Collections.Generic; +using System.Text; + +namespace LiveRadar.Configuration +{ + class LiveRadarConfiguration : IBaseConfiguration + { + public List Maps { get; set; } + + public IBaseConfiguration Generate() + { + Maps = new List() + { + new MapInfo() + { + Name = "mp_afghan", + MaxLeft = 4600, // ymax + MaxRight = -1100, // ymin + MaxBottom = -1400, // xmin + MaxTop = 4600, // xmax + Left = 52, // pxmin + Right = 898, // pxmax + Bottom = 930, // yxmax + Top = 44 // pymin + }, + new MapInfo() + { + Name = "mp_rust", + Top = 212, + Bottom = 812, + Left = 314, + Right = 856, + MaxRight = -225, + MaxLeft = 1809, + MaxTop = 1773, + MaxBottom = -469 + }, + + new MapInfo() + { + Name = "mp_subbase", + MaxLeft = 1841, // ymax + MaxRight = -3817, // ymin + MaxBottom = -1585, // xmin + MaxTop = 2593, // xmax + Left = 18, // pxmin + Right = 968, // pxmax + Bottom = 864, // pymax + Top = 160, // pymin + CenterX = 0, + CenterY = 0, + Rotation = 0 + }, + + new MapInfo() + { + Name = "mp_estate", + Top = 52, + Bottom = 999, + Left= 173, + Right = 942, + MaxTop = 2103, + MaxBottom = -5077, + MaxLeft = 4437, + MaxRight = -1240, + Rotation = 143, + CenterX = -1440, + CenterY = 1920, + Scaler = 0.85f + }, + + new MapInfo() + { + Name = "mp_highrise", + MaxBottom = -3909, + MaxTop = 1649, + MaxRight = 5111, + MaxLeft = 8906, + Left = 108, + Right = 722, + Top = 66, + Bottom = 974, + }, + + new MapInfo() + { + Name = "mp_quarry", + MaxBottom = -5905, + MaxTop = -1423, + MaxRight = -2095, + MaxLeft = 3217, + Left = 126, + Right = 968, + Top = 114, + Bottom = 824 + } + }; + + return this; + } + + public string Name() => "LiveRadar"; + } +} diff --git a/Plugins/LiveRadar/MapInfo.cs b/Plugins/LiveRadar/MapInfo.cs index eeb738453..00d04cda7 100644 --- a/Plugins/LiveRadar/MapInfo.cs +++ b/Plugins/LiveRadar/MapInfo.cs @@ -18,6 +18,10 @@ namespace LiveRadar public int MaxBottom { get; set; } public int MaxLeft { get; set; } public int MaxRight { get; set; } + public float Rotation { get; set; } + public float CenterX { get; set; } + public float CenterY { get; set; } + public float Scaler { get; set; } = 1.0f; public int Width => MaxLeft - MaxRight; public int Height => MaxTop - MaxBottom; diff --git a/Plugins/LiveRadar/Plugin.cs b/Plugins/LiveRadar/Plugin.cs index cbb519829..b1e8266d5 100644 --- a/Plugins/LiveRadar/Plugin.cs +++ b/Plugins/LiveRadar/Plugin.cs @@ -1,4 +1,6 @@ -using SharedLibraryCore; +using LiveRadar.Configuration; +using SharedLibraryCore; +using SharedLibraryCore.Configuration; using SharedLibraryCore.Interfaces; using System; using System.Linq; @@ -14,6 +16,8 @@ namespace LiveRadar public string Author => "RaidMax"; + internal static BaseConfigurationHandler Config; + public Task OnEventAsync(GameEvent E, Server S) { if (E.Type == GameEvent.EventType.Unknown) @@ -21,18 +25,28 @@ namespace LiveRadar if (E.Data?.StartsWith("LiveRadar") ?? false) { var radarUpdate = RadarEvent.Parse(E.Data); - var client = S.GetClientsAsList().First(_client => _client.NetworkId == radarUpdate.Guid); - radarUpdate.Name = client.Name; - client.SetAdditionalProperty("LiveRadar", radarUpdate); + var client = S.Manager.GetActiveClients().FirstOrDefault(_client => _client.NetworkId == radarUpdate.Guid); + + if (client != null) + { + radarUpdate.Name = client.Name; + client.SetAdditionalProperty("LiveRadar", radarUpdate); + } } } return Task.CompletedTask; } - public Task OnLoadAsync(IManager manager) + public async Task OnLoadAsync(IManager manager) { - return Task.CompletedTask; + // load custom configuration + Config = new BaseConfigurationHandler("LiveRadarConfiguration"); + if (Config.Configuration() == null) + { + Config.Set((LiveRadarConfiguration)new LiveRadarConfiguration().Generate()); + await Config.Save(); + } } public Task OnTickAsync(Server S) diff --git a/Plugins/LiveRadar/RadarEvent.cs b/Plugins/LiveRadar/RadarEvent.cs index c8c47e4f9..056c2bd66 100644 --- a/Plugins/LiveRadar/RadarEvent.cs +++ b/Plugins/LiveRadar/RadarEvent.cs @@ -17,11 +17,11 @@ namespace LiveRadar public int Kills { get; set; } public int Deaths { get; set; } public int Score { get; set; } + public int PlayTime { get; set; } public string Weapon { get; set; } public int Health { get; set; } public bool IsAlive { get; set; } public Vector3 RadianAngles => new Vector3(ViewAngles.X.ToRadians(), ViewAngles.Y.ToRadians(), ViewAngles.Z.ToRadians()); - public RadarEvent Previous { get; set; } public int Id => GetHashCode(); public override bool Equals(object obj) @@ -41,7 +41,7 @@ namespace LiveRadar public static RadarEvent Parse(string input) { - var items = input.Split(';').ToList(); + var items = input.Split(';').Skip(1).ToList(); var parsedEvent = new RadarEvent() { @@ -54,7 +54,8 @@ namespace LiveRadar Score = int.Parse(items[6]), Weapon = items[7], Health = int.Parse(items[8]), - IsAlive = items[9] == "1" + IsAlive = items[9] == "1", + PlayTime = Convert.ToInt32(items[10]) }; return parsedEvent; diff --git a/Plugins/LiveRadar/Web/Controllers/RadarController.cs b/Plugins/LiveRadar/Web/Controllers/RadarController.cs index 367b8fa5d..dbb17dec6 100644 --- a/Plugins/LiveRadar/Web/Controllers/RadarController.cs +++ b/Plugins/LiveRadar/Web/Controllers/RadarController.cs @@ -10,34 +10,34 @@ namespace LiveRadar.Web.Controllers { public class RadarController : BaseController { + private static readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings() + { + ReferenceLoopHandling = ReferenceLoopHandling.Ignore, + ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver() + }; + [HttpGet] public IActionResult Index() { + ViewBag.IsFluid = true; return View(); } public IActionResult Map(long? serverId = null) { - var map = new MapInfo() - { - Name = "mp_rust", - Top = 248, - Bottom = 212, - Left = 314, - Right = 167, - MaxRight = -225, - MaxLeft = 1809, - MaxTop = 1641, - MaxBottom = -469 - }; + var server = Manager.GetServers().FirstOrDefault(); + + var map = Plugin.Config.Configuration().Maps.FirstOrDefault(_map => _map.Name == server.CurrentMap.Name); return Json(map); } + [HttpGet] + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Data(long? serverId = null) { var server = serverId == null ? Manager.GetServers()[0] : Manager.GetServers().First(_server => _server.GetHashCode() == serverId); - var radarInfo = server.GetClientsAsList().Select(_client => _client.GetAdditionalProperty("LiveRadar")); + var radarInfo = server.GetClientsAsList().Select(_client => _client.GetAdditionalProperty("LiveRadar")).ToList(); return Json(radarInfo); } @@ -50,18 +50,10 @@ namespace LiveRadar.Web.Controllers if (client != null) { radarUpdate.Name = client.Name; - var previous = client.GetAdditionalProperty("LiveRadar"); - // this prevents us from creating a never ending linked list - if (previous != null) - { - previous.Previous = null; - } - - radarUpdate.Previous = previous; client.SetAdditionalProperty("LiveRadar", radarUpdate); } return Ok(); } } -} +} \ No newline at end of file diff --git a/Plugins/LiveRadar/Web/Views/LiveRadar/Index.cshtml b/Plugins/LiveRadar/Web/Views/LiveRadar/Index.cshtml index 87064e414..e9fa1aa01 100644 --- a/Plugins/LiveRadar/Web/Views/LiveRadar/Index.cshtml +++ b/Plugins/LiveRadar/Web/Views/LiveRadar/Index.cshtml @@ -1,23 +1,108 @@ @model IEnumerable + +
+
+
+
+
+
+ +
+
- -
+
+
+ + + @section scripts { } \ No newline at end of file diff --git a/Plugins/ScriptPlugins/SharedGUIDKick.js b/Plugins/ScriptPlugins/SharedGUIDKick.js index c0cc3a95e..07584a5d4 100644 --- a/Plugins/ScriptPlugins/SharedGUIDKick.js +++ b/Plugins/ScriptPlugins/SharedGUIDKick.js @@ -11,8 +11,8 @@ var plugin = { // connect or join event if (gameEvent.Type === 3) { - // this GUID seems to have been packed in a IW4 torrent and results in an unreasonable amount of people using the same GUID - if (gameEvent.Origin.NetworkId === -805366929435212061) { + // this GUID seems to have been packed in a IW4 torrent and results in an unreasonable amount of people using the same GUID + if (gameEvent.Origin.NetworkId === -805366929435212061 || gameEvent.Origin.NetworkId == -3304388024725980231) { gameEvent.Origin.Kick('Your GUID is generic. Delete players/guids.dat and rejoin', _IW4MAdminClient); } } diff --git a/SharedLibraryCore/Events/EventAPI.cs b/SharedLibraryCore/Events/EventAPI.cs index f834678c3..102f5fe98 100644 --- a/SharedLibraryCore/Events/EventAPI.cs +++ b/SharedLibraryCore/Events/EventAPI.cs @@ -7,7 +7,7 @@ namespace SharedLibraryCore.Events { public class EventApi { - const int MaxEvents = 100; + const int MaxEvents = 25; static ConcurrentQueue RecentEvents = new ConcurrentQueue(); public static IEnumerable GetEvents(bool shouldConsume) diff --git a/WebfrontCore/Controllers/BaseController.cs b/WebfrontCore/Controllers/BaseController.cs index 79bb4fc49..9407c979b 100644 --- a/WebfrontCore/Controllers/BaseController.cs +++ b/WebfrontCore/Controllers/BaseController.cs @@ -51,6 +51,7 @@ namespace WebfrontCore.Controllers }).ToList(); ViewBag.Version = Manager.Version; + ViewBag.IsFluid = false; } public override void OnActionExecuting(ActionExecutingContext context) diff --git a/WebfrontCore/Views/Shared/_Layout.cshtml b/WebfrontCore/Views/Shared/_Layout.cshtml index 7655fbafc..fcabbc6bb 100644 --- a/WebfrontCore/Views/Shared/_Layout.cshtml +++ b/WebfrontCore/Views/Shared/_Layout.cshtml @@ -125,7 +125,7 @@
-
+
@RenderBody()