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;
|
2020-08-17 22:21:11 -04:00
|
|
|
|
using SharedLibraryCore.Dtos.Meta.Responses;
|
2019-12-02 16:52:36 -05:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2020-08-17 22:21:11 -04:00
|
|
|
|
using SharedLibraryCore.QueryHelper;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2022-03-23 09:43:57 -04:00
|
|
|
|
using System.Threading;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
using System.Threading.Tasks;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
using Data.Models;
|
2022-07-20 11:32:26 -04:00
|
|
|
|
using SharedLibraryCore.Services;
|
2021-11-23 18:26:33 -05:00
|
|
|
|
using Stats.Config;
|
2022-04-04 23:16:40 -04:00
|
|
|
|
using WebfrontCore.Permissions;
|
2023-01-23 17:38:16 -05:00
|
|
|
|
using WebfrontCore.QueryHelpers.Models;
|
2020-08-17 22:21:11 -04:00
|
|
|
|
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
|
|
|
|
{
|
2022-03-23 09:43:57 -04:00
|
|
|
|
private readonly IMetaServiceV2 _metaService;
|
2022-01-28 18:28:49 -05:00
|
|
|
|
private readonly StatsConfiguration _config;
|
2022-04-19 19:43:58 -04:00
|
|
|
|
private readonly IGeoLocationService _geoLocationService;
|
2022-07-20 11:32:26 -04:00
|
|
|
|
private readonly ClientService _clientService;
|
2022-09-08 16:03:38 -04:00
|
|
|
|
private readonly IInteractionRegistration _interactionRegistration;
|
2023-01-23 17:38:16 -05:00
|
|
|
|
private readonly IResourceQueryHelper<ClientResourceRequest, ClientResourceResponse> _clientResourceHelper;
|
2019-12-02 16:52:36 -05:00
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
public ClientController(IManager manager, IMetaServiceV2 metaService, StatsConfiguration config,
|
2023-01-23 17:38:16 -05:00
|
|
|
|
IGeoLocationService geoLocationService, ClientService clientService,
|
|
|
|
|
IInteractionRegistration interactionRegistration,
|
|
|
|
|
IResourceQueryHelper<ClientResourceRequest, ClientResourceResponse> clientResourceHelper) : base(manager)
|
2020-08-17 22:21:11 -04:00
|
|
|
|
{
|
|
|
|
|
_metaService = metaService;
|
2022-01-28 18:28:49 -05:00
|
|
|
|
_config = config;
|
2022-04-19 19:43:58 -04:00
|
|
|
|
_geoLocationService = geoLocationService;
|
2022-07-20 11:32:26 -04:00
|
|
|
|
_clientService = clientService;
|
2022-09-08 16:03:38 -04:00
|
|
|
|
_interactionRegistration = interactionRegistration;
|
2023-01-23 17:38:16 -05:00
|
|
|
|
_clientResourceHelper = clientResourceHelper;
|
2019-12-02 16:52:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
[Obsolete]
|
|
|
|
|
public IActionResult ProfileAsync(int id, MetaType? metaFilterType,
|
|
|
|
|
CancellationToken token = default) => RedirectToAction("Profile", "Client", new
|
2022-04-19 23:34:35 -04:00
|
|
|
|
{ id, metaFilterType });
|
2022-04-19 19:43:58 -04:00
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> Profile(int id, MetaType? metaFilterType, CancellationToken token = default)
|
2018-02-21 20:29:23 -05:00
|
|
|
|
{
|
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
|
|
|
|
|
2022-02-22 18:09:50 -05:00
|
|
|
|
var activePenalties = await Manager.GetPenaltyService().GetActivePenaltiesAsync(client.AliasLinkId,
|
2022-06-15 20:37:34 -04:00
|
|
|
|
client.CurrentAliasId, client.NetworkId, client.GameName, client.IPAddress);
|
2020-08-17 22:21:11 -04:00
|
|
|
|
|
2022-02-01 19:20:29 -05:00
|
|
|
|
var persistentMetaTask = new[]
|
|
|
|
|
{
|
2022-04-19 19:43:58 -04:00
|
|
|
|
_metaService.GetPersistentMetaByLookup(EFMeta.ClientTagV2, EFMeta.ClientTagNameV2, client.ClientId,
|
|
|
|
|
token),
|
2022-07-20 11:32:26 -04:00
|
|
|
|
_metaService.GetPersistentMeta("GravatarEmail", client.ClientId, token),
|
2022-02-01 19:20:29 -05:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var persistentMeta = await Task.WhenAll(persistentMetaTask);
|
|
|
|
|
var tag = persistentMeta[0];
|
|
|
|
|
var gravatar = persistentMeta[1];
|
2022-07-20 11:32:26 -04:00
|
|
|
|
var note = await _metaService.GetPersistentMetaValue<ClientNoteMetaResponse>("ClientNotes", client.ClientId,
|
|
|
|
|
token);
|
2022-02-01 19:20:29 -05:00
|
|
|
|
|
2022-03-23 09:43:57 -04:00
|
|
|
|
if (tag?.Value != null)
|
2021-01-24 12:47:19 -05:00
|
|
|
|
{
|
2022-03-23 09:43:57 -04:00
|
|
|
|
client.SetAdditionalProperty(EFMeta.ClientTagV2, tag.Value);
|
2021-01-24 12:47:19 -05:00
|
|
|
|
}
|
2018-09-02 17:59:27 -04:00
|
|
|
|
|
2022-07-20 12:39:46 -04:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(note?.Note))
|
2022-07-20 11:32:26 -04:00
|
|
|
|
{
|
|
|
|
|
note.OriginEntityName = await _clientService.GetClientNameById(note.OriginEntityId);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-17 10:17:43 -04:00
|
|
|
|
var interactions =
|
|
|
|
|
await _interactionRegistration.GetInteractions("Webfront::Profile", id, client.GameName, token);
|
2022-09-08 16:03:38 -04:00
|
|
|
|
|
2022-02-28 16:20:46 -05:00
|
|
|
|
// even though we haven't set their level to "banned" yet
|
|
|
|
|
// (ie they haven't reconnected with the infringing player identifier)
|
|
|
|
|
// we want to show them as banned as to not confuse people.
|
2022-07-25 12:54:55 -04:00
|
|
|
|
var hasActiveBan = activePenalties.Any(penalty => penalty.Type == EFPenalty.PenaltyType.Ban);
|
|
|
|
|
if (hasActiveBan)
|
2022-02-28 16:20:46 -05:00
|
|
|
|
{
|
|
|
|
|
client.Level = Data.Models.Client.EFClient.Permission.Banned;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-22 12:09:25 -04:00
|
|
|
|
var displayLevelInt = (int)client.Level;
|
|
|
|
|
var displayLevel = client.Level.ToLocalizedLevelName();
|
2019-07-24 11:36:37 -04:00
|
|
|
|
|
2022-07-25 12:54:55 -04:00
|
|
|
|
// if a linked ban has been revoked but they haven't reconnected, we should not show them as still banned
|
|
|
|
|
var shouldHideBanLevel = !hasActiveBan && client.Level == Data.Models.Client.EFClient.Permission.Banned;
|
|
|
|
|
if (!Authorized && client.Level.ShouldHideLevel() || shouldHideBanLevel)
|
2019-07-24 11:36:37 -04:00
|
|
|
|
{
|
2021-03-22 12:09:25 -04:00
|
|
|
|
displayLevelInt = (int)Data.Models.Client.EFClient.Permission.User;
|
|
|
|
|
displayLevel = Data.Models.Client.EFClient.Permission.User.ToLocalizedLevelName();
|
2019-07-24 11:36:37 -04:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-24 12:47:19 -05:00
|
|
|
|
displayLevel = string.IsNullOrEmpty(client.Tag) ? displayLevel : $"{displayLevel} ({client.Tag})";
|
2022-04-19 19:43:58 -04:00
|
|
|
|
var ingameClient = Manager.GetActiveClients().FirstOrDefault(c => c.ClientId == client.ClientId);
|
2021-01-24 12:47:19 -05:00
|
|
|
|
|
2022-02-01 19:20:29 -05:00
|
|
|
|
var clientDto = new PlayerInfo
|
2018-02-21 20:29:23 -05:00
|
|
|
|
{
|
|
|
|
|
Name = client.Name,
|
2022-06-15 20:37:34 -04:00
|
|
|
|
Game = client.GameName,
|
2019-07-24 11:36:37 -04:00
|
|
|
|
Level = displayLevel,
|
|
|
|
|
LevelInt = displayLevelInt,
|
2018-02-21 20:29:23 -05:00
|
|
|
|
ClientId = client.ClientId,
|
2022-04-19 19:43:58 -04:00
|
|
|
|
IPAddress = PermissionsSet.HasPermission(WebfrontEntity.ClientIPAddress, WebfrontPermission.Read)
|
|
|
|
|
? client.IPAddressString
|
|
|
|
|
: null,
|
2018-02-21 20:29:23 -05:00
|
|
|
|
NetworkId = client.NetworkId,
|
2020-08-17 22:21:11 -04:00
|
|
|
|
Meta = new List<InformationResponse>(),
|
2018-02-21 20:29:23 -05:00
|
|
|
|
Aliases = client.AliasLink.Children
|
2022-04-19 19:43:58 -04:00
|
|
|
|
.Select(alias => (alias.Name, alias.DateAdded))
|
|
|
|
|
.GroupBy(alias => alias.Name.StripColors())
|
2019-12-27 15:42:17 -05:00
|
|
|
|
// we want the longest "duplicate" name
|
2022-04-19 19:43:58 -04:00
|
|
|
|
.Select(grp => grp.OrderByDescending(item => item.Name.Length).First())
|
2019-11-15 15:50:20 -05:00
|
|
|
|
.Distinct()
|
2018-02-21 20:29:23 -05:00
|
|
|
|
.ToList(),
|
2022-04-19 19:43:58 -04:00
|
|
|
|
IPs = PermissionsSet.HasPermission(WebfrontEntity.ClientIPAddress, WebfrontPermission.Read)
|
|
|
|
|
? client.AliasLink.Children
|
|
|
|
|
.Select(alias => (alias.IPAddress.ConvertIPtoString(), alias.DateAdded))
|
|
|
|
|
.GroupBy(alias => alias.Item1)
|
|
|
|
|
.Select(grp => grp.OrderByDescending(item => item.DateAdded).First())
|
|
|
|
|
.Distinct()
|
|
|
|
|
.ToList()
|
|
|
|
|
: new List<(string, DateTime)>(),
|
|
|
|
|
HasActivePenalty = activePenalties.Any(penalty => penalty.Type != EFPenalty.PenaltyType.Flag),
|
|
|
|
|
Online = ingameClient != null,
|
2020-08-17 22:21:11 -04:00
|
|
|
|
TimeOnline = (DateTime.UtcNow - client.LastConnection).HumanizeForCurrentCulture(),
|
|
|
|
|
LinkedAccounts = client.LinkedAccounts,
|
2022-04-19 19:43:58 -04:00
|
|
|
|
MetaFilterType = metaFilterType,
|
|
|
|
|
ConnectProtocolUrl = ingameClient?.CurrentServer.EventParser.URLProtocolFormat.FormatExt(
|
|
|
|
|
ingameClient.CurrentServer.ResolvedIpEndPoint.Address.IsInternal()
|
|
|
|
|
? Program.Manager.ExternalIPAddress
|
2023-04-04 23:21:18 -04:00
|
|
|
|
: ingameClient.CurrentServer.ListenAddress,
|
|
|
|
|
ingameClient.CurrentServer.ListenPort),
|
2022-04-19 19:43:58 -04:00
|
|
|
|
CurrentServerName = ingameClient?.CurrentServer?.Hostname,
|
2022-07-20 11:32:26 -04:00
|
|
|
|
GeoLocationInfo = await _geoLocationService.Locate(client.IPAddressString),
|
2022-09-08 16:03:38 -04:00
|
|
|
|
NoteMeta = string.IsNullOrWhiteSpace(note?.Note) ? null: note,
|
|
|
|
|
Interactions = interactions.ToList()
|
2018-02-21 20:29:23 -05:00
|
|
|
|
};
|
2018-03-09 03:01:12 -05:00
|
|
|
|
|
2020-08-17 22:21:11 -04:00
|
|
|
|
var meta = await _metaService.GetRuntimeMeta<InformationResponse>(new ClientPaginationRequest
|
|
|
|
|
{
|
|
|
|
|
ClientId = client.ClientId,
|
|
|
|
|
Before = DateTime.UtcNow
|
|
|
|
|
}, MetaType.Information);
|
|
|
|
|
|
2019-04-14 11:55:05 -04:00
|
|
|
|
if (gravatar != null)
|
|
|
|
|
{
|
2020-08-17 22:21:11 -04:00
|
|
|
|
clientDto.Meta.Add(new InformationResponse()
|
2019-04-14 11:55:05 -04:00
|
|
|
|
{
|
|
|
|
|
Key = "GravatarEmail",
|
2020-08-17 22:21:11 -04:00
|
|
|
|
Type = MetaType.Other,
|
2019-04-14 11:55:05 -04:00
|
|
|
|
Value = gravatar.Value
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-06-26 21:17:24 -04:00
|
|
|
|
|
2022-10-24 19:58:12 -04:00
|
|
|
|
// Reducing the enum value for Temp/Mute so bans appear in client banner first
|
|
|
|
|
clientDto.ActivePenalty = activePenalties.MaxBy(penalty => penalty.Type switch
|
|
|
|
|
{
|
|
|
|
|
EFPenalty.PenaltyType.TempMute => 0,
|
|
|
|
|
EFPenalty.PenaltyType.Mute => 1,
|
|
|
|
|
_ => (int)penalty.Type
|
|
|
|
|
});
|
2020-08-17 22:21:11 -04:00
|
|
|
|
clientDto.Meta.AddRange(Authorized ? meta : meta.Where(m => !m.IsSensitive));
|
2019-04-14 11:55:05 -04:00
|
|
|
|
|
2022-02-01 19:20:29 -05:00
|
|
|
|
var strippedName = clientDto.Name.StripColors();
|
2022-07-05 13:02:43 -04:00
|
|
|
|
ViewBag.Title = $"{strippedName} | {Localization["WEBFRONT_CLIENT_PROFILE_TITLE"]}";
|
|
|
|
|
ViewBag.Description = Localization["WEBFRONT_PROFILE_DESCRIPTION"].FormatExt(strippedName);
|
2022-01-28 18:28:49 -05:00
|
|
|
|
ViewBag.UseNewStats = _config?.EnableAdvancedMetrics ?? true;
|
2018-02-24 00:56:03 -05:00
|
|
|
|
|
2018-02-21 20:29:23 -05:00
|
|
|
|
return View("Profile/Index", clientDto);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
public async Task<IActionResult> Privileged()
|
2018-02-21 20:29:23 -05:00
|
|
|
|
{
|
2021-03-23 11:28:17 -04:00
|
|
|
|
if (Manager.GetApplicationSettings().Configuration().EnablePrivilegedUserPrivacy && !Authorized)
|
|
|
|
|
{
|
|
|
|
|
return RedirectToAction("Index", "Home");
|
|
|
|
|
}
|
2022-04-19 19:43:58 -04:00
|
|
|
|
|
2018-03-06 02:22:19 -05:00
|
|
|
|
var admins = (await Manager.GetClientService().GetPrivilegedClients())
|
2019-09-27 16:49:03 -04:00
|
|
|
|
.OrderByDescending(_client => _client.Level)
|
|
|
|
|
.ThenBy(_client => _client.Name);
|
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
|
|
|
|
|
2022-04-21 13:39:09 -04:00
|
|
|
|
adminsDict[admin.Level].Add(new ClientInfo
|
2018-02-21 20:29:23 -05:00
|
|
|
|
{
|
|
|
|
|
Name = admin.Name,
|
2022-04-19 19:43:58 -04:00
|
|
|
|
ClientId = admin.ClientId,
|
2022-04-21 13:39:09 -04:00
|
|
|
|
LastConnection = admin.LastConnection,
|
2022-06-07 22:58:32 -04:00
|
|
|
|
IsMasked = admin.Masked,
|
2022-06-15 20:37:34 -04:00
|
|
|
|
Game = admin.GameName
|
2018-02-21 20:29:23 -05:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-05 18:52:04 -04:00
|
|
|
|
ViewBag.Title = Localization["WEBFRONT_CLIENT_PRIVILEGED_TITLE"];
|
2021-01-08 20:21:23 -05:00
|
|
|
|
ViewBag.Description = Localization["WEBFRONT_DESCRIPTION_PRIVILEGED"];
|
|
|
|
|
ViewBag.Keywords = Localization["WEBFRONT_KEYWORDS_PRIVILEGED"];
|
2018-03-13 17:30:22 -04:00
|
|
|
|
|
2018-02-21 20:29:23 -05:00
|
|
|
|
return View("Privileged/Index", adminsDict);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
public async Task<IActionResult> Find(string clientName)
|
2018-02-21 20:29:23 -05:00
|
|
|
|
{
|
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);
|
2019-11-15 15:50:20 -05:00
|
|
|
|
|
|
|
|
|
foreach (var client in clientsDto)
|
2019-07-24 11:36:37 -04:00
|
|
|
|
{
|
2021-03-22 12:09:25 -04:00
|
|
|
|
if (!Authorized && ((Data.Models.Client.EFClient.Permission)client.LevelInt).ShouldHideLevel())
|
2019-07-24 11:36:37 -04:00
|
|
|
|
{
|
2021-03-22 12:09:25 -04:00
|
|
|
|
client.LevelInt = (int)Data.Models.Client.EFClient.Permission.User;
|
|
|
|
|
client.Level = Data.Models.Client.EFClient.Permission.User.ToLocalizedLevelName();
|
2019-07-24 11:36:37 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-21 20:29:23 -05:00
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
ViewBag.SearchTerm = clientName;
|
|
|
|
|
ViewBag.ResultCount = clientsDto.Count;
|
2022-07-05 13:42:17 -04:00
|
|
|
|
ViewBag.Title = Localization["WEBFRONT_SEARCH_RESULTS_TITLE"];
|
2022-06-16 15:02:44 -04:00
|
|
|
|
|
2018-02-21 20:29:23 -05:00
|
|
|
|
return View("Find/Index", clientsDto);
|
|
|
|
|
}
|
2019-03-27 20:40:26 -04:00
|
|
|
|
|
2023-01-23 17:38:16 -05:00
|
|
|
|
public async Task<IActionResult> AdvancedFind(ClientResourceRequest request)
|
|
|
|
|
{
|
|
|
|
|
ViewBag.Title = Localization["WEBFRONT_SEARCH_RESULTS_TITLE"];
|
|
|
|
|
ViewBag.ClientResourceRequest = request;
|
|
|
|
|
|
|
|
|
|
var response = await _clientResourceHelper.QueryResource(request);
|
|
|
|
|
return request.Offset > 0
|
|
|
|
|
? PartialView("Find/_AdvancedFindList", response.Results)
|
|
|
|
|
: View("Find/AdvancedFind", response.Results);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 19:43:58 -04:00
|
|
|
|
public IActionResult Meta(int id, int count, int offset, long? startAt, MetaType? metaFilterType,
|
|
|
|
|
CancellationToken token)
|
2019-03-27 20:40:26 -04:00
|
|
|
|
{
|
2020-08-17 22:21:11 -04:00
|
|
|
|
var request = new ClientPaginationRequest
|
2019-04-16 12:32:42 -04:00
|
|
|
|
{
|
2020-08-17 22:21:11 -04:00
|
|
|
|
ClientId = id,
|
|
|
|
|
Count = count,
|
|
|
|
|
Offset = offset,
|
|
|
|
|
Before = DateTime.FromFileTimeUtc(startAt ?? DateTime.UtcNow.ToFileTimeUtc())
|
|
|
|
|
};
|
|
|
|
|
|
2022-04-04 23:16:40 -04:00
|
|
|
|
return ViewComponent(typeof(ProfileMetaListViewComponent), new
|
2019-03-27 20:40:26 -04:00
|
|
|
|
{
|
2022-04-04 23:16:40 -04:00
|
|
|
|
clientId = request.ClientId,
|
|
|
|
|
count = request.Count,
|
|
|
|
|
offset = request.Offset,
|
|
|
|
|
startAt = request.Before,
|
|
|
|
|
metaType = metaFilterType,
|
|
|
|
|
token
|
|
|
|
|
});
|
2019-03-27 20:40:26 -04:00
|
|
|
|
}
|
2018-02-21 20:29:23 -05:00
|
|
|
|
}
|
|
|
|
|
}
|