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;
|
|
|
|
|
using SharedLibraryCore.Dtos;
|
|
|
|
|
using SharedLibraryCore.Services;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
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-05-24 15:48:57 -04:00
|
|
|
|
if (client == null)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
2018-04-08 02:44:42 -04:00
|
|
|
|
|
2018-06-26 21:17:24 -04:00
|
|
|
|
#if DEBUG
|
|
|
|
|
Authorized = true;
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-02-21 20:29:23 -05:00
|
|
|
|
var clientDto = new PlayerInfo()
|
|
|
|
|
{
|
|
|
|
|
Name = client.Name,
|
|
|
|
|
Level = client.Level.ToString(),
|
2018-04-02 01:25:06 -04:00
|
|
|
|
LevelInt = (int)client.Level,
|
2018-02-21 20:29:23 -05:00
|
|
|
|
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-04-15 00:26:27 -04:00
|
|
|
|
Online = Manager.GetActiveClients().FirstOrDefault(c => c.ClientId == client.ClientId) != null,
|
2018-05-14 13:55:10 -04:00
|
|
|
|
TimeOnline = (DateTime.UtcNow - client.LastConnection).TimeSpanText(),
|
|
|
|
|
LinkedAccounts = client.LinkedAccounts
|
2018-02-21 20:29:23 -05:00
|
|
|
|
};
|
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);
|
|
|
|
|
|
2018-04-08 02:44:42 -04:00
|
|
|
|
if (Authorized && client.Level > SharedLibraryCore.Objects.Player.Permission.Trusted)
|
2018-03-09 03:01:12 -05:00
|
|
|
|
clientDto.Meta.Add(new ProfileMeta()
|
|
|
|
|
{
|
2018-05-05 18:52:04 -04:00
|
|
|
|
Key = Localization["WEBFRONT_CLIENT_META_MASKED"],
|
2018-05-14 13:55:10 -04:00
|
|
|
|
Value = client.Masked ? Localization["WEBFRONT_CLIENT_META_TRUE"] : Localization["WEBFRONT_CLIENT_META_FALSE"],
|
2018-03-13 17:30:22 -04:00
|
|
|
|
Sensitive = true,
|
2018-03-09 03:01:12 -05:00
|
|
|
|
When = DateTime.MinValue
|
|
|
|
|
});
|
|
|
|
|
|
2018-04-02 01:25:06 -04:00
|
|
|
|
if (Authorized)
|
|
|
|
|
{
|
2018-04-02 23:11:19 -04:00
|
|
|
|
clientDto.Meta.AddRange(client.AliasLink.Children
|
|
|
|
|
.GroupBy(a => a.Name)
|
|
|
|
|
.Select(a => a.First())
|
|
|
|
|
.Select(a => new ProfileMeta()
|
|
|
|
|
{
|
|
|
|
|
Key = "AliasEvent",
|
2018-05-05 18:52:04 -04:00
|
|
|
|
Value = $"{Localization["WEBFRONT_CLIENT_META_JOINED"]} {a.Name}",
|
2018-04-02 23:11:19 -04:00
|
|
|
|
Sensitive = true,
|
|
|
|
|
When = a.DateAdded
|
|
|
|
|
}));
|
2018-04-02 01:25:06 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-26 21:17:24 -04:00
|
|
|
|
if (Authorized)
|
|
|
|
|
{
|
|
|
|
|
penaltyMeta.ForEach(p => p.Value.Offense = p.Value.AutomatedOffense ?? p.Value.Offense);
|
|
|
|
|
administeredPenaltiesMeta.ForEach(p => p.Value.Offense = p.Value.AutomatedOffense ?? p.Value.Offense);
|
|
|
|
|
}
|
|
|
|
|
|
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));
|
2018-03-27 20:27:01 -04:00
|
|
|
|
clientDto.Meta.AddRange(Authorized ? administeredPenaltiesMeta : administeredPenaltiesMeta.Where(m => !m.Sensitive));
|
2018-06-02 00:48:10 -04:00
|
|
|
|
clientDto.Meta.AddRange(client.Meta.Select(m => new ProfileMeta()
|
|
|
|
|
{
|
|
|
|
|
When = m.Created,
|
|
|
|
|
Key = m.Key,
|
|
|
|
|
Value = m.Value,
|
|
|
|
|
Show = false,
|
|
|
|
|
}));
|
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
|
|
|
|
|
2018-03-13 17:30:22 -04:00
|
|
|
|
ViewBag.Title = clientDto.Name.Substring(clientDto.Name.Length - 1).ToLower()[0] == 's' ?
|
|
|
|
|
clientDto.Name + "'" :
|
|
|
|
|
clientDto.Name + "'s";
|
2018-05-05 18:52:04 -04:00
|
|
|
|
ViewBag.Title += " " + Localization["WEBFRONT_CLIENT_PROFILE_TITLE"];
|
2018-03-13 17:30:22 -04:00
|
|
|
|
ViewBag.Description = $"Client information for {clientDto.Name}";
|
|
|
|
|
ViewBag.Keywords = $"IW4MAdmin, client, profile, {clientDto.Name}";
|
2018-02-24 00:56:03 -05:00
|
|
|
|
|
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)
|
2018-05-14 13:55:10 -04:00
|
|
|
|
.OrderByDescending(a => a.Level).ThenByDescending(a => a.LastConnection)
|
|
|
|
|
.GroupBy(a => a.AliasLinkId).Select(a => a.First());
|
|
|
|
|
|
2018-04-08 02:44:42 -04:00
|
|
|
|
var adminsDict = new Dictionary<SharedLibraryCore.Objects.Player.Permission, IList<ClientInfo>>();
|
2018-04-02 23:11:19 -04:00
|
|
|
|
|
2018-02-21 20:29:23 -05:00
|
|
|
|
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
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-05 18:52:04 -04:00
|
|
|
|
ViewBag.Title = Localization["WEBFRONT_CLIENT_PRIVILEGED_TITLE"];
|
2018-03-13 17:30:22 -04:00
|
|
|
|
ViewBag.Description = "List of all privileged clients on IW4MAdmin";
|
|
|
|
|
ViewBag.Keywords = "IW4MAdmin, privileged, admins, clients, administrators";
|
|
|
|
|
|
2018-02-21 20:29:23 -05:00
|
|
|
|
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(),
|
2018-04-02 01:25:06 -04:00
|
|
|
|
LevelInt = (int)c.Level,
|
2018-02-21 20:29:23 -05:00
|
|
|
|
ClientId = c.ClientId,
|
|
|
|
|
LastSeen = Utilities.GetTimePassed(c.LastConnection, false)
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
|
2018-05-05 18:52:04 -04:00
|
|
|
|
ViewBag.Title = $"{clientsDto.Count} {Localization["WEBFRONT_CLIENT_SEARCH_MATCHING"]} \"{clientName}\"";
|
2018-02-21 20:29:23 -05:00
|
|
|
|
return View("Find/Index", clientsDto);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|