IW4M-Admin/WebfrontCore/Controllers/Client/ClientController.cs

205 lines
7.9 KiB
C#
Raw Normal View History

2018-02-21 20:29:23 -05:00
using Microsoft.AspNetCore.Mvc;
2018-04-08 02:44:42 -04:00
using SharedLibraryCore;
using SharedLibraryCore.Database.Models;
2018-04-08 02:44:42 -04:00
using SharedLibraryCore.Dtos;
using SharedLibraryCore.Dtos.Meta.Responses;
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;
using SharedLibraryCore.QueryHelper;
2018-02-21 20:29:23 -05:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Data.Models;
using Stats.Config;
using WebfrontCore.ViewComponents;
2018-02-21 20:29:23 -05:00
namespace WebfrontCore.Controllers
{
2018-03-06 02:22:19 -05:00
public class ClientController : BaseController
2018-02-21 20:29:23 -05:00
{
private readonly IMetaService _metaService;
2022-01-28 18:28:49 -05:00
private readonly StatsConfiguration _config;
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-01-28 18:28:49 -05:00
public ClientController(IManager manager, IMetaService metaService, StatsConfiguration config) : base(manager)
{
_metaService = metaService;
2022-01-28 18:28:49 -05:00
_config = config;
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
}
public async Task<IActionResult> ProfileAsync(int id, MetaType? metaFilterType)
2018-02-21 20:29:23 -05:00
{
2018-03-06 02:22:19 -05:00
var client = await Manager.GetClientService().Get(id);
if (client == null)
{
return NotFound();
}
2018-04-08 02:44:42 -04:00
var activePenalties = await Manager.GetPenaltyService().GetActivePenaltiesAsync(client.AliasLinkId, client.CurrentAliasId, client.IPAddress);
2022-02-01 19:20:29 -05:00
var persistentMetaTask = new[]
{
_metaService.GetPersistentMeta(EFMeta.ClientTag, client),
_metaService.GetPersistentMeta("GravatarEmail", client)
};
var persistentMeta = await Task.WhenAll(persistentMetaTask);
var tag = persistentMeta[0];
var gravatar = persistentMeta[1];
if (tag?.LinkedMeta != null)
{
client.SetAdditionalProperty(EFMeta.ClientTag, tag.LinkedMeta.Value);
}
var displayLevelInt = (int)client.Level;
var displayLevel = client.Level.ToLocalizedLevelName();
if (!Authorized && client.Level.ShouldHideLevel())
{
displayLevelInt = (int)Data.Models.Client.EFClient.Permission.User;
displayLevel = Data.Models.Client.EFClient.Permission.User.ToLocalizedLevelName();
}
displayLevel = string.IsNullOrEmpty(client.Tag) ? displayLevel : $"{displayLevel} ({client.Tag})";
2022-02-01 19:20:29 -05:00
var clientDto = new PlayerInfo
2018-02-21 20:29:23 -05:00
{
Name = client.Name,
Level = displayLevel,
LevelInt = displayLevelInt,
2018-02-21 20:29:23 -05:00
ClientId = client.ClientId,
IPAddress = client.IPAddressString,
NetworkId = client.NetworkId,
Meta = new List<InformationResponse>(),
2018-02-21 20:29:23 -05:00
Aliases = client.AliasLink.Children
.Select(_alias => _alias.Name)
.GroupBy(_alias => _alias.StripColors())
// we want the longest "duplicate" name
.Select(_grp => _grp.OrderByDescending(_name => _name.Length).First())
.Distinct()
.OrderBy(a => a)
2018-02-21 20:29:23 -05:00
.ToList(),
IPs = client.AliasLink.Children
.Where(i => i.IPAddress != null)
.OrderByDescending(i => i.DateAdded)
2018-02-21 20:29:23 -05:00
.Select(i => i.IPAddress.ConvertIPtoString())
.Prepend(client.CurrentAlias.IPAddress.ConvertIPtoString())
2018-02-21 20:29:23 -05:00
.Distinct()
.ToList(),
HasActivePenalty = activePenalties.Any(_penalty => _penalty.Type != EFPenalty.PenaltyType.Flag),
Online = Manager.GetActiveClients().FirstOrDefault(c => c.ClientId == client.ClientId) != null,
TimeOnline = (DateTime.UtcNow - client.LastConnection).HumanizeForCurrentCulture(),
LinkedAccounts = client.LinkedAccounts,
MetaFilterType = metaFilterType
2018-02-21 20:29:23 -05:00
};
2018-03-09 03:01:12 -05:00
var meta = await _metaService.GetRuntimeMeta<InformationResponse>(new ClientPaginationRequest
{
ClientId = client.ClientId,
Before = DateTime.UtcNow
}, MetaType.Information);
if (gravatar != null)
{
clientDto.Meta.Add(new InformationResponse()
{
Key = "GravatarEmail",
Type = MetaType.Other,
Value = gravatar.Value
});
}
clientDto.ActivePenalty = activePenalties.OrderByDescending(_penalty => _penalty.Type).FirstOrDefault();
clientDto.Meta.AddRange(Authorized ? meta : meta.Where(m => !m.IsSensitive));
2022-02-01 19:20:29 -05:00
var strippedName = clientDto.Name.StripColors();
2019-08-02 19:04:34 -04:00
ViewBag.Title = strippedName.Substring(strippedName.Length - 1).ToLower()[0] == 's' ?
strippedName + "'" :
strippedName + "'s";
ViewBag.Title += " " + Localization["WEBFRONT_CLIENT_PROFILE_TITLE"];
2019-08-02 19:04:34 -04:00
ViewBag.Description = $"Client information for {strippedName}";
ViewBag.Keywords = $"IW4MAdmin, client, profile, {strippedName}";
2022-01-28 18:28:49 -05:00
ViewBag.UseNewStats = _config?.EnableAdvancedMetrics ?? true;
2018-02-21 20:29:23 -05:00
return View("Profile/Index", clientDto);
}
public async Task<IActionResult> PrivilegedAsync()
{
if (Manager.GetApplicationSettings().Configuration().EnablePrivilegedUserPrivacy && !Authorized)
{
return RedirectToAction("Index", "Home");
}
2018-03-06 02:22:19 -05:00
var admins = (await Manager.GetClientService().GetPrivilegedClients())
.OrderByDescending(_client => _client.Level)
.ThenBy(_client => _client.Name);
var adminsDict = new Dictionary<EFClient.Permission, IList<ClientInfo>>();
2018-02-21 20:29:23 -05:00
foreach (var admin in admins)
{
if (!adminsDict.ContainsKey(admin.Level))
{
2018-02-21 20:29:23 -05:00
adminsDict.Add(admin.Level, new List<ClientInfo>());
}
2018-02-21 20:29:23 -05:00
adminsDict[admin.Level].Add(new ClientInfo()
{
Name = admin.Name,
ClientId = admin.ClientId
});
}
ViewBag.Title = Localization["WEBFRONT_CLIENT_PRIVILEGED_TITLE"];
ViewBag.Description = Localization["WEBFRONT_DESCRIPTION_PRIVILEGED"];
ViewBag.Keywords = Localization["WEBFRONT_KEYWORDS_PRIVILEGED"];
2018-02-21 20:29:23 -05:00
return View("Privileged/Index", adminsDict);
}
public async Task<IActionResult> FindAsync(string clientName)
{
if (string.IsNullOrWhiteSpace(clientName))
{
return StatusCode(400);
}
2019-04-25 22:05:35 -04:00
var clientsDto = await Manager.GetClientService().FindClientsByIdentifier(clientName);
foreach (var client in clientsDto)
{
if (!Authorized && ((Data.Models.Client.EFClient.Permission)client.LevelInt).ShouldHideLevel())
{
client.LevelInt = (int)Data.Models.Client.EFClient.Permission.User;
client.Level = Data.Models.Client.EFClient.Permission.User.ToLocalizedLevelName();
}
}
2018-02-21 20:29:23 -05:00
ViewBag.Title = $"{clientsDto.Count} {Localization["WEBFRONT_CLIENT_SEARCH_MATCHING"]} \"{clientName}\"";
2018-02-21 20:29:23 -05:00
return View("Find/Index", clientsDto);
}
public async Task<IActionResult> Meta(int id, int count, int offset, long? startAt, MetaType? metaFilterType)
{
var request = new ClientPaginationRequest
{
ClientId = id,
Count = count,
Offset = offset,
Before = DateTime.FromFileTimeUtc(startAt ?? DateTime.UtcNow.ToFileTimeUtc())
};
var meta = await ProfileMetaListViewComponent.GetClientMeta(_metaService, metaFilterType, Client.Level, request);
if (!meta.Any())
{
return Ok();
}
return View("Components/ProfileMetaList/_List", meta);
}
2018-02-21 20:29:23 -05:00
}
}