From 0b7b0a3a999ab3ffb78cd9b86fc880ce477acdad Mon Sep 17 00:00:00 2001 From: hydrant Date: Sun, 18 Apr 2021 03:39:35 +0200 Subject: [PATCH] =?UTF-8?q?[HOTFIX]=20Mehr=20Logs=20beim=20Tod,=20DeathLog?= =?UTF-8?q?s=20korrekt=20f=C3=BCllen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ReallifeGamemode.Server/Events/Death.cs | 60 ++++++++++++++-------- ReallifeGamemode.Server/Gangwar/Gangwar.cs | 13 ++++- ReallifeGamemode.Server/Gangwar/Turf.cs | 9 +++- 3 files changed, 59 insertions(+), 23 deletions(-) diff --git a/ReallifeGamemode.Server/Events/Death.cs b/ReallifeGamemode.Server/Events/Death.cs index d341aacb..e935582b 100644 --- a/ReallifeGamemode.Server/Events/Death.cs +++ b/ReallifeGamemode.Server/Events/Death.cs @@ -25,9 +25,19 @@ namespace ReallifeGamemode.Server.Events { public class Death : Script { + private readonly Dictionary lastPlayerDeathTime = new Dictionary(); + + [ServerEvent(Event.PlayerDeath)] public void OnPlayerDeath(Player player, Player killer, uint reason) { + if (lastPlayerDeathTime.TryGetValue(player, out DateTime lastDeathTime) && DateTime.Now - lastDeathTime < TimeSpan.FromSeconds(5)) + { + return; + } + + lastPlayerDeathTime[player] = DateTime.Now; + if (!player.IsLoggedIn()) { player.Kick(); @@ -51,18 +61,28 @@ namespace ReallifeGamemode.Server.Events float killerPosZ = -1; float killerHeading = -1; + NAPI.Util.ConsoleOutput($"OnPlayerDeath - Player {player.Name} died - Killer = {(killer != null ? killer.Name : "no killer found")}"); + if (killer.IsLoggedIn()) { + NAPI.Util.ConsoleOutput($"OnPlayerDeath - Player {player.Name} died - Killer is logged in"); + var killerUser = killer.GetUser(dbContext); if (killerUser != null) { + NAPI.Util.ConsoleOutput($"OnPlayerDeath - Player {player.Name} died - Killer GetUser is not null"); killerId = killerUser.Id; killerPosX = killer.Position.X; killerPosY = killer.Position.Y; killerPosZ = killer.Position.Z; killerHeading = killer.Heading; - if (player.HasData("inGangWar") && killer.HasData("inGangWar")) + + var playerInGangwar = player.HasData("inGangWar"); + var killerInGangwar = killer.HasData("inGangWar"); + NAPI.Util.ConsoleOutput($"OnPlayerDeath - Player {player.Name} died - PlayerInGangwar = {playerInGangwar}, KillerInGangwar = {killerInGangwar}"); + if (playerInGangwar && killerInGangwar) { + NAPI.Util.ConsoleOutput($"OnPlayerDeath - Player {player.Name} died - Both players in gangwar, setting kill"); Gangwar.Gangwar.GangwarKill(killer, player); } @@ -78,6 +98,22 @@ namespace ReallifeGamemode.Server.Events } } + var dead = new Database.Entities.Logs.Death + { + VictimId = player.GetUser().Id, + KillerId = killerId, + KillerPositionX = killerPosX, + KillerPositionY = killerPosY, + KillerPositionZ = killerPosZ, + KillerHeading = killerHeading, + VictimPositionX = player.Position.X, + VictimPositionY = player.Position.Y, + VictimPositionZ = player.Position.Z, + VictimHeading = player.Heading, + CauseOfDeath = reason.ToString() + }; + dbContext.DeathLogs.Add(dead); + bool copNearby = NAPI.Pools.GetAllPlayers().Any(u => u.IsDuty() && u.IsAlive() && u.Position.DistanceToSquared(player.Position) <= 200 * 200); if (user.Wanteds > 0) @@ -100,7 +136,7 @@ namespace ReallifeGamemode.Server.Events { user.Dead = true; - if (!player.HasData("reviveSperre") && player.GetData("isDead") == false && !player.HasData("inGangWar") && player.GetData("SAdminduty") == false) + if (!player.HasData("reviveSperre") && player.GetData("isDead") == false && !player.HasData("inGangWar") && player.GetData("SAdminduty") == false) { //MEDIC AUFTRAG MedicTask reviveTask = new MedicTask() @@ -118,7 +154,7 @@ namespace ReallifeGamemode.Server.Events ChatService.BroadcastFaction("~y~[MEDIC] ~w~" + player.Name + " ist soeben verstorben.", new List() { 2 }); } - player.SetData("isDead", true); + player.SetData("isDead", true); if (player.GetUser().IsAdmin(AdminLevel.ADMIN) == true) { @@ -157,22 +193,6 @@ namespace ReallifeGamemode.Server.Events dbContext.Remove(item); } - - var dead = new Database.Entities.Logs.Death - { - VictimId = player.GetUser().Id, - KillerId = killerId, - KillerPositionX = killerPosX, - KillerPositionY = killerPosY, - KillerPositionZ = killerPosZ, - KillerHeading = killerHeading, - VictimPositionX = player.Position.X, - VictimPositionY = player.Position.Y, - VictimPositionZ = player.Position.Z, - VictimHeading = player.Heading, - CauseOfDeath = reason.ToString() - }; - dbContext.DeathLogs.Add(dead); } } Job.JobBase job = Managers.JobManager.GetJob(player.GetUser().JobId ?? -1); @@ -242,7 +262,7 @@ namespace ReallifeGamemode.Server.Events player.RemoveAllWeapons(); MedicTask task = Medic.ReviveTasks.FirstOrDefault(t => t.Victim == player.Name); - if(task != null) + if (task != null) { Player medicPlayer = PlayerService.GetPlayerByNameOrId(task.MedicName); Medic.RemoveTaskFromList(task); diff --git a/ReallifeGamemode.Server/Gangwar/Gangwar.cs b/ReallifeGamemode.Server/Gangwar/Gangwar.cs index b2a3b9b3..376d5e77 100644 --- a/ReallifeGamemode.Server/Gangwar/Gangwar.cs +++ b/ReallifeGamemode.Server/Gangwar/Gangwar.cs @@ -49,13 +49,22 @@ namespace ReallifeGamemode.Server.Gangwar public static void GangwarKill(Player killer, Player victim) { - if (killer.HasData("GotInsideOfTurf") && victim.HasData("GotInsideOfTurf")) + var killerInsideTurf = killer.HasData("GotInsideOfTurf"); + var victimInsideTurf = victim.HasData("GotInsideOfTurf"); + + NAPI.Util.ConsoleOutput($"GangwarKill - Victim {victim.Name} - KillerInsideTurf = {killerInsideTurf}, VictimInsideTurf = {victimInsideTurf}"); + + if (killerInsideTurf && victimInsideTurf) { + NAPI.Util.ConsoleOutput($"GangwarKill - Victim {victim.Name} - Killer and Victim are in Turf area"); foreach (var turf in getTurfs()) { if (turf.getId() == victim.GetData("inGangWar")) { - turf.setKill(victim.GetUser().Faction.Name); + NAPI.Util.ConsoleOutput($"GangwarKill - Victim {victim.Name} - Killed in turf id {turf.getId()}"); + var victimFactionName = victim.GetUser().Faction.Name; + NAPI.Util.ConsoleOutput($"GangwarKill - Victim {victim.Name} - Faction Name = {victimFactionName}"); + turf.setKill(victimFactionName); return; } } diff --git a/ReallifeGamemode.Server/Gangwar/Turf.cs b/ReallifeGamemode.Server/Gangwar/Turf.cs index dfd08df8..809af885 100644 --- a/ReallifeGamemode.Server/Gangwar/Turf.cs +++ b/ReallifeGamemode.Server/Gangwar/Turf.cs @@ -203,11 +203,16 @@ namespace ReallifeGamemode.Server.Gangwar public void enter(Player client) { User user = client.GetUser(); + if(user == null || user.FactionId == null) + { + return; + } + if (this.status == "attack") { if (user.Faction.Name != getOwner() && user.Faction.Name != getAttacker()) return; - Player gPlayer = playerInGangwar.Where(c => c != null && !c.Handle.IsNull && c.IsLoggedIn() && c.GetUser()?.Id == user.Id).FirstOrDefault(); + Player gPlayer = playerInGangwar.Where(c => c != null && !c.Handle.IsNull && c.IsLoggedIn() && c.Handle.Value == client.Handle.Value).FirstOrDefault(); if (gPlayer == null) { using (var dbContext = new DatabaseContext()) @@ -366,10 +371,12 @@ namespace ReallifeGamemode.Server.Gangwar { if (getOwner() == FactionName) { + NAPI.Util.ConsoleOutput($"GangwarKill - Adding Point for Faction {getAttacker()}"); Att_Score += 1; } else if (getAttacker() == FactionName) { + NAPI.Util.ConsoleOutput($"GangwarKill - Adding Point for Faction {getOwner()}"); Def_Score += 1; } }