2019-07-05 21:53:03 -04:00
|
|
|
|
using LiveRadar.Configuration;
|
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Configuration;
|
2019-06-30 14:37:59 -04:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace LiveRadar
|
|
|
|
|
{
|
|
|
|
|
public class Plugin : IPlugin
|
|
|
|
|
{
|
|
|
|
|
public string Name => "Live Radar";
|
|
|
|
|
|
|
|
|
|
public float Version => (float)Utilities.GetVersionAsDouble();
|
|
|
|
|
|
|
|
|
|
public string Author => "RaidMax";
|
|
|
|
|
|
2020-02-11 17:44:06 -05:00
|
|
|
|
private readonly IConfigurationHandler<LiveRadarConfiguration> _configurationHandler;
|
|
|
|
|
|
|
|
|
|
public Plugin(IConfigurationHandlerFactory configurationHandlerFactory)
|
|
|
|
|
{
|
|
|
|
|
_configurationHandler = configurationHandlerFactory.GetConfigurationHandler<LiveRadarConfiguration>("LiveRadarConfiguration");
|
|
|
|
|
}
|
2019-07-05 21:53:03 -04:00
|
|
|
|
|
2019-06-30 14:37:59 -04:00
|
|
|
|
public Task OnEventAsync(GameEvent E, Server S)
|
|
|
|
|
{
|
|
|
|
|
if (E.Type == GameEvent.EventType.Unknown)
|
|
|
|
|
{
|
|
|
|
|
if (E.Data?.StartsWith("LiveRadar") ?? false)
|
|
|
|
|
{
|
2019-07-29 13:08:25 -04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var radarUpdate = RadarEvent.Parse(E.Data);
|
|
|
|
|
var client = S.Manager.GetActiveClients().FirstOrDefault(_client => _client.NetworkId == radarUpdate.Guid);
|
|
|
|
|
|
|
|
|
|
if (client != null)
|
|
|
|
|
{
|
2019-08-02 19:04:34 -04:00
|
|
|
|
radarUpdate.Name = client.Name.StripColors();
|
2019-07-29 13:08:25 -04:00
|
|
|
|
client.SetAdditionalProperty("LiveRadar", radarUpdate);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-05 21:53:03 -04:00
|
|
|
|
|
2020-02-11 17:44:06 -05:00
|
|
|
|
catch (Exception e)
|
2019-07-05 21:53:03 -04:00
|
|
|
|
{
|
2019-07-29 13:08:25 -04:00
|
|
|
|
S.Logger.WriteWarning($"Could not parse live radar output: {e.Data}");
|
|
|
|
|
S.Logger.WriteDebug(e.GetExceptionInfo());
|
2019-07-05 21:53:03 -04:00
|
|
|
|
}
|
2019-06-30 14:37:59 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-05 21:53:03 -04:00
|
|
|
|
public async Task OnLoadAsync(IManager manager)
|
2019-06-30 14:37:59 -04:00
|
|
|
|
{
|
2020-02-11 17:44:06 -05:00
|
|
|
|
if (_configurationHandler.Configuration() == null)
|
2019-07-05 21:53:03 -04:00
|
|
|
|
{
|
2020-02-11 17:44:06 -05:00
|
|
|
|
_configurationHandler.Set((LiveRadarConfiguration)new LiveRadarConfiguration().Generate());
|
|
|
|
|
await _configurationHandler.Save();
|
2019-07-05 21:53:03 -04:00
|
|
|
|
}
|
2019-07-19 11:33:00 -04:00
|
|
|
|
|
2020-04-11 19:05:18 -04:00
|
|
|
|
if (manager.GetServers().Any(_server => _server.GameName == Server.Game.IW4))
|
|
|
|
|
{
|
|
|
|
|
manager.GetPageList().Pages.Add(Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_RADAR_TITLE"], "/Radar/All");
|
|
|
|
|
}
|
2019-06-30 14:37:59 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task OnTickAsync(Server S)
|
|
|
|
|
{
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task OnUnloadAsync()
|
|
|
|
|
{
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|