2018-04-26 02:13:04 -04:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using System;
|
2018-04-28 01:22:18 -04:00
|
|
|
|
using System.Collections.Concurrent;
|
2018-04-26 02:13:04 -04:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin.Application
|
|
|
|
|
{
|
|
|
|
|
class GameEventHandler : IEventHandler
|
|
|
|
|
{
|
2018-04-28 01:22:18 -04:00
|
|
|
|
private ConcurrentQueue<GameEvent> EventQueue;
|
|
|
|
|
private ConcurrentQueue<GameEvent> StatusSensitiveQueue;
|
2018-04-26 02:13:04 -04:00
|
|
|
|
private IManager Manager;
|
|
|
|
|
|
|
|
|
|
public GameEventHandler(IManager mgr)
|
|
|
|
|
{
|
2018-04-28 01:22:18 -04:00
|
|
|
|
EventQueue = new ConcurrentQueue<GameEvent>();
|
|
|
|
|
StatusSensitiveQueue = new ConcurrentQueue<GameEvent>();
|
2018-04-26 02:13:04 -04:00
|
|
|
|
Manager = mgr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddEvent(GameEvent gameEvent)
|
|
|
|
|
{
|
|
|
|
|
#if DEBUG
|
|
|
|
|
Manager.GetLogger().WriteDebug($"Got new event of type {gameEvent.Type} for {gameEvent.Owner}");
|
|
|
|
|
#endif
|
2018-04-28 01:22:18 -04:00
|
|
|
|
// we need this to keep accurate track of the score
|
|
|
|
|
if (gameEvent.Type == GameEvent.EventType.Script ||
|
2018-05-03 01:25:49 -04:00
|
|
|
|
gameEvent.Type == GameEvent.EventType.Kill ||
|
|
|
|
|
gameEvent.Type == GameEvent.EventType.MapChange)
|
2018-04-28 01:22:18 -04:00
|
|
|
|
{
|
|
|
|
|
#if DEBUG
|
|
|
|
|
Manager.GetLogger().WriteDebug($"Added sensitive event to queue");
|
|
|
|
|
#endif
|
|
|
|
|
StatusSensitiveQueue.Enqueue(gameEvent);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
EventQueue.Enqueue(gameEvent);
|
|
|
|
|
}
|
2018-04-26 02:13:04 -04:00
|
|
|
|
#if DEBUG
|
|
|
|
|
Manager.GetLogger().WriteDebug($"There are now {EventQueue.Count} events in queue");
|
|
|
|
|
#endif
|
|
|
|
|
Manager.SetHasEvent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string[] GetEventOutput()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-28 01:22:18 -04:00
|
|
|
|
public GameEvent GetNextSensitiveEvent()
|
|
|
|
|
{
|
|
|
|
|
if (StatusSensitiveQueue.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
if (!StatusSensitiveQueue.TryDequeue(out GameEvent newEvent))
|
|
|
|
|
{
|
|
|
|
|
Manager.GetLogger().WriteWarning("Could not dequeue time sensitive event for processing");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return newEvent;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-26 02:13:04 -04:00
|
|
|
|
public GameEvent GetNextEvent()
|
|
|
|
|
{
|
2018-04-28 01:22:18 -04:00
|
|
|
|
if (EventQueue.Count > 0)
|
|
|
|
|
{
|
2018-04-26 02:13:04 -04:00
|
|
|
|
#if DEBUG
|
2018-04-28 01:22:18 -04:00
|
|
|
|
Manager.GetLogger().WriteDebug("Getting next event to be processed");
|
2018-04-26 02:13:04 -04:00
|
|
|
|
#endif
|
2018-04-28 01:22:18 -04:00
|
|
|
|
if (!EventQueue.TryDequeue(out GameEvent newEvent))
|
|
|
|
|
{
|
|
|
|
|
Manager.GetLogger().WriteWarning("Could not dequeue event for processing");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return newEvent;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-26 02:13:04 -04:00
|
|
|
|
|
2018-04-28 01:22:18 -04:00
|
|
|
|
return null;
|
2018-04-26 02:13:04 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|