mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-11 15:52:25 -05:00
hide chat for password protected servers for issue #162
This commit is contained in:
38
Plugins/Stats/Dtos/ChatSearchQuery.cs
Normal file
38
Plugins/Stats/Dtos/ChatSearchQuery.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using SharedLibraryCore.QueryHelper;
|
||||
using System;
|
||||
|
||||
namespace Stats.Dtos
|
||||
{
|
||||
public class ChatSearchQuery : ClientPaginationRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// specifies the partial content of the message to search for
|
||||
/// </summary>
|
||||
public string MessageContains { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// identifier for the server
|
||||
/// </summary>
|
||||
public string ServerId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// identifier for the client
|
||||
/// </summary>
|
||||
public new int? ClientId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// only look for messages sent after this date
|
||||
/// </summary>
|
||||
public DateTime SentAfter { get; set; } = DateTime.UtcNow.AddYears(-100);
|
||||
|
||||
/// <summary>
|
||||
/// only look for messages sent before this date0
|
||||
/// </summary>
|
||||
public DateTime SentBefore { get; set; } = DateTime.UtcNow;
|
||||
|
||||
/// <summary>
|
||||
/// indicates if the chat is on the meta page
|
||||
/// </summary>
|
||||
public bool IsProfileMeta { get; set; }
|
||||
}
|
||||
}
|
@ -248,6 +248,10 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
|
||||
ctx.Entry(server).Property(_prop => _prop.HostName).IsModified = true;
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
|
||||
ctx.Entry(server).Property(_prop => _prop.IsPasswordProtected).IsModified = true;
|
||||
server.IsPasswordProtected = !string.IsNullOrEmpty(sv.GamePassword);
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
|
||||
// check to see if the stats have ever been initialized
|
||||
|
@ -16,5 +16,6 @@ namespace IW4MAdmin.Plugins.Stats.Models
|
||||
public string EndPoint { get; set; }
|
||||
public Game? GameName { get; set; }
|
||||
public string HostName { get; set; }
|
||||
public bool IsPasswordProtected { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -5,12 +5,11 @@ using Microsoft.EntityFrameworkCore;
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Database;
|
||||
using SharedLibraryCore.Database.Models;
|
||||
using SharedLibraryCore.Dtos;
|
||||
using SharedLibraryCore.Dtos.Meta.Responses;
|
||||
using SharedLibraryCore.Helpers;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using SharedLibraryCore.QueryHelper;
|
||||
using SharedLibraryCore.Services;
|
||||
using Stats.Dtos;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -36,14 +35,16 @@ namespace IW4MAdmin.Plugins.Stats
|
||||
private readonly IDatabaseContextFactory _databaseContextFactory;
|
||||
private readonly ITranslationLookup _translationLookup;
|
||||
private readonly IMetaService _metaService;
|
||||
private readonly IResourceQueryHelper<ChatSearchQuery, MessageResponse> _chatQueryHelper;
|
||||
|
||||
public Plugin(IConfigurationHandlerFactory configurationHandlerFactory, IDatabaseContextFactory databaseContextFactory,
|
||||
ITranslationLookup translationLookup, IMetaService metaService)
|
||||
ITranslationLookup translationLookup, IMetaService metaService, IResourceQueryHelper<ChatSearchQuery, MessageResponse> chatQueryHelper)
|
||||
{
|
||||
Config = configurationHandlerFactory.GetConfigurationHandler<StatsConfiguration>("StatsPluginSettings");
|
||||
_databaseContextFactory = databaseContextFactory;
|
||||
_translationLookup = translationLookup;
|
||||
_metaService = metaService;
|
||||
_chatQueryHelper = chatQueryHelper;
|
||||
}
|
||||
|
||||
public async Task OnEventAsync(GameEvent E, Server S)
|
||||
@ -199,7 +200,7 @@ namespace IW4MAdmin.Plugins.Stats
|
||||
using (var ctx = _databaseContextFactory.CreateContext(enableTracking: false))
|
||||
{
|
||||
clientStats = await ctx.Set<EFClientStatistics>().Where(c => c.ClientId == request.ClientId).ToListAsync();
|
||||
messageCount = await ctx.Set<EFClientMessage>().CountAsync(_message => _message.ClientId == request.ClientId);
|
||||
messageCount = await ctx.Set<EFClientMessage>().CountAsync(_message => _message.ClientId == request.ClientId);
|
||||
}
|
||||
|
||||
int kills = clientStats.Sum(c => c.Kills);
|
||||
@ -392,45 +393,16 @@ namespace IW4MAdmin.Plugins.Stats
|
||||
|
||||
async Task<IEnumerable<MessageResponse>> getMessages(ClientPaginationRequest request)
|
||||
{
|
||||
List<MessageResponse> messageMeta;
|
||||
using (var ctx = _databaseContextFactory.CreateContext(enableTracking: false))
|
||||
var query = new ChatSearchQuery()
|
||||
{
|
||||
var messages = ctx.Set<EFClientMessage>()
|
||||
.Where(m => m.ClientId == request.ClientId)
|
||||
.Where(_message => _message.TimeSent < request.Before)
|
||||
.OrderByDescending(_message => _message.TimeSent)
|
||||
.Take(request.Count);
|
||||
ClientId = request.ClientId,
|
||||
Before = request.Before,
|
||||
SentBefore = request.Before ?? DateTime.UtcNow,
|
||||
Count = request.Count,
|
||||
IsProfileMeta = true
|
||||
};
|
||||
|
||||
messageMeta = await messages.Select(m => new MessageResponse()
|
||||
{
|
||||
// todo: game name
|
||||
Message = m.Message,
|
||||
When = m.TimeSent,
|
||||
ServerId = m.ServerId,
|
||||
Type = MetaType.ChatMessage
|
||||
}).ToListAsync();
|
||||
|
||||
foreach (var meta in messageMeta)
|
||||
{
|
||||
if ((meta.Message).IsQuickMessage())
|
||||
{
|
||||
try
|
||||
{
|
||||
var quickMessages = ServerManager.GetApplicationSettings().Configuration()
|
||||
.QuickMessages
|
||||
.First(/*_qm => _qm.Game == meta.GameName*/);
|
||||
meta.Message = quickMessages.Messages[(meta.Message as string).Substring(1)];
|
||||
meta.Type = MetaType.QuickMessage;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return messageMeta;
|
||||
return (await _chatQueryHelper.QueryResource(query)).Results;
|
||||
}
|
||||
|
||||
if (Config.Configuration().EnableAntiCheat)
|
||||
|
@ -16,7 +16,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2.4.7" PrivateAssets="All" />
|
||||
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2.4.9" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
|
Reference in New Issue
Block a user