update plugins to support command interception
This commit is contained in:
parent
40466f84c4
commit
186db53bad
@ -158,8 +158,6 @@ namespace IW4MAdmin
|
|||||||
await E.Origin.Lock();
|
await E.Origin.Lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
var canExecuteCommand = true;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!await ProcessEvent(E))
|
if (!await ProcessEvent(E))
|
||||||
@ -188,32 +186,31 @@ namespace IW4MAdmin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var canExecuteCommand = Manager.CommandInterceptors.All(interceptor =>
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var loginPlugin = Manager.Plugins.FirstOrDefault(plugin => plugin.Name == "Login");
|
return interceptor(E);
|
||||||
|
|
||||||
if (loginPlugin != null)
|
|
||||||
{
|
|
||||||
await loginPlugin.OnEventAsync(E, this);
|
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!canExecuteCommand)
|
||||||
|
{
|
||||||
|
E.Origin.Tell(_translationLookup["SERVER_COMMANDS_INTERCEPTED"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (AuthorizationException e)
|
else if (E.Type == GameEvent.EventType.Command && E.Extra is Command cmd)
|
||||||
{
|
{
|
||||||
E.Origin.Tell($"{loc["COMMAND_NOTAUTHORIZED"]} - {e.Message}");
|
ServerLogger.LogInformation("Executing command {Command} for {Client}", cmd.Name,
|
||||||
canExecuteCommand = false;
|
E.Origin.ToString());
|
||||||
}
|
|
||||||
|
|
||||||
// hack: this prevents commands from getting executing that 'shouldn't' be
|
|
||||||
if (E.Type == GameEvent.EventType.Command && E.Extra is Command cmd &&
|
|
||||||
(canExecuteCommand || E.Origin?.Level == Permission.Console))
|
|
||||||
{
|
|
||||||
ServerLogger.LogInformation("Executing command {Command} for {Client}", cmd.Name, E.Origin.ToString());
|
|
||||||
await cmd.ExecuteAsync(E);
|
await cmd.ExecuteAsync(E);
|
||||||
}
|
}
|
||||||
|
|
||||||
var pluginTasks = Manager.Plugins
|
var pluginTasks = Manager.Plugins
|
||||||
.Where(plugin => plugin.Name != "Login")
|
|
||||||
.Select(async plugin => await CreatePluginTask(plugin, E));
|
.Select(async plugin => await CreatePluginTask(plugin, E));
|
||||||
|
|
||||||
await Task.WhenAll(pluginTasks);
|
await Task.WhenAll(pluginTasks);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<PackageId>RaidMax.IW4MAdmin.Data</PackageId>
|
<PackageId>RaidMax.IW4MAdmin.Data</PackageId>
|
||||||
<Title>RaidMax.IW4MAdmin.Data</Title>
|
<Title>RaidMax.IW4MAdmin.Data</Title>
|
||||||
<Authors />
|
<Authors />
|
||||||
<PackageVersion>1.2.0</PackageVersion>
|
<PackageVersion>2022.10.11.1</PackageVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.SyndicationFeed.ReaderWriter" Version="1.0.2" />
|
<PackageReference Include="Microsoft.SyndicationFeed.ReaderWriter" Version="1.0.2" />
|
||||||
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2022.9.8.1" PrivateAssets="All" />
|
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2022.10.11.1" PrivateAssets="All" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2022.9.8.1" PrivateAssets="All" />
|
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2022.10.11.1" PrivateAssets="All" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2022.9.8.1" PrivateAssets="All" />
|
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2022.10.11.1" PrivateAssets="All" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||||
|
@ -26,47 +26,20 @@ namespace IW4MAdmin.Plugins.Login
|
|||||||
_configHandler = configurationHandlerFactory.GetConfigurationHandler<Configuration>("LoginPluginSettings");
|
_configHandler = configurationHandlerFactory.GetConfigurationHandler<Configuration>("LoginPluginSettings");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task OnEventAsync(GameEvent E, Server S)
|
public Task OnEventAsync(GameEvent gameEvent, Server server)
|
||||||
{
|
{
|
||||||
if (E.IsRemote || _configHandler.Configuration().RequirePrivilegedClientLogin == false)
|
if (gameEvent.IsRemote || _configHandler.Configuration().RequirePrivilegedClientLogin == false)
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
|
|
||||||
if (E.Type == GameEvent.EventType.Connect)
|
if (gameEvent.Type == GameEvent.EventType.Connect)
|
||||||
{
|
{
|
||||||
AuthorizedClients.TryAdd(E.Origin.ClientId, false);
|
AuthorizedClients.TryAdd(gameEvent.Origin.ClientId, false);
|
||||||
E.Origin.SetAdditionalProperty("IsLoggedIn", false);
|
gameEvent.Origin.SetAdditionalProperty("IsLoggedIn", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (E.Type == GameEvent.EventType.Disconnect)
|
if (gameEvent.Type == GameEvent.EventType.Disconnect)
|
||||||
{
|
{
|
||||||
AuthorizedClients.TryRemove(E.Origin.ClientId, out bool value);
|
AuthorizedClients.TryRemove(gameEvent.Origin.ClientId, out _);
|
||||||
}
|
|
||||||
|
|
||||||
if (E.Type == GameEvent.EventType.Command)
|
|
||||||
{
|
|
||||||
if (E.Origin.Level < EFClient.Permission.Moderator ||
|
|
||||||
E.Origin.Level == EFClient.Permission.Console)
|
|
||||||
return Task.CompletedTask;
|
|
||||||
|
|
||||||
if (E.Extra.GetType() == typeof(SetPasswordCommand) &&
|
|
||||||
E.Origin?.Password == null)
|
|
||||||
return Task.CompletedTask;
|
|
||||||
|
|
||||||
if (E.Extra.GetType() == typeof(LoginCommand))
|
|
||||||
return Task.CompletedTask;
|
|
||||||
|
|
||||||
if (E.Extra.GetType() == typeof(RequestTokenCommand))
|
|
||||||
return Task.CompletedTask;
|
|
||||||
|
|
||||||
if (!AuthorizedClients[E.Origin.ClientId])
|
|
||||||
{
|
|
||||||
throw new AuthorizationException(Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_LOGIN_AUTH"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
E.Origin.SetAdditionalProperty("IsLoggedIn", true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
@ -76,6 +49,36 @@ namespace IW4MAdmin.Plugins.Login
|
|||||||
{
|
{
|
||||||
AuthorizedClients = new ConcurrentDictionary<int, bool>();
|
AuthorizedClients = new ConcurrentDictionary<int, bool>();
|
||||||
|
|
||||||
|
manager.CommandInterceptors.Add(gameEvent =>
|
||||||
|
{
|
||||||
|
if (gameEvent.Type != GameEvent.EventType.Command)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gameEvent.Origin.Level < EFClient.Permission.Moderator ||
|
||||||
|
gameEvent.Origin.Level == EFClient.Permission.Console)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (gameEvent.Extra.GetType() == typeof(SetPasswordCommand) &&
|
||||||
|
gameEvent.Origin?.Password == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (gameEvent.Extra.GetType() == typeof(LoginCommand))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (gameEvent.Extra.GetType() == typeof(RequestTokenCommand))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (!AuthorizedClients[gameEvent.Origin.ClientId])
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
gameEvent.Origin.SetAdditionalProperty("IsLoggedIn", true);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
await _configHandler.BuildAsync();
|
await _configHandler.BuildAsync();
|
||||||
if (_configHandler.Configuration() == null)
|
if (_configHandler.Configuration() == null)
|
||||||
{
|
{
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2022.9.8.1" PrivateAssets="All"/>
|
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2022.10.11.1" PrivateAssets="All"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2022.9.8.1" PrivateAssets="All" />
|
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2022.10.11.1" PrivateAssets="All" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2022.9.8.1" PrivateAssets="All" />
|
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2022.10.11.1" PrivateAssets="All" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2022.9.8.1" PrivateAssets="All" />
|
<PackageReference Include="RaidMax.IW4MAdmin.SharedLibraryCore" Version="2022.10.11.1" PrivateAssets="All" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<PackageId>RaidMax.IW4MAdmin.SharedLibraryCore</PackageId>
|
<PackageId>RaidMax.IW4MAdmin.SharedLibraryCore</PackageId>
|
||||||
<Version>2022.9.8.1</Version>
|
<Version>2022.10.11.1</Version>
|
||||||
<Authors>RaidMax</Authors>
|
<Authors>RaidMax</Authors>
|
||||||
<Company>Forever None</Company>
|
<Company>Forever None</Company>
|
||||||
<Configurations>Debug;Release;Prerelease</Configurations>
|
<Configurations>Debug;Release;Prerelease</Configurations>
|
||||||
@ -19,7 +19,7 @@
|
|||||||
<IsPackable>true</IsPackable>
|
<IsPackable>true</IsPackable>
|
||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
<Description>Shared Library for IW4MAdmin</Description>
|
<Description>Shared Library for IW4MAdmin</Description>
|
||||||
<PackageVersion>2022.9.8.1</PackageVersion>
|
<PackageVersion>2022.10.11.1</PackageVersion>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<NoWarn>$(NoWarn);1591</NoWarn>
|
<NoWarn>$(NoWarn);1591</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user