anti cheat

This commit is contained in:
hydrant
2021-04-11 02:10:12 +02:00
parent 692b7aa916
commit 2fd484f31d
20 changed files with 336 additions and 49 deletions

View File

@@ -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);
}

View File

@@ -251,6 +251,9 @@ gangwarHandle(globalData);
import animationSync from './util/animationSync'; import animationSync from './util/animationSync';
animationSync(); animationSync();
import antiCheat from './admin/anticheat';
antiCheat(globalData);
require('./Gui/policedepartment'); require('./Gui/policedepartment');
require('./Gui/helptext'); require('./Gui/helptext');

View File

@@ -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));
}
}
}

View File

@@ -390,7 +390,7 @@ namespace ReallifeGamemode.Server.Commands
player.Vehicle.Position = target.Position; player.Vehicle.Position = target.Position;
NAPI.Entity.SetEntityVelocity(player.Vehicle, new Vector3()); 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."); ChatService.SendMessage(player, "~c~* Du hast dich teleportiert.");
} }
@@ -416,7 +416,7 @@ namespace ReallifeGamemode.Server.Commands
target.Vehicle.Position = player.Position; target.Vehicle.Position = player.Position;
NAPI.Entity.SetEntityVelocity(target.Vehicle, new Vector3()); NAPI.Entity.SetEntityVelocity(target.Vehicle, new Vector3());
} }
else target.Position = player.Position; else target.SafeTeleport(player.Position);
ChatService.SendMessage(target, "~c~* Du wurdest teleportiert."); 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<Vector3>("mark"); if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = player.GetData<Vector3>("mark");
else player.Position = player.GetData<Vector3>("mark"); else player.SafeTeleport(player.GetData<Vector3>("mark"));
} }
[Command("flip", "")] [Command("flip", "")]
@@ -648,7 +648,7 @@ namespace ReallifeGamemode.Server.Commands
} }
else 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 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); Vector3 playerPosition = new Vector3(player.Position.X + value, player.Position.Y, player.Position.Z);
if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition; if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition;
else player.Position = playerPosition; else player.SafeTeleport(playerPosition);
} }
else if (playerHeading < 315 && playerHeading >= 225) else if (playerHeading < 315 && playerHeading >= 225)
{ {
Vector3 playerPosition = new Vector3(player.Position.X, player.Position.Y - value, player.Position.Z); Vector3 playerPosition = new Vector3(player.Position.X, player.Position.Y - value, player.Position.Z);
if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition; if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition;
else player.Position = playerPosition; elseplayer.SafeTeleport(playerPosition);
} }
else if (playerHeading >= 135 && playerHeading < 225) else if (playerHeading >= 135 && playerHeading < 225)
{ {
Vector3 playerPosition = new Vector3(player.Position.X - value, player.Position.Y, player.Position.Z); Vector3 playerPosition = new Vector3(player.Position.X - value, player.Position.Y, player.Position.Z);
if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition; if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition;
else player.Position = playerPosition; else player.SafeTeleport(playerPosition);
} }
else if (playerHeading >= 45 && playerHeading < 135) else if (playerHeading >= 45 && playerHeading < 135)
{ {
Vector3 playerPosition = new Vector3(player.Position.X, player.Position.Y + value, player.Position.Z); Vector3 playerPosition = new Vector3(player.Position.X, player.Position.Y + value, player.Position.Z);
if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition; 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); Vector3 playerPosition = new Vector3(player.Position.X - value, player.Position.Y, player.Position.Z);
if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition; if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition;
else player.Position = playerPosition; else player.SafeTeleport(playerPosition);
} }
else if (playerHeading < 315 && playerHeading >= 225) else if (playerHeading < 315 && playerHeading >= 225)
{ {
Vector3 playerPosition = new Vector3(player.Position.X, player.Position.Y + value, player.Position.Z); Vector3 playerPosition = new Vector3(player.Position.X, player.Position.Y + value, player.Position.Z);
if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition; if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition;
else player.Position = playerPosition; else player.SafeTeleport(playerPosition);
} }
else if (playerHeading >= 135 && playerHeading < 225) else if (playerHeading >= 135 && playerHeading < 225)
{ {
Vector3 playerPosition = new Vector3(player.Position.X + value, player.Position.Y, player.Position.Z); Vector3 playerPosition = new Vector3(player.Position.X + value, player.Position.Y, player.Position.Z);
if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition; if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition;
else player.Position = playerPosition; else player.SafeTeleport(playerPosition);
} }
else if (playerHeading >= 45 && playerHeading < 135) else if (playerHeading >= 45 && playerHeading < 135)
{ {
Vector3 playerPosition = new Vector3(player.Position.X, player.Position.Y - value, player.Position.Z); Vector3 playerPosition = new Vector3(player.Position.X, player.Position.Y - value, player.Position.Z);
if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = playerPosition; 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); player.Vehicle.Position = new Vector3(p.X, p.Y, p.Z);
NAPI.Entity.SetEntityVelocity(player.Vehicle, new Vector3()); 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; return;
} }
if (player.IsInVehicle && player.VehicleSeat == 0) player.Vehicle.Position = new Vector3(x, y, z); 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)")] [Command("slap", "~m~Benutzung: ~s~/slap [Spieler] (Höhe)")]
@@ -1112,7 +1112,7 @@ namespace ReallifeGamemode.Server.Commands
Vector3 oldPos = target.Position; 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 + ""); ChatService.SendMessage(player, "Du hast " + target.Name + " geslappt. Höhe: " + wert + "");
} }
@@ -1151,7 +1151,7 @@ namespace ReallifeGamemode.Server.Commands
return; 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]")] [Command("ghv", "~m~Benutzung: ~s~/ghv [Fahrzeug ID]")]
@@ -1171,7 +1171,7 @@ namespace ReallifeGamemode.Server.Commands
} }
v.Position = player.Position; 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")] [Command("factionlist", "~m~Benutzung: ~s~/factionlist")]
@@ -1443,7 +1443,7 @@ namespace ReallifeGamemode.Server.Commands
u.Dead = false; u.Dead = false;
dbContext.SaveChanges(); dbContext.SaveChanges();
} }
NAPI.Player.SpawnPlayer(target, target.Position); target.SafeTeleport(target.Position, 0, true);
target.Health = 100; target.Health = 100;
Medic.delReviveTask(target); Medic.delReviveTask(target);
@@ -2184,7 +2184,7 @@ namespace ReallifeGamemode.Server.Commands
public void sendCPfunc(Player user, int x, int y, int z) public void sendCPfunc(Player user, int x, int y, int z)
{ {
Vector3 pos = new Vector3(x, y, z); Vector3 pos = new Vector3(x, y, z);
user.Position = pos; user.SafeTeleport(pos);
} }
[Command("sethandmoney", "~m~Benutzung: ~s~/sethandmoney [Name/ID] [Menge]")] [Command("sethandmoney", "~m~Benutzung: ~s~/sethandmoney [Name/ID] [Menge]")]
@@ -2414,7 +2414,7 @@ namespace ReallifeGamemode.Server.Commands
managedPlayer.SendNotification(toPlayerNotification); managedPlayer.SendNotification(toPlayerNotification);
ChatService.SendMessage(managedPlayer, toPlayerChat); ChatService.SendMessage(managedPlayer, toPlayerChat);
NAPI.Player.SpawnPlayer(managedPlayer, managedPlayer.Position); managedPlayer.SafeTeleport(managedPlayer.Position, 0, true);
managedPlayer.Health = 100; managedPlayer.Health = 100;
Medic.delReviveTask(managedPlayer); Medic.delReviveTask(managedPlayer);
@@ -2671,7 +2671,7 @@ namespace ReallifeGamemode.Server.Commands
Convert.ToByte(vehicle.PrimaryColor), Convert.ToByte(vehicle.SecondaryColor), business, price); Convert.ToByte(vehicle.PrimaryColor), Convert.ToByte(vehicle.SecondaryColor), business, price);
player.SendNotification("Shopfahrzeug ~g~" + vehicle.DisplayName + "~s~ gespeichert.", true); player.SendNotification("Shopfahrzeug ~g~" + vehicle.DisplayName + "~s~ gespeichert.", true);
Vector3 oldPos = player.Position; 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!"); else ChatService.SendMessage(player, "~m~Du sitzt in keinem Fahrzeug!");
break; break;

View File

@@ -343,7 +343,7 @@ namespace ReallifeGamemode.Server.Commands
u.Dead = false; u.Dead = false;
dbContext.SaveChanges(); dbContext.SaveChanges();
} }
NAPI.Player.SpawnPlayer(deadPlayer, deadPlayer.Position); deadPlayer.SafeTeleport(deadPlayer.Position, 0, true);
deadPlayer.Health = 50; deadPlayer.Health = 50;
MedicTask task = Medic.ReviveTasks.FirstOrDefault(t => t.Victim == deadPlayer.Name); MedicTask task = Medic.ReviveTasks.FirstOrDefault(t => t.Victim == deadPlayer.Name);

View File

@@ -190,7 +190,7 @@ namespace ReallifeGamemode.Server.DrivingSchool
veh.Position = sVeh.Position; veh.Position = sVeh.Position;
veh.Rotation = new Vector3(0, 0, sVeh.Heading); 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")] [RemoteEvent("drivingSchoolEvent")]
@@ -304,7 +304,7 @@ namespace ReallifeGamemode.Server.DrivingSchool
veh.Position = sVeh.Position; veh.Position = sVeh.Position;
veh.Rotation = new Vector3(0, 0, sVeh.Heading); 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")] [RemoteEvent("bikeSchoolEvent")]

View File

@@ -128,7 +128,7 @@ namespace ReallifeGamemode.Server.DrivingSchool
dbContext.SaveChanges(); dbContext.SaveChanges();
} }
user.ResetData("ActiveSchool"); 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")] [RemoteEvent("planeSchoolEvent")]

View File

@@ -26,7 +26,7 @@ namespace ReallifeGamemode.Server.Events
player.TriggerEvent("CLIENT:StopSound"); player.TriggerEvent("CLIENT:StopSound");
//player.SetSharedData("vehicleAdminSpeed2", 1.0); //player.SetSharedData("vehicleAdminSpeed2", 1.0);
player.SetData("isLoggedIn", false); 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; bool registered = false;

View File

@@ -238,7 +238,7 @@ namespace ReallifeGamemode.Server.Events
Player medicPlayer = PlayerService.GetPlayerByNameOrId(task.MedicName); Player medicPlayer = PlayerService.GetPlayerByNameOrId(task.MedicName);
Medic.RemoveTaskFromList(task); 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);
} }
} }
} }

View File

@@ -51,7 +51,7 @@ namespace ReallifeGamemode.Server.Events
client.WarpOutOfVehicle(); client.WarpOutOfVehicle();
ServerVehicle sVeh = VehicleManager.GetServerVehicleFromVehicle(vehicle); ServerVehicle sVeh = VehicleManager.GetServerVehicleFromVehicle(vehicle);
ServerVehicleExtensions.Spawn(sVeh, vehicle); ServerVehicleExtensions.Spawn(sVeh, vehicle);
client.Position = sVeh.Position; client.SafeTeleport(sVeh.Position);
CheckPointHandle.DeleteCheckpoints(client); CheckPointHandle.DeleteCheckpoints(client);
} }
} }

View File

@@ -113,7 +113,7 @@ namespace ReallifeGamemode.Server.Events
currentPlayerCreatorDimension++; currentPlayerCreatorDimension++;
NAPI.Data.SetWorldData("playerCreatorDimension", currentPlayerCreatorDimension); NAPI.Data.SetWorldData("playerCreatorDimension", currentPlayerCreatorDimension);
player.Dimension = NAPI.Data.GetWorldData("playerCreatorDimension"); 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.Rotation = new Vector3(0, 0, 180);
player.TriggerEvent("toggleCreator"); player.TriggerEvent("toggleCreator");
} }
@@ -123,7 +123,7 @@ namespace ReallifeGamemode.Server.Events
UpdateCharacterCloth.LoadCharacterDefaults(player); UpdateCharacterCloth.LoadCharacterDefaults(player);
if (user.JailTime <= 0) 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 else
{ {

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using GTANetworkAPI; using GTANetworkAPI;
using ReallifeGamemode.Server.Extensions;
namespace ReallifeGamemode.Server.Events namespace ReallifeGamemode.Server.Events
{ {
@@ -10,7 +11,7 @@ namespace ReallifeGamemode.Server.Events
[RemoteEvent("CLIENT:SET_InFrontOfPos")] [RemoteEvent("CLIENT:SET_InFrontOfPos")]
public void SetFrontOfPos(Player player, Vector3 pos) public void SetFrontOfPos(Player player, Vector3 pos)
{ {
player.Position = pos; player.SafeTeleport(pos);
} }
} }
} }

View File

@@ -3,6 +3,7 @@ using GTANetworkAPI;
using ReallifeGamemode.Database.Entities; using ReallifeGamemode.Database.Entities;
using Newtonsoft.Json; using Newtonsoft.Json;
using ReallifeGamemode.Database.Models; using ReallifeGamemode.Database.Models;
using ReallifeGamemode.Server.Extensions;
/** /**
* @overview Life of German Reallife - Event Register (Register.cs) * @overview Life of German Reallife - Event Register (Register.cs)
@@ -63,7 +64,7 @@ namespace ReallifeGamemode.Server.Events
NAPI.Data.SetWorldData("playerCreatorDimension", currentPlayerCreatorDimension); NAPI.Data.SetWorldData("playerCreatorDimension", currentPlayerCreatorDimension);
player.Dimension = NAPI.Data.GetWorldData("playerCreatorDimension"); player.Dimension = NAPI.Data.GetWorldData("playerCreatorDimension");
player.TriggerEvent("toggleCreator"); 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); //player.Position = new Vector3(user.PositionX, user.PositionY, user.PositionZ);
} }
else else

View File

@@ -1,4 +1,5 @@
using GTANetworkAPI; using GTANetworkAPI;
using ReallifeGamemode.Server.Extensions;
using ReallifeGamemode.Server.Managers; using ReallifeGamemode.Server.Managers;
namespace ReallifeGamemode.Server.Events namespace ReallifeGamemode.Server.Events
@@ -11,7 +12,7 @@ namespace ReallifeGamemode.Server.Events
ElevatorPoint elevator = PositionManager.ElevatorPoints.Find(e => e.Stage == stage); ElevatorPoint elevator = PositionManager.ElevatorPoints.Find(e => e.Stage == stage);
if (elevator != null) if (elevator != null)
{ {
client.Position = elevator.Position; client.SafeTeleport(elevator.Position);
} }
} }
} }

View File

@@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json; using Newtonsoft.Json;
using ReallifeGamemode.Database.Entities; using ReallifeGamemode.Database.Entities;
using ReallifeGamemode.Database.Models; using ReallifeGamemode.Database.Models;
using ReallifeGamemode.Server.Admin;
using ReallifeGamemode.Server.Managers; using ReallifeGamemode.Server.Managers;
using ReallifeGamemode.Server.Services; using ReallifeGamemode.Server.Services;
using ReallifeGamemode.Server.Types; 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) public static void SetJailTime(this User user, bool killed)
{ {
if (user == null) if (user == null)

View File

@@ -59,7 +59,7 @@ namespace ReallifeGamemode.Server.Job
if (quit) if (quit)
{ {
ChatService.SendMessage(player, $"~y~[Job]~s~ Du hast deinen Job ~o~{this.Name}~s~ beendet."); 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); JobStop?.Invoke(player);

View File

@@ -254,7 +254,7 @@ namespace ReallifeGamemode.Server.Managers
//}; //};
//player.SetHeadOverlay(4, makeupHo); //player.SetHeadOverlay(4, makeupHo);
//player.SetHeadOverlay(5, blushHo); //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.TriggerEvent("draw", player.Name, player.Handle.Value);
player.Dimension = 0; player.Dimension = 0;
} }

View File

@@ -203,30 +203,30 @@ namespace ReallifeGamemode.Server.Managers
if (player.GetUser().JobId == 1)//Taxifahrer if (player.GetUser().JobId == 1)//Taxifahrer
{ {
player.TriggerEvent("CLIENT:stopFare"); 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); player.Heading = (-171.50303649902344f);
} }
if (player.GetUser().JobId == 2)//Müllmann 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); player.Heading = (-15.922085762023926f);
} }
if (player.GetUser().JobId == 3)//Pilot if (player.GetUser().JobId == 3)//Pilot
{ {
if (!player.HasData("PilotenBase") || player.GetData<int>("PilotenBase") == 1) //Sandyshores if (!player.HasData("PilotenBase") || player.GetData<int>("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); player.Heading = (-154.65234375f);
} }
if (player.HasData("PilotenBase") && player.GetData<int>("PilotenBase") == 2) //LS Airport if (player.HasData("PilotenBase") && player.GetData<int>("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); player.Heading = (48.44f);
} }
} }
if (player.GetUser().JobId == 4)//Busfahrer 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); player.Heading = (57.03f);
} }
} }

View File

@@ -5,6 +5,7 @@ using ReallifeGamemode.Server.Shop.Clothing;
using ReallifeGamemode.Server.Shop.SevenEleven; using ReallifeGamemode.Server.Shop.SevenEleven;
using ReallifeGamemode.Server.Shop.Friseur; using ReallifeGamemode.Server.Shop.Friseur;
using ReallifeGamemode.Server.Util; using ReallifeGamemode.Server.Util;
using ReallifeGamemode.Server.Extensions;
namespace ReallifeGamemode.Server.Managers namespace ReallifeGamemode.Server.Managers
{ {
@@ -293,7 +294,7 @@ namespace ReallifeGamemode.Server.Managers
return; return;
} }
player.Position = ElevatorPoints.Where(e => e.Stage == level).First().Position; player.SafeTeleport(ElevatorPoints.Where(e => e.Stage == level).First().Position);
} }
} }
} }

View File

@@ -33,12 +33,16 @@ namespace ReallifeGamemode.Server.Wanted
player.Armor = 0; player.Armor = 0;
Random rnd = new Random(); Random rnd = new Random();
int rndInt = rnd.Next(1, 3); int rndInt = rnd.Next(1, 3);
Vector3 position = new Vector3();
if (rndInt == 1) 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) 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) 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 Jailtime[user.Id] = user.JailTime; // 54 sec for each wanted star -> in total 45min for 50 Wanteds
int timeMinutes; int timeMinutes;
@@ -135,7 +139,7 @@ namespace ReallifeGamemode.Server.Wanted
if (user.JailTime <= 0) if (user.JailTime <= 0)
{ {
Jailtime.Remove(user.Id); 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); player.TriggerEvent("jailTime", 0);
return; return;
} }
@@ -179,7 +183,7 @@ namespace ReallifeGamemode.Server.Wanted
dbContext.SaveChanges(); dbContext.SaveChanges();
} }
player.Health = 100; 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.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"); ChatService.SendMessage(player, "!{#8181E9}Der Beamte " + cop.Name + " hat dich aus dem Knast entlassen");
@@ -199,7 +203,7 @@ namespace ReallifeGamemode.Server.Wanted
dbContext.SaveChanges(); dbContext.SaveChanges();
target.Health = 100; 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.HQMessage(" Admin " + admin.Name + " hat " + user.Name + " aus dem Knast entlassen.");
ChatService.SendMessage(target, "!{#8181E9}Admin " + admin.Name + " hat dich aus dem Knast entlassen"); ChatService.SendMessage(target, "!{#8181E9}Admin " + admin.Name + " hat dich aus dem Knast entlassen");