From 0bb235fbfd31087dc014a0ecccf8d2a1f3ce22c9 Mon Sep 17 00:00:00 2001 From: Lennart Kampshoff Date: Wed, 3 Oct 2018 12:50:23 +0200 Subject: [PATCH] Fixed server crash when unknown vehicle is spawned, Car gets teleported on /to and /gh --- Server/Commands/Admin.cs | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/Server/Commands/Admin.cs b/Server/Commands/Admin.cs index 4011db65..20f53b1c 100644 --- a/Server/Commands/Admin.cs +++ b/Server/Commands/Admin.cs @@ -38,7 +38,7 @@ namespace reallife_gamemode.Server.Commands } [Command("veh", "~m~Benutzung: ~s~/veh [Fahrzeug] (Farbe 1) (Farbe 2)")] - public void CmdAdminVeh(Client player, VehicleHash hash, int color1 = 111, int color2 = 111) + public void CmdAdminVeh(Client player, string hash, int color1 = 111, int color2 = 111) { if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true) { @@ -52,7 +52,24 @@ namespace reallife_gamemode.Server.Commands return; } - Vehicle v = NAPI.Vehicle.CreateVehicle(hash, player.Position, player.Rotation.Z, color1, color2); + hash = hash.ToUpper(); + + uint.TryParse(hash, out uint vehHash); + if (vehHash == 0) + { + if (Enum.IsDefined(typeof(VehicleHash), hash)) + { + vehHash = (uint)Enum.Parse(typeof(VehicleHash), hash); + } + } + + if(vehHash == 0) + { + player.SendChatMessage("~r~[FEHLER]~s~ Dieses Fahrzeug existiert nicht."); + return; + } + + Vehicle v = NAPI.Vehicle.CreateVehicle(vehHash, player.Position, player.Rotation.Z, color1, color2); player.SetIntoVehicle(v.Handle, -1); } @@ -113,7 +130,8 @@ namespace reallife_gamemode.Server.Commands return; } - player.Position = target.Position; + if (player.IsInVehicle && player.VehicleSeat == -1) player.Vehicle.Position = target.Position; + else player.Position = target.Position; } [Command("position")] @@ -125,7 +143,7 @@ namespace reallife_gamemode.Server.Commands return; } - player.SendChatMessage("Position: X Y Z: " + player.Position + ""); + player.SendChatMessage("Position: X Y Z: " + player.Position); } [Command("gotox", "~m~Benutzung: ~s~/gotox [X] [Y] [Z]")] @@ -157,7 +175,8 @@ namespace reallife_gamemode.Server.Commands return; } - target.Position = player.Position; + if (target.IsInVehicle && target.VehicleSeat == -1) target.Vehicle.Position = player.Position; + else target.Position = player.Position; target.SendChatMessage("Du wurdest von " + player.Name + " teleportiert."); }