Ejemplo n.º 1
0
        public void Unban(IAltPlayer player, ulong hwid)
        {
            if (!player.IsAdmin)
            {
                player.SendChatMessage("{FF0000} No permission!");
                return;
            }

            var target = Misc.BannedPlayers.FirstOrDefault(tuple => tuple.Item1 == hwid);

            if (target == null)
            {
                player.SendChatMessage($"{{FF0000}}Player with hwid {hwid} not found!");
                return;
            }

            if (Misc.BannedPlayers.All(tuple => tuple.Item1 != hwid))
            {
                player.SendChatMessage($"{{FF0000}}Player with hwid {hwid} not banned!");
                return;
            }

            // remove banned player from list
            Misc.BannedPlayers.Remove(new Tuple <ulong, ulong>(player.HardwareIdHash, player.HardwareIdExHash));
            player.SendChatMessage($"{{00FF00}}Player with hwid {hwid} unbanned!");
            player.Emit("set_last_command");
        }
Ejemplo n.º 2
0
        public async Task OnWeaponDamage(IAltPlayer player, IEntity target, uint weapon, ushort damage,
                                         Position shotOffset, BodyPart bodyPart)
        {
            await using (var asyncContext = AsyncContext.Create())
            {
                if (!player.TryToAsync(asyncContext, out var asyncPlayer))
                {
                    return;
                }
                if (!Misc.BlacklistedWeapons.Contains(weapon) || player is not {
                } damagePlayer)
                {
                    return;
                }
                if (!damagePlayer.TryToAsync(asyncContext, out var asyncDamagePlayer))
                {
                    return;
                }



                Alt.Server.LogColored($"~r~ Banned Player: {asyncDamagePlayer.Name} ({asyncDamagePlayer.Id}) for using illegal weapon!");
                //Misc.BannedPlayers.Add(<ulong, ulong>(damagePlayer.HardwareIdHash, damagePlayer.HardwareIdExHash));
                Misc.BannedPlayers.Add(new Tuple <ulong, ulong>(asyncDamagePlayer.HardwareIdHash, asyncDamagePlayer.HardwareIdExHash));
                string json = JsonSerializer.Serialize(Misc.BannedPlayers);
                File.WriteAllText(@"BannedPlayers.json", json);

                asyncPlayer.Kick("You're banned from this server!");
            }
        }
Ejemplo n.º 3
0
        public void ClearAllVehicles(IAltPlayer player, int distance = 0)
        {
            if (!player.IsAdmin)
            {
                player.SendChatMessage("{FF0000} No permission!");
                return;
            }

            if (distance == 0)
            {
                foreach (var veh in Alt.GetAllVehicles())
                {
                    veh.Remove();
                }
                return;
            }

            var distSqr = distance * distance;

            foreach (var veh in Alt.GetAllVehicles())
            {
                // compare squared distance between player and vehicle
                if (Vector3.DistanceSquared(veh.Position, player.Position) <= distSqr)
                {
                    veh.Remove();
                }
            }
            player.Emit("set_last_command");
        }
Ejemplo n.º 4
0
 public void ClearVehicles(IAltPlayer player)
 {
     // get all vehicles owned by player
     foreach (var veh in player.Vehicles)
     {
         veh.Remove();
     }
     player.Emit("set_last_command");
 }
Ejemplo n.º 5
0
        public void OnPlayerDisconnect(IAltPlayer player, string reason)
        {
            var vehicles = player.Vehicles;

            foreach (var veh in vehicles)
            {
                veh.Remove();
            }
        }
Ejemplo n.º 6
0
        public void SpawnVeh(IAltPlayer player, string vehicleName)
        {
            if (Misc.BlacklistedVehicle.Contains(Alt.Hash(vehicleName)))
            {
                player.SendChatMessage("{FF0000} Vehicle is blacklisted.");
                return;
            }

            if (!Enum.IsDefined(typeof(VehicleModel), Alt.Hash(vehicleName)))
            {
                player.SendChatMessage("{FF0000} Invalid vehicle model!");
                return;
            }

            if (Alt.GetAllVehicles().Any(veh => veh.Position.Distance(player.Position) < 3))
            {
                player.SendChatMessage("{FF0000} You are too close to a vehicle!");
                return;
            }

            if (player.LastVehicleSpawn.AddSeconds(10) > DateTime.Now)
            {
                player.SendChatMessage("{FF0000} You have to wait 10s before spawning a new vehicle!");
                return;
            }

            if (player.Vehicles.Count >= 3)
            {
                var target = player.Vehicles.OrderBy(veh => veh.SpawnTime).First();
                player.Vehicles.Remove(target);
                target.Remove();
                player.SendChatMessage("{FF0000} You can't have more than 3 vehicles. We removed your oldest one!");
            }

            if (player.IsInVehicle)
            {
                player.SendChatMessage("{FF0000} You are already in a vehicle we replaced it for you!");
                player.Vehicle.Remove();
                return;
            }

            lock (StatsHandler.StatsData)
            {
                StatsHandler.StatsData.VehiclesSpawned++;
            }

            var spawnedVeh = (AltVehicle)Alt.CreateVehicle(Alt.Hash(vehicleName),
                                                           player.Position + new Position(1, 0, 0), new Rotation(0, 0, player.Rotation.Yaw));

            player.SetIntoVehicle(spawnedVeh, 1);
            player.LastVehicleSpawn = DateTime.Now;
            player.Vehicles.Add(spawnedVeh);
            spawnedVeh.Owner = player;
            player.Emit("set_last_command");
        }
Ejemplo n.º 7
0
        public void Dimension(IAltPlayer player, int dimension = 0)
        {
            if (!player.IsAdmin)
            {
                player.SendChatMessage("{FF0000} No permission!");
                return;
            }

            player.Dimension = dimension;
            player.Emit("set_last_command");
        }
Ejemplo n.º 8
0
        public void GetWeapons(IAltPlayer player)
        {
            // give all weapons from WeaponModel Enum to player
            var weapons = Misc.WhitelistedWeapons;

            foreach (var weapon in weapons)
            {
                player.GiveWeapon(weapon, 1000, false);
            }

            player.Emit("set_last_command");
        }
Ejemplo n.º 9
0
        public void Tune(IAltPlayer player, int index, int value)
        {
            if (!player.IsInVehicle)
            {
                player.SendChatMessage("{FF0000} You're not in a vehicle!");
                return;
            }

            player.Vehicle.ModKit = 1;
            player.Vehicle.SetMod((byte)index, (byte)value);
            player.Emit("set_last_command");
        }
Ejemplo n.º 10
0
        public void Teleport(IAltPlayer player, int id = 0)
        {
            if (id > Misc.SpawnPositions.Length || id <= 0)
            {
                player.SendChatMessage(
                    $"{{FF0000}}Invalid Spawnpoint! (Minimum 1, Maximum: {Misc.SpawnPositions.Length})");
                return;
            }

            var spawnpoint = Misc.SpawnPositions[id - 1];

            player.Position = spawnpoint + new Position(_random.Next(0, 10), _random.Next(0, 10), 0);
            player.Emit("set_last_command");
        }
Ejemplo n.º 11
0
        public void NoClip(IAltPlayer player)
        {
            if (!player.IsAdmin)
            {
                player.SendChatMessage("{FF0000} No permission!");
                return;
            }

            player.NoClip   = !player.NoClip;
            player.Streamed = !player.NoClip;
            player.Visible  = !player.NoClip;
            player.SendChatMessage($"{{00FF00}}NoClip is now {(player.NoClip ? "enabled" : "disabled")}!");
            player.Emit("set_last_command");
            player.Emit("noclip", player.NoClip);
        }
Ejemplo n.º 12
0
        public async Task OnPlayerConnect(IAltPlayer player, string reason)
        {
            await using (var asyncContext = AsyncContext.Create())
            {
                if (!player.TryToAsync(asyncContext, out var asyncPlayer))
                {
                    return;
                }

                if (Misc.BannedPlayers.Contains(new Tuple <ulong, ulong>(asyncPlayer.HardwareIdHash, asyncPlayer.HardwareIdExHash)))
                {
                    asyncPlayer.Kick("You're banned from this server!");
                    AltAsync.Log($"HWID: {asyncPlayer.HardwareIdHash}, SC: {asyncPlayer.SocialClubId}. Tried to join the server with a ban.");
                    return;
                }

                if (Misc.Operators.Contains(new Tuple <ulong, ulong>(asyncPlayer.HardwareIdHash, asyncPlayer.HardwareIdExHash)))
                {
                    asyncPlayer.IsAdmin = true;
                }

                // select random entry from SpawnPoints
                var randomSpawnPoint = Misc.SpawnPositions.ElementAt(_random.Next(0, Misc.SpawnPositions.Length));
                asyncPlayer.Spawn(randomSpawnPoint + new Position(_random.Next(0, 10), _random.Next(0, 10), 0));
                asyncPlayer.Model = (uint)PedModel.FreemodeMale01;
                asyncPlayer.SetDateTime(1, 1, 1, Misc.Hour, 1, 1);
                asyncPlayer.SetWeather(Misc.Weather);

                asyncPlayer.Emit("draw_dmzone", Misc.DMPos.X, Misc.DMPos.Y, Misc.DMRadius, 150);

                if (asyncPlayer.IsAdmin)
                {
                    asyncPlayer.Emit("set_chat_state", true);
                }
            }

            // create async context
            lock (StatsHandler.StatsData)
            {
                StatsHandler.StatsData.PlayerConnections++;
            }

            return;
        }
Ejemplo n.º 13
0
        public void SetTime(IAltPlayer player, int hour)
        {
            if (!player.IsAdmin)
            {
                player.SendChatMessage("{FF0000} No permission!");
                return;
            }
            if (hour > 23 || hour < 0)
            {
                player.SendChatMessage("{FF0000} Invalid hour!");
                return;
            }

            foreach (var p in Alt.GetAllPlayers())
            {
                p.SetDateTime(0, 0, 0, hour, 0, 0);
            }
            player.Emit("set_last_command");
        }
Ejemplo n.º 14
0
        public void Dm(IAltPlayer player)
        {
            player.SendChatMessage(player.DmMode ? "{00FF00} Respawning in Death Match Zone disabled!" : "{00FF00}Respawning in Death Match Zone enabled!");
            player.DmMode = !player.DmMode;

            if (player.DmMode)
            {
                var weapons = Misc.WhitelistedWeapons;
                foreach (var weapon in weapons)
                {
                    player.GiveWeapon(weapon, 1000, false);
                }

                var randomSpawnPoint = Misc.AirportSpawnPositions.ElementAt(_random.Next(0, Misc.AirportSpawnPositions.Length));
                player.Spawn(randomSpawnPoint + new Position(_random.Next(0, 10), _random.Next(0, 10), 0));
            }

            player.Emit("set_last_command");
        }
Ejemplo n.º 15
0
 public void SetWeather(IAltPlayer player, uint weather)
 {
     if (!player.IsAdmin)
     {
         player.SendChatMessage("{FF0000} No permission!");
         return;
     }
     if (weather > 14)
     {
         player.SendChatMessage("{FF0000} Invalid weather!");
         return;
     }
     foreach (var p in Alt.GetAllPlayers())
     {
         p.SetWeather(weather);
     }
     Misc.Weather = weather;
     player.Emit("set_last_command");
 }
Ejemplo n.º 16
0
        public void TpTo(IAltPlayer player, int target)
        {
            if (!player.IsAdmin)
            {
                player.SendChatMessage("{FF0000} No permission!");
                return;
            }

            var targetPlayer = Alt.GetAllPlayers().FirstOrDefault(p => p.Id == target);

            if (targetPlayer == null)
            {
                player.SendChatMessage("{FF0000} Player not found!");
                return;
            }
            player.Position = targetPlayer.Position;
            player.SendChatMessage("{00FF00} You were teleported to " + targetPlayer.Name + "!");
            player.Emit("set_last_command");
        }
Ejemplo n.º 17
0
        public void TpAllhere(IAltPlayer player)
        {
            if (!player.IsAdmin)
            {
                player.SendChatMessage("{FF0000} No permission!");
                return;
            }

            foreach (var p in Alt.GetAllPlayers())
            {
                if (p is not {
                } target)
                {
                    continue;
                }
                target.Position = player.Position;
                target.SendChatMessage("{00FF00} You were teleported to " + player.Name + "!");
            }
            player.Emit("set_last_command");
        }
Ejemplo n.º 18
0
        public void Ban(IAltPlayer player, int id)
        {
            if (!player.IsAdmin)
            {
                player.SendChatMessage("{FF0000} No permission!");
                return;
            }

            var target = Alt.GetAllPlayers().FirstOrDefault(p => p.Id == id);

            if (target == null)
            {
                player.SendChatMessage($"{{FF0000}}Player with id {id} not found!");
                return;
            }

            target.Kick("You've been banned from this server!");
            Misc.BannedPlayers.Add(new Tuple <ulong, ulong>(target.HardwareIdHash, target.HardwareIdExHash));
            player.SendChatMessage($"{{00FF00}}Player with id {id} banned!");
            player.Emit("set_last_command");
        }
Ejemplo n.º 19
0
        public void ToggleChat(IAltPlayer player, bool state)
        {
            // check if player is operator
            if (!player.IsAdmin && !Misc.ChatState)
            {
                player.SendChatMessage("{FF0000} No permission!");
                return;
            }

            player.SendChatMessage("{00FF00} Chat is now " + (state ? "enabled" : "disabled") + "!");
            Misc.ChatState = state;
            foreach (var p in Alt.GetAllPlayers())
            {
                // check if player is operator
                if (player.IsAdmin)
                {
                    continue;
                }
                p.Emit("set_chat_state", state);
            }
        }
Ejemplo n.º 20
0
        public async Task OnPlayerDead(IAltPlayer player, IEntity killer, uint weapon)
        {
            var spawnPointPool = player.DmMode ? Misc.AirportSpawnPositions : Misc.SpawnPositions;

            await using (var asyncContext = AsyncContext.Create())
            {
                if (!player.TryToAsync(asyncContext, out var asyncPlayer))
                {
                    return;
                }
                if (killer is not IAltPlayer killerPlayer)
                {
                    return;
                }
                if (!killerPlayer.TryToAsync(asyncContext, out var asyncKillerPlayer))
                {
                    return;
                }

                var randomSpawnPoint = spawnPointPool.ElementAt(_random.Next(0, spawnPointPool.Length));
                asyncPlayer.Spawn(randomSpawnPoint + new Position(_random.Next(0, 10), _random.Next(0, 10), 0));

                lock (StatsHandler.StatsData)
                {
                    StatsHandler.StatsData.PlayerDeaths++;
                }

                if (!Misc.BlacklistedWeapons.Contains(weapon))
                {
                    return;
                }
                Alt.Server.LogColored($"~r~ Banned Player: {asyncKillerPlayer.Name} ({asyncKillerPlayer.Id}) for using illegal weapon!");
                Misc.BannedPlayers.Add(new Tuple <ulong, ulong>(asyncKillerPlayer.HardwareIdHash, asyncKillerPlayer.HardwareIdExHash));
                string json = JsonSerializer.Serialize(Misc.BannedPlayers);
                await File.WriteAllTextAsync(@"BannedPlayers.json", json);

                asyncKillerPlayer.Kick("You're banned from this server!");
            }
        }
Ejemplo n.º 21
0
        public void OnChatMessage(IAltPlayer player, params string[] args)
        {
            var message = string.Join("", args);

            if (args.Length == 0 || message.Length == 0)
            {
                return;
            }

            if (args[0].StartsWith("/"))
            {
                return;
            }
            if (!Misc.ChatState && !player.IsAdmin)
            {
                player.SendChatMessage("{FF0000}Chat is disabled!");
                return;
            }

            foreach (var p in Alt.GetAllPlayers())
            {
                p.SendChatMessage(
                    $"{(player.IsAdmin ? "{008736}" : "{FFFFFF}")} <b>{player.Name}({player.Id})</b>: {{FFFFFF}}{message}");
Ejemplo n.º 22
0
 public bool OnProjectileStart(IAltPlayer player, Position startPosition, Position direction, uint ammoHash, uint weaponHash)
 {
     return(false);
 }
Ejemplo n.º 23
0
 public bool OnExplosion(IAltPlayer player, ExplosionType explosionType, Position position, uint explosionFx,
                         IEntity target)
 {
     return(false);
 }
Ejemplo n.º 24
0
 public bool OnFireStart(IAltPlayer player, FireInfo[] fireInfos)
 {
     return(false);
 }
Ejemplo n.º 25
0
 public void RemoveWeaponComponent(IAltPlayer player, string name)
 {
     player.RemoveWeaponComponent(player.CurrentWeapon, Alt.Hash(name));
     player.Emit("set_last_command");
 }
Ejemplo n.º 26
0
        public void Announce(IAltPlayer player, string header, int time, params string[] body)
        {
            var message = string.Join(" ", body);

            Alt.EmitAllClients("announce", header, message, time);
        }
Ejemplo n.º 27
0
 public void Respawn(IAltPlayer player)
 {
     player.Spawn(player.Position);
 }
Ejemplo n.º 28
0
 public void Position(IAltPlayer player)
 {
     Alt.Log($"new Position({player.Position.X}, {player.Position.Y}, {player.Position.Z}),");
 }