2020-02-11 17:44:06 -05:00
|
|
|
|
using LiveRadar.Configuration;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
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;
|
2022-01-28 10:35:01 -05:00
|
|
|
|
using System.Threading.Tasks;
|
2021-08-14 12:30:15 -04:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2019-06-30 14:37:59 -04:00
|
|
|
|
|
|
|
|
|
namespace LiveRadar.Web.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class RadarController : BaseController
|
|
|
|
|
{
|
2019-12-02 16:52:36 -05:00
|
|
|
|
private readonly IManager _manager;
|
2022-01-28 10:35:01 -05:00
|
|
|
|
private static LiveRadarConfiguration _config;
|
|
|
|
|
private readonly IConfigurationHandler<LiveRadarConfiguration> _configurationHandler;
|
2019-12-02 16:52:36 -05:00
|
|
|
|
|
2022-04-22 16:13:51 -04:00
|
|
|
|
public RadarController(IManager manager, IConfigurationHandlerFactory configurationHandlerFactory) :
|
|
|
|
|
base(manager)
|
2019-12-02 16:52:36 -05:00
|
|
|
|
{
|
|
|
|
|
_manager = manager;
|
2022-01-28 10:35:01 -05:00
|
|
|
|
_configurationHandler =
|
|
|
|
|
configurationHandlerFactory.GetConfigurationHandler<LiveRadarConfiguration>("LiveRadarConfiguration");
|
2019-12-02 16:52:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-30 14:37:59 -04:00
|
|
|
|
[HttpGet]
|
2022-04-22 16:13:51 -04:00
|
|
|
|
[Route("Radar/{serverId?}")]
|
2022-04-19 19:43:58 -04:00
|
|
|
|
public IActionResult Index(string serverId = null)
|
2019-06-30 14:37:59 -04:00
|
|
|
|
{
|
2022-04-22 16:13:51 -04:00
|
|
|
|
var servers = _manager.GetServers()
|
2022-04-19 19:43:58 -04:00
|
|
|
|
.Where(server => server.GameName == Server.Game.IW4)
|
|
|
|
|
.Select(server => new ServerInfo
|
2019-08-10 10:08:26 -04:00
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
Name = server.Hostname,
|
|
|
|
|
IPAddress = server.IP,
|
|
|
|
|
Port = server.Port
|
2019-08-10 10:08:26 -04:00
|
|
|
|
});
|
2022-04-22 16:13:51 -04:00
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
ViewBag.Title = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_RADAR_TITLE"];
|
|
|
|
|
ViewBag.SelectedServerId = string.IsNullOrEmpty(serverId) ? servers.FirstOrDefault()?.Endpoint : serverId;
|
2019-07-19 11:33:00 -04:00
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
// ReSharper disable once Mvc.ViewNotResolved
|
|
|
|
|
return View("~/Views/Plugins/LiveRadar/Radar/Index.cshtml", servers);
|
2019-06-30 14:37:59 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-19 11:33:00 -04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("Radar/{serverId}/Map")]
|
2022-04-22 16:13:51 -04:00
|
|
|
|
public async Task<IActionResult> Map(string serverId = null)
|
2019-06-30 14:37:59 -04:00
|
|
|
|
{
|
2022-04-22 16:13:51 -04:00
|
|
|
|
var server = serverId == null
|
|
|
|
|
? _manager.GetServers().FirstOrDefault()
|
|
|
|
|
: _manager.GetServers().FirstOrDefault(server => server.ToString() == serverId);
|
|
|
|
|
|
2021-08-14 12:30:15 -04:00
|
|
|
|
if (server == null)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
2022-01-28 10:35:01 -05:00
|
|
|
|
|
|
|
|
|
if (_config == null)
|
|
|
|
|
{
|
|
|
|
|
await _configurationHandler.BuildAsync();
|
|
|
|
|
_config = _configurationHandler.Configuration() ?? new LiveRadarConfiguration();
|
|
|
|
|
}
|
2022-04-22 16:13:51 -04:00
|
|
|
|
|
|
|
|
|
var map = _config.Maps.FirstOrDefault(map => map.Name == server.CurrentMap.Name);
|
2019-06-30 14:37:59 -04:00
|
|
|
|
|
2021-08-14 12:30:15 -04:00
|
|
|
|
if (map == null)
|
2019-07-19 11:33:00 -04:00
|
|
|
|
{
|
2021-08-14 12:30:15 -04:00
|
|
|
|
// occurs if we don't recognize the map
|
|
|
|
|
return StatusCode(StatusCodes.Status422UnprocessableEntity);
|
2019-07-19 11:33:00 -04:00
|
|
|
|
}
|
2022-04-22 16:13:51 -04:00
|
|
|
|
|
2021-08-14 12:30:15 -04:00
|
|
|
|
map.Alias = server.CurrentMap.Alias;
|
|
|
|
|
return Json(map);
|
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)]
|
2022-04-22 16:13:51 -04:00
|
|
|
|
public IActionResult Data(string serverId = null)
|
2019-06-30 14:37:59 -04:00
|
|
|
|
{
|
2022-04-22 16:13:51 -04:00
|
|
|
|
var server = serverId == null
|
|
|
|
|
? _manager.GetServers().FirstOrDefault()
|
|
|
|
|
: _manager.GetServers().FirstOrDefault(server => server.ToString() == serverId);
|
|
|
|
|
|
|
|
|
|
if (server == null)
|
2019-07-02 18:30:05 -04:00
|
|
|
|
{
|
2022-04-22 16:13:51 -04:00
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var radarInfo = server.GetClientsAsList()
|
|
|
|
|
.Select(client => client.GetAdditionalProperty<RadarEvent>("LiveRadar")).ToList();
|
|
|
|
|
|
|
|
|
|
return Json(radarInfo);
|
2019-06-30 14:37:59 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-28 10:35:01 -05:00
|
|
|
|
}
|