remove unneeded classes
This commit is contained in:
parent
51fae05a73
commit
5f5fb8230e
@ -1,46 +0,0 @@
|
||||
using IW4MAdmin.Application.Misc;
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Events;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
|
||||
namespace IW4MAdmin.Application
|
||||
{
|
||||
public class GameEventHandler : IEventHandler
|
||||
{
|
||||
private readonly EventLog _eventLog;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IEventPublisher _eventPublisher;
|
||||
private static readonly GameEvent.EventType[] overrideEvents = new[]
|
||||
{
|
||||
GameEvent.EventType.Connect,
|
||||
GameEvent.EventType.Disconnect,
|
||||
GameEvent.EventType.Quit,
|
||||
GameEvent.EventType.Stop
|
||||
};
|
||||
|
||||
public GameEventHandler(ILogger<GameEventHandler> logger, IEventPublisher eventPublisher)
|
||||
{
|
||||
_eventLog = new EventLog();
|
||||
_logger = logger;
|
||||
_eventPublisher = eventPublisher;
|
||||
}
|
||||
|
||||
public void HandleEvent(IManager manager, GameEvent gameEvent)
|
||||
{
|
||||
if (manager.IsRunning || overrideEvents.Contains(gameEvent.Type))
|
||||
{
|
||||
EventApi.OnGameEvent(gameEvent);
|
||||
_eventPublisher.Publish(gameEvent);
|
||||
Task.Factory.StartNew(() => manager.ExecuteEvent(gameEvent));
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogDebug("Skipping event as we're shutting down {eventId}", gameEvent.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -462,7 +462,6 @@ namespace IW4MAdmin.Application
|
||||
.AddSingleton(typeof(IDataValueCache<,>), typeof(DataValueCache<,>))
|
||||
.AddSingleton<IServerDataViewer, ServerDataViewer>()
|
||||
.AddSingleton<IServerDataCollector, ServerDataCollector>()
|
||||
.AddSingleton<IEventPublisher, EventPublisher>()
|
||||
.AddSingleton<IGeoLocationService>(new GeoLocationService(Path.Join(".", "Resources", "GeoLite2-Country.mmdb")))
|
||||
.AddSingleton<IAlertManager, AlertManager>()
|
||||
.AddTransient<IScriptPluginTimerHelper, ScriptPluginTimerHelper>()
|
||||
|
@ -1,27 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
using SharedLibraryCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace IW4MAdmin.Application.Misc
|
||||
{
|
||||
public class EventLog : Dictionary<long, IList<GameEvent>>
|
||||
{
|
||||
private static JsonSerializerSettings serializationSettings;
|
||||
|
||||
public static JsonSerializerSettings BuildVcrSerializationSettings()
|
||||
{
|
||||
if (serializationSettings == null)
|
||||
{
|
||||
serializationSettings = new JsonSerializerSettings() { Formatting = Formatting.Indented, ReferenceLoopHandling = ReferenceLoopHandling.Ignore };
|
||||
serializationSettings.Converters.Add(new IPAddressConverter());
|
||||
serializationSettings.Converters.Add(new IPEndPointConverter());
|
||||
serializationSettings.Converters.Add(new GameEventConverter());
|
||||
serializationSettings.Converters.Add(new ClientEntityConverter());
|
||||
}
|
||||
|
||||
return serializationSettings;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
|
||||
namespace IW4MAdmin.Application.Misc
|
||||
{
|
||||
public class EventPublisher : IEventPublisher
|
||||
{
|
||||
public event EventHandler<GameEvent> OnClientDisconnect;
|
||||
public event EventHandler<GameEvent> OnClientConnect;
|
||||
public event EventHandler<GameEvent> OnClientMetaUpdated;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public EventPublisher(ILogger<EventPublisher> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Publish(GameEvent gameEvent)
|
||||
{
|
||||
_logger.LogDebug("Handling publishing event of type {EventType}", gameEvent.Type);
|
||||
|
||||
try
|
||||
{
|
||||
if (gameEvent.Type == GameEvent.EventType.Connect)
|
||||
{
|
||||
OnClientConnect?.Invoke(this, gameEvent);
|
||||
}
|
||||
|
||||
if (gameEvent.Type == GameEvent.EventType.Disconnect && gameEvent.Origin.ClientId != 0)
|
||||
{
|
||||
OnClientDisconnect?.Invoke(this, gameEvent);
|
||||
}
|
||||
|
||||
if (gameEvent.Type == GameEvent.EventType.MetaUpdated)
|
||||
{
|
||||
OnClientMetaUpdated?.Invoke(this, gameEvent);
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Could not publish event of type {EventType}", gameEvent.Type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Events;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace IW4MAdmin.Application
|
||||
{
|
||||
class SerialGameEventHandler : IEventHandler
|
||||
{
|
||||
private delegate void GameEventAddedEventHandler(object sender, GameEventArgs args);
|
||||
private event GameEventAddedEventHandler GameEventAdded;
|
||||
|
||||
private static readonly GameEvent.EventType[] overrideEvents = new[]
|
||||
{
|
||||
GameEvent.EventType.Connect,
|
||||
GameEvent.EventType.Disconnect,
|
||||
GameEvent.EventType.Quit,
|
||||
GameEvent.EventType.Stop
|
||||
};
|
||||
|
||||
public SerialGameEventHandler()
|
||||
{
|
||||
GameEventAdded += GameEventHandler_GameEventAdded;
|
||||
}
|
||||
|
||||
private async void GameEventHandler_GameEventAdded(object sender, GameEventArgs args)
|
||||
{
|
||||
await (sender as IManager).ExecuteEvent(args.Event);
|
||||
EventApi.OnGameEvent(args.Event);
|
||||
}
|
||||
|
||||
public void HandleEvent(IManager manager, GameEvent gameEvent)
|
||||
{
|
||||
if (manager.IsRunning || overrideEvents.Contains(gameEvent.Type))
|
||||
{
|
||||
GameEventAdded?.Invoke(manager, new GameEventArgs(null, false, gameEvent));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
namespace SharedLibraryCore.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// handles games events (from log, manual events, etc)
|
||||
/// </summary>
|
||||
public interface IEventHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Add a game event event to the queue to be processed
|
||||
/// </summary>
|
||||
/// <param name="manager">application manager instance</param>
|
||||
/// <param name="gameEvent">game event</param>
|
||||
void HandleEvent(IManager manager, GameEvent gameEvent);
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace SharedLibraryCore.Interfaces
|
||||
{
|
||||
public interface IEventPublisher
|
||||
{
|
||||
event EventHandler<GameEvent> OnClientDisconnect;
|
||||
event EventHandler<GameEvent> OnClientConnect;
|
||||
|
||||
void Publish(GameEvent gameEvent);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user