2018-04-26 01:13:04 -05:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using System;
|
2018-04-28 00:22:18 -05:00
|
|
|
|
using System.Collections.Concurrent;
|
2018-04-26 01:13:04 -05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin.Application
|
|
|
|
|
{
|
|
|
|
|
class GameEventHandler : IEventHandler
|
|
|
|
|
{
|
2018-04-28 00:22:18 -05:00
|
|
|
|
private ConcurrentQueue<GameEvent> EventQueue;
|
2018-06-30 20:55:16 -05:00
|
|
|
|
private Queue<GameEvent> DelayedEventQueue;
|
2018-04-26 01:13:04 -05:00
|
|
|
|
private IManager Manager;
|
|
|
|
|
|
|
|
|
|
public GameEventHandler(IManager mgr)
|
|
|
|
|
{
|
2018-04-28 00:22:18 -05:00
|
|
|
|
EventQueue = new ConcurrentQueue<GameEvent>();
|
2018-06-30 20:55:16 -05:00
|
|
|
|
DelayedEventQueue = new Queue<GameEvent>();
|
2018-05-10 00:34:29 -05:00
|
|
|
|
|
2018-04-26 01:13:04 -05:00
|
|
|
|
Manager = mgr;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-30 20:55:16 -05:00
|
|
|
|
public void AddEvent(GameEvent gameEvent, bool delayedExecution = false)
|
2018-04-26 01:13:04 -05:00
|
|
|
|
{
|
|
|
|
|
#if DEBUG
|
|
|
|
|
Manager.GetLogger().WriteDebug($"Got new event of type {gameEvent.Type} for {gameEvent.Owner}");
|
|
|
|
|
#endif
|
2018-06-30 20:55:16 -05:00
|
|
|
|
if (delayedExecution)
|
2018-04-28 00:22:18 -05:00
|
|
|
|
{
|
2018-06-30 20:55:16 -05:00
|
|
|
|
DelayedEventQueue.Enqueue(gameEvent);
|
2018-04-28 00:22:18 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
EventQueue.Enqueue(gameEvent);
|
2018-05-10 00:34:29 -05:00
|
|
|
|
Manager.SetHasEvent();
|
2018-04-28 00:22:18 -05:00
|
|
|
|
}
|
2018-04-26 01:13:04 -05:00
|
|
|
|
#if DEBUG
|
|
|
|
|
Manager.GetLogger().WriteDebug($"There are now {EventQueue.Count} events in queue");
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string[] GetEventOutput()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-30 20:55:16 -05:00
|
|
|
|
public GameEvent GetNextEvent()
|
2018-07-04 21:09:42 -05:00
|
|
|
|
{
|
2018-07-01 19:30:38 -05:00
|
|
|
|
if (EventQueue.Count > 0)
|
2018-04-28 00:22:18 -05:00
|
|
|
|
{
|
2018-04-26 01:13:04 -05:00
|
|
|
|
#if DEBUG
|
2018-07-01 19:30:38 -05:00
|
|
|
|
Manager.GetLogger().WriteDebug("Getting next event to be processed");
|
2018-04-26 01:13:04 -05:00
|
|
|
|
#endif
|
2018-07-01 19:30:38 -05:00
|
|
|
|
if (!EventQueue.TryDequeue(out GameEvent newEvent))
|
2018-04-28 00:22:18 -05:00
|
|
|
|
{
|
2018-07-04 21:09:42 -05:00
|
|
|
|
Manager.GetLogger().WriteError("Could not dequeue event for processing");
|
2018-04-28 00:22:18 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return newEvent;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-26 01:13:04 -05:00
|
|
|
|
|
2018-04-28 00:22:18 -05:00
|
|
|
|
return null;
|
2018-04-26 01:13:04 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|