mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-11 15:52:25 -05:00
implement new eventing system
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@ -27,7 +28,7 @@ public class RemoteCommandService : IRemoteCommandService
|
||||
public async Task<IEnumerable<CommandResponseInfo>> Execute(int originId, int? targetId, string command,
|
||||
IEnumerable<string> arguments, Server server)
|
||||
{
|
||||
var (success, result) = await ExecuteWithResult(originId, targetId, command, arguments, server);
|
||||
var (_, result) = await ExecuteWithResult(originId, targetId, command, arguments, server);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -56,7 +57,8 @@ public class RemoteCommandService : IRemoteCommandService
|
||||
: $"{_appConfig.CommandPrefix}{command}",
|
||||
Origin = client,
|
||||
Owner = server,
|
||||
IsRemote = true
|
||||
IsRemote = true,
|
||||
CorrelationId = Guid.NewGuid()
|
||||
};
|
||||
|
||||
server.Manager.AddEvent(remoteEvent);
|
||||
@ -72,7 +74,7 @@ public class RemoteCommandService : IRemoteCommandService
|
||||
{
|
||||
response = new[]
|
||||
{
|
||||
new CommandResponseInfo()
|
||||
new CommandResponseInfo
|
||||
{
|
||||
ClientId = client.ClientId,
|
||||
Response = Utilities.CurrentLocalization.LocalizationIndex["SERVER_ERROR_COMMAND_TIMEOUT"]
|
||||
@ -90,7 +92,7 @@ public class RemoteCommandService : IRemoteCommandService
|
||||
}
|
||||
}
|
||||
|
||||
catch (System.OperationCanceledException)
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
response = new[]
|
||||
{
|
||||
|
@ -12,8 +12,10 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Configuration;
|
||||
using SharedLibraryCore.Events.Management;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using SharedLibraryCore.Interfaces.Events;
|
||||
|
||||
namespace IW4MAdmin.Application.Misc
|
||||
{
|
||||
@ -24,28 +26,20 @@ namespace IW4MAdmin.Application.Misc
|
||||
private readonly IManager _manager;
|
||||
private readonly IDatabaseContextFactory _contextFactory;
|
||||
private readonly ApplicationConfiguration _appConfig;
|
||||
private readonly IEventPublisher _eventPublisher;
|
||||
|
||||
private bool _inProgress;
|
||||
private TimeSpan _period;
|
||||
|
||||
public ServerDataCollector(ILogger<ServerDataCollector> logger, ApplicationConfiguration appConfig,
|
||||
IManager manager, IDatabaseContextFactory contextFactory, IEventPublisher eventPublisher)
|
||||
IManager manager, IDatabaseContextFactory contextFactory)
|
||||
{
|
||||
_logger = logger;
|
||||
_appConfig = appConfig;
|
||||
_manager = manager;
|
||||
_contextFactory = contextFactory;
|
||||
_eventPublisher = eventPublisher;
|
||||
|
||||
_eventPublisher.OnClientConnect += SaveConnectionInfo;
|
||||
_eventPublisher.OnClientDisconnect += SaveConnectionInfo;
|
||||
}
|
||||
|
||||
~ServerDataCollector()
|
||||
{
|
||||
_eventPublisher.OnClientConnect -= SaveConnectionInfo;
|
||||
_eventPublisher.OnClientDisconnect -= SaveConnectionInfo;
|
||||
IManagementEventSubscriptions.ClientStateAuthorized += SaveConnectionInfo;
|
||||
IManagementEventSubscriptions.ClientStateDisposed += SaveConnectionInfo;
|
||||
}
|
||||
|
||||
public async Task BeginCollectionAsync(TimeSpan? period = null, CancellationToken cancellationToken = default)
|
||||
@ -131,18 +125,19 @@ namespace IW4MAdmin.Application.Misc
|
||||
await context.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
private void SaveConnectionInfo(object sender, GameEvent gameEvent)
|
||||
private async Task SaveConnectionInfo(ClientStateEvent stateEvent, CancellationToken token)
|
||||
{
|
||||
using var context = _contextFactory.CreateContext(enableTracking: false);
|
||||
await using var context = _contextFactory.CreateContext(enableTracking: false);
|
||||
context.ConnectionHistory.Add(new EFClientConnectionHistory
|
||||
{
|
||||
ClientId = gameEvent.Origin.ClientId,
|
||||
ServerId = gameEvent.Owner.GetIdForServer().Result,
|
||||
ConnectionType = gameEvent.Type == GameEvent.EventType.Connect
|
||||
ClientId = stateEvent.Client.ClientId,
|
||||
ServerId = await stateEvent.Client.CurrentServer.GetIdForServer(),
|
||||
ConnectionType = stateEvent is ClientStateAuthorizeEvent
|
||||
? Reference.ConnectionType.Connect
|
||||
: Reference.ConnectionType.Disconnect
|
||||
});
|
||||
context.SaveChanges();
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ namespace IW4MAdmin.Application.Misc
|
||||
.Where(rating => rating.Client.Level != EFClient.Permission.Banned)
|
||||
.Where(rating => rating.Ranking != null)
|
||||
.CountAsync(cancellationToken);
|
||||
}, nameof(_rankedClientsCache), serverId is null ? null: new[] { (object)serverId }, _cacheTimeSpan);
|
||||
}, nameof(_rankedClientsCache), serverId is null ? null: new[] { (object)serverId }, _cacheTimeSpan);
|
||||
|
||||
try
|
||||
{
|
||||
|
Reference in New Issue
Block a user