2020-08-17 22:21:11 -04:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Database.Models;
|
|
|
|
|
using SharedLibraryCore.Dtos.Meta.Responses;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using SharedLibraryCore.QueryHelper;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2022-03-23 09:43:57 -04:00
|
|
|
|
using System.Threading;
|
2020-08-17 22:21:11 -04:00
|
|
|
|
using System.Threading.Tasks;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
2020-08-17 22:21:11 -04:00
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin.Application.Meta
|
|
|
|
|
{
|
|
|
|
|
public class MetaRegistration : IMetaRegistration
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private ITranslationLookup _transLookup;
|
2022-03-23 09:43:57 -04:00
|
|
|
|
private readonly IMetaServiceV2 _metaService;
|
2020-08-17 22:21:11 -04:00
|
|
|
|
private readonly IEntityService<EFClient> _clientEntityService;
|
|
|
|
|
private readonly IResourceQueryHelper<ClientPaginationRequest, ReceivedPenaltyResponse> _receivedPenaltyHelper;
|
2022-03-23 09:43:57 -04:00
|
|
|
|
|
|
|
|
|
private readonly IResourceQueryHelper<ClientPaginationRequest, AdministeredPenaltyResponse>
|
|
|
|
|
_administeredPenaltyHelper;
|
|
|
|
|
|
2020-08-17 22:21:11 -04:00
|
|
|
|
private readonly IResourceQueryHelper<ClientPaginationRequest, UpdatedAliasResponse> _updatedAliasHelper;
|
2022-03-23 09:43:57 -04:00
|
|
|
|
|
2021-08-31 19:21:40 -04:00
|
|
|
|
private readonly IResourceQueryHelper<ClientPaginationRequest, ConnectionHistoryResponse>
|
|
|
|
|
_connectionHistoryHelper;
|
2022-03-23 09:43:57 -04:00
|
|
|
|
|
2022-02-23 13:47:00 -05:00
|
|
|
|
private readonly IResourceQueryHelper<ClientPaginationRequest, PermissionLevelChangedResponse>
|
|
|
|
|
_permissionLevelHelper;
|
2020-08-17 22:21:11 -04:00
|
|
|
|
|
2022-03-23 09:43:57 -04:00
|
|
|
|
public MetaRegistration(ILogger<MetaRegistration> logger, IMetaServiceV2 metaService,
|
2022-02-23 13:47:00 -05:00
|
|
|
|
ITranslationLookup transLookup, IEntityService<EFClient> clientEntityService,
|
2020-08-17 22:21:11 -04:00
|
|
|
|
IResourceQueryHelper<ClientPaginationRequest, ReceivedPenaltyResponse> receivedPenaltyHelper,
|
|
|
|
|
IResourceQueryHelper<ClientPaginationRequest, AdministeredPenaltyResponse> administeredPenaltyHelper,
|
2021-08-31 19:21:40 -04:00
|
|
|
|
IResourceQueryHelper<ClientPaginationRequest, UpdatedAliasResponse> updatedAliasHelper,
|
2022-02-23 13:47:00 -05:00
|
|
|
|
IResourceQueryHelper<ClientPaginationRequest, ConnectionHistoryResponse> connectionHistoryHelper,
|
|
|
|
|
IResourceQueryHelper<ClientPaginationRequest, PermissionLevelChangedResponse> permissionLevelHelper)
|
2020-08-17 22:21:11 -04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_transLookup = transLookup;
|
|
|
|
|
_metaService = metaService;
|
|
|
|
|
_clientEntityService = clientEntityService;
|
|
|
|
|
_receivedPenaltyHelper = receivedPenaltyHelper;
|
|
|
|
|
_administeredPenaltyHelper = administeredPenaltyHelper;
|
|
|
|
|
_updatedAliasHelper = updatedAliasHelper;
|
2021-08-31 19:21:40 -04:00
|
|
|
|
_connectionHistoryHelper = connectionHistoryHelper;
|
2022-02-23 13:47:00 -05:00
|
|
|
|
_permissionLevelHelper = permissionLevelHelper;
|
2020-08-17 22:21:11 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Register()
|
|
|
|
|
{
|
2022-03-23 09:43:57 -04:00
|
|
|
|
_metaService.AddRuntimeMeta<ClientPaginationRequest, InformationResponse>(MetaType.Information,
|
|
|
|
|
GetProfileMeta);
|
|
|
|
|
_metaService.AddRuntimeMeta<ClientPaginationRequest, ReceivedPenaltyResponse>(MetaType.ReceivedPenalty,
|
|
|
|
|
GetReceivedPenaltiesMeta);
|
|
|
|
|
_metaService.AddRuntimeMeta<ClientPaginationRequest, AdministeredPenaltyResponse>(MetaType.Penalized,
|
|
|
|
|
GetAdministeredPenaltiesMeta);
|
|
|
|
|
_metaService.AddRuntimeMeta<ClientPaginationRequest, UpdatedAliasResponse>(MetaType.AliasUpdate,
|
|
|
|
|
GetUpdatedAliasMeta);
|
|
|
|
|
_metaService.AddRuntimeMeta<ClientPaginationRequest, ConnectionHistoryResponse>(MetaType.ConnectionHistory,
|
|
|
|
|
GetConnectionHistoryMeta);
|
2022-02-23 13:47:00 -05:00
|
|
|
|
_metaService.AddRuntimeMeta<ClientPaginationRequest, PermissionLevelChangedResponse>(
|
|
|
|
|
MetaType.PermissionLevel, GetPermissionLevelMeta);
|
2020-08-17 22:21:11 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-23 09:43:57 -04:00
|
|
|
|
private async Task<IEnumerable<InformationResponse>> GetProfileMeta(ClientPaginationRequest request,
|
|
|
|
|
CancellationToken cancellationToken = default)
|
2020-08-17 22:21:11 -04:00
|
|
|
|
{
|
|
|
|
|
var metaList = new List<InformationResponse>();
|
2022-03-23 09:43:57 -04:00
|
|
|
|
var lastMapMeta =
|
|
|
|
|
await _metaService.GetPersistentMeta("LastMapPlayed", request.ClientId, cancellationToken);
|
2020-08-17 22:21:11 -04:00
|
|
|
|
|
|
|
|
|
if (lastMapMeta != null)
|
|
|
|
|
{
|
|
|
|
|
metaList.Add(new InformationResponse()
|
|
|
|
|
{
|
|
|
|
|
ClientId = request.ClientId,
|
|
|
|
|
MetaId = lastMapMeta.MetaId,
|
|
|
|
|
Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_LAST_MAP"],
|
|
|
|
|
Value = lastMapMeta.Value,
|
|
|
|
|
ShouldDisplay = true,
|
|
|
|
|
Type = MetaType.Information,
|
|
|
|
|
Order = 6
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-23 09:43:57 -04:00
|
|
|
|
var lastServerMeta =
|
|
|
|
|
await _metaService.GetPersistentMeta("LastServerPlayed", request.ClientId, cancellationToken);
|
2020-08-17 22:21:11 -04:00
|
|
|
|
|
|
|
|
|
if (lastServerMeta != null)
|
|
|
|
|
{
|
|
|
|
|
metaList.Add(new InformationResponse()
|
|
|
|
|
{
|
|
|
|
|
ClientId = request.ClientId,
|
|
|
|
|
MetaId = lastServerMeta.MetaId,
|
|
|
|
|
Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_LAST_SERVER"],
|
|
|
|
|
Value = lastServerMeta.Value,
|
|
|
|
|
ShouldDisplay = true,
|
|
|
|
|
Type = MetaType.Information,
|
2022-04-19 19:43:58 -04:00
|
|
|
|
Order = 7
|
2020-08-17 22:21:11 -04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var client = await _clientEntityService.Get(request.ClientId);
|
|
|
|
|
|
|
|
|
|
if (client == null)
|
|
|
|
|
{
|
2022-03-23 09:43:57 -04:00
|
|
|
|
_logger.LogWarning("No client found with id {ClientId} when generating profile meta", request.ClientId);
|
2020-08-17 22:21:11 -04:00
|
|
|
|
return metaList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
metaList.Add(new InformationResponse()
|
|
|
|
|
{
|
|
|
|
|
ClientId = client.ClientId,
|
|
|
|
|
Key = _transLookup["WEBFRONT_PROFILE_META_PLAY_TIME"],
|
|
|
|
|
Value = TimeSpan.FromHours(client.TotalConnectionTime / 3600.0).HumanizeForCurrentCulture(),
|
|
|
|
|
ShouldDisplay = true,
|
2022-04-19 19:43:58 -04:00
|
|
|
|
Order = 8,
|
2020-08-17 22:21:11 -04:00
|
|
|
|
Type = MetaType.Information
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
metaList.Add(new InformationResponse()
|
|
|
|
|
{
|
|
|
|
|
ClientId = client.ClientId,
|
|
|
|
|
Key = _transLookup["WEBFRONT_PROFILE_META_FIRST_SEEN"],
|
|
|
|
|
Value = (DateTime.UtcNow - client.FirstConnection).HumanizeForCurrentCulture(),
|
|
|
|
|
ShouldDisplay = true,
|
2022-04-19 19:43:58 -04:00
|
|
|
|
Order = 9,
|
2020-08-17 22:21:11 -04:00
|
|
|
|
Type = MetaType.Information
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
metaList.Add(new InformationResponse()
|
|
|
|
|
{
|
|
|
|
|
ClientId = client.ClientId,
|
|
|
|
|
Key = _transLookup["WEBFRONT_PROFILE_META_LAST_SEEN"],
|
|
|
|
|
Value = (DateTime.UtcNow - client.LastConnection).HumanizeForCurrentCulture(),
|
|
|
|
|
ShouldDisplay = true,
|
2022-04-19 19:43:58 -04:00
|
|
|
|
Order = 10,
|
2020-08-17 22:21:11 -04:00
|
|
|
|
Type = MetaType.Information
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
metaList.Add(new InformationResponse()
|
|
|
|
|
{
|
|
|
|
|
ClientId = client.ClientId,
|
|
|
|
|
Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_CONNECTIONS"],
|
2022-03-23 09:43:57 -04:00
|
|
|
|
Value = client.Connections.ToString("#,##0",
|
|
|
|
|
new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName)),
|
2020-08-17 22:21:11 -04:00
|
|
|
|
ShouldDisplay = true,
|
2022-04-19 19:43:58 -04:00
|
|
|
|
Order = 11,
|
2020-08-17 22:21:11 -04:00
|
|
|
|
Type = MetaType.Information
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
metaList.Add(new InformationResponse()
|
|
|
|
|
{
|
|
|
|
|
ClientId = client.ClientId,
|
|
|
|
|
Key = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_MASKED"],
|
2022-03-23 09:43:57 -04:00
|
|
|
|
Value = client.Masked
|
|
|
|
|
? Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_TRUE"]
|
|
|
|
|
: Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_FALSE"],
|
2020-08-17 22:21:11 -04:00
|
|
|
|
IsSensitive = true,
|
2022-04-19 19:43:58 -04:00
|
|
|
|
Order = 12,
|
2020-08-17 22:21:11 -04:00
|
|
|
|
Type = MetaType.Information
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return metaList;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-23 09:43:57 -04:00
|
|
|
|
private async Task<IEnumerable<ReceivedPenaltyResponse>> GetReceivedPenaltiesMeta(
|
|
|
|
|
ClientPaginationRequest request, CancellationToken token = default)
|
2020-08-17 22:21:11 -04:00
|
|
|
|
{
|
|
|
|
|
var penalties = await _receivedPenaltyHelper.QueryResource(request);
|
|
|
|
|
return penalties.Results;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-23 09:43:57 -04:00
|
|
|
|
private async Task<IEnumerable<AdministeredPenaltyResponse>> GetAdministeredPenaltiesMeta(
|
|
|
|
|
ClientPaginationRequest request, CancellationToken token = default)
|
2020-08-17 22:21:11 -04:00
|
|
|
|
{
|
|
|
|
|
var penalties = await _administeredPenaltyHelper.QueryResource(request);
|
|
|
|
|
return penalties.Results;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-23 09:43:57 -04:00
|
|
|
|
private async Task<IEnumerable<UpdatedAliasResponse>> GetUpdatedAliasMeta(ClientPaginationRequest request,
|
|
|
|
|
CancellationToken token = default)
|
2020-08-17 22:21:11 -04:00
|
|
|
|
{
|
|
|
|
|
var aliases = await _updatedAliasHelper.QueryResource(request);
|
|
|
|
|
return aliases.Results;
|
|
|
|
|
}
|
2022-03-23 09:43:57 -04:00
|
|
|
|
|
|
|
|
|
private async Task<IEnumerable<ConnectionHistoryResponse>> GetConnectionHistoryMeta(
|
|
|
|
|
ClientPaginationRequest request, CancellationToken token = default)
|
2021-08-31 19:21:40 -04:00
|
|
|
|
{
|
|
|
|
|
var connections = await _connectionHistoryHelper.QueryResource(request);
|
|
|
|
|
return connections.Results;
|
|
|
|
|
}
|
2022-02-23 13:47:00 -05:00
|
|
|
|
|
|
|
|
|
private async Task<IEnumerable<PermissionLevelChangedResponse>> GetPermissionLevelMeta(
|
2022-03-23 09:43:57 -04:00
|
|
|
|
ClientPaginationRequest request, CancellationToken token = default)
|
2022-02-23 13:47:00 -05:00
|
|
|
|
{
|
|
|
|
|
var permissionChanges = await _permissionLevelHelper.QueryResource(request);
|
|
|
|
|
return permissionChanges.Results;
|
|
|
|
|
}
|
2020-08-17 22:21:11 -04:00
|
|
|
|
}
|
|
|
|
|
}
|