IW4M-Admin/Plugins/LiveRadar/Controllers/RadarController.cs

98 lines
3.4 KiB
C#
Raw Normal View History

using LiveRadar.Configuration;
using Microsoft.AspNetCore.Mvc;
2019-08-02 19:04:34 -04:00
using SharedLibraryCore;
using SharedLibraryCore.Dtos;
move all the deployment setup into 2.4 pr (#85) * don't run build commands in release * fix test file * Set up CI with Azure Pipelines [skip ci] * Include fonts and fix automessage hidden command * more project changes * migration from bower to libman * more lib man changes * project update for sneaky commands * add missing canvas.js dep update projects not to have stupid extra dlls include in previous * update pipeline file * update post publish script and pipeline definition * fix broken yaml * move encoding conversion to seperate script * remove extra uneeded rank icons remove garbage language files being created remove frontend lib when done * fix publish script path * grab localizations through powershell * fix broken batch :shrug: * actually fixed * only include runtime compilation in debug mode for webfront * don't deploy un minified css use full jquery version * add step to download the scss for open iconic change the font path * update mkdir for iconic path * don't include old iconic css * correct font path for real now * copy script plugins * lots of changes for deployment * build the projects * use projectdir instead of solution dir * nerf script commands plugin fix live radar left over command * actually kill script command post build * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * fix the font file copy (I think) * maybe fix delete folder issue * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines
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
{
move all the deployment setup into 2.4 pr (#85) * don't run build commands in release * fix test file * Set up CI with Azure Pipelines [skip ci] * Include fonts and fix automessage hidden command * more project changes * migration from bower to libman * more lib man changes * project update for sneaky commands * add missing canvas.js dep update projects not to have stupid extra dlls include in previous * update pipeline file * update post publish script and pipeline definition * fix broken yaml * move encoding conversion to seperate script * remove extra uneeded rank icons remove garbage language files being created remove frontend lib when done * fix publish script path * grab localizations through powershell * fix broken batch :shrug: * actually fixed * only include runtime compilation in debug mode for webfront * don't deploy un minified css use full jquery version * add step to download the scss for open iconic change the font path * update mkdir for iconic path * don't include old iconic css * correct font path for real now * copy script plugins * lots of changes for deployment * build the projects * use projectdir instead of solution dir * nerf script commands plugin fix live radar left over command * actually kill script command post build * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * fix the font file copy (I think) * maybe fix delete folder issue * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines
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;
move all the deployment setup into 2.4 pr (#85) * don't run build commands in release * fix test file * Set up CI with Azure Pipelines [skip ci] * Include fonts and fix automessage hidden command * more project changes * migration from bower to libman * more lib man changes * project update for sneaky commands * add missing canvas.js dep update projects not to have stupid extra dlls include in previous * update pipeline file * update post publish script and pipeline definition * fix broken yaml * move encoding conversion to seperate script * remove extra uneeded rank icons remove garbage language files being created remove frontend lib when done * fix publish script path * grab localizations through powershell * fix broken batch :shrug: * actually fixed * only include runtime compilation in debug mode for webfront * don't deploy un minified css use full jquery version * add step to download the scss for open iconic change the font path * update mkdir for iconic path * don't include old iconic css * correct font path for real now * copy script plugins * lots of changes for deployment * build the projects * use projectdir instead of solution dir * nerf script commands plugin fix live radar left over command * actually kill script command post build * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * fix the font file copy (I think) * maybe fix delete folder issue * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines
2019-12-02 16:52:36 -05:00
2022-04-22 16:13:51 -04:00
public RadarController(IManager manager, IConfigurationHandlerFactory configurationHandlerFactory) :
base(manager)
move all the deployment setup into 2.4 pr (#85) * don't run build commands in release * fix test file * Set up CI with Azure Pipelines [skip ci] * Include fonts and fix automessage hidden command * more project changes * migration from bower to libman * more lib man changes * project update for sneaky commands * add missing canvas.js dep update projects not to have stupid extra dlls include in previous * update pipeline file * update post publish script and pipeline definition * fix broken yaml * move encoding conversion to seperate script * remove extra uneeded rank icons remove garbage language files being created remove frontend lib when done * fix publish script path * grab localizations through powershell * fix broken batch :shrug: * actually fixed * only include runtime compilation in debug mode for webfront * don't deploy un minified css use full jquery version * add step to download the scss for open iconic change the font path * update mkdir for iconic path * don't include old iconic css * correct font path for real now * copy script plugins * lots of changes for deployment * build the projects * use projectdir instead of solution dir * nerf script commands plugin fix live radar left over command * actually kill script command post build * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * fix the font file copy (I think) * maybe fix delete folder issue * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines
2019-12-02 16:52:36 -05:00
{
_manager = manager;
2022-01-28 10:35:01 -05:00
_configurationHandler =
configurationHandlerFactory.GetConfigurationHandler<LiveRadarConfiguration>("LiveRadarConfiguration");
move all the deployment setup into 2.4 pr (#85) * don't run build commands in release * fix test file * Set up CI with Azure Pipelines [skip ci] * Include fonts and fix automessage hidden command * more project changes * migration from bower to libman * more lib man changes * project update for sneaky commands * add missing canvas.js dep update projects not to have stupid extra dlls include in previous * update pipeline file * update post publish script and pipeline definition * fix broken yaml * move encoding conversion to seperate script * remove extra uneeded rank icons remove garbage language files being created remove frontend lib when done * fix publish script path * grab localizations through powershell * fix broken batch :shrug: * actually fixed * only include runtime compilation in debug mode for webfront * don't deploy un minified css use full jquery version * add step to download the scss for open iconic change the font path * update mkdir for iconic path * don't include old iconic css * correct font path for real now * copy script plugins * lots of changes for deployment * build the projects * use projectdir instead of solution dir * nerf script commands plugin fix live radar left over command * actually kill script command post build * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * fix the font file copy (I think) * maybe fix delete folder issue * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines
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
{
2022-04-19 19:43:58 -04:00
Name = server.Hostname,
IPAddress = server.IP,
Port = server.Port
});
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;
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
}
[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)
{
2021-08-14 12:30:15 -04:00
// occurs if we don't recognize the map
return StatusCode(StatusCodes.Status422UnprocessableEntity);
}
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]
[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
}