From 16aab6a8bbcfcc62e4db29f45bfe28ffda2457aa Mon Sep 17 00:00:00 2001 From: hydrant Date: Tue, 25 May 2021 20:45:31 +0200 Subject: [PATCH] =?UTF-8?q?l=C3=BCckenlose=20nachvollziehbarkeit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/AdminCommands.cs | 3 +++ ReallifeGamemode.Server/Commands/UserCommands.cs | 16 +++++++++++++--- ReallifeGamemode.Server/Events/Death.cs | 15 ++++++++++----- ReallifeGamemode.Server/Events/Key.cs | 7 ++++++- ReallifeGamemode.Server/Gangwar/Gangwar.cs | 16 ++++++++++------ ReallifeGamemode.Server/Gangwar/Turf.cs | 4 ++-- 6 files changed, 44 insertions(+), 17 deletions(-) diff --git a/ReallifeGamemode.Server/Commands/AdminCommands.cs b/ReallifeGamemode.Server/Commands/AdminCommands.cs index 3da213f2..2d38395c 100644 --- a/ReallifeGamemode.Server/Commands/AdminCommands.cs +++ b/ReallifeGamemode.Server/Commands/AdminCommands.cs @@ -1935,6 +1935,7 @@ namespace ReallifeGamemode.Server.Commands { if (!managedPlayer.IsLoggedIn()) return; managedPlayer.GiveWeapon(weaponHash, munition); + logger.LogInformation("Admin {0} gave the weapon {1} (ammo: {2}) to player {3}", player.Name, weapon, munition, managedPlayer.Name); ChatService.SendMessage(managedPlayer, "~b~Admin " + player.Name + " hat im Radius von " + radius + " eine/n " + weapon + " mit " + munition + " Munition vergeben."); } ChatService.SendMessage(player, "~b~Du hast " + peopleInRange.Count + " Spielern eine " + weapon + " mit " + munition + " Munition gegeben"); @@ -3826,6 +3827,8 @@ namespace ReallifeGamemode.Server.Commands return; } + logger.LogInformation("Admin {0} gave the weapon {1} (ammo: {2}) to player {3}", player.Name, hash, ammo, target.Name); + target.GiveWeapon((WeaponHash)uHash, ammo); ChatService.SendMessage(target, "~b~Du hast von " + player.Name + " eine/n " + hash + " mit einer Munition von " + ammo + " erhalten."); ChatService.SendMessage(player, "~b~Du hast " + target.Name + " eine/n " + hash + " mit einer Munition von " + ammo + " gegeben."); diff --git a/ReallifeGamemode.Server/Commands/UserCommands.cs b/ReallifeGamemode.Server/Commands/UserCommands.cs index ec9dfcd2..4875c2e0 100644 --- a/ReallifeGamemode.Server/Commands/UserCommands.cs +++ b/ReallifeGamemode.Server/Commands/UserCommands.cs @@ -45,19 +45,24 @@ namespace ReallifeGamemode.Server.Commands } [Command("eventport", "~m~eventport")] - public void CmdUserEventport(Player player, String option = "") + public void CmdUserEventport(Player player, string option = "") { if (!player.IsLoggedIn()) return; + option = option.ToLower(); if (option == "on") { if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true) { return; } - PositionManager.eventportPosition = player.Position; + Vector3 position = player.Position; + PositionManager.eventportPosition = position; PositionManager.eventportActive = true; + player.SendChatMessage("~y~Du hast hier erfolgreich einen Eventport gesetzt."); + ChatService.BroadcastAdmin($"~b~[ADMIN]~s~ ~y~{player.Name}~s~ hat einen Eventport erstellt.", AdminLevel.ADMIN); + logger.LogInformation("Admin {0} created the eventport at x: {1}, y: {2}, z: {3}", player.Name, position.X, position.Y, position.Z); return; } @@ -69,6 +74,8 @@ namespace ReallifeGamemode.Server.Commands } PositionManager.eventportActive = false; player.SendChatMessage("~y~Du hast den Eventport deaktiviert."); + ChatService.BroadcastAdmin($"~b~[ADMIN]~s~ ~y~{player.Name}~s~ hat einen Eventport deaktiviert.", AdminLevel.ADMIN); + logger.LogInformation("Admin {0} removed the eventport", player.Name); return; } @@ -92,7 +99,10 @@ namespace ReallifeGamemode.Server.Commands int randomX = rnd.Next(-3, 3); int randomY = rnd.Next(-3, 3); - Vector3 teleportPosition = new Vector3(PositionManager.eventportPosition.X + randomX, PositionManager.eventportPosition.Y + randomY, PositionManager.eventportPosition.Z); + Vector3 currentEventport = PositionManager.eventportPosition; + Vector3 teleportPosition = new Vector3(currentEventport.X + randomX, currentEventport.Y + randomY, currentEventport.Z); + + logger.LogInformation("Player {0} used the eventport to x: {1}, y: {2}, z: {3}", player.Name, currentEventport.X, currentEventport.Y, currentEventport.Z); player.SafeTeleport(teleportPosition); player.SendNotification("Du hast dich zum Event teleportiert"); diff --git a/ReallifeGamemode.Server/Events/Death.cs b/ReallifeGamemode.Server/Events/Death.cs index f64e53a6..4c3a3637 100644 --- a/ReallifeGamemode.Server/Events/Death.cs +++ b/ReallifeGamemode.Server/Events/Death.cs @@ -2,12 +2,14 @@ using System.Collections.Generic; using System.Linq; using GTANetworkAPI; +using Microsoft.Extensions.Logging; using ReallifeGamemode.Database.Entities; using ReallifeGamemode.Database.Models; using ReallifeGamemode.Server.Extensions; using ReallifeGamemode.Server.Factions.Medic; using ReallifeGamemode.Server.Inventory; using ReallifeGamemode.Server.Inventory.Interfaces; +using ReallifeGamemode.Server.Log; using ReallifeGamemode.Server.Managers; using ReallifeGamemode.Server.Services; using ReallifeGamemode.Server.Types; @@ -25,6 +27,8 @@ namespace ReallifeGamemode.Server.Events { public class Death : Script { + private static readonly ILogger logger = LogManager.GetLogger(); + private readonly Dictionary lastPlayerDeathTime = new Dictionary(); [ServerEvent(Event.PlayerDeath)] @@ -61,16 +65,16 @@ 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")}"); + logger.LogDebug($"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"); + logger.LogDebug($"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"); + logger.LogDebug($"OnPlayerDeath - Player {player.Name} died - Killer GetUser is not null"); killerId = killerUser.Id; killerPosX = killer.Position.X; killerPosY = killer.Position.Y; @@ -80,10 +84,10 @@ namespace ReallifeGamemode.Server.Events var playerInGangwar = player.HasData("inGangWar"); var killerInGangwar = killer.HasData("inGangWar"); - NAPI.Util.ConsoleOutput($"OnPlayerDeath - Player {player.Name} died - PlayerInGangwar = {playerInGangwar}, KillerInGangwar = {killerInGangwar}"); + logger.LogDebug($"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"); + logger.LogDebug($"OnPlayerDeath - Player {player.Name} died - Both players in gangwar, setting kill"); Gangwar.Gangwar.GangwarKill(killer, player); } @@ -228,6 +232,7 @@ namespace ReallifeGamemode.Server.Events [RemoteEvent("RespawnPlayerAtHospital")] public void RespawnPlayerAtHospital(Player player) { + logger.LogInformation("Player {0} respawned at the hospital", player.Name); player.SetData("isDead", false); using (var dbContext = new DatabaseContext()) { diff --git a/ReallifeGamemode.Server/Events/Key.cs b/ReallifeGamemode.Server/Events/Key.cs index c41554ca..69f12ced 100644 --- a/ReallifeGamemode.Server/Events/Key.cs +++ b/ReallifeGamemode.Server/Events/Key.cs @@ -297,7 +297,7 @@ namespace ReallifeGamemode.Server.Events dbContext.VehicleItems.Remove(v); } - logger.LogInformation("Player {0} took the weapon deal item {1} (amount: {2}) out of weapon vehicle {3}", player.Name, v.VehicleId, itemToAdd, v.VehicleId); + logger.LogInformation("Player {0} took the weapon deal item {1} (amount: {2}) out of weapon vehicle {3}", player.Name, v.ItemId, itemToAdd, v.VehicleId); InventoryManager.AddItemToInventory(player, v.ItemId, itemToAdd); nearestBehindVehiclePoint.usePoint(player); @@ -909,6 +909,11 @@ namespace ReallifeGamemode.Server.Events return; } + if (player.Dead == true) + { + return; + } + bool state = VehicleStreaming.GetEngineState(v); ServerVehicle sV = v.GetServerVehicle(); if (sV != null) diff --git a/ReallifeGamemode.Server/Gangwar/Gangwar.cs b/ReallifeGamemode.Server/Gangwar/Gangwar.cs index 8d6ac346..10474ac8 100644 --- a/ReallifeGamemode.Server/Gangwar/Gangwar.cs +++ b/ReallifeGamemode.Server/Gangwar/Gangwar.cs @@ -1,16 +1,20 @@ using System.Collections.Generic; using System.Linq; using GTANetworkAPI; +using Microsoft.Extensions.Logging; using Newtonsoft.Json; using ReallifeGamemode.Database.Entities; using ReallifeGamemode.Database.Models; using ReallifeGamemode.Server.Extensions; +using ReallifeGamemode.Server.Log; using ReallifeGamemode.Server.Services; namespace ReallifeGamemode.Server.Gangwar { public class Gangwar : Script { + private static ILogger logger = LogManager.GetLogger(); + public static Turf[] _loadedTurfs; private static List turfs; public const int GANGWAR_TOTAL_TIME = 900; @@ -53,19 +57,19 @@ namespace ReallifeGamemode.Server.Gangwar var killerInsideTurf = killer.HasData("GotInsideOfTurf"); var victimInsideTurf = victim.HasData("GotInsideOfTurf"); - NAPI.Util.ConsoleOutput($"GangwarKill - Victim {victim.Name} - KillerInsideTurf = {killerInsideTurf}, VictimInsideTurf = {victimInsideTurf}"); + logger.LogDebug($"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"); + logger.LogDebug($"GangwarKill - Victim {victim.Name} - Killer and Victim are in Turf area"); killer.TriggerEvent("gangWarKillNotification", victim.Name); foreach (var turf in getTurfs()) { if (turf.getId() == victim.GetData("inGangWar")) { - NAPI.Util.ConsoleOutput($"GangwarKill - Victim {victim.Name} - Killed in turf id {turf.getId()}"); + logger.LogDebug($"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}"); + logger.LogDebug($"GangwarKill - Victim {victim.Name} - Faction Name = {victimFactionName}"); turf.setKill(victimFactionName); return; } @@ -96,7 +100,7 @@ namespace ReallifeGamemode.Server.Gangwar [RemoteEvent("Gangarea:Leave")] public void RmtEvent_TurfLeave(Player client, string jsonId) { - if(string.IsNullOrEmpty(jsonId)) + if (string.IsNullOrEmpty(jsonId)) { return; } @@ -189,7 +193,7 @@ namespace ReallifeGamemode.Server.Gangwar public void RmtEvent_StartGangwar(Player client) { User user = client.GetUser(); - if(user == null || user.Faction == null) + if (user == null || user.Faction == null) { return; } diff --git a/ReallifeGamemode.Server/Gangwar/Turf.cs b/ReallifeGamemode.Server/Gangwar/Turf.cs index 58f29fb1..b094a328 100644 --- a/ReallifeGamemode.Server/Gangwar/Turf.cs +++ b/ReallifeGamemode.Server/Gangwar/Turf.cs @@ -385,12 +385,12 @@ namespace ReallifeGamemode.Server.Gangwar { if (getOwner() == FactionName) { - NAPI.Util.ConsoleOutput($"GangwarKill - Adding Point for Faction {getAttacker()}"); + logger.LogDebug($"GangwarKill - Adding Point for Faction {getAttacker()}"); Att_Score += 1; } else if (getAttacker() == FactionName) { - NAPI.Util.ConsoleOutput($"GangwarKill - Adding Point for Faction {getOwner()}"); + logger.LogDebug($"GangwarKill - Adding Point for Faction {getOwner()}"); Def_Score += 1; } }