2020-02-11 17:44:06 -05:00
|
|
|
|
using LiveRadar.Configuration;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2019-06-30 14:37:59 -04:00
|
|
|
|
using Newtonsoft.Json;
|
2019-08-02 19:04:34 -04:00
|
|
|
|
using SharedLibraryCore;
|
2019-07-19 11:33:00 -04:00
|
|
|
|
using SharedLibraryCore.Dtos;
|
2019-12-02 16:52:36 -05:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2019-06-30 14:37:59 -04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace LiveRadar.Web.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class RadarController : BaseController
|
|
|
|
|
{
|
2019-07-05 21:53:03 -04:00
|
|
|
|
private static readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings()
|
|
|
|
|
{
|
|
|
|
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
|
|
|
|
ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver()
|
|
|
|
|
};
|
|
|
|
|
|
2019-12-02 16:52:36 -05:00
|
|
|
|
private readonly IManager _manager;
|
2020-02-11 17:44:06 -05:00
|
|
|
|
private readonly LiveRadarConfiguration _config;
|
2019-12-02 16:52:36 -05:00
|
|
|
|
|
2020-02-11 17:44:06 -05:00
|
|
|
|
public RadarController(IManager manager, IConfigurationHandlerFactory configurationHandlerFactory) : base(manager)
|
2019-12-02 16:52:36 -05:00
|
|
|
|
{
|
|
|
|
|
_manager = manager;
|
2020-02-11 17:44:06 -05:00
|
|
|
|
_config = configurationHandlerFactory.GetConfigurationHandler<LiveRadarConfiguration>("LiveRadarConfiguration").Configuration() ?? new LiveRadarConfiguration();
|
2019-12-02 16:52:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-30 14:37:59 -04:00
|
|
|
|
[HttpGet]
|
2019-07-19 11:33:00 -04:00
|
|
|
|
[Route("Radar/{serverId}")]
|
2019-10-09 16:51:02 -04:00
|
|
|
|
public IActionResult Index(long? serverId = null)
|
2019-06-30 14:37:59 -04:00
|
|
|
|
{
|
2019-07-05 21:53:03 -04:00
|
|
|
|
ViewBag.IsFluid = true;
|
2019-08-10 10:08:26 -04:00
|
|
|
|
ViewBag.Title = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_RADAR_TITLE"];
|
2019-12-02 16:52:36 -05:00
|
|
|
|
ViewBag.ActiveServerId = serverId ?? _manager.GetServers().FirstOrDefault()?.EndPoint;
|
|
|
|
|
ViewBag.Servers = _manager.GetServers()
|
2019-08-10 10:08:26 -04:00
|
|
|
|
.Where(_server => _server.GameName == Server.Game.IW4)
|
|
|
|
|
.Select(_server => new ServerInfo()
|
|
|
|
|
{
|
|
|
|
|
Name = _server.Hostname,
|
|
|
|
|
ID = _server.EndPoint
|
|
|
|
|
});
|
2019-07-19 11:33:00 -04:00
|
|
|
|
|
2019-06-30 14:37:59 -04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-19 11:33:00 -04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("Radar/{serverId}/Map")]
|
2019-06-30 14:37:59 -04:00
|
|
|
|
public IActionResult Map(long? serverId = null)
|
|
|
|
|
{
|
2019-12-02 16:52:36 -05:00
|
|
|
|
var server = serverId == null ? _manager.GetServers().FirstOrDefault() : _manager.GetServers().FirstOrDefault(_server => _server.EndPoint == serverId);
|
2020-02-11 17:44:06 -05:00
|
|
|
|
var map = _config.Maps.FirstOrDefault(_map => _map.Name == server.CurrentMap.Name);
|
2019-06-30 14:37:59 -04:00
|
|
|
|
|
2019-07-19 11:33:00 -04:00
|
|
|
|
if (map != null)
|
|
|
|
|
{
|
|
|
|
|
map.Alias = server.CurrentMap.Alias;
|
|
|
|
|
return Json(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// occurs if we don't recognize the map
|
|
|
|
|
return StatusCode(500);
|
2019-06-30 14:37:59 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-05 21:53:03 -04:00
|
|
|
|
[HttpGet]
|
2019-07-19 11:33:00 -04:00
|
|
|
|
[Route("Radar/{serverId}/Data")]
|
2019-07-05 21:53:03 -04:00
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
2019-06-30 14:37:59 -04:00
|
|
|
|
public IActionResult Data(long? serverId = null)
|
|
|
|
|
{
|
2019-12-02 16:52:36 -05:00
|
|
|
|
var server = serverId == null ? _manager.GetServers()[0] : _manager.GetServers().First(_server => _server.EndPoint == serverId);
|
2019-07-05 21:53:03 -04:00
|
|
|
|
var radarInfo = server.GetClientsAsList().Select(_client => _client.GetAdditionalProperty<RadarEvent>("LiveRadar")).ToList();
|
2019-06-30 14:37:59 -04:00
|
|
|
|
return Json(radarInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2019-07-19 11:33:00 -04:00
|
|
|
|
[Route("Radar/Update")]
|
2019-06-30 14:37:59 -04:00
|
|
|
|
public IActionResult Update(string payload)
|
|
|
|
|
{
|
|
|
|
|
var radarUpdate = RadarEvent.Parse(payload);
|
2019-12-02 16:52:36 -05:00
|
|
|
|
var client = _manager.GetActiveClients().FirstOrDefault(_client => _client.NetworkId == radarUpdate.Guid);
|
2019-07-02 18:30:05 -04:00
|
|
|
|
|
|
|
|
|
if (client != null)
|
|
|
|
|
{
|
2019-08-02 19:04:34 -04:00
|
|
|
|
radarUpdate.Name = client.Name.StripColors();
|
2019-07-02 18:30:05 -04:00
|
|
|
|
client.SetAdditionalProperty("LiveRadar", radarUpdate);
|
|
|
|
|
}
|
2019-06-30 14:37:59 -04:00
|
|
|
|
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-05 21:53:03 -04:00
|
|
|
|
}
|