From 88af0327369458af897e70d52217f9404ace128c Mon Sep 17 00:00:00 2001 From: RaidMax Date: Mon, 30 Sep 2019 13:00:44 -0500 Subject: [PATCH 1/4] Update shared GUIDs --- Plugins/ScriptPlugins/SharedGUIDKick.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Plugins/ScriptPlugins/SharedGUIDKick.js b/Plugins/ScriptPlugins/SharedGUIDKick.js index 265d3644a..8ff7d70ff 100644 --- a/Plugins/ScriptPlugins/SharedGUIDKick.js +++ b/Plugins/ScriptPlugins/SharedGUIDKick.js @@ -18,7 +18,11 @@ var plugin = { gameEvent.Origin.NetworkId === 2908745942105435771 || gameEvent.Origin.NetworkId === -6492697076432899192 || gameEvent.Origin.NetworkId === 1145760003260769995 || - gameEvent.Origin.NetworkId === -7102887284306116957) { + gameEvent.Origin.NetworkId === -7102887284306116957 || + gameEvent.Origin.NetworkId === 3474936520447289592 || + gameEvent.Origin.NetworkId === -1168897558496584395 || + gameEvent.Origin.NetworkId === 8348020621355817691 || + gameEvent.Origin.NetworkId === 3259219574061214058) { gameEvent.Origin.Kick('Your GUID is generic. Delete players/guids.dat and rejoin', _IW4MAdminClient); } } From a7872aaffd37c8fdcf1decdda9510b00d8e04646 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Mon, 7 Oct 2019 17:35:37 -0500 Subject: [PATCH 2/4] ensure that demoted clients are logged out from the webfront --- Application/ApplicationManager.cs | 4 +- SharedLibraryCore/Events/GameEvent.cs | 4 + SharedLibraryCore/Interfaces/IManager.cs | 2 + .../Middleware/ClaimsPermissionRemoval.cs | 91 +++++++++++++++++++ WebfrontCore/Startup.cs | 3 + 5 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 WebfrontCore/Middleware/ClaimsPermissionRemoval.cs diff --git a/Application/ApplicationManager.cs b/Application/ApplicationManager.cs index d37d6e1c3..16ce05d64 100644 --- a/Application/ApplicationManager.cs +++ b/Application/ApplicationManager.cs @@ -21,6 +21,7 @@ using System.Reflection; using System.Text; using System.Threading; using System.Threading.Tasks; +using static SharedLibraryCore.GameEvent; namespace IW4MAdmin.Application { @@ -31,8 +32,6 @@ namespace IW4MAdmin.Application public ILogger Logger => GetLogger(0); public bool Running { get; private set; } public bool IsInitialized { get; private set; } - // define what the delagate function looks like - public delegate void OnServerEventEventHandler(object sender, GameEventArgs e); // expose the event handler so we can execute the events public OnServerEventEventHandler OnServerEvent { get; set; } public DateTime StartTime { get; private set; } @@ -53,7 +52,6 @@ namespace IW4MAdmin.Application public BaseConfigurationHandler ConfigHandler; GameEventHandler Handler; readonly IPageList PageList; - readonly SemaphoreSlim ProcessingEvent = new SemaphoreSlim(1, 1); readonly Dictionary Loggers = new Dictionary(); private readonly MetaService _metaService; private readonly TimeSpan _throttleTimeout = new TimeSpan(0, 1, 0); diff --git a/SharedLibraryCore/Events/GameEvent.cs b/SharedLibraryCore/Events/GameEvent.cs index 4dac83b9a..dba5cb3ee 100644 --- a/SharedLibraryCore/Events/GameEvent.cs +++ b/SharedLibraryCore/Events/GameEvent.cs @@ -1,4 +1,5 @@ using SharedLibraryCore.Database.Models; +using SharedLibraryCore.Events; using System; using System.Threading; using System.Threading.Tasks; @@ -7,6 +8,9 @@ namespace SharedLibraryCore { public class GameEvent { + // define what the delagate function looks like + public delegate void OnServerEventEventHandler(object sender, GameEventArgs e); + public enum EventFailReason { /// diff --git a/SharedLibraryCore/Interfaces/IManager.cs b/SharedLibraryCore/Interfaces/IManager.cs index bdce35aac..a6b39f513 100644 --- a/SharedLibraryCore/Interfaces/IManager.cs +++ b/SharedLibraryCore/Interfaces/IManager.cs @@ -5,6 +5,7 @@ using SharedLibraryCore.Configuration; using System.Reflection; using SharedLibraryCore.Database.Models; using System.Threading; +using static SharedLibraryCore.GameEvent; namespace SharedLibraryCore.Interfaces { @@ -43,5 +44,6 @@ namespace SharedLibraryCore.Interfaces string ExternalIPAddress { get; } CancellationToken CancellationToken { get; } bool IsRestartRequested { get; } + OnServerEventEventHandler OnServerEvent { get; set; } } } diff --git a/WebfrontCore/Middleware/ClaimsPermissionRemoval.cs b/WebfrontCore/Middleware/ClaimsPermissionRemoval.cs new file mode 100644 index 000000000..5a99d3556 --- /dev/null +++ b/WebfrontCore/Middleware/ClaimsPermissionRemoval.cs @@ -0,0 +1,91 @@ +using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Http; +using SharedLibraryCore.Events; +using SharedLibraryCore.Interfaces; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; +using System.Threading.Tasks; +using static SharedLibraryCore.Database.Models.EFClient; +using static SharedLibraryCore.GameEvent; + +namespace WebfrontCore.Middleware +{ + /// + /// Facilitates the removal of identity claims when client is demoted + /// + internal class ClaimsPermissionRemoval + { + private readonly IManager _manager; + private readonly List _privilegedClientIds; + private readonly RequestDelegate _nextRequest; + + public ClaimsPermissionRemoval(RequestDelegate nextRequest, IManager manager) + { + _manager = manager; + _manager.OnServerEvent += OnGameEvent; + _privilegedClientIds = new List(); + _nextRequest = nextRequest; + } + + /// + /// Callback for the game event + /// + /// + /// + private void OnGameEvent(object sender, GameEventArgs args) + { + if (args.Event.Type == EventType.ChangePermission && + args.Event.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); + } + } + // and add if promoted + else if (perm > Permission.Trusted && + !_privilegedClientIds.Contains(args.Event.Target.ClientId)) + { + lock (_privilegedClientIds) + { + _privilegedClientIds.Add(args.Event.Target.ClientId); + } + } + } + } + + public async Task Invoke(HttpContext context) + { + // we want to load the initial list of privileged clients + if (_privilegedClientIds.Count == 0) + { + var ids = (await _manager.GetClientService().GetPrivilegedClients()) + .Select(_client => _client.ClientId); + + lock (_privilegedClientIds) + { + _privilegedClientIds.AddRange(ids); + } + } + + // sid stores the clientId + string claimsId = context.User.Claims.FirstOrDefault(_claim => _claim.Type == ClaimTypes.Sid)?.Value; + + if (!string.IsNullOrEmpty(claimsId)) + { + int clientId = int.Parse(claimsId); + // they've been removed + if (!_privilegedClientIds.Contains(clientId) && clientId != 1) + { + await context.SignOutAsync(); + } + } + + await _nextRequest.Invoke(context); + } + } +} diff --git a/WebfrontCore/Startup.cs b/WebfrontCore/Startup.cs index 8e64dd8b2..d9608d2ca 100644 --- a/WebfrontCore/Startup.cs +++ b/WebfrontCore/Startup.cs @@ -113,6 +113,9 @@ namespace WebfrontCore app.UseAuthentication(); app.UseCors("AllowAll"); + // prevents banned/demoted users from keeping their claims + app.UseMiddleware(Program.Manager); + app.UseMvc(routes => { routes.MapRoute( From 76cfe30c0f37ef0e9e7d3bd0989ae502e7a8da86 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Mon, 7 Oct 2019 17:39:17 -0500 Subject: [PATCH 3/4] update version number --- Application/Application.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Application/Application.csproj b/Application/Application.csproj index ce8bb944e..722283c10 100644 --- a/Application/Application.csproj +++ b/Application/Application.csproj @@ -6,7 +6,7 @@ 2.2.2 false RaidMax.IW4MAdmin.Application - 2.2.8.3 + 2.2.8.4 RaidMax Forever None IW4MAdmin @@ -33,8 +33,8 @@ false true true - 2.2.8.3 - 2.2.8.3 + 2.2.8.4 + 2.2.8.4 7.1 From c630f65317426b2fce9c2a0c7c984a0d248647cb Mon Sep 17 00:00:00 2001 From: RaidMax Date: Tue, 8 Oct 2019 16:47:36 -0500 Subject: [PATCH 4/4] update the project files even though the culprit was actually the publish file --- Application/Application.csproj | 6 +----- Application/Misc/Logger.cs | 2 +- Plugins/AutomessageFeed/AutomessageFeed.csproj | 1 + Plugins/IW4ScriptCommands/IW4ScriptCommands.csproj | 7 +------ Plugins/Login/Login.csproj | 8 ++------ Plugins/ProfanityDeterment/ProfanityDeterment.csproj | 6 +----- Plugins/Stats/Stats.csproj | 8 ++------ Plugins/Tests/Tests.csproj | 7 +------ Plugins/Web/StatsWeb/StatsWeb.csproj | 1 + Plugins/Welcome/Welcome.csproj | 6 +----- RunPublishPre.cmd | 6 +++--- SharedLibraryCore/SharedLibraryCore.csproj | 8 ++------ WebfrontCore/WebfrontCore.csproj | 3 +-- 13 files changed, 18 insertions(+), 51 deletions(-) diff --git a/Application/Application.csproj b/Application/Application.csproj index 722283c10..7df6ef3e6 100644 --- a/Application/Application.csproj +++ b/Application/Application.csproj @@ -3,8 +3,8 @@ Exe netcoreapp2.2 - 2.2.2 false + true RaidMax.IW4MAdmin.Application 2.2.8.4 RaidMax @@ -54,10 +54,6 @@ - - - - diff --git a/Application/Misc/Logger.cs b/Application/Misc/Logger.cs index d08349a4e..0aebe8889 100644 --- a/Application/Misc/Logger.cs +++ b/Application/Misc/Logger.cs @@ -80,7 +80,7 @@ namespace IW4MAdmin.Application { Console.WriteLine(LogLine); } - await File.AppendAllTextAsync(FileName, $"{LogLine}{Environment.NewLine}"); + File.AppendAllText(FileName, $"{LogLine}{Environment.NewLine}"); #endif } diff --git a/Plugins/AutomessageFeed/AutomessageFeed.csproj b/Plugins/AutomessageFeed/AutomessageFeed.csproj index 47d92a060..a6b4082c9 100644 --- a/Plugins/AutomessageFeed/AutomessageFeed.csproj +++ b/Plugins/AutomessageFeed/AutomessageFeed.csproj @@ -3,6 +3,7 @@ netcoreapp2.2 true + true 7.1 diff --git a/Plugins/IW4ScriptCommands/IW4ScriptCommands.csproj b/Plugins/IW4ScriptCommands/IW4ScriptCommands.csproj index ae9424209..b3b3901e6 100644 --- a/Plugins/IW4ScriptCommands/IW4ScriptCommands.csproj +++ b/Plugins/IW4ScriptCommands/IW4ScriptCommands.csproj @@ -3,7 +3,7 @@ Library netcoreapp2.2 - 2.2.2 + true Debug;Release;Prerelease @@ -22,9 +22,4 @@ false - - - - - diff --git a/Plugins/Login/Login.csproj b/Plugins/Login/Login.csproj index 12463fd10..20d8f2b88 100644 --- a/Plugins/Login/Login.csproj +++ b/Plugins/Login/Login.csproj @@ -3,7 +3,7 @@ Library netcoreapp2.2 - 2.2.2 + true RaidMax.IW4MAdmin.Plugins.Login @@ -23,11 +23,7 @@ false - - - - - + diff --git a/Plugins/ProfanityDeterment/ProfanityDeterment.csproj b/Plugins/ProfanityDeterment/ProfanityDeterment.csproj index 6a36bd557..1e3e6e338 100644 --- a/Plugins/ProfanityDeterment/ProfanityDeterment.csproj +++ b/Plugins/ProfanityDeterment/ProfanityDeterment.csproj @@ -3,7 +3,7 @@ Library netcoreapp2.2 - 2.2.2 + true RaidMax.IW4MAdmin.Plugins.ProfanityDeterment @@ -22,10 +22,6 @@ - - - - diff --git a/Plugins/Stats/Stats.csproj b/Plugins/Stats/Stats.csproj index 4f371e775..a534b2682 100644 --- a/Plugins/Stats/Stats.csproj +++ b/Plugins/Stats/Stats.csproj @@ -3,7 +3,7 @@ Library netcoreapp2.2 - 2.2.2 + true RaidMax.IW4MAdmin.Plugins.Stats @@ -24,11 +24,7 @@ false - - - - - + diff --git a/Plugins/Tests/Tests.csproj b/Plugins/Tests/Tests.csproj index 872f54352..21316e67f 100644 --- a/Plugins/Tests/Tests.csproj +++ b/Plugins/Tests/Tests.csproj @@ -3,7 +3,7 @@ Library netcoreapp2.2 - 2.2.2 + true 7.1 @@ -25,9 +25,4 @@ - - - - - diff --git a/Plugins/Web/StatsWeb/StatsWeb.csproj b/Plugins/Web/StatsWeb/StatsWeb.csproj index e4550db72..c80077498 100644 --- a/Plugins/Web/StatsWeb/StatsWeb.csproj +++ b/Plugins/Web/StatsWeb/StatsWeb.csproj @@ -1,6 +1,7 @@  netcoreapp2.2 + true true true Debug;Release;Prerelease diff --git a/Plugins/Welcome/Welcome.csproj b/Plugins/Welcome/Welcome.csproj index caefd0da7..313429d6b 100644 --- a/Plugins/Welcome/Welcome.csproj +++ b/Plugins/Welcome/Welcome.csproj @@ -3,7 +3,7 @@ Library netcoreapp2.2 - 2.2.2 + true RaidMax.IW4MAdmin.Plugins.Welcome @@ -22,10 +22,6 @@ - - - - diff --git a/RunPublishPre.cmd b/RunPublishPre.cmd index f046f5a50..a6ee9f45a 100644 --- a/RunPublishPre.cmd +++ b/RunPublishPre.cmd @@ -1,6 +1,6 @@ -dotnet publish WebfrontCore/WebfrontCore.csproj -c Prerelease -o X:\IW4MAdmin\Publish\WindowsPrerelease /p:PublishProfile=Prerelease -dotnet publish Application/Application.csproj -c Prerelease -o X:\IW4MAdmin\Publish\WindowsPrerelease /p:PublishProfile=Prerelease -dotnet publish GameLogServer/GameLogServer.pyproj -c Release -o X:\IW4MAdmin\Publish\WindowsPrerelease\GameLogServer +dotnet publish WebfrontCore/WebfrontCore.csproj -c Prerelease -f netcoreapp2.2 --force -o X:\IW4MAdmin\Publish\WindowsPrerelease /p:PublishProfile=Prerelease +dotnet publish Application/Application.csproj -c Prerelease -f netcoreapp2.2 --force -o X:\IW4MAdmin\Publish\WindowsPrerelease /p:PublishProfile=Prerelease +dotnet publish GameLogServer/GameLogServer.pyproj -c Release -f netcoreapp2.2 --force -o X:\IW4MAdmin\Publish\WindowsPrerelease\GameLogServer call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat" msbuild GameLogServer/GameLogServer.pyproj /p:PublishProfile=PreRelease /p:DeployOnBuild=true /p:PublishProfileRootFolder=X:\IW4MAdmin\GameLogServer\ cd "X:\IW4MAdmin\DEPLOY\" diff --git a/SharedLibraryCore/SharedLibraryCore.csproj b/SharedLibraryCore/SharedLibraryCore.csproj index f416b1e93..78c235727 100644 --- a/SharedLibraryCore/SharedLibraryCore.csproj +++ b/SharedLibraryCore/SharedLibraryCore.csproj @@ -3,7 +3,7 @@ Library netcoreapp2.2 - 2.2.2 + true RaidMax.IW4MAdmin.SharedLibraryCore @@ -51,11 +51,7 @@ - - - - - + diff --git a/WebfrontCore/WebfrontCore.csproj b/WebfrontCore/WebfrontCore.csproj index 57266fcac..a5430f7fb 100644 --- a/WebfrontCore/WebfrontCore.csproj +++ b/WebfrontCore/WebfrontCore.csproj @@ -2,7 +2,7 @@ netcoreapp2.2 - 2.2.2 + true true true true @@ -83,7 +83,6 @@ all runtime; build; native; contentfiles; analyzers -