2019-06-30 14:37:59 -04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Newtonsoft.Json;
|
2019-07-19 11:33:00 -04:00
|
|
|
|
using SharedLibraryCore.Dtos;
|
2019-06-30 14:37:59 -04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using WebfrontCore.Controllers;
|
|
|
|
|
|
|
|
|
|
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-06-30 14:37:59 -04:00
|
|
|
|
[HttpGet]
|
2019-07-19 11:33:00 -04:00
|
|
|
|
[Route("Radar/{serverId}")]
|
|
|
|
|
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-07-19 11:33:00 -04:00
|
|
|
|
ViewBag.Title = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_RADAR_TITLE"];
|
|
|
|
|
ViewBag.ActiveServerId = serverId ?? Manager.GetServers().FirstOrDefault()?.EndPoint;
|
|
|
|
|
ViewBag.Servers = Manager.GetServers().Select(_server => new ServerInfo()
|
|
|
|
|
{
|
|
|
|
|
Name = _server.Hostname,
|
|
|
|
|
ID = _server.EndPoint
|
|
|
|
|
});
|
|
|
|
|
|
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-07-19 11:33:00 -04:00
|
|
|
|
var server = serverId == null ? Manager.GetServers().FirstOrDefault() : Manager.GetServers().FirstOrDefault(_server => _server.EndPoint == serverId);
|
2019-07-05 21:53:03 -04:00
|
|
|
|
var map = Plugin.Config.Configuration().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-07-19 11:33:00 -04: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-07-02 18:30:05 -04:00
|
|
|
|
var client = Manager.GetActiveClients().FirstOrDefault(_client => _client.NetworkId == radarUpdate.Guid);
|
|
|
|
|
|
|
|
|
|
if (client != null)
|
|
|
|
|
{
|
|
|
|
|
radarUpdate.Name = client.Name;
|
|
|
|
|
client.SetAdditionalProperty("LiveRadar", radarUpdate);
|
|
|
|
|
}
|
2019-06-30 14:37:59 -04:00
|
|
|
|
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-05 21:53:03 -04:00
|
|
|
|
}
|