2019-11-15 15:50:20 -05:00
|
|
|
|
using IW4MAdmin.Application.Misc;
|
|
|
|
|
using SharedLibraryCore;
|
2018-08-30 21:53:00 -04:00
|
|
|
|
using SharedLibraryCore.Events;
|
2018-04-26 02:13:04 -04:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2019-10-09 16:51:02 -04:00
|
|
|
|
using System.Linq;
|
2020-04-20 11:45:58 -04:00
|
|
|
|
using System.Threading.Tasks;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
2018-04-26 02:13:04 -04:00
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin.Application
|
|
|
|
|
{
|
2020-05-04 17:50:02 -04:00
|
|
|
|
public class GameEventHandler : IEventHandler
|
2018-04-26 02:13:04 -04:00
|
|
|
|
{
|
2020-05-04 17:50:02 -04:00
|
|
|
|
private readonly EventLog _eventLog;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
private readonly ILogger _logger;
|
2019-11-15 15:50:20 -05:00
|
|
|
|
private static readonly GameEvent.EventType[] overrideEvents = new[]
|
2019-10-09 16:51:02 -04:00
|
|
|
|
{
|
|
|
|
|
GameEvent.EventType.Connect,
|
|
|
|
|
GameEvent.EventType.Disconnect,
|
|
|
|
|
GameEvent.EventType.Quit,
|
|
|
|
|
GameEvent.EventType.Stop
|
|
|
|
|
};
|
|
|
|
|
|
2020-11-11 18:31:26 -05:00
|
|
|
|
public GameEventHandler(ILogger<GameEventHandler> logger)
|
2018-04-26 02:13:04 -04:00
|
|
|
|
{
|
2020-05-04 17:50:02 -04:00
|
|
|
|
_eventLog = new EventLog();
|
2020-11-11 18:31:26 -05:00
|
|
|
|
_logger = logger;
|
2019-11-15 15:50:20 -05:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 17:50:02 -04:00
|
|
|
|
public void HandleEvent(IManager manager, GameEvent gameEvent)
|
2018-04-26 02:13:04 -04:00
|
|
|
|
{
|
2020-05-04 17:50:02 -04:00
|
|
|
|
if (manager.IsRunning || overrideEvents.Contains(gameEvent.Type))
|
2019-10-09 16:51:02 -04:00
|
|
|
|
{
|
2020-05-04 17:50:02 -04:00
|
|
|
|
EventApi.OnGameEvent(gameEvent);
|
|
|
|
|
Task.Factory.StartNew(() => manager.ExecuteEvent(gameEvent));
|
2019-10-09 16:51:02 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-11-11 18:31:26 -05:00
|
|
|
|
_logger.LogDebug("Skipping event as we're shutting down {eventId}", gameEvent.Id);
|
2019-10-09 16:51:02 -04:00
|
|
|
|
}
|
2018-04-26 02:13:04 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|