diff --git a/ReallifeGamemode.Client/admin/anticheat.ts b/ReallifeGamemode.Client/admin/anticheat.ts new file mode 100644 index 00000000..1703050b --- /dev/null +++ b/ReallifeGamemode.Client/admin/anticheat.ts @@ -0,0 +1,210 @@ +export default function antiCheat(globalData: IGlobalData) { + + const allowedWeaponHashes: number[] = [ + 453432689, + 3219281620, + 1593441988, + 2578377531, + 736523883, + 171789620, + 3220176749, + 487013001, + 2210333304, + 1649403952, + 100416529, + 2725352035, + 2508868239, + 2343591895, + 3638508604, + 1737195953 + ] + + mp.events.add("playerJoin", () => { + mp.events.call("client:respawning") + }); + + mp.events.add("client:checkInvincible", () => { + if (mp.players.local.dimension == 0) return + if (!Behaviour.active) return + var healthBefore = Behaviour.health + mp.players.local.applyDamageTo(1, true); + setTimeout(() => { + if (healthBefore == Behaviour.health) { + if (mp.players.local.getHealth() > 0) { + mp.events.callRemote('CLIENT:CheatDetection', "Static Godmode") + } + } + else { + Behaviour.sleep(1) + mp.players.local.setHealth(healthBefore + 100) + } + }, 500); + }) + + setInterval(() => { + mp.events.call("client:checkInvincible") + }, 30000); + + mp.events.add('SERVER:AntiCheat:weaponSwap', () => { + Behaviour.resetWeapon() + }) + + mp.events.add('playerWeaponShot', () => { + if (Behaviour.checkWeaponhash()) { + mp.events.callRemote("CLIENT:CheatDetection", "Unallowed Weapon", Behaviour.weapon) + } + if (Behaviour.reloadingWeapon) { + mp.events.callRemote("CLIENT:CheatDetection", "No Reload") + Behaviour.resetWeapon() + } + Behaviour.updateMagSize() + }); + + mp.keys.bind(0x52, true, () => { + Behaviour.reloading = true + setTimeout(() => { + Behaviour.magazin = mp.game.weapon.getWeaponClipSize(mp.game.invoke(`0x0A6DB4965674D243`, mp.players.local.handle)) + Behaviour.reloading = false + }, 2000); + }) + + mp.events.add('client:respawning', () => { + if (Behaviour.active) Behaviour.sleep(3) + }) + + class PlayerBehaviour { + active: boolean; + flags: number; + hits: number; + reloadingWeapon: boolean; + pos: Vector3Mp; + health: number; + weapon: number; + magazin: number; + firstshot: boolean; + reloading: boolean; + range_to_btm: number; + + constructor() { + this.active = true + this.flags, this.hits = 0 + this.reloadingWeapon = false + this.pos = mp.players.local.position + this.health = Number(mp.players.local.getHealth()) + Number(mp.players.local.getArmour()) + this.weapon = Number(mp.game.invoke(`0x0A6DB4965674D243`, mp.players.local.handle)); + this.magazin = mp.game.weapon.getWeaponClipSize(this.weapon) + this.firstshot = true + } + sleep(duration) { + this.active = false + setTimeout(() => { + this.active = true + }, duration * 1000); + } + secs() { + return Math.round(Date.now() / 1000) + } + + isRagdollOnHeight(height) { + this.range_to_btm = mp.game.gameplay.getGroundZFor3dCoord(mp.players.local.position.x, mp.players.local.position.y, mp.players.local.position.z, 0, false); + if (Math.abs(mp.players.local.position.z - this.range_to_btm) > Math.abs(height - this.range_to_btm)) { + if (!this.isWalking()) { + return false; + } else if (this.active && this.range_to_btm > 0) { + return true; + } + return false + } + } + isWalking() { + if (mp.players.local.isFalling() || mp.players.local.isRagdoll()) return false + else if (!mp.players.local.vehicle) return true + } + subtractVector(v1, v2) { + return { "x": v1.x - v2.x, "y": v1.y - v2.y, "z": v1.z - v2.z } + } + VehicleFasterThan(max) { + if (mp.players.local.vehicle) { + if (mp.players.local.vehicle.getClass() != 16) { + return mp.players.local.vehicle.getSpeed() * 3.6 > max + } + } + return false + } + checkCarPos(maxHeight = 50) { + if (mp.players.local.vehicle) { + if (mp.players.local.vehicle.getClass() != 15 && mp.players.local.vehicle.getClass() != 16) { + this.range_to_btm = mp.game.gameplay.getGroundZFor3dCoord(mp.players.local.position.x, mp.players.local.position.y, mp.players.local.position.z, 0, false); + if (mp.players.local.position.z - this.range_to_btm > maxHeight + this.range_to_btm) { + return true + } + return false + } + } + } + checkWeaponhash() { + let h = this.weapon + if (allowedWeaponHashes.indexOf(h) === -1) { + return true + } + return false + } + resetWeapon() { + this.weapon = mp.game.invoke(`0x0A6DB4965674D243`, mp.players.local.handle) + this.magazin = mp.game.weapon.getWeaponClipSize(this.weapon) + this.reloadingWeapon = false + } + updateMagSize() { + this.weapon = mp.game.invoke(`0x0A6DB4965674D243`, mp.players.local.handle) + if (this.firstshot) { + this.firstshot = false + this.resetWeapon() + } + this.magazin -= 1 + if (this.magazin <= 0) { + this.reloadingWeapon = true + setTimeout(() => { + this.reloadingWeapon = false + this.resetWeapon() + }, 1250); + } + } + } + + var Behaviour = new PlayerBehaviour() + var loop = Behaviour.secs() + + mp.events.add("render", () => { + Behaviour.health = Number(mp.players.local.getHealth()) + Number(mp.players.local.getArmour()) + if (loop < Behaviour.secs()) { + if (Behaviour.active) { + let Difference = Behaviour.subtractVector(Behaviour.pos, mp.players.local.position) + if (Math.abs(Difference.x) > 30 || Math.abs(Difference.y) > 30) { + if (Behaviour.isWalking()) { + mp.gui.chat.push("tp hack"); + mp.events.callRemote("CLIENT:CheatDetection", "Flyhack/Teleport") + } + } + if (mp.players.local.vehicle) { + if (Behaviour.checkCarPos(25)) { + mp.events.callRemote("CLIENT:CheatDetection", "Vehicle Flyhack") + } + if (Behaviour.VehicleFasterThan(250)) { + mp.events.callRemote("CLIENT:CheatDetection", "Vehicle Speedhack") + } + } + } + Behaviour.pos = mp.players.local.position + loop = Behaviour.secs() + 3; + } + }); + + setInterval(() => { + let hp = Behaviour.health + setTimeout(() => { + if (hp < Behaviour.health && Behaviour.active) { + mp.events.callRemote("CLIENT:CheatDetection", "Healkey (unexpected HP added)") + } + }, 400); + }, 500); +} \ No newline at end of file diff --git a/ReallifeGamemode.Client/index.ts b/ReallifeGamemode.Client/index.ts index 6dd166b9..5b1aaf90 100644 --- a/ReallifeGamemode.Client/index.ts +++ b/ReallifeGamemode.Client/index.ts @@ -251,6 +251,9 @@ gangwarHandle(globalData); import animationSync from './util/animationSync'; animationSync(); +import antiCheat from './admin/anticheat'; +antiCheat(globalData); + require('./Gui/policedepartment'); require('./Gui/helptext'); diff --git a/ReallifeGamemode.Server/Admin/AntiCheat.cs b/ReallifeGamemode.Server/Admin/AntiCheat.cs new file mode 100644 index 00000000..ffc8937a --- /dev/null +++ b/ReallifeGamemode.Server/Admin/AntiCheat.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using GTANetworkAPI; +using ReallifeGamemode.Server.Extensions; +using ReallifeGamemode.Server.Managers; +using ReallifeGamemode.Server.Services; +using ReallifeGamemode.Server.Types; + +namespace ReallifeGamemode.Server.Admin +{ + public class AntiCheat : Script + { + private static TimeSpan antiCheatMessageCooldown = new TimeSpan(0, 0, 30); + private static Dictionary<(string, string), DateTime> lastAntiCheatBroadcastTime = new Dictionary<(string, string), DateTime>(); + + [ServerEvent(Event.PlayerWeaponSwitch)] + public void OnAntiCheatPlayerWeeaponSwitch(Player player, WeaponHash oldWeapon, WeaponHash newWeapon) + { + player.TriggerEvent("SERVER:AntiCheat:weaponSwap"); + } + + [RemoteEvent("CLIENT:CheatDetection")] + public void OnAntiCheatCheatDetected(Player cheater, string cheat) + { + if (!cheater.IsLoggedIn()) + { + cheater.Kick(); + } + + if(cheater.IsAdminDuty()) + { + return; + } + + if (lastAntiCheatBroadcastTime.Any(a => a.Key.Item1 == cheater.Name && a.Key.Item2 == cheat) + && DateTime.Now - lastAntiCheatBroadcastTime[(cheater.Name, cheat)] < antiCheatMessageCooldown) + { + return; + } + lastAntiCheatBroadcastTime[(cheater.Name, cheat)] = DateTime.Now; + ChatService.BroadcastAdmin($"~r~[ANTICHEAT]~s~ Verdacht auf ~y~{cheat}~s~ bei ~y~{cheater.Name}~s~ (~y~{cheater.Handle.Value}~s~)", AdminLevel.ADMIN); + } + + internal static void NoTpAntiCheatForPlayer(string name) + { + lastAntiCheatBroadcastTime[(name, "Flyhack/Teleport")] = DateTime.Now.Subtract(antiCheatMessageCooldown).Add(TimeSpan.FromSeconds(5)); + } + } +} diff --git a/ReallifeGamemode.Server/Commands/AdminCommands.cs b/ReallifeGamemode.Server/Commands/AdminCommands.cs index 0efa1b6e..b4495950 100644 --- a/ReallifeGamemode.Server/Commands/AdminCommands.cs +++ b/ReallifeGamemode.Server/Commands/AdminCommands.cs @@ -390,7 +390,7 @@ namespace ReallifeGamemode.Server.Commands player.Vehicle.Position = target.Position; NAPI.Entity.SetEntityVelocity(player.Vehicle, new Vector3()); } - else player.Position = target.Position; + else player.SafeTeleport(target.Position); ChatService.SendMessage(player, "~c~* Du hast dich teleportiert."); } @@ -416,7 +416,7 @@ namespace ReallifeGamemode.Server.Commands target.Vehicle.Position = player.Position; NAPI.Entity.SetEntityVelocity(target.Vehicle, new Vector3()); } - else target.Position = player.Position; + else target.SafeTeleport(player.Position); ChatService.SendMessage(target, "~c~* Du wurdest teleportiert."); } @@ -611,7 +611,7 @@ namespace ReallifeGamemode.Server.Commands } if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = player.GetData("mark"); - else player.Position = player.GetData("mark"); + else player.SafeTeleport(player.GetData("mark")); } [Command("flip", "")] @@ -648,7 +648,7 @@ namespace ReallifeGamemode.Server.Commands } else { - player.Position = new Vector3(player.Position.X, player.Position.Y, player.Position.Z + value); + player.SafeTeleport(new Vector3(player.Position.X, player.Position.Y, player.Position.Z + value)); } } @@ -667,7 +667,7 @@ namespace ReallifeGamemode.Server.Commands } else { - player.Position = new Vector3(player.Position.X, player.Position.Y, player.Position.Z - value); + player.SafeTeleport(new Vector3(player.Position.X, player.Position.Y, player.Position.Z - value)); } } @@ -686,25 +686,25 @@ namespace ReallifeGamemode.Server.Commands { Vector3 playerPosition = new Vector3(player.Position.X + value, player.Position.Y, player.Position.Z); if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition; - else player.Position = playerPosition; + else player.SafeTeleport(playerPosition); } else if (playerHeading < 315 && playerHeading >= 225) { Vector3 playerPosition = new Vector3(player.Position.X, player.Position.Y - value, player.Position.Z); if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition; - else player.Position = playerPosition; + elseplayer.SafeTeleport(playerPosition); } else if (playerHeading >= 135 && playerHeading < 225) { Vector3 playerPosition = new Vector3(player.Position.X - value, player.Position.Y, player.Position.Z); if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition; - else player.Position = playerPosition; + else player.SafeTeleport(playerPosition); } else if (playerHeading >= 45 && playerHeading < 135) { Vector3 playerPosition = new Vector3(player.Position.X, player.Position.Y + value, player.Position.Z); if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition; - else player.Position = playerPosition; + else player.SafeTeleport(playerPosition); } } @@ -723,25 +723,25 @@ namespace ReallifeGamemode.Server.Commands { Vector3 playerPosition = new Vector3(player.Position.X - value, player.Position.Y, player.Position.Z); if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition; - else player.Position = playerPosition; + else player.SafeTeleport(playerPosition); } else if (playerHeading < 315 && playerHeading >= 225) { Vector3 playerPosition = new Vector3(player.Position.X, player.Position.Y + value, player.Position.Z); if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition; - else player.Position = playerPosition; + else player.SafeTeleport(playerPosition); } else if (playerHeading >= 135 && playerHeading < 225) { Vector3 playerPosition = new Vector3(player.Position.X + value, player.Position.Y, player.Position.Z); if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition; - else player.Position = playerPosition; + else player.SafeTeleport(playerPosition); } else if (playerHeading >= 45 && playerHeading < 135) { Vector3 playerPosition = new Vector3(player.Position.X, player.Position.Y - value, player.Position.Z); if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition; - else player.Position = playerPosition; + else player.SafeTeleport(playerPosition); } } @@ -976,7 +976,7 @@ namespace ReallifeGamemode.Server.Commands player.Vehicle.Position = new Vector3(p.X, p.Y, p.Z); NAPI.Entity.SetEntityVelocity(player.Vehicle, new Vector3()); } - else player.Position = new Vector3(p.X, p.Y, p.Z); + else player.SafeTeleport(new Vector3(p.X, p.Y, p.Z)); } } @@ -1091,7 +1091,7 @@ namespace ReallifeGamemode.Server.Commands return; } if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = new Vector3(x, y, z); - else player.Position = new Vector3(x, y, z); + else player.SafeTeleport(new Vector3(x, y, z)); } [Command("slap", "~m~Benutzung: ~s~/slap [Spieler] (Höhe)")] @@ -1112,7 +1112,7 @@ namespace ReallifeGamemode.Server.Commands Vector3 oldPos = target.Position; - target.Position = new Vector3(oldPos.X, oldPos.Y, oldPos.Z + wert); + target.SafeTeleport(new Vector3(oldPos.X, oldPos.Y, oldPos.Z + wert)); ChatService.SendMessage(player, "Du hast " + target.Name + " geslappt. Höhe: " + wert + ""); } @@ -1151,7 +1151,7 @@ namespace ReallifeGamemode.Server.Commands return; } - player.Position = v.Position.Add(new Vector3(0, 0, 2)); + player.SafeTeleport(v.Position.Add(new Vector3(0, 0, 2))); } [Command("ghv", "~m~Benutzung: ~s~/ghv [Fahrzeug ID]")] @@ -1171,7 +1171,7 @@ namespace ReallifeGamemode.Server.Commands } v.Position = player.Position; - player.Position = player.Position.Add(new Vector3(0, 0, 2)); + player.SafeTeleport(player.Position.Add(new Vector3(0, 0, 2))); } [Command("factionlist", "~m~Benutzung: ~s~/factionlist")] @@ -1443,7 +1443,7 @@ namespace ReallifeGamemode.Server.Commands u.Dead = false; dbContext.SaveChanges(); } - NAPI.Player.SpawnPlayer(target, target.Position); + target.SafeTeleport(target.Position, 0, true); target.Health = 100; Medic.delReviveTask(target); @@ -2184,7 +2184,7 @@ namespace ReallifeGamemode.Server.Commands public void sendCPfunc(Player user, int x, int y, int z) { Vector3 pos = new Vector3(x, y, z); - user.Position = pos; + user.SafeTeleport(pos); } [Command("sethandmoney", "~m~Benutzung: ~s~/sethandmoney [Name/ID] [Menge]")] @@ -2414,7 +2414,7 @@ namespace ReallifeGamemode.Server.Commands managedPlayer.SendNotification(toPlayerNotification); ChatService.SendMessage(managedPlayer, toPlayerChat); - NAPI.Player.SpawnPlayer(managedPlayer, managedPlayer.Position); + managedPlayer.SafeTeleport(managedPlayer.Position, 0, true); managedPlayer.Health = 100; Medic.delReviveTask(managedPlayer); @@ -2671,7 +2671,7 @@ namespace ReallifeGamemode.Server.Commands Convert.ToByte(vehicle.PrimaryColor), Convert.ToByte(vehicle.SecondaryColor), business, price); player.SendNotification("Shopfahrzeug ~g~" + vehicle.DisplayName + "~s~ gespeichert.", true); Vector3 oldPos = player.Position; - player.Position = new Vector3(oldPos.X, oldPos.Y, oldPos.Z + 2.5); + player.SafeTeleport(new Vector3(oldPos.X, oldPos.Y, oldPos.Z + 2.5)); } else ChatService.SendMessage(player, "~m~Du sitzt in keinem Fahrzeug!"); break; diff --git a/ReallifeGamemode.Server/Commands/FactionCommands.cs b/ReallifeGamemode.Server/Commands/FactionCommands.cs index eec24506..674cb182 100644 --- a/ReallifeGamemode.Server/Commands/FactionCommands.cs +++ b/ReallifeGamemode.Server/Commands/FactionCommands.cs @@ -343,7 +343,7 @@ namespace ReallifeGamemode.Server.Commands u.Dead = false; dbContext.SaveChanges(); } - NAPI.Player.SpawnPlayer(deadPlayer, deadPlayer.Position); + deadPlayer.SafeTeleport(deadPlayer.Position, 0, true); deadPlayer.Health = 50; MedicTask task = Medic.ReviveTasks.FirstOrDefault(t => t.Victim == deadPlayer.Name); diff --git a/ReallifeGamemode.Server/DrivingSchool/DrivingSchool.cs b/ReallifeGamemode.Server/DrivingSchool/DrivingSchool.cs index d88b8ce9..9163cc08 100644 --- a/ReallifeGamemode.Server/DrivingSchool/DrivingSchool.cs +++ b/ReallifeGamemode.Server/DrivingSchool/DrivingSchool.cs @@ -190,7 +190,7 @@ namespace ReallifeGamemode.Server.DrivingSchool veh.Position = sVeh.Position; veh.Rotation = new Vector3(0, 0, sVeh.Heading); - user.Position = new Vector3(-814.39, -1336.76, 5.15); + user.SafeTeleport(new Vector3(-814.39, -1336.76, 5.15)); } [RemoteEvent("drivingSchoolEvent")] @@ -304,7 +304,7 @@ namespace ReallifeGamemode.Server.DrivingSchool veh.Position = sVeh.Position; veh.Rotation = new Vector3(0, 0, sVeh.Heading); - user.Position = new Vector3(-814.39, -1336.76, 5.15); + user.SafeTeleport(new Vector3(-814.39, -1336.76, 5.15)); } [RemoteEvent("bikeSchoolEvent")] diff --git a/ReallifeGamemode.Server/DrivingSchool/PlaneSchool.cs b/ReallifeGamemode.Server/DrivingSchool/PlaneSchool.cs index 3a1cce79..310860ec 100644 --- a/ReallifeGamemode.Server/DrivingSchool/PlaneSchool.cs +++ b/ReallifeGamemode.Server/DrivingSchool/PlaneSchool.cs @@ -128,7 +128,7 @@ namespace ReallifeGamemode.Server.DrivingSchool dbContext.SaveChanges(); } user.ResetData("ActiveSchool"); - user.Position = new Vector3(-1083.96, -2476.96, 13.07); + user.SafeTeleport(new Vector3(-1083.96, -2476.96, 13.07)); } [RemoteEvent("planeSchoolEvent")] diff --git a/ReallifeGamemode.Server/Events/Connect.cs b/ReallifeGamemode.Server/Events/Connect.cs index becbb3b9..083b1542 100644 --- a/ReallifeGamemode.Server/Events/Connect.cs +++ b/ReallifeGamemode.Server/Events/Connect.cs @@ -26,7 +26,7 @@ namespace ReallifeGamemode.Server.Events player.TriggerEvent("CLIENT:StopSound"); //player.SetSharedData("vehicleAdminSpeed2", 1.0); player.SetData("isLoggedIn", false); - player.Position = new Vector3(-1883.736, -781.4911, -10); + player.SafeTeleport(new Vector3(-1883.736, -781.4911, -10)); bool registered = false; diff --git a/ReallifeGamemode.Server/Events/Death.cs b/ReallifeGamemode.Server/Events/Death.cs index 70d2424c..f7522093 100644 --- a/ReallifeGamemode.Server/Events/Death.cs +++ b/ReallifeGamemode.Server/Events/Death.cs @@ -238,7 +238,7 @@ namespace ReallifeGamemode.Server.Events Player medicPlayer = PlayerService.GetPlayerByNameOrId(task.MedicName); Medic.RemoveTaskFromList(task); - NAPI.Player.SpawnPlayer(player, new Vector3(-495.45, -336.33, 34.5), -98.36f); + player.SafeTeleport(new Vector3(-495.45, -336.33, 34.5), 0, true); } } } diff --git a/ReallifeGamemode.Server/Events/ExitVehicle.cs b/ReallifeGamemode.Server/Events/ExitVehicle.cs index 12bc6306..b6e0187a 100644 --- a/ReallifeGamemode.Server/Events/ExitVehicle.cs +++ b/ReallifeGamemode.Server/Events/ExitVehicle.cs @@ -51,7 +51,7 @@ namespace ReallifeGamemode.Server.Events client.WarpOutOfVehicle(); ServerVehicle sVeh = VehicleManager.GetServerVehicleFromVehicle(vehicle); ServerVehicleExtensions.Spawn(sVeh, vehicle); - client.Position = sVeh.Position; + client.SafeTeleport(sVeh.Position); CheckPointHandle.DeleteCheckpoints(client); } } diff --git a/ReallifeGamemode.Server/Events/Login.cs b/ReallifeGamemode.Server/Events/Login.cs index 95b25e83..98164ab9 100644 --- a/ReallifeGamemode.Server/Events/Login.cs +++ b/ReallifeGamemode.Server/Events/Login.cs @@ -113,7 +113,7 @@ namespace ReallifeGamemode.Server.Events currentPlayerCreatorDimension++; NAPI.Data.SetWorldData("playerCreatorDimension", currentPlayerCreatorDimension); player.Dimension = NAPI.Data.GetWorldData("playerCreatorDimension"); - player.Position = new Vector3(402.8664, -996.4108, -99.00027); + player.SafeTeleport(new Vector3(402.8664, -996.4108, -99.00027)); player.Rotation = new Vector3(0, 0, 180); player.TriggerEvent("toggleCreator"); } @@ -123,7 +123,7 @@ namespace ReallifeGamemode.Server.Events UpdateCharacterCloth.LoadCharacterDefaults(player); if (user.JailTime <= 0) { - NAPI.Player.SpawnPlayer(player, new Vector3(user.PositionX, user.PositionY, user.PositionZ), 0); + player.SafeTeleport(new Vector3(user.PositionX, user.PositionY, user.PositionZ), 0, true); } else { @@ -151,7 +151,7 @@ namespace ReallifeGamemode.Server.Events { player.SetData("isDead", false); } - }, delayTime: 1000); + }, delayTime: 1000); } } } diff --git a/ReallifeGamemode.Server/Events/PlayerEvent.cs b/ReallifeGamemode.Server/Events/PlayerEvent.cs index abd12a3c..4f6ed48b 100644 --- a/ReallifeGamemode.Server/Events/PlayerEvent.cs +++ b/ReallifeGamemode.Server/Events/PlayerEvent.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Text; using GTANetworkAPI; +using ReallifeGamemode.Server.Extensions; namespace ReallifeGamemode.Server.Events { @@ -10,7 +11,7 @@ namespace ReallifeGamemode.Server.Events [RemoteEvent("CLIENT:SET_InFrontOfPos")] public void SetFrontOfPos(Player player, Vector3 pos) { - player.Position = pos; + player.SafeTeleport(pos); } } } diff --git a/ReallifeGamemode.Server/Events/Register.cs b/ReallifeGamemode.Server/Events/Register.cs index 8536642b..be48a443 100644 --- a/ReallifeGamemode.Server/Events/Register.cs +++ b/ReallifeGamemode.Server/Events/Register.cs @@ -3,6 +3,7 @@ using GTANetworkAPI; using ReallifeGamemode.Database.Entities; using Newtonsoft.Json; using ReallifeGamemode.Database.Models; +using ReallifeGamemode.Server.Extensions; /** * @overview Life of German Reallife - Event Register (Register.cs) @@ -63,7 +64,7 @@ namespace ReallifeGamemode.Server.Events NAPI.Data.SetWorldData("playerCreatorDimension", currentPlayerCreatorDimension); player.Dimension = NAPI.Data.GetWorldData("playerCreatorDimension"); player.TriggerEvent("toggleCreator"); - player.Position = new Vector3(402.8664, -996.4108, -99.00027); + player.SafeTeleport(new Vector3(402.8664, -996.4108, -99.00027)); //player.Position = new Vector3(user.PositionX, user.PositionY, user.PositionZ); } else diff --git a/ReallifeGamemode.Server/Events/UpdateCharacterElevator.cs b/ReallifeGamemode.Server/Events/UpdateCharacterElevator.cs index 33955c27..f7947846 100644 --- a/ReallifeGamemode.Server/Events/UpdateCharacterElevator.cs +++ b/ReallifeGamemode.Server/Events/UpdateCharacterElevator.cs @@ -1,4 +1,5 @@ using GTANetworkAPI; +using ReallifeGamemode.Server.Extensions; using ReallifeGamemode.Server.Managers; namespace ReallifeGamemode.Server.Events @@ -11,7 +12,7 @@ namespace ReallifeGamemode.Server.Events ElevatorPoint elevator = PositionManager.ElevatorPoints.Find(e => e.Stage == stage); if (elevator != null) { - client.Position = elevator.Position; + client.SafeTeleport(elevator.Position); } } } diff --git a/ReallifeGamemode.Server/Extensions/ClientExtension.cs b/ReallifeGamemode.Server/Extensions/ClientExtension.cs index 3853d13b..9b92db14 100644 --- a/ReallifeGamemode.Server/Extensions/ClientExtension.cs +++ b/ReallifeGamemode.Server/Extensions/ClientExtension.cs @@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; using ReallifeGamemode.Database.Entities; using ReallifeGamemode.Database.Models; +using ReallifeGamemode.Server.Admin; using ReallifeGamemode.Server.Managers; using ReallifeGamemode.Server.Services; using ReallifeGamemode.Server.Types; @@ -59,6 +60,20 @@ namespace ReallifeGamemode.Server.Extensions } } + public static void SafeTeleport(this Player player, Vector3 position, float heading = 0, bool spawn = false) + { + AntiCheat.NoTpAntiCheatForPlayer(player.Name); + if (spawn) + { + NAPI.Player.SpawnPlayer(player, position, heading); + } + else + { + player.Position = position; + player.Heading = heading; + } + } + public static void SetJailTime(this User user, bool killed) { if (user == null) diff --git a/ReallifeGamemode.Server/Job/JobBase.cs b/ReallifeGamemode.Server/Job/JobBase.cs index 016a0882..8a0baa0b 100644 --- a/ReallifeGamemode.Server/Job/JobBase.cs +++ b/ReallifeGamemode.Server/Job/JobBase.cs @@ -59,7 +59,7 @@ namespace ReallifeGamemode.Server.Job if (quit) { ChatService.SendMessage(player, $"~y~[Job]~s~ Du hast deinen Job ~o~{this.Name}~s~ beendet."); - player.Position = JobManager.playerJobStartPosition[player]; + player.SafeTeleport(JobManager.playerJobStartPosition[player]); } JobStop?.Invoke(player); diff --git a/ReallifeGamemode.Server/Managers/CharacterCreator.cs b/ReallifeGamemode.Server/Managers/CharacterCreator.cs index 233563b7..6273452b 100644 --- a/ReallifeGamemode.Server/Managers/CharacterCreator.cs +++ b/ReallifeGamemode.Server/Managers/CharacterCreator.cs @@ -254,7 +254,7 @@ namespace ReallifeGamemode.Server.Managers //}; //player.SetHeadOverlay(4, makeupHo); //player.SetHeadOverlay(5, blushHo); - NAPI.Player.SpawnPlayer(player, Main.DEFAULT_SPAWN_POSITION, Main.DEFAULT_SPAWN_HEADING); + player.SafeTeleport(Main.DEFAULT_SPAWN_POSITION, Main.DEFAULT_SPAWN_HEADING, true); player.TriggerEvent("draw", player.Name, player.Handle.Value); player.Dimension = 0; } diff --git a/ReallifeGamemode.Server/Managers/JobManager.cs b/ReallifeGamemode.Server/Managers/JobManager.cs index 2201ff66..2acfd127 100644 --- a/ReallifeGamemode.Server/Managers/JobManager.cs +++ b/ReallifeGamemode.Server/Managers/JobManager.cs @@ -203,30 +203,30 @@ namespace ReallifeGamemode.Server.Managers if (player.GetUser().JobId == 1)//Taxifahrer { player.TriggerEvent("CLIENT:stopFare"); - player.Position = new Vector3(-628.598388671875, -2107.609130859375, 6.072586536407471); + player.SafeTeleport(new Vector3(-628.598388671875, -2107.609130859375, 6.072586536407471)); player.Heading = (-171.50303649902344f); } if (player.GetUser().JobId == 2)//Müllmann { - player.Position = new Vector3(485.4114685058594, -2173.25, 5.918273448944092); + player.SafeTeleport(new Vector3(485.4114685058594, -2173.25, 5.918273448944092)); player.Heading = (-15.922085762023926f); } if (player.GetUser().JobId == 3)//Pilot { if (!player.HasData("PilotenBase") || player.GetData("PilotenBase") == 1) //Sandyshores { - player.Position = new Vector3(1707.2711181640625, 3276.216064453125, 41.155494689941406); + player.SafeTeleport(new Vector3(1707.2711181640625, 3276.216064453125, 41.155494689941406)); player.Heading = (-154.65234375f); } if (player.HasData("PilotenBase") && player.GetData("PilotenBase") == 2) //LS Airport { - player.Position = new Vector3(-1622.48, -3151.58, 13); + player.SafeTeleport(new Vector3(-1622.48, -3151.58, 13)); player.Heading = (48.44f); } } if (player.GetUser().JobId == 4)//Busfahrer { - player.Position = new Vector3(-535.46, -2144.97, 5.95); + player.SafeTeleport(new Vector3(-535.46, -2144.97, 5.95)); player.Heading = (57.03f); } } diff --git a/ReallifeGamemode.Server/Managers/PositionManager.cs b/ReallifeGamemode.Server/Managers/PositionManager.cs index 4209340f..ec0ea301 100644 --- a/ReallifeGamemode.Server/Managers/PositionManager.cs +++ b/ReallifeGamemode.Server/Managers/PositionManager.cs @@ -5,6 +5,7 @@ using ReallifeGamemode.Server.Shop.Clothing; using ReallifeGamemode.Server.Shop.SevenEleven; using ReallifeGamemode.Server.Shop.Friseur; using ReallifeGamemode.Server.Util; +using ReallifeGamemode.Server.Extensions; namespace ReallifeGamemode.Server.Managers { @@ -293,7 +294,7 @@ namespace ReallifeGamemode.Server.Managers return; } - player.Position = ElevatorPoints.Where(e => e.Stage == level).First().Position; + player.SafeTeleport(ElevatorPoints.Where(e => e.Stage == level).First().Position); } } } diff --git a/ReallifeGamemode.Server/Wanted/Jail.cs b/ReallifeGamemode.Server/Wanted/Jail.cs index 92fad29b..2c259e40 100644 --- a/ReallifeGamemode.Server/Wanted/Jail.cs +++ b/ReallifeGamemode.Server/Wanted/Jail.cs @@ -33,12 +33,16 @@ namespace ReallifeGamemode.Server.Wanted player.Armor = 0; Random rnd = new Random(); int rndInt = rnd.Next(1, 3); + Vector3 position = new Vector3(); if (rndInt == 1) - NAPI.Player.SpawnPlayer(player, new Vector3(458.9842, -997.2126, 24.91485)); //send client to jail + position = new Vector3(458.9842, -997.2126, 24.91485); //send client to jail if (rndInt == 2) - NAPI.Player.SpawnPlayer(player, new Vector3(459.696, -994.3766, 24.91486)); //send client to jail + position = new Vector3(459.696, -994.3766, 24.91486); //send client to jail if (rndInt == 3) - NAPI.Player.SpawnPlayer(player, new Vector3(458.3372, -1001.258, 24.91485)); //send client to jail + position = new Vector3(458.3372, -1001.258, 24.91485); //send client to jail + + player.SafeTeleport(position, 0, true); + Jailtime[user.Id] = user.JailTime; // 54 sec for each wanted star -> in total 45min for 50 Wanteds int timeMinutes; @@ -135,7 +139,7 @@ namespace ReallifeGamemode.Server.Wanted if (user.JailTime <= 0) { Jailtime.Remove(user.Id); - player.Position = new Vector3(427.879, -984.65, 30.71); + player.SafeTeleport(new Vector3(427.879, -984.65, 30.71)); player.TriggerEvent("jailTime", 0); return; } @@ -179,7 +183,7 @@ namespace ReallifeGamemode.Server.Wanted dbContext.SaveChanges(); } player.Health = 100; - player.Position = new Vector3(427.879, -984.65, 30.71); + player.SafeTeleport(new Vector3(427.879, -984.65, 30.71)); ChatService.HQMessage("!{#8181E9}HQ: Beamter " + cop.Name + " hat " + user.Name + " aus dem Knast entlassen."); ChatService.SendMessage(player, "!{#8181E9}Der Beamte " + cop.Name + " hat dich aus dem Knast entlassen"); @@ -199,7 +203,7 @@ namespace ReallifeGamemode.Server.Wanted dbContext.SaveChanges(); target.Health = 100; - target.Position = new Vector3(427.879, -984.65, 30.71); + target.SafeTeleport(new Vector3(427.879, -984.65, 30.71)); ChatService.HQMessage(" Admin " + admin.Name + " hat " + user.Name + " aus dem Knast entlassen."); ChatService.SendMessage(target, "!{#8181E9}Admin " + admin.Name + " hat dich aus dem Knast entlassen");