2018-02-21 20:29:23 -05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore;
|
2018-11-05 22:01:29 -05:00
|
|
|
|
using SharedLibraryCore.Database.Models;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
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;
|
2019-05-29 17:55:35 -04:00
|
|
|
|
using static SharedLibraryCore.Database.Models.EFPenalty;
|
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
|
|
|
|
{
|
|
|
|
|
public async Task<IActionResult> ProfileAsync(int id)
|
|
|
|
|
{
|
2018-03-06 02:22:19 -05:00
|
|
|
|
var client = await Manager.GetClientService().Get(id);
|
2019-03-29 22:56:56 -04:00
|
|
|
|
|
2018-05-24 15:48:57 -04:00
|
|
|
|
if (client == null)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
2018-04-08 02:44:42 -04:00
|
|
|
|
|
2019-06-25 19:01:47 -04:00
|
|
|
|
var activePenalties = (await Manager.GetPenaltyService().GetActivePenaltiesAsync(client.AliasLinkId, client.IPAddress))
|
|
|
|
|
.Where(_penalty => _penalty.Type != PenaltyType.Flag);
|
2018-09-02 17:59:27 -04:00
|
|
|
|
|
2018-02-21 20:29:23 -05:00
|
|
|
|
var clientDto = new PlayerInfo()
|
|
|
|
|
{
|
|
|
|
|
Name = client.Name,
|
2018-08-03 22:11:58 -04:00
|
|
|
|
Level = client.Level.ToLocalizedLevelName(),
|
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,
|
|
|
|
|
Meta = new List<ProfileMeta>(),
|
|
|
|
|
Aliases = client.AliasLink.Children
|
|
|
|
|
.Where(a => a.Name != client.Name)
|
|
|
|
|
.Select(a => a.Name)
|
|
|
|
|
.Distinct()
|
2018-12-29 13:43:40 -05:00
|
|
|
|
.OrderBy(a => a)
|
2018-02-21 20:29:23 -05:00
|
|
|
|
.ToList(),
|
|
|
|
|
IPs = client.AliasLink.Children
|
|
|
|
|
.Select(i => i.IPAddress.ConvertIPtoString())
|
2018-12-29 13:43:40 -05:00
|
|
|
|
.Union(new List<string>() { client.CurrentAlias.IPAddress.ConvertIPtoString() })
|
|
|
|
|
.Where(i => !string.IsNullOrEmpty(i))
|
2018-02-21 20:29:23 -05:00
|
|
|
|
.Distinct()
|
|
|
|
|
.OrderBy(i => i)
|
|
|
|
|
.ToList(),
|
2019-06-25 19:01:47 -04:00
|
|
|
|
HasActivePenalty = activePenalties.Count() > 0,
|
|
|
|
|
ActivePenaltyType = activePenalties.Count() > 0 ? activePenalties.First().Type.ToString() : null,
|
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
|
|
|
|
|
2019-03-29 22:56:56 -04:00
|
|
|
|
var meta = await MetaService.GetRuntimeMeta(client.ClientId, 0, 1, DateTime.UtcNow);
|
2019-04-14 11:55:05 -04:00
|
|
|
|
var gravatar = await new MetaService().GetPersistentMeta("GravatarEmail", client);
|
|
|
|
|
if (gravatar != null)
|
|
|
|
|
{
|
|
|
|
|
clientDto.Meta.Add(new ProfileMeta()
|
|
|
|
|
{
|
|
|
|
|
Key = "GravatarEmail",
|
|
|
|
|
Type = ProfileMeta.MetaType.Other,
|
|
|
|
|
Value = gravatar.Value
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-06-26 21:17:24 -04:00
|
|
|
|
|
2019-02-17 19:48:40 -05:00
|
|
|
|
var currentPenalty = activePenalties.FirstOrDefault();
|
|
|
|
|
|
2019-05-29 17:55:35 -04:00
|
|
|
|
if (currentPenalty != null && currentPenalty.Type == PenaltyType.TempBan)
|
2019-02-17 19:48:40 -05:00
|
|
|
|
{
|
|
|
|
|
clientDto.Meta.Add(new ProfileMeta()
|
|
|
|
|
{
|
|
|
|
|
Key = Localization["WEBFRONT_CLIENT_META_REMAINING_BAN"],
|
|
|
|
|
Value = ((currentPenalty.Expires - DateTime.UtcNow) ?? new TimeSpan()).TimeSpanText(),
|
|
|
|
|
When = currentPenalty.When
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-06 02:22:19 -05:00
|
|
|
|
clientDto.Meta.AddRange(Authorized ? meta : meta.Where(m => !m.Sensitive));
|
2019-04-14 11:55:05 -04: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())
|
2019-03-24 22:34:20 -04:00
|
|
|
|
.GroupBy(a => a.AliasLinkId)
|
|
|
|
|
.Select(_client => _client.OrderByDescending(_c => _c.LastConnection).First())
|
2018-11-25 22:11:55 -05:00
|
|
|
|
.OrderByDescending(_client => _client.Level);
|
2018-05-14 13:55:10 -04:00
|
|
|
|
|
2018-11-05 22:01:29 -05:00
|
|
|
|
var adminsDict = new Dictionary<EFClient.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))
|
2018-11-25 22:11:55 -05:00
|
|
|
|
{
|
2018-02-21 20:29:23 -05:00
|
|
|
|
adminsDict.Add(admin.Level, new List<ClientInfo>());
|
2018-11-25 22:11:55 -05:00
|
|
|
|
}
|
2018-02-21 20:29:23 -05:00
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2019-05-13 11:36:11 -04:00
|
|
|
|
if (string.IsNullOrWhiteSpace(clientName))
|
|
|
|
|
{
|
|
|
|
|
return StatusCode(400);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-25 22:05:35 -04:00
|
|
|
|
var clientsDto = await Manager.GetClientService().FindClientsByIdentifier(clientName);
|
2018-02-21 20:29:23 -05:00
|
|
|
|
|
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);
|
|
|
|
|
}
|
2019-03-27 20:40:26 -04:00
|
|
|
|
|
2019-03-29 22:56:56 -04:00
|
|
|
|
public async Task<IActionResult> Meta(int id, int count, int offset, DateTime? startAt)
|
2019-03-27 20:40:26 -04:00
|
|
|
|
{
|
2019-04-16 12:32:42 -04:00
|
|
|
|
IEnumerable<ProfileMeta> meta = await MetaService.GetRuntimeMeta(id, startAt == null ? offset : 0, count, startAt ?? DateTime.UtcNow);
|
2019-03-27 20:40:26 -04:00
|
|
|
|
|
2019-04-16 12:32:42 -04:00
|
|
|
|
if (!Authorized)
|
|
|
|
|
{
|
|
|
|
|
meta = meta.Where(_meta => !_meta.Sensitive);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (meta.Count() == 0)
|
2019-03-27 20:40:26 -04:00
|
|
|
|
{
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View("Components/ProfileMetaList/_List", meta);
|
|
|
|
|
}
|
2018-02-21 20:29:23 -05:00
|
|
|
|
}
|
|
|
|
|
}
|