IW4M-Admin/WebfrontCore/Controllers/ClientController.cs
RaidMax 9db8ad80ef fixed bug with lifetime hit ratio causing erroneous ban
ip lookup on profile shows error if failed
truncate chat messages over 50 characters
removed html raw on client messages :c
show client rank colors on server overview if authorized
break long messages on profile page
prevent masked status showing up to non privileged users in webfront
2018-03-28 22:01:09 -05:00

118 lines
4.8 KiB
C#

using Microsoft.AspNetCore.Mvc;
using SharedLibrary;
using SharedLibrary.Dtos;
using SharedLibrary.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebfrontCore.Controllers
{
public class ClientController : BaseController
{
public async Task<IActionResult> ProfileAsync(int id)
{
var client = await Manager.GetClientService().Get(id);
var clientDto = new PlayerInfo()
{
Name = client.Name,
Level = client.Level.ToString(),
ClientId = client.ClientId,
IPAddress = client.IPAddressString,
NetworkId = client.NetworkId,
ConnectionCount = client.Connections,
FirstSeen = Utilities.GetTimePassed(client.FirstConnection, false),
LastSeen = Utilities.GetTimePassed(client.LastConnection, false),
TimePlayed = Math.Round(client.TotalConnectionTime / 3600.0, 1).ToString("#,##0"),
Meta = new List<ProfileMeta>(),
Aliases = client.AliasLink.Children
.Where(a => a.Name != client.Name)
.Select(a => a.Name)
.Distinct()
.OrderBy(a => a)
.ToList(),
IPs = client.AliasLink.Children
.Select(i => i.IPAddress.ConvertIPtoString())
.Distinct()
.OrderBy(i => i)
.ToList(),
};
var meta = await MetaService.GetMeta(client.ClientId);
var penaltyMeta = await Manager.GetPenaltyService()
.ReadGetClientPenaltiesAsync(client.ClientId);
var administeredPenaltiesMeta = await Manager.GetPenaltyService()
.ReadGetClientPenaltiesAsync(client.ClientId, false);
if (Authorized && client.Level > SharedLibrary.Objects.Player.Permission.Trusted)
clientDto.Meta.Add(new ProfileMeta()
{
Key = "Masked",
Value = client.Masked ? "Is" : "Is not",
Sensitive = true,
When = DateTime.MinValue
});
clientDto.Meta.AddRange(Authorized ? meta : meta.Where(m => !m.Sensitive));
clientDto.Meta.AddRange(Authorized ? penaltyMeta : penaltyMeta.Where(m => !m.Sensitive));
clientDto.Meta.AddRange(Authorized ? administeredPenaltiesMeta : administeredPenaltiesMeta.Where(m => !m.Sensitive));
clientDto.Meta = clientDto.Meta
.OrderByDescending(m => m.When)
.ToList();
ViewBag.Title = clientDto.Name.Substring(clientDto.Name.Length - 1).ToLower()[0] == 's' ?
clientDto.Name + "'" :
clientDto.Name + "'s";
ViewBag.Title += " Profile";
ViewBag.Description = $"Client information for {clientDto.Name}";
ViewBag.Keywords = $"IW4MAdmin, client, profile, {clientDto.Name}";
return View("Profile/Index", clientDto);
}
public async Task<IActionResult> PrivilegedAsync()
{
var admins = (await Manager.GetClientService().GetPrivilegedClients())
.Where(a => a.Active)
.OrderByDescending(a => a.Level);
var adminsDict = new Dictionary<SharedLibrary.Objects.Player.Permission, IList<ClientInfo>>();
foreach (var admin in admins)
{
if (!adminsDict.ContainsKey(admin.Level))
adminsDict.Add(admin.Level, new List<ClientInfo>());
adminsDict[admin.Level].Add(new ClientInfo()
{
Name = admin.Name,
ClientId = admin.ClientId
});
}
ViewBag.Title = "Privileged Clients";
ViewBag.Description = "List of all privileged clients on IW4MAdmin";
ViewBag.Keywords = "IW4MAdmin, privileged, admins, clients, administrators";
return View("Privileged/Index", adminsDict);
}
public async Task<IActionResult> FindAsync(string clientName)
{
var clients = (await Manager.GetClientService().GetClientByName(clientName))
.OrderByDescending(c => c.LastConnection);
var clientsDto = clients.Select(c => new PlayerInfo()
{
Name = c.Name,
Level = c.Level.ToString(),
ClientId = c.ClientId,
LastSeen = Utilities.GetTimePassed(c.LastConnection, false)
})
.ToList();
ViewBag.Title = $"Clients Matching \"{clientName}\"";
return View("Find/Index", clientsDto);
}
}
}