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;
|
2018-05-10 01:34:29 -04:00
|
|
|
|
using System.Linq;
|
2018-04-26 02:13:04 -04:00
|
|
|
|
using System.Text;
|
2018-05-10 01:34:29 -04:00
|
|
|
|
using System.Threading;
|
2018-04-26 02:13:04 -04:00
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin.Application
|
|
|
|
|
{
|
|
|
|
|
class GameEventHandler : IEventHandler
|
|
|
|
|
{
|
2018-04-28 01:22:18 -04:00
|
|
|
|
private ConcurrentQueue<GameEvent> EventQueue;
|
2018-05-10 01:34:29 -04:00
|
|
|
|
private Queue<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>();
|
2018-05-10 01:34:29 -04:00
|
|
|
|
StatusSensitiveQueue = new Queue<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
|
2018-05-10 01:34:29 -04:00
|
|
|
|
if (gameEvent.Type == GameEvent.EventType.Kill ||
|
|
|
|
|
gameEvent.Type == GameEvent.EventType.Damage ||
|
|
|
|
|
gameEvent.Type == GameEvent.EventType.ScriptDamage ||
|
|
|
|
|
gameEvent.Type == GameEvent.EventType.ScriptKill ||
|
2018-05-03 01:25:49 -04:00
|
|
|
|
gameEvent.Type == GameEvent.EventType.MapChange)
|
2018-04-28 01:22:18 -04:00
|
|
|
|
{
|
|
|
|
|
#if DEBUG
|
|
|
|
|
Manager.GetLogger().WriteDebug($"Added sensitive event to queue");
|
|
|
|
|
#endif
|
2018-05-10 01:34:29 -04:00
|
|
|
|
lock (StatusSensitiveQueue)
|
|
|
|
|
{
|
|
|
|
|
StatusSensitiveQueue.Enqueue(gameEvent);
|
|
|
|
|
}
|
2018-04-28 01:22:18 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
EventQueue.Enqueue(gameEvent);
|
2018-05-10 01:34:29 -04:00
|
|
|
|
Manager.SetHasEvent();
|
2018-04-28 01:22:18 -04:00
|
|
|
|
}
|
2018-04-26 02:13:04 -04:00
|
|
|
|
#if DEBUG
|
|
|
|
|
Manager.GetLogger().WriteDebug($"There are now {EventQueue.Count} events in queue");
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string[] GetEventOutput()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-28 01:22:18 -04:00
|
|
|
|
public GameEvent GetNextSensitiveEvent()
|
|
|
|
|
{
|
|
|
|
|
if (StatusSensitiveQueue.Count > 0)
|
|
|
|
|
{
|
2018-05-10 01:34:29 -04:00
|
|
|
|
lock (StatusSensitiveQueue)
|
2018-04-28 01:22:18 -04:00
|
|
|
|
{
|
2018-05-10 01:34:29 -04:00
|
|
|
|
if (!StatusSensitiveQueue.TryDequeue(out GameEvent newEvent))
|
|
|
|
|
{
|
|
|
|
|
Manager.GetLogger().WriteWarning("Could not dequeue time sensitive event for processing");
|
|
|
|
|
}
|
2018-04-28 01:22:18 -04:00
|
|
|
|
|
2018-05-10 01:34:29 -04:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return newEvent;
|
|
|
|
|
}
|
2018-04-28 01:22:18 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|