update live radar plugin to IPluginV2

This commit is contained in:
RaidMax 2023-02-11 20:46:08 -06:00
parent 2688790736
commit ba9e393363
8 changed files with 586 additions and 583 deletions

View File

@ -1,391 +1,390 @@
using SharedLibraryCore.Interfaces; using SharedLibraryCore.Interfaces;
using System.Collections.Generic; using System.Collections.Generic;
namespace LiveRadar.Configuration namespace IW4MAdmin.Plugins.LiveRadar.Configuration;
public class LiveRadarConfiguration : IBaseConfiguration
{ {
class LiveRadarConfiguration : IBaseConfiguration public List<MapInfo> Maps { get; set; }
public IBaseConfiguration Generate()
{ {
public List<MapInfo> Maps { get; set; } Maps = new List<MapInfo>()
public IBaseConfiguration Generate()
{ {
Maps = new List<MapInfo>() new MapInfo()
{ {
new MapInfo() Name = "mp_afghan",
{ MaxLeft = 4600, // ymax
Name = "mp_afghan", MaxRight = -1100, // ymin
MaxLeft = 4600, // ymax MaxBottom = -1400, // xmin
MaxRight = -1100, // ymin MaxTop = 4600, // xmax
MaxBottom = -1400, // xmin Left = 52, // pxmin
MaxTop = 4600, // xmax Right = 898, // pxmax
Left = 52, // pxmin Bottom = 930, // pymax
Right = 898, // pxmax Top = 44 // pymin
Bottom = 930, // pymax },
Top = 44 // pymin
},
new MapInfo() new MapInfo()
{ {
Name = "mp_rust", Name = "mp_rust",
Top = 212, Top = 212,
Bottom = 812, Bottom = 812,
Left = 314, Left = 314,
Right = 856, Right = 856,
MaxRight = -225, MaxRight = -225,
MaxLeft = 1809, MaxLeft = 1809,
MaxTop = 1773, MaxTop = 1773,
MaxBottom = -469 MaxBottom = -469
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_terminal", Name = "mp_terminal",
Top = 174, Top = 174,
Bottom = 846, Bottom = 846,
Left = 18, Left = 18,
Right = 1011, Right = 1011,
MaxTop = 2929, MaxTop = 2929,
MaxBottom = -513, MaxBottom = -513,
MaxLeft = 7521, MaxLeft = 7521,
MaxRight = 2447 MaxRight = 2447
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_subbase", Name = "mp_subbase",
MaxLeft = 1841, MaxLeft = 1841,
MaxRight = -3817, MaxRight = -3817,
MaxBottom = -1585, MaxBottom = -1585,
MaxTop = 2593, MaxTop = 2593,
Left = 18, Left = 18,
Right = 968, Right = 968,
Bottom = 864, Bottom = 864,
Top = 160, Top = 160,
ViewPositionRotation = 180, ViewPositionRotation = 180,
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_estate", Name = "mp_estate",
Top = 52, Top = 52,
Bottom = 999, Bottom = 999,
Left = 173, Left = 173,
Right = 942, Right = 942,
MaxTop = 2103, MaxTop = 2103,
MaxBottom = -5077, MaxBottom = -5077,
MaxLeft = 4437, MaxLeft = 4437,
MaxRight = -1240, MaxRight = -1240,
Rotation = 143, Rotation = 143,
CenterX = -1440, CenterX = -1440,
CenterY = 1920, CenterY = 1920,
Scaler = 0.85f, Scaler = 0.85f,
ViewPositionRotation = 180 ViewPositionRotation = 180
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_highrise", Name = "mp_highrise",
MaxBottom = -3909, MaxBottom = -3909,
MaxTop = 1649, MaxTop = 1649,
MaxRight = 5111, MaxRight = 5111,
MaxLeft = 8906, MaxLeft = 8906,
Left = 108, Left = 108,
Right = 722, Right = 722,
Top = 66, Top = 66,
Bottom = 974, Bottom = 974,
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_quarry", Name = "mp_quarry",
MaxBottom = -5905, MaxBottom = -5905,
MaxTop = -1423, MaxTop = -1423,
MaxRight = -2095, MaxRight = -2095,
MaxLeft = 3217, MaxLeft = 3217,
Left = 126, Left = 126,
Right = 968, Right = 968,
Top = 114, Top = 114,
Bottom = 824 Bottom = 824
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_boneyard", Name = "mp_boneyard",
MaxBottom = -1756, MaxBottom = -1756,
MaxTop = 2345, MaxTop = 2345,
MaxRight = -715, MaxRight = -715,
MaxLeft = 1664, MaxLeft = 1664,
Left = 248, Left = 248,
Right = 728, Right = 728,
Top = 68, Top = 68,
Bottom = 897 Bottom = 897
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_brecourt", Name = "mp_brecourt",
MaxBottom = -3797, MaxBottom = -3797,
MaxTop = 4240, MaxTop = 4240,
MaxRight = -3876, MaxRight = -3876,
MaxLeft = 2575, MaxLeft = 2575,
Left = 240, Left = 240,
Right = 846, Right = 846,
Top = 180, Top = 180,
Bottom = 934 Bottom = 934
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_checkpoint", Name = "mp_checkpoint",
MaxBottom = -2273, MaxBottom = -2273,
MaxTop = 2153, MaxTop = 2153,
MaxRight = -3457, MaxRight = -3457,
MaxLeft = 2329, MaxLeft = 2329,
Left = 30, Left = 30,
Right = 1010, Right = 1010,
Top = 136, Top = 136,
Bottom = 890 Bottom = 890
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_derail", Name = "mp_derail",
MaxBottom = -2775, MaxBottom = -2775,
MaxTop = 3886, MaxTop = 3886,
MaxRight = -3807, MaxRight = -3807,
MaxLeft = 4490, MaxLeft = 4490,
Left = 130, Left = 130,
Right = 892, Right = 892,
Top = 210, Top = 210,
Bottom = 829 Bottom = 829
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_favela", Name = "mp_favela",
MaxBottom = -2017, MaxBottom = -2017,
MaxTop = 1769, MaxTop = 1769,
MaxRight = -1239, MaxRight = -1239,
MaxLeft = 2998, MaxLeft = 2998,
Left = 120, Left = 120,
Right = 912, Right = 912,
Top = 174, Top = 174,
Bottom = 878 Bottom = 878
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_invasion", Name = "mp_invasion",
MaxBottom = -3673, MaxBottom = -3673,
MaxTop = 2540, MaxTop = 2540,
MaxRight = -3835, MaxRight = -3835,
MaxLeft = 980, MaxLeft = 980,
Left = 20, Left = 20,
Right = 808, Right = 808,
Top = 0, Top = 0,
Bottom = 1006 Bottom = 1006
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_nightshift", Name = "mp_nightshift",
MaxBottom = -2497, MaxBottom = -2497,
MaxTop = 1977, MaxTop = 1977,
MaxRight = -2265, MaxRight = -2265,
MaxLeft = 945, MaxLeft = 945,
Left = 246, Left = 246,
Right = 826, Right = 826,
Top = 104, Top = 104,
Bottom = 916 Bottom = 916
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_rundown", Name = "mp_rundown",
MaxBottom = -2304, MaxBottom = -2304,
MaxTop = 3194, MaxTop = 3194,
MaxRight = -3558, MaxRight = -3558,
MaxLeft = 3361, MaxLeft = 3361,
Left = 32, Left = 32,
Right = 1030, Right = 1030,
Top = 96, Top = 96,
Bottom = 892 Bottom = 892
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_underpass", Name = "mp_underpass",
MaxBottom = -601, MaxBottom = -601,
MaxTop = 3761, MaxTop = 3761,
MaxRight = -1569, MaxRight = -1569,
MaxLeft = 3615, MaxLeft = 3615,
Left = 42, Left = 42,
Right = 978, Right = 978,
Top = 157, Top = 157,
Bottom = 944 Bottom = 944
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_abandon", Name = "mp_abandon",
MaxBottom = -1290, MaxBottom = -1290,
MaxTop = 3855, MaxTop = 3855,
MaxRight = -2907, MaxRight = -2907,
MaxLeft = 2723, MaxLeft = 2723,
Left = 6, Left = 6,
Right = 1016, Right = 1016,
Top = 32, Top = 32,
Bottom = 945 Bottom = 945
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_compact", Name = "mp_compact",
MaxBottom = 0, MaxBottom = 0,
MaxTop = 4264, MaxTop = 4264,
MaxRight = -1552, MaxRight = -1552,
MaxLeft = 3344, MaxLeft = 3344,
Left = 35, Left = 35,
Right = 1003, Right = 1003,
Top = 94, Top = 94,
Bottom = 935 Bottom = 935
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_complex", Name = "mp_complex",
MaxBottom = -2869, MaxBottom = -2869,
MaxTop = 2867, MaxTop = 2867,
MaxRight = -4204, MaxRight = -4204,
MaxLeft = -1218, MaxLeft = -1218,
Left = 282, Left = 282,
Right = 749, Right = 749,
Top = 48, Top = 48,
Bottom = 991 Bottom = 991
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_crash", Name = "mp_crash",
MaxBottom = -953, MaxBottom = -953,
MaxTop = 1811, MaxTop = 1811,
MaxRight = -2129, MaxRight = -2129,
MaxLeft = 2277, MaxLeft = 2277,
Left = 52, Left = 52,
Right = 1017, Right = 1017,
Top = 201, Top = 201,
Bottom = 807 Bottom = 807
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_fuel2", Name = "mp_fuel2",
MaxBottom = -2218, MaxBottom = -2218,
MaxTop = 4324, MaxTop = 4324,
MaxRight = -3115, MaxRight = -3115,
MaxLeft = 3193, MaxLeft = 3193,
Left = 39, Left = 39,
Right = 888, Right = 888,
Top = 24, Top = 24,
Bottom = 906 Bottom = 906
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_overgrown", Name = "mp_overgrown",
MaxBottom = -2052, MaxBottom = -2052,
MaxTop = 3236, MaxTop = 3236,
MaxRight = -5393, MaxRight = -5393,
MaxLeft = 808, MaxLeft = 808,
Left = 17, Left = 17,
Right = 1024, Right = 1024,
Top = 0, Top = 0,
Bottom = 847 Bottom = 847
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_storm", Name = "mp_storm",
MaxBottom = -2317, MaxBottom = -2317,
MaxTop = 2537, MaxTop = 2537,
MaxRight = -2223, MaxRight = -2223,
MaxLeft = 2097, MaxLeft = 2097,
Left = 79, Left = 79,
Right = 932, Right = 932,
Top = 20, Top = 20,
Bottom = 995 Bottom = 995
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_strike", Name = "mp_strike",
MaxBottom = -2504, MaxBottom = -2504,
MaxTop = 3359, MaxTop = 3359,
MaxRight = -3105, MaxRight = -3105,
MaxLeft = 2822, MaxLeft = 2822,
Left = 40, Left = 40,
Right = 969, Right = 969,
Top = 36, Top = 36,
Bottom = 955 Bottom = 955
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_trailerpark", Name = "mp_trailerpark",
MaxBottom = -2709, MaxBottom = -2709,
MaxTop = 2027, MaxTop = 2027,
MaxRight = -1719, MaxRight = -1719,
MaxLeft = 1666, MaxLeft = 1666,
Left = 152, Left = 152,
Right = 785, Right = 785,
Top = 50, Top = 50,
Bottom = 931 Bottom = 931
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_vacant", Name = "mp_vacant",
MaxBottom = -2089, MaxBottom = -2089,
MaxTop = 1652, MaxTop = 1652,
MaxRight = -1393, MaxRight = -1393,
MaxLeft = 1789, MaxLeft = 1789,
Left = 122, Left = 122,
Right = 909, Right = 909,
Top = 16, Top = 16,
Bottom = 951 Bottom = 951
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_nuked", Name = "mp_nuked",
MaxLeft = 1211, MaxLeft = 1211,
MaxRight = -557, MaxRight = -557,
MaxBottom = -2110, MaxBottom = -2110,
MaxTop = 2092, MaxTop = 2092,
Left = 340, Left = 340,
Right = 698, Right = 698,
Bottom = 930, Bottom = 930,
Top = 92 Top = 92
}, },
new MapInfo() new MapInfo()
{ {
Name = "mp_killhouse", Name = "mp_killhouse",
MaxLeft = 4276, MaxLeft = 4276,
MaxRight = 2973, MaxRight = 2973,
MaxBottom = -1164, MaxBottom = -1164,
MaxTop = 1392, MaxTop = 1392,
Left = 319, Left = 319,
Right = 758, Right = 758,
Bottom = 937, Bottom = 937,
Top = 87 Top = 87
} }
}; };
return this; return this;
}
public string Name() => "LiveRadar";
} }
public string Name() => "LiveRadar";
} }

View File

@ -1,26 +1,24 @@
using LiveRadar.Configuration; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using SharedLibraryCore; using SharedLibraryCore;
using SharedLibraryCore.Dtos; using SharedLibraryCore.Dtos;
using SharedLibraryCore.Interfaces; using SharedLibraryCore.Interfaces;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using IW4MAdmin.Plugins.LiveRadar.Configuration;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
namespace LiveRadar.Web.Controllers namespace IW4MAdmin.Plugins.LiveRadar.Web.Controllers
{ {
public class RadarController : BaseController public class RadarController : BaseController
{ {
private readonly IManager _manager; private readonly IManager _manager;
private static LiveRadarConfiguration _config; private readonly LiveRadarConfiguration _config;
private readonly IConfigurationHandler<LiveRadarConfiguration> _configurationHandler;
public RadarController(IManager manager, IConfigurationHandlerFactory configurationHandlerFactory) : public RadarController(IManager manager, LiveRadarConfiguration config) :
base(manager) base(manager)
{ {
_manager = manager; _manager = manager;
_configurationHandler = _config = config;
configurationHandlerFactory.GetConfigurationHandler<LiveRadarConfiguration>("LiveRadarConfiguration");
} }
[HttpGet] [HttpGet]
@ -32,8 +30,8 @@ namespace LiveRadar.Web.Controllers
.Select(server => new ServerInfo .Select(server => new ServerInfo
{ {
Name = server.Hostname, Name = server.Hostname,
IPAddress = server.IP, IPAddress = server.ListenAddress,
Port = server.Port Port = server.ListenPort
}); });
ViewBag.Title = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_RADAR_TITLE"]; ViewBag.Title = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_RADAR_TITLE"];
@ -56,12 +54,6 @@ namespace LiveRadar.Web.Controllers
return NotFound(); return NotFound();
} }
if (_config == null)
{
await _configurationHandler.BuildAsync();
_config = _configurationHandler.Configuration() ?? new LiveRadarConfiguration();
}
var map = _config.Maps.FirstOrDefault(map => map.Name == server.CurrentMap.Name); var map = _config.Maps.FirstOrDefault(map => map.Name == server.CurrentMap.Name);
if (map == null) if (map == null)

View File

@ -0,0 +1,38 @@
using SharedLibraryCore;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Interfaces;
using System.Collections.Generic;
using SharedLibraryCore.Events.Game;
using EventGeneratorCallback = System.ValueTuple<string, string,
System.Func<string, SharedLibraryCore.Interfaces.IEventParserConfiguration,
SharedLibraryCore.GameEvent,
SharedLibraryCore.GameEvent>>;
namespace IW4MAdmin.Plugins.LiveRadar.Events;
public class Script : IRegisterEvent
{
private const string EventLiveRadar = "LiveRadar";
private EventGeneratorCallback LiveRadar()
{
return (EventLiveRadar, EventLiveRadar, (eventLine, _, _) =>
{
var radarEvent = new LiveRadarEvent
{
Type = GameEvent.EventType.Other,
Subtype = EventLiveRadar,
Origin = new EFClient { NetworkId = 0 },
ScriptData = eventLine
};
return radarEvent;
}
);
}
public IEnumerable<EventGeneratorCallback> Events => new[] { LiveRadar() };
}
public class LiveRadarEvent : GameScriptEvent
{
}

View File

@ -1,33 +0,0 @@
using SharedLibraryCore;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Interfaces;
using System.Collections.Generic;
using EventGeneratorCallback = System.ValueTuple<string, string,
System.Func<string, SharedLibraryCore.Interfaces.IEventParserConfiguration,
SharedLibraryCore.GameEvent,
SharedLibraryCore.GameEvent>>;
namespace LiveRadar.Events
{
public class Script : IRegisterEvent
{
private const string EVENT_LIVERADAR = "LiveRadar";
private EventGeneratorCallback LiveRadar()
{
return (EVENT_LIVERADAR, EVENT_LIVERADAR, (string eventLine, IEventParserConfiguration config, GameEvent autoEvent) =>
{
string[] lineSplit = eventLine.Split(";");
autoEvent.Type = GameEvent.EventType.Other;
autoEvent.Subtype = EVENT_LIVERADAR;
autoEvent.Origin = new EFClient() { NetworkId = 0 };
autoEvent.Extra = lineSplit[1]; // guid
return autoEvent;
}
);
}
public IEnumerable<EventGeneratorCallback> Events => new[] { LiveRadar() };
}
}

View File

@ -16,7 +16,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2022.10.13.1" PrivateAssets="All" /> <PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2023.2.11.1" PrivateAssets="All" />
</ItemGroup> </ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent"> <Target Name="PostBuild" AfterTargets="PostBuildEvent">

View File

@ -1,31 +1,26 @@
using System; namespace IW4MAdmin.Plugins.LiveRadar;
using System.Collections.Generic;
using System.Text;
namespace LiveRadar public class MapInfo
{ {
public class MapInfo public string Name { get; set; }
{ public string Alias { get; set; }
public string Name { get; set; } // distance from the edge of the minimap image
public string Alias { get; set; } // to the "playable" area
// distance from the edge of the minimap image public int Top { get; set; }
// to the "playable" area public int Bottom { get; set; }
public int Top { get; set; } public int Left { get; set; }
public int Bottom { get; set; } public int Right { get; set; }
public int Left { get; set; } // maximum coordinate values for the map
public int Right { get; set; } public int MaxTop { get; set; }
// maximum coordinate values for the map public int MaxBottom { get; set; }
public int MaxTop { get; set; } public int MaxLeft { get; set; }
public int MaxBottom { get; set; } public int MaxRight { get; set; }
public int MaxLeft { get; set; } public float Rotation { get; set; }
public int MaxRight { get; set; } public float ViewPositionRotation { get; set; }
public float Rotation { get; set; } public float CenterX { get; set; }
public float ViewPositionRotation { get; set; } public float CenterY { get; set; }
public float CenterX { get; set; } public float Scaler { get; set; } = 1.0f;
public float CenterY { get; set; }
public float Scaler { get; set; } = 1.0f;
public int Width => MaxLeft - MaxRight; public int Width => MaxLeft - MaxRight;
public int Height => MaxTop - MaxBottom; public int Height => MaxTop - MaxBottom;
}
} }

View File

@ -1,132 +1,145 @@
using LiveRadar.Configuration; using SharedLibraryCore;
using SharedLibraryCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Data.Models;
using IW4MAdmin.Plugins.LiveRadar.Configuration;
using IW4MAdmin.Plugins.LiveRadar.Events;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SharedLibraryCore.Configuration; using SharedLibraryCore.Configuration;
using SharedLibraryCore.Events.Game;
using SharedLibraryCore.Events.Server;
using SharedLibraryCore.Interfaces; using SharedLibraryCore.Interfaces;
using SharedLibraryCore.Interfaces.Events;
using ILogger = Microsoft.Extensions.Logging.ILogger; using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace LiveRadar namespace IW4MAdmin.Plugins.LiveRadar;
public class Plugin : IPluginV2
{ {
public class Plugin : IPlugin public string Name => "Live Radar";
public string Version => Utilities.GetVersionAsString();
public string Author => "RaidMax";
private bool _addedPage;
private readonly Dictionary<string, long> _botGuidLookups;
private readonly object _lockObject = new();
private readonly ILogger _logger;
private readonly ApplicationConfiguration _appConfig;
public static void RegisterDependencies(IServiceCollection serviceCollection)
{ {
public string Name => "Live Radar"; serviceCollection.AddConfiguration<LiveRadarConfiguration>();
}
public float Version => (float)Utilities.GetVersionAsDouble(); public Plugin(ILogger<Plugin> logger, ApplicationConfiguration appConfig)
{
_botGuidLookups = new Dictionary<string, long>();
_logger = logger;
_appConfig = appConfig;
public string Author => "RaidMax"; IGameServerEventSubscriptions.MonitoringStarted += OnMonitoringStarted;
IGameEventSubscriptions.ClientEnteredMatch += OnClientEnteredMatch;
IGameEventSubscriptions.ScriptEventTriggered += OnScriptEvent;
}
private readonly IConfigurationHandler<LiveRadarConfiguration> _configurationHandler; private Task OnScriptEvent(GameScriptEvent scriptEvent, CancellationToken token)
private readonly Dictionary<string, long> _botGuidLookups; {
private bool addedPage; if (scriptEvent is not LiveRadarEvent radarEvent)
private readonly object lockObject = new object();
private readonly ILogger _logger;
private readonly ApplicationConfiguration _appConfig;
public Plugin(ILogger<Plugin> logger, IConfigurationHandlerFactory configurationHandlerFactory, ApplicationConfiguration appConfig)
{ {
_configurationHandler = configurationHandlerFactory.GetConfigurationHandler<LiveRadarConfiguration>("LiveRadarConfiguration"); return Task.CompletedTask;
_botGuidLookups = new Dictionary<string, long>();
_logger = logger;
_appConfig = appConfig;
} }
public Task OnEventAsync(GameEvent E, Server S) try
{
var originalBotGuid = radarEvent.ScriptData.Split(";")[1];
if (originalBotGuid.IsBotGuid() && _appConfig.IgnoreBots)
{
return Task.CompletedTask;
}
var botKey = $"BotGuid_{originalBotGuid}";
long generatedBotGuid;
lock (_lockObject)
{
var hasBotKey = _botGuidLookups.ContainsKey(botKey);
if (!hasBotKey && originalBotGuid.IsBotGuid())
{
// edge case where the bot guid has not been registered yet
return Task.CompletedTask;
}
generatedBotGuid = hasBotKey
? _botGuidLookups[botKey]
: (originalBotGuid ?? "0").ConvertGuidToLong(NumberStyles.HexNumber);
}
var radarUpdate = RadarEvent.Parse(scriptEvent.ScriptData, generatedBotGuid);
var client =
radarEvent.Owner.ConnectedClients.FirstOrDefault(client => client.NetworkId == radarUpdate.Guid);
if (client != null)
{
radarUpdate.Name = client.Name.StripColors();
client.SetAdditionalProperty("LiveRadar", radarUpdate);
}
}
catch (Exception e)
{
_logger.LogError(e, "Could not parse live radar output: {Data}", e.Data);
}
return Task.CompletedTask;
}
private Task OnClientEnteredMatch(ClientEnterMatchEvent clientEvent, CancellationToken token)
{
if (!clientEvent.Client.IsBot)
{
return Task.CompletedTask;
}
var botKey = $"BotGuid_{clientEvent.ClientNetworkId}";
lock (_lockObject)
{
if (!_botGuidLookups.ContainsKey(botKey))
{
_botGuidLookups.Add(botKey, clientEvent.Client.NetworkId);
}
}
return Task.CompletedTask;
}
private Task OnMonitoringStarted(MonitorStartEvent monitorEvent, CancellationToken token)
{
lock (_lockObject)
{ {
// if it's an IW4 game, with custom callbacks, we want to // if it's an IW4 game, with custom callbacks, we want to
// enable the live radar page // enable the live radar page
lock (lockObject) var shouldRegisterPage = monitorEvent.Server.GameCode != Reference.Game.IW4 ||
!monitorEvent.Server.IsLegacyGameIntegrationEnabled ||
_addedPage;
if (shouldRegisterPage)
{ {
if (E.Type == GameEvent.EventType.Start && return Task.CompletedTask;
S.GameName == Server.Game.IW4 &&
S.CustomCallback &&
!addedPage)
{
E.Owner.Manager.GetPageList().Pages.Add(Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_RADAR_TITLE"], "/Radar");
addedPage = true;
}
} }
if (E.Type == GameEvent.EventType.PreConnect && E.Origin.IsBot) (monitorEvent.Source as IManager)?.GetPageList().Pages
{ .Add(Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_RADAR_TITLE"], "/Radar");
string botKey = $"BotGuid_{E.Extra}"; _addedPage = true;
lock (lockObject)
{
if (!_botGuidLookups.ContainsKey(botKey))
{
_botGuidLookups.Add(botKey, E.Origin.NetworkId);
}
}
}
if (E.Type == GameEvent.EventType.Other && E.Subtype == "LiveRadar")
{
try
{
if (((string) E.Extra).IsBotGuid() && _appConfig.IgnoreBots)
{
return Task.CompletedTask;
}
string botKey = $"BotGuid_{E.Extra}";
long generatedBotGuid;
lock (lockObject)
{
var hasBotKey = _botGuidLookups.ContainsKey(botKey);
if (!hasBotKey && ((string)E.Extra).IsBotGuid())
{
// edge case where the bot guid has not been registered yet
return Task.CompletedTask;
}
generatedBotGuid = hasBotKey
? _botGuidLookups[botKey]
: (E.Extra.ToString() ?? "0").ConvertGuidToLong(NumberStyles.HexNumber);
}
var radarUpdate = RadarEvent.Parse(E.Data, generatedBotGuid);
var client = S.Manager.GetActiveClients().FirstOrDefault(_client => _client.NetworkId == radarUpdate.Guid);
if (client != null)
{
radarUpdate.Name = client.Name.StripColors();
client.SetAdditionalProperty("LiveRadar", radarUpdate);
}
}
catch (Exception e)
{
_logger.LogError(e, "Could not parse live radar output: {data}", e.Data);
}
}
return Task.CompletedTask;
} }
public async Task OnLoadAsync(IManager manager) return Task.CompletedTask;
{
await _configurationHandler.BuildAsync();
if (_configurationHandler.Configuration() == null)
{
_configurationHandler.Set((LiveRadarConfiguration)new LiveRadarConfiguration().Generate());
await _configurationHandler.Save();
}
}
public Task OnTickAsync(Server S)
{
return Task.CompletedTask;
}
public Task OnUnloadAsync()
{
return Task.CompletedTask;
}
} }
} }

View File

@ -5,60 +5,59 @@ using System.Linq;
// ReSharper disable CompareOfFloatsByEqualityOperator // ReSharper disable CompareOfFloatsByEqualityOperator
#pragma warning disable CS0659 #pragma warning disable CS0659
namespace LiveRadar namespace IW4MAdmin.Plugins.LiveRadar;
public class RadarEvent
{ {
public class RadarEvent public string Name { get; set; }
public long Guid { get; set; }
public Vector3 Location { get; set; }
public Vector3 ViewAngles { get; set; }
public string Team { get; set; }
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 int Id => GetHashCode();
public override bool Equals(object obj)
{ {
public string Name { get; set; } if (obj is RadarEvent re)
public long Guid { get; set; }
public Vector3 Location { get; set; }
public Vector3 ViewAngles { get; set; }
public string Team { get; set; }
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 int Id => GetHashCode();
public override bool Equals(object obj)
{ {
if (obj is RadarEvent re) return re.ViewAngles.X == ViewAngles.X &&
{ re.ViewAngles.Y == ViewAngles.Y &&
return re.ViewAngles.X == ViewAngles.X && re.ViewAngles.Z == ViewAngles.Z &&
re.ViewAngles.Y == ViewAngles.Y && re.Location.X == Location.X &&
re.ViewAngles.Z == ViewAngles.Z && re.Location.Y == Location.Y &&
re.Location.X == Location.X && re.Location.Z == Location.Z;
re.Location.Y == Location.Y &&
re.Location.Z == Location.Z;
}
return false;
} }
public static RadarEvent Parse(string input, long generatedBotGuid) return false;
}
public static RadarEvent Parse(string input, long generatedBotGuid)
{
var items = input.Split(';').Skip(1).ToList();
var parsedEvent = new RadarEvent()
{ {
var items = input.Split(';').Skip(1).ToList(); Guid = generatedBotGuid,
Location = Vector3.Parse(items[1]),
ViewAngles = Vector3.Parse(items[2]).FixIW4Angles(),
Team = items[3],
Kills = int.Parse(items[4]),
Deaths = int.Parse(items[5]),
Score = int.Parse(items[6]),
Weapon = items[7],
Health = int.Parse(items[8]),
IsAlive = items[9] == "1",
PlayTime = Convert.ToInt32(items[10])
};
var parsedEvent = new RadarEvent() return parsedEvent;
{
Guid = generatedBotGuid,
Location = Vector3.Parse(items[1]),
ViewAngles = Vector3.Parse(items[2]).FixIW4Angles(),
Team = items[3],
Kills = int.Parse(items[4]),
Deaths = int.Parse(items[5]),
Score = int.Parse(items[6]),
Weapon = items[7],
Health = int.Parse(items[8]),
IsAlive = items[9] == "1",
PlayTime = Convert.ToInt32(items[10])
};
return parsedEvent;
}
} }
} }