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

@ -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,6 +1,7 @@
<?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"
developmentDependency="true"/>
<package id="Microsoft.CodeAnalysis.CSharp" version="3.3.1" targetFramework="net48"/> <package id="Microsoft.CodeAnalysis.CSharp" version="3.3.1" targetFramework="net48"/>
<package id="Microsoft.CodeAnalysis.Common" version="3.3.1" targetFramework="net48"/> <package id="Microsoft.CodeAnalysis.Common" version="3.3.1" targetFramework="net48"/>
<package id="Northwood.PluginAPI" version="12.0.0" targetFramework="net48"/> <package id="Northwood.PluginAPI" version="12.0.0" targetFramework="net48"/>