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

60 lines
2.0 KiB
C#
Raw Normal View History

2019-06-30 14:37:59 -04:00
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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]
public IActionResult Index()
{
2019-07-05 21:53:03 -04:00
ViewBag.IsFluid = true;
2019-06-30 14:37:59 -04:00
return View();
}
public IActionResult Map(long? serverId = null)
{
2019-07-05 21:53:03 -04:00
var server = Manager.GetServers().FirstOrDefault();
var map = Plugin.Config.Configuration().Maps.FirstOrDefault(_map => _map.Name == server.CurrentMap.Name);
2019-07-08 21:21:08 -04:00
map.Alias = server.CurrentMap.Alias;
2019-06-30 14:37:59 -04:00
return Json(map);
}
2019-07-05 21:53:03 -04:00
[HttpGet]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
2019-06-30 14:37:59 -04:00
public IActionResult Data(long? serverId = null)
{
var server = serverId == null ? Manager.GetServers()[0] : Manager.GetServers().First(_server => _server.GetHashCode() == 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]
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
}