IW4M-Admin/WebfrontCore/Controllers/ClientController.cs

110 lines
4.2 KiB
C#
Raw Normal View History

2018-02-21 20:29:23 -05:00
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
{
2018-03-06 02:22:19 -05:00
public class ClientController : BaseController
2018-02-21 20:29:23 -05:00
{
public async Task<IActionResult> ProfileAsync(int id)
{
2018-03-06 02:22:19 -05:00
var client = await Manager.GetClientService().Get(id);
2018-02-21 20:29:23 -05:00
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(),
};
2018-03-09 03:01:12 -05:00
2018-03-06 02:22:19 -05:00
var meta = await MetaService.GetMeta(client.ClientId);
2018-03-09 03:01:12 -05:00
var penaltyMeta = await Manager.GetPenaltyService()
.ReadGetClientPenaltiesAsync(client.ClientId);
var administeredPenaltiesMeta = await Manager.GetPenaltyService()
.ReadGetClientPenaltiesAsync(client.ClientId, false);
if (client.Level > SharedLibrary.Objects.Player.Permission.Trusted)
clientDto.Meta.Add(new ProfileMeta()
{
Key = "Masked",
Value = client.Masked ? "Is" : "Is not",
Sensitive = false,
When = DateTime.MinValue
});
2018-03-06 02:22:19 -05:00
clientDto.Meta.AddRange(Authorized ? meta : meta.Where(m => !m.Sensitive));
2018-03-09 03:01:12 -05:00
clientDto.Meta.AddRange(Authorized ? penaltyMeta : penaltyMeta.Where(m => !m.Sensitive));
clientDto.Meta.AddRange(Authorized ? administeredPenaltiesMeta : penaltyMeta.Where(m => !m.Sensitive));
2018-03-06 02:22:19 -05:00
clientDto.Meta = clientDto.Meta
.OrderByDescending(m => m.When)
.ToList();
2018-02-21 20:29:23 -05:00
ViewBag.Title = clientDto.Name;
2018-02-21 20:29:23 -05:00
return View("Profile/Index", clientDto);
}
public async Task<IActionResult> PrivilegedAsync()
{
2018-03-06 02:22:19 -05:00
var admins = (await Manager.GetClientService().GetPrivilegedClients())
2018-02-21 20:29:23 -05:00
.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 = "Current Privileged Users";
return View("Privileged/Index", adminsDict);
}
public async Task<IActionResult> FindAsync(string clientName)
{
2018-03-06 02:22:19 -05:00
var clients = (await Manager.GetClientService().GetClientByName(clientName))
2018-02-21 20:29:23 -05:00
.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.Name = $"Clients Matching \"{clientName}\"";
return View("Find/Index", clientsDto);
}
}
}