From 1241ac459ec39913ee74bce717107656b12dbf86 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Fri, 22 May 2020 21:38:38 -0500 Subject: [PATCH] re-enable claims permission add/remove --- Application/ApplicationManager.cs | 3 +++ Application/GameEventHandler.cs | 9 --------- SharedLibraryCore/Interfaces/IManager.cs | 5 +++++ .../Middleware/ClaimsPermissionRemoval.cs | 18 +++++++++--------- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Application/ApplicationManager.cs b/Application/ApplicationManager.cs index 72977a317..482c62012 100644 --- a/Application/ApplicationManager.cs +++ b/Application/ApplicationManager.cs @@ -43,6 +43,7 @@ namespace IW4MAdmin.Application public string ExternalIPAddress { get; private set; } public bool IsRestartRequested { get; private set; } public IMiddlewareActionHandler MiddlewareActionHandler { get; } + public event EventHandler OnGameEventExecuted; private readonly List _commands; private readonly ILogger _logger; private readonly List MessageTokens; @@ -164,6 +165,8 @@ namespace IW4MAdmin.Application skip: // tell anyone waiting for the output that we're done newEvent.Complete(); + OnGameEventExecuted?.Invoke(this, newEvent); + #if DEBUG == true Logger.WriteDebug($"Exiting event process for {newEvent.Id}"); #endif diff --git a/Application/GameEventHandler.cs b/Application/GameEventHandler.cs index f43b646f6..1dfc52829 100644 --- a/Application/GameEventHandler.cs +++ b/Application/GameEventHandler.cs @@ -43,15 +43,6 @@ namespace IW4MAdmin.Application EventApi.OnGameEvent(gameEvent); Task.Factory.StartNew(() => manager.ExecuteEvent(gameEvent)); - - /*if (!_eventLog.ContainsKey(gameEvent.Owner.EndPoint)) - { - _eventLog.Add(gameEvent.Owner.EndPoint,new List()); - } - _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 else diff --git a/SharedLibraryCore/Interfaces/IManager.cs b/SharedLibraryCore/Interfaces/IManager.cs index efce6464f..95bf4b882 100644 --- a/SharedLibraryCore/Interfaces/IManager.cs +++ b/SharedLibraryCore/Interfaces/IManager.cs @@ -5,6 +5,7 @@ using SharedLibraryCore.Configuration; using SharedLibraryCore.Database.Models; using System.Threading; using System.Collections; +using System; namespace SharedLibraryCore.Interfaces { @@ -80,5 +81,9 @@ namespace SharedLibraryCore.Interfaces /// /// name of command void RemoveCommandByName(string name); + /// + /// event executed when event has finished executing + /// + event EventHandler OnGameEventExecuted; } } diff --git a/WebfrontCore/Middleware/ClaimsPermissionRemoval.cs b/WebfrontCore/Middleware/ClaimsPermissionRemoval.cs index 43525d30a..bc8e4c813 100644 --- a/WebfrontCore/Middleware/ClaimsPermissionRemoval.cs +++ b/WebfrontCore/Middleware/ClaimsPermissionRemoval.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Http; -using SharedLibraryCore.Events; +using SharedLibraryCore; using SharedLibraryCore.Interfaces; using System.Collections.Generic; using System.Linq; @@ -23,7 +23,7 @@ namespace WebfrontCore.Middleware public ClaimsPermissionRemoval(RequestDelegate nextRequest, IManager manager) { _manager = manager; - //_manager.OnServerEvent += OnGameEvent; + _manager.OnGameEventExecuted += OnGameEvent; _privilegedClientIds = new List(); _nextRequest = nextRequest; } @@ -32,27 +32,27 @@ namespace WebfrontCore.Middleware /// Callback for the game event /// /// - /// - private void OnGameEvent(object sender, GameEventArgs args) + /// + private void OnGameEvent(object sender, GameEvent gameEvent) { - if (args.Event.Type == EventType.ChangePermission && - args.Event.Extra is Permission perm) + if (gameEvent.Type == EventType.ChangePermission && + gameEvent.Extra is Permission perm) { // we want to remove the claims when the client is demoted if (perm < Permission.Trusted) { lock (_privilegedClientIds) { - _privilegedClientIds.RemoveAll(id => id == args.Event.Target.ClientId); + _privilegedClientIds.RemoveAll(id => id == gameEvent.Target.ClientId); } } // and add if promoted else if (perm > Permission.Trusted && - !_privilegedClientIds.Contains(args.Event.Target.ClientId)) + !_privilegedClientIds.Contains(gameEvent.Target.ClientId)) { lock (_privilegedClientIds) { - _privilegedClientIds.Add(args.Event.Target.ClientId); + _privilegedClientIds.Add(gameEvent.Target.ClientId); } } }