1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-16 18:19:38 -05:00

Initial .net 6 upgrades

This commit is contained in:
RaidMax
2022-01-26 10:32:16 -06:00
parent 513f0afd34
commit 6f6dd035ee
170 changed files with 2805 additions and 2577 deletions

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Concurrent;
using System.Collections.Generic;
using SharedLibraryCore.Dtos;
@ -7,8 +6,8 @@ namespace SharedLibraryCore.Events
{
public class EventApi
{
const int MaxEvents = 25;
static ConcurrentQueue<EventInfo> RecentEvents = new ConcurrentQueue<EventInfo>();
private const int MaxEvents = 25;
private static readonly ConcurrentQueue<EventInfo> RecentEvents = new ConcurrentQueue<EventInfo>();
public static IEnumerable<EventInfo> GetEvents(bool shouldConsume)
{
@ -28,32 +27,38 @@ namespace SharedLibraryCore.Events
var E = gameEvent;
// don't want to clog up the api with unknown events
if (E.Type == GameEvent.EventType.Unknown)
{
return;
}
var apiEvent = new EventInfo()
var apiEvent = new EventInfo
{
ExtraInfo = E.Extra?.ToString() ?? E.Data,
GameInfo = new EntityInfo()
GameInfo = new EntityInfo
{
Name = E.Owner.GameName.ToString(),
Id = (int)E.Owner.GameName
},
OwnerEntity = new EntityInfo()
OwnerEntity = new EntityInfo
{
Name = E.Owner.Hostname,
Id = E.Owner.EndPoint
},
OriginEntity = E.Origin == null ? null : new EntityInfo()
{
Id = E.Origin.ClientId,
Name = E.Origin.Name
},
TargetEntity = E.Target == null ? null : new EntityInfo()
{
Id = E.Target.ClientId,
Name = E.Target.Name
},
EventType = new EntityInfo()
OriginEntity = E.Origin == null
? null
: new EntityInfo
{
Id = E.Origin.ClientId,
Name = E.Origin.Name
},
TargetEntity = E.Target == null
? null
: new EntityInfo
{
Id = E.Target.ClientId,
Name = E.Target.Name
},
EventType = new EntityInfo
{
Id = (int)E.Type,
Name = E.Type.ToString()
@ -66,16 +71,18 @@ namespace SharedLibraryCore.Events
}
/// <summary>
/// Adds event to the list and removes first added if reached max capacity
/// Adds event to the list and removes first added if reached max capacity
/// </summary>
/// <param name="info">EventInfo to add</param>
private static void AddNewEvent(EventInfo info)
{
// remove the first added event
if (RecentEvents.Count >= MaxEvents)
{
RecentEvents.TryDequeue(out _);
}
RecentEvents.Enqueue(info);
}
}
}
}