re-enable claims permission add/remove

This commit is contained in:
RaidMax 2020-05-22 21:38:38 -05:00
parent 4afd1f3cdc
commit 1241ac459e
4 changed files with 17 additions and 18 deletions

View File

@ -43,6 +43,7 @@ namespace IW4MAdmin.Application
public string ExternalIPAddress { get; private set; } public string ExternalIPAddress { get; private set; }
public bool IsRestartRequested { get; private set; } public bool IsRestartRequested { get; private set; }
public IMiddlewareActionHandler MiddlewareActionHandler { get; } public IMiddlewareActionHandler MiddlewareActionHandler { get; }
public event EventHandler<GameEvent> OnGameEventExecuted;
private readonly List<IManagerCommand> _commands; private readonly List<IManagerCommand> _commands;
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly List<MessageToken> MessageTokens; private readonly List<MessageToken> MessageTokens;
@ -164,6 +165,8 @@ namespace IW4MAdmin.Application
skip: skip:
// tell anyone waiting for the output that we're done // tell anyone waiting for the output that we're done
newEvent.Complete(); newEvent.Complete();
OnGameEventExecuted?.Invoke(this, newEvent);
#if DEBUG == true #if DEBUG == true
Logger.WriteDebug($"Exiting event process for {newEvent.Id}"); Logger.WriteDebug($"Exiting event process for {newEvent.Id}");
#endif #endif

View File

@ -43,15 +43,6 @@ namespace IW4MAdmin.Application
EventApi.OnGameEvent(gameEvent); EventApi.OnGameEvent(gameEvent);
Task.Factory.StartNew(() => manager.ExecuteEvent(gameEvent)); Task.Factory.StartNew(() => manager.ExecuteEvent(gameEvent));
/*if (!_eventLog.ContainsKey(gameEvent.Owner.EndPoint))
{
_eventLog.Add(gameEvent.Owner.EndPoint,new List<GameEvent>());
}
_eventLog[gameEvent.Owner.EndPoint].Add(gameEvent);
string serializedEvents = JsonConvert.SerializeObject(_eventLog, EventLog.BuildVcrSerializationSettings());
System.IO.File.WriteAllText("output.json", serializedEvents);*/
//Task.Run(() => GameEventHandler_GameEventAdded(this, new GameEventArgs(null, false, gameEvent)));
} }
#if DEBUG #if DEBUG
else else

View File

@ -5,6 +5,7 @@ using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models; using SharedLibraryCore.Database.Models;
using System.Threading; using System.Threading;
using System.Collections; using System.Collections;
using System;
namespace SharedLibraryCore.Interfaces namespace SharedLibraryCore.Interfaces
{ {
@ -80,5 +81,9 @@ namespace SharedLibraryCore.Interfaces
/// </summary> /// </summary>
/// <param name="name">name of command</param> /// <param name="name">name of command</param>
void RemoveCommandByName(string name); void RemoveCommandByName(string name);
/// <summary>
/// event executed when event has finished executing
/// </summary>
event EventHandler<GameEvent> OnGameEventExecuted;
} }
} }

View File

@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using SharedLibraryCore.Events; using SharedLibraryCore;
using SharedLibraryCore.Interfaces; using SharedLibraryCore.Interfaces;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -23,7 +23,7 @@ namespace WebfrontCore.Middleware
public ClaimsPermissionRemoval(RequestDelegate nextRequest, IManager manager) public ClaimsPermissionRemoval(RequestDelegate nextRequest, IManager manager)
{ {
_manager = manager; _manager = manager;
//_manager.OnServerEvent += OnGameEvent; _manager.OnGameEventExecuted += OnGameEvent;
_privilegedClientIds = new List<int>(); _privilegedClientIds = new List<int>();
_nextRequest = nextRequest; _nextRequest = nextRequest;
} }
@ -32,27 +32,27 @@ namespace WebfrontCore.Middleware
/// Callback for the game event /// Callback for the game event
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="args"></param> /// <param name="gameEvent"></param>
private void OnGameEvent(object sender, GameEventArgs args) private void OnGameEvent(object sender, GameEvent gameEvent)
{ {
if (args.Event.Type == EventType.ChangePermission && if (gameEvent.Type == EventType.ChangePermission &&
args.Event.Extra is Permission perm) gameEvent.Extra is Permission perm)
{ {
// we want to remove the claims when the client is demoted // we want to remove the claims when the client is demoted
if (perm < Permission.Trusted) if (perm < Permission.Trusted)
{ {
lock (_privilegedClientIds) lock (_privilegedClientIds)
{ {
_privilegedClientIds.RemoveAll(id => id == args.Event.Target.ClientId); _privilegedClientIds.RemoveAll(id => id == gameEvent.Target.ClientId);
} }
} }
// and add if promoted // and add if promoted
else if (perm > Permission.Trusted && else if (perm > Permission.Trusted &&
!_privilegedClientIds.Contains(args.Event.Target.ClientId)) !_privilegedClientIds.Contains(gameEvent.Target.ClientId))
{ {
lock (_privilegedClientIds) lock (_privilegedClientIds)
{ {
_privilegedClientIds.Add(args.Event.Target.ClientId); _privilegedClientIds.Add(gameEvent.Target.ClientId);
} }
} }
} }