use footprint + permissions

This commit is contained in:
Axwabo 2023-02-09 09:13:08 +01:00
parent fb2167e223
commit 7b15c5d758
5 changed files with 78 additions and 69 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.CodeAnalysis.Analyzers.2.9.8\build\Microsoft.CodeAnalysis.Analyzers.props" Condition="Exists('..\packages\Microsoft.CodeAnalysis.Analyzers.2.9.8\build\Microsoft.CodeAnalysis.Analyzers.props')" /> <Import Project="..\packages\Microsoft.CodeAnalysis.Analyzers.2.9.8\build\Microsoft.CodeAnalysis.Analyzers.props" Condition="Exists('..\packages\Microsoft.CodeAnalysis.Analyzers.2.9.8\build\Microsoft.CodeAnalysis.Analyzers.props')"/>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"/>
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -57,26 +57,26 @@
<Reference Include="Mirror.Components"> <Reference Include="Mirror.Components">
<HintPath>..\..\assemblies\Mirror.Components.dll</HintPath> <HintPath>..\..\assemblies\Mirror.Components.dll</HintPath>
</Reference> </Reference>
<Reference Include="mscorlib" /> <Reference Include="mscorlib"/>
<Reference Include="NwPluginAPI.Analyzers, Version=12.0.0.0, Culture=neutral, processorArchitecture=Amd64"> <Reference Include="NwPluginAPI.Analyzers, Version=12.0.0.0, Culture=neutral, processorArchitecture=Amd64">
<HintPath>..\packages\Northwood.PluginAPI.Analyzers.12.0.0\lib\netstandard2.0\NwPluginAPI.Analyzers.dll</HintPath> <HintPath>..\packages\Northwood.PluginAPI.Analyzers.12.0.0\lib\netstandard2.0\NwPluginAPI.Analyzers.dll</HintPath>
</Reference> </Reference>
<Reference Include="PluginAPI, Version=12.0.0.0, Culture=neutral, processorArchitecture=Amd64"> <Reference Include="PluginAPI, Version=12.0.0.0, Culture=neutral, processorArchitecture=Amd64">
<HintPath>..\packages\Northwood.PluginAPI.12.0.0\lib\net48\PluginAPI.dll</HintPath> <HintPath>..\packages\Northwood.PluginAPI.12.0.0\lib\net48\PluginAPI.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System"/>
<Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll</HintPath> <HintPath>..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <Reference Include="System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Collections.Immutable.1.5.0\lib\netstandard2.0\System.Collections.Immutable.dll</HintPath> <HintPath>..\packages\System.Collections.Immutable.1.5.0\lib\netstandard2.0\System.Collections.Immutable.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Core" /> <Reference Include="System.Core"/>
<Reference Include="System.Data" /> <Reference Include="System.Data"/>
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll</HintPath> <HintPath>..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Numerics" /> <Reference Include="System.Numerics"/>
<Reference Include="System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <Reference Include="System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll</HintPath> <HintPath>..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference> </Reference>
@ -92,7 +92,7 @@
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.3\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath> <HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.3\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Xml" /> <Reference Include="System.Xml"/>
<Reference Include="UnityEngine"> <Reference Include="UnityEngine">
<HintPath>..\..\assemblies\UnityEngine.dll</HintPath> <HintPath>..\..\assemblies\UnityEngine.dll</HintPath>
</Reference> </Reference>
@ -104,24 +104,24 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="DeathLogConfig.cs" /> <Compile Include="DeathLogConfig.cs"/>
<Compile Include="DeathLogPlugin.cs" /> <Compile Include="DeathLogPlugin.cs"/>
<Compile Include="LogHandler.cs" /> <Compile Include="LogHandler.cs"/>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.2.9.8\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll" /> <Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.2.9.8\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll"/>
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.2.9.8\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" /> <Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.2.9.8\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll"/>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup> <PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText> <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
</PropertyGroup> </PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.Analyzers.2.9.8\build\Microsoft.CodeAnalysis.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.Analyzers.2.9.8\build\Microsoft.CodeAnalysis.Analyzers.props'))" /> <Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.Analyzers.2.9.8\build\Microsoft.CodeAnalysis.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.Analyzers.2.9.8\build\Microsoft.CodeAnalysis.Analyzers.props'))"/>
</Target> </Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

View File

@ -4,4 +4,6 @@ public sealed class DeathLogConfig {
public bool LogSimpleDeaths { get; set; } = true; public bool LogSimpleDeaths { get; set; } = true;
public PlayerPermissions VisibilityRequirement { get; set; } = PlayerPermissions.Overwatch;
} }

View File

@ -25,9 +25,9 @@ public sealed class DeathLogPlugin {
[PluginEvent(ServerEventType.PlayerDying)] [PluginEvent(ServerEventType.PlayerDying)]
public void OnPlayerDeath(Player player, Player attacker, DamageHandlerBase handler) { public void OnPlayerDeath(Player player, Player attacker, DamageHandlerBase handler) {
if (attacker != null && handler is AttackerDamageHandler adh) if (attacker != null && handler is AttackerDamageHandler adh)
LogHandler.LogAttackerDeathMessage(player, attacker, adh); LogHandler.LogAttackerDeathMessage(player, attacker, adh, Config.VisibilityRequirement);
else if (Config.LogSimpleDeaths) else if (Config.LogSimpleDeaths)
LogHandler.LogSimpleDeathMessage(player, handler); LogHandler.LogSimpleDeathMessage(player, handler, Config.VisibilityRequirement);
} }
} }

View File

@ -11,6 +11,8 @@ namespace DeathLog;
public static class LogHandler { public static class LogHandler {
private static readonly Color DntColor = new(0.59f, 0.59f, 0.59f);
private static bool IsWeapon(ItemType type) => type is ItemType.GunCOM15 private static bool IsWeapon(ItemType type) => type is ItemType.GunCOM15
or ItemType.GunCOM18 or ItemType.GunCOM18
or ItemType.GunCom45 or ItemType.GunCom45
@ -24,10 +26,10 @@ public static class LogHandler {
or ItemType.ParticleDisruptor or ItemType.ParticleDisruptor
or ItemType.Jailbird; or ItemType.Jailbird;
public static void LogSimpleDeathMessage(Player player, DamageHandlerBase handler) => Log("DEATH LOG" + "#" + string.Format( public static void LogSimpleDeathMessage(Player player, DamageHandlerBase handler, PlayerPermissions permissions) => Log("DEATH LOG" + "#" + string.Format(
GetDeathMessage(handler), GetDeathMessage(handler),
GetVictimStatus(player) GetVictimStatus(player)
), true); ), true, permissions);
private static string GetDeathMessage(DamageHandlerBase handler) => handler switch { private static string GetDeathMessage(DamageHandlerBase handler) => handler switch {
CustomReasonDamageHandler custom => $"{{0}} has died: {custom._deathReason.Bold().Color("orange").Size(30)}", CustomReasonDamageHandler custom => $"{{0}} has died: {custom._deathReason.Bold().Color("orange").Size(30)}",
@ -36,31 +38,35 @@ public static class LogHandler {
_ => $"{{0}} has died. {"Reason is unknown".Italic()}" _ => $"{{0}} has died. {"Reason is unknown".Italic()}"
}; };
public static void LogAttackerDeathMessage(Player victim, Player attacker, AttackerDamageHandler handler) { public static void LogAttackerDeathMessage(Player victim, Player attacker, AttackerDamageHandler handler, PlayerPermissions permissions) {
var isCuffed = victim.IsDisarmed; var isCuffed = victim.IsDisarmed;
var inv = victim.ReferenceHub.inventory; var inv = victim.ReferenceHub.inventory;
var hasWeaponEquipped = IsWeapon(inv.CurItem.TypeId); var hasWeaponEquipped = IsWeapon(inv.CurItem.TypeId);
var carriesWeapon = inv.UserInventory.Items.Any(item => IsWeapon(item.Value.ItemTypeId)); var carriesWeapon = inv.UserInventory.Items.Any(item => IsWeapon(item.Value.ItemTypeId));
var victimRole = victim.Role; var victimRole = victim.Role;
var attackerRole = attacker.Role; var footprint = handler.Attacker;
var attackerRole = footprint.Role;
var canBeKos = victimRole == RoleTypeId.ClassD && attackerRole == RoleTypeId.Scientist var canBeKos = victimRole == RoleTypeId.ClassD && attackerRole == RoleTypeId.Scientist
|| victimRole == RoleTypeId.Scientist && attackerRole == RoleTypeId.ClassD || victimRole == RoleTypeId.Scientist && attackerRole == RoleTypeId.ClassD
|| victimRole == RoleTypeId.ClassD && attackerRole is RoleTypeId.FacilityGuard or RoleTypeId.NtfPrivate or RoleTypeId.NtfSergeant or RoleTypeId.NtfSpecialist or RoleTypeId.NtfCaptain; || victimRole == RoleTypeId.ClassD && attackerRole is RoleTypeId.FacilityGuard or RoleTypeId.NtfPrivate or RoleTypeId.NtfSergeant or RoleTypeId.NtfSpecialist or RoleTypeId.NtfCaptain;
Log("KILL LOG".Bold().Color("yellow") + "#" + string.Format( Log("KILL LOG".Bold().Color("yellow") + "#" + string.Format(
GetKillMessage(handler, canBeKos, hasWeaponEquipped, isCuffed, carriesWeapon, attacker.Rm().CurrentRole is FpcStandardScp), GetKillMessage(handler, canBeKos, hasWeaponEquipped, isCuffed, carriesWeapon, PlayerRoleLoader.TryGetRoleTemplate(attackerRole, out FpcStandardScp _)),
GetKillerStatus(attacker), GetKillerStatus(attacker),
GetVictimStatus(victim) GetVictimStatus(victim)
), !isCuffed && (!canBeKos || !hasWeaponEquipped)); ), !isCuffed && (!canBeKos || !hasWeaponEquipped), permissions);
} }
private static void Log(string msg, bool success) { private static void Log(string msg, bool success, PlayerPermissions playerPermissions) {
foreach (var p in Player.GetPlayers().Where(p => p.RemoteAdminAccess)) foreach (var p in Player.GetPlayers()) {
p.ReferenceHub.queryProcessor._sender.RaReply(msg, success, true, ""); var sender = p.ReferenceHub.queryProcessor._sender;
if (p.RemoteAdminAccess && PermissionsHandler.IsPermitted(sender.Permissions, playerPermissions))
sender.RaReply(msg, success, true, "");
}
} }
private static string GetIdWithDnt(Player player) { private static string GetIdWithDnt(Player player) {
var dnt = player.DoNotTrack; var dnt = player.DoNotTrack;
return $"{(dnt ? "(DNT)".Color(new Color(0.59f, 0.59f, 0.59f)).Size(50) + " " : "")}{player.UserId} {player.PlayerId.ToString().Bold().Color("yellow").Size(30)}"; return $"{(dnt ? "(DNT)".Color(DntColor).Size(50) + " " : "")}{player.UserId} {player.PlayerId.ToString().Bold().Color("yellow").Size(30)}";
} }
private static object GetKillerStatus(Player attacker) { private static object GetKillerStatus(Player attacker) {
@ -111,7 +117,7 @@ public static class LogHandler {
}; };
private static string GetScp049AttackType(Scp049DamageHandler scp049) => scp049.DamageSubType switch { private static string GetScp049AttackType(Scp049DamageHandler scp049) => scp049.DamageSubType switch {
Scp049DamageHandler.AttackType.Instakill => "Instakill", Scp049DamageHandler.AttackType.Instakill => "SCP-049 Instakill",
Scp049DamageHandler.AttackType.Scp0492 => "SCP-049-2", Scp049DamageHandler.AttackType.Scp0492 => "SCP-049-2",
Scp049DamageHandler.AttackType.CardiacArrest => "Cardiac Arrest", Scp049DamageHandler.AttackType.CardiacArrest => "Cardiac Arrest",
_ => "[an unknown attack type]" _ => "[an unknown attack type]"

View File

@ -1,17 +1,18 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Microsoft.CodeAnalysis.Analyzers" version="2.9.8" targetFramework="net48" developmentDependency="true" /> <package id="Microsoft.CodeAnalysis.Analyzers" version="2.9.8" targetFramework="net48"
<package id="Microsoft.CodeAnalysis.CSharp" version="3.3.1" targetFramework="net48" /> developmentDependency="true"/>
<package id="Microsoft.CodeAnalysis.Common" version="3.3.1" targetFramework="net48" /> <package id="Microsoft.CodeAnalysis.CSharp" version="3.3.1" targetFramework="net48"/>
<package id="Northwood.PluginAPI" version="12.0.0" targetFramework="net48" /> <package id="Microsoft.CodeAnalysis.Common" version="3.3.1" targetFramework="net48"/>
<package id="Northwood.PluginAPI.Analyzers" version="12.0.0" targetFramework="net48" /> <package id="Northwood.PluginAPI" version="12.0.0" targetFramework="net48"/>
<package id="System.Buffers" version="4.4.0" targetFramework="net48" /> <package id="Northwood.PluginAPI.Analyzers" version="12.0.0" targetFramework="net48"/>
<package id="System.Collections.Immutable" version="1.5.0" targetFramework="net48" /> <package id="System.Buffers" version="4.4.0" targetFramework="net48"/>
<package id="System.Memory" version="4.5.3" targetFramework="net48" /> <package id="System.Collections.Immutable" version="1.5.0" targetFramework="net48"/>
<package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net48" /> <package id="System.Memory" version="4.5.3" targetFramework="net48"/>
<package id="System.Reflection.Metadata" version="1.6.0" targetFramework="net48" /> <package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net48"/>
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net48" /> <package id="System.Reflection.Metadata" version="1.6.0" targetFramework="net48"/>
<package id="System.Text.Encoding.CodePages" version="4.5.1" targetFramework="net48" /> <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net48"/>
<package id="System.Threading.Tasks.Extensions" version="4.5.3" targetFramework="net48" /> <package id="System.Text.Encoding.CodePages" version="4.5.1" targetFramework="net48"/>
<package id="YamlDotNet" version="11.0.1" targetFramework="net48" /> <package id="System.Threading.Tasks.Extensions" version="4.5.3" targetFramework="net48"/>
<package id="YamlDotNet" version="11.0.1" targetFramework="net48"/>
</packages> </packages>