finished server selection for live radar and adding it as button to home screen

only update flag for recent players if country code is available
This commit is contained in:
RaidMax 2019-07-19 10:33:00 -05:00
parent 5c90228320
commit 38f1169061
8 changed files with 54 additions and 16 deletions

View File

@ -1,9 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using SharedLibraryCore.Dtos;
using System.Linq;
using System.Text;
using WebfrontCore.Controllers;
namespace LiveRadar.Web.Controllers
@ -17,32 +15,50 @@ namespace LiveRadar.Web.Controllers
};
[HttpGet]
public IActionResult Index()
[Route("Radar/{serverId}")]
public IActionResult Index(long? serverId = null)
{
ViewBag.IsFluid = true;
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
});
return View();
}
[HttpGet]
[Route("Radar/{serverId}/Map")]
public IActionResult Map(long? serverId = null)
{
var server = Manager.GetServers().FirstOrDefault();
var server = serverId == null ? Manager.GetServers().FirstOrDefault() : Manager.GetServers().FirstOrDefault(_server => _server.EndPoint == serverId);
var map = Plugin.Config.Configuration().Maps.FirstOrDefault(_map => _map.Name == server.CurrentMap.Name);
map.Alias = server.CurrentMap.Alias;
if (map != null)
{
map.Alias = server.CurrentMap.Alias;
return Json(map);
}
// occurs if we don't recognize the map
return StatusCode(500);
}
[HttpGet]
[Route("Radar/{serverId}/Data")]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Data(long? serverId = null)
{
var server = serverId == null ? Manager.GetServers()[0] : Manager.GetServers().First(_server => _server.GetHashCode() == serverId);
var server = serverId == null ? Manager.GetServers()[0] : Manager.GetServers().First(_server => _server.EndPoint == serverId);
var radarInfo = server.GetClientsAsList().Select(_client => _client.GetAdditionalProperty<RadarEvent>("LiveRadar")).ToList();
return Json(radarInfo);
}
[HttpGet]
[Route("Radar/Update")]
public IActionResult Update(string payload)
{
var radarUpdate = RadarEvent.Parse(payload);

View File

@ -20,6 +20,12 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<Content Update="Views\_ViewImports.cshtml">
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy &quot;$(TargetPath)&quot; &quot;$(SolutionDir)BUILD\Plugins&quot;&#xD;&#xA;copy &quot;$(TargetDir)$(TargetName).Views$(TargetExt)&quot; $(SolutionDir)BUILD\Plugins&quot;" />
</Target>

View File

@ -47,6 +47,8 @@ namespace LiveRadar
Config.Set((LiveRadarConfiguration)new LiveRadarConfiguration().Generate());
await Config.Save();
}
manager.GetPageList().Pages.Add(Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_RADAR_TITLE"], "/Radar/All");
}
public Task OnTickAsync(Server S)

View File

@ -11,8 +11,21 @@
background-size: 1.5rem 1.5rem;
}
</style>
<div class="row p-0 ml-auto mr-auto mb-4">
<div class="col-12 col-xl-10 p-0 ml-auto mr-auto p-0 pl-lg-3 pr-lg-3 ">
<ul class="nav nav-tabs border-top border-bottom nav-fill" role="tablist">
@foreach (SharedLibraryCore.Dtos.ServerInfo server in ViewBag.Servers)
{
<li class="nav-item">
<a asp-controller="Radar" asp-action="Index" asp-route-serverId="@server.ID" class="nav-link @(server.ID == ViewBag.ActiveServerId ? "active": "")" aria-selected="@(server.ID == ViewBag.ActiveServerId ? "true": "false")">@server.Name</a>
</li>
}
</ul>
</div>
</div>
<div class="row p-0 ml-auto mr-auto col-12 col-xl-10">
<div class="p-0 pl-lg-3 pr-lg-3 m-0 col-lg-3 col-12 text-lg-right text-center player-data-left" style="opacity: 0">
<div class="p-0 pl-lg-3 pr-lg-3 m-0 col-lg-3 col-12 text-lg-right text-center player-data-left" style="opacity: 0;">
</div>
<div class="pl-0 pr-0 pl-lg-3 pr-lg-3 col-lg-6 col-12 pb-4">
<div id="map_name" class="h4 text-center pb-2 pt-2 mb-0 bg-primary">&mdash;</div>
@ -21,12 +34,12 @@
</div>
</div>
<div class="p-0 pl-lg-3 pr-lg-3 m-0 col-lg-3 col-12 text-lg-left text-center player-data-right" style="opacity: 0">
<div class="p-0 pl-lg-3 pr-lg-3 m-0 col-lg-3 col-12 text-lg-left text-center player-data-right" style="opacity: 0;">
</div>
</div>
<!-- images used by canvas -->
<img class="hide" id="hud_death" src="~/images/death.png" />
<img class="hide" id="hud_death" src="~/images/radar/death.png" />
@section scripts {
@ -263,7 +276,7 @@
</div>
<div class="player-stat-icon" style="background-image:url('/images/radar/kills.png')"></div>
<div class="pr-2">${player.kills}</div>
<div class="player-stat-icon" style="background-image:url('/images/hud_weapons/hud_death.png')"></div>
<div class="player-stat-icon" style="background-image:url('/images/radar/death.png')"></div>
<div class="pr-3">${player.deaths}</div>
<span class="align-self-center oi oi-target pr-1"></span>
<div class="pr-3 ">${player.deaths == 0 ? player.kills.toFixed(2) : (player.kills / player.deaths).toFixed(2)}</div>

View File

@ -0,0 +1 @@
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

View File

@ -39,8 +39,6 @@
<Content Remove="Views\Plugins\Stats\_MessageContext.cshtml" />
<Content Remove="Views\Plugins\Stats\_PenaltyInfo.cshtml" />
<Content Remove="Views\Plugins\_ViewImports.cshtml" />
<Content Remove="wwwroot\css\bootstrap-custom.css" />
<Content Remove="wwwroot\css\bootstrap-custom.min.css" />
</ItemGroup>
<ItemGroup>

View File

@ -95,7 +95,9 @@ $(document).ready(function () {
$.each(ipAddresses, function (index, address) {
$.get('https://ip2c.org/' + $(address).data('ip'), function (result) {
const countryCode = result.split(';')[1].toLowerCase();
if (countryCode != 'zz') {
$(address).css('background-image', `url(https://www.countryflags.io/${countryCode}/flat/64.png)`);
}
});
});
}