From 6248ae2088e1d1c928891f314bb77e31b74b76f7 Mon Sep 17 00:00:00 2001 From: "starlkytminecraft@gmail.com" Date: Thu, 22 Feb 2024 00:35:48 +0300 Subject: [PATCH 01/13] Fixes #426 --- Obsidian.API/_Interfaces/IServerConfiguration.cs | 8 ++++++++ Obsidian/Client.cs | 2 +- Obsidian/Net/Packets/ClientInformationPacket.cs | 2 +- Obsidian/Utilities/ServerConfiguration.cs | 8 ++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Obsidian.API/_Interfaces/IServerConfiguration.cs b/Obsidian.API/_Interfaces/IServerConfiguration.cs index f2f6b5078..1595c041e 100644 --- a/Obsidian.API/_Interfaces/IServerConfiguration.cs +++ b/Obsidian.API/_Interfaces/IServerConfiguration.cs @@ -109,6 +109,14 @@ public interface IServerConfiguration /// public RconConfig? Rcon { get; set; } + /// + /// The view distance of the server. + /// + /// + /// Players with higher view distance will use the server's view distance. + /// + public byte ViewDistance { get; set; } + public List WhitelistedIPs { get; set; } public List Whitelisted { get; set; } } diff --git a/Obsidian/Client.cs b/Obsidian/Client.cs index f610edf82..409bb079c 100644 --- a/Obsidian/Client.cs +++ b/Obsidian/Client.cs @@ -565,7 +565,7 @@ await QueuePacketAsync(new SynchronizePlayerPositionPacket TeleportId = Player.TeleportId }); - await Player.UpdateChunksAsync(distance: 7); + await Player.UpdateChunksAsync(distance: server.Configuration.ViewDistance); await SendInfoAsync(); await this.server.EventDispatcher.ExecuteEventAsync(new PlayerJoinEventArgs(Player, this.server, DateTimeOffset.Now)); } diff --git a/Obsidian/Net/Packets/ClientInformationPacket.cs b/Obsidian/Net/Packets/ClientInformationPacket.cs index 99df5b3a3..319dc1217 100644 --- a/Obsidian/Net/Packets/ClientInformationPacket.cs +++ b/Obsidian/Net/Packets/ClientInformationPacket.cs @@ -36,7 +36,7 @@ public async ValueTask HandleAsync(Server server, Player player) player.ClientInformation = new() { Locale = this.Locale, - ViewDistance = this.ViewDistance, + ViewDistance = sbyte.Min(ViewDistance, (sbyte) server.Configuration.ViewDistance), ChatMode = this.ChatMode, ChatColors = this.ChatColors, DisplayedSkinParts = this.DisplayedSkinParts, diff --git a/Obsidian/Utilities/ServerConfiguration.cs b/Obsidian/Utilities/ServerConfiguration.cs index 965dd5837..016193950 100644 --- a/Obsidian/Utilities/ServerConfiguration.cs +++ b/Obsidian/Utilities/ServerConfiguration.cs @@ -48,6 +48,12 @@ public sealed class ServerConfiguration : IServerConfiguration public bool AllowLan { get; set; } = true; // Enabled because it's super useful for debugging tbh + public byte ViewDistance + { + get => viewDistance; + set => viewDistance = value >= 3 ? value : viewDistance; + } + public int PregenerateChunkRange { get; set; } = 15; // by default, pregenerate range from -15 to 15 [JsonConverter(typeof(JsonStringEnumConverter))] @@ -64,6 +70,8 @@ public sealed class ServerConfiguration : IServerConfiguration public ServerListQuery ServerListQuery { get; set; } = ServerListQuery.Full; public int TimeTickSpeedMultiplier { get; set; } = 1; + + private byte viewDistance = 10; } public sealed class ServerWorld From 94b7c4527523a9ffb538beae03e33410d612cd0d Mon Sep 17 00:00:00 2001 From: "starlkytminecraft@gmail.com" Date: Thu, 22 Feb 2024 15:28:38 +0300 Subject: [PATCH 02/13] Fix initial view distance chunks --- Obsidian/Client.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Obsidian/Client.cs b/Obsidian/Client.cs index 409bb079c..f610edf82 100644 --- a/Obsidian/Client.cs +++ b/Obsidian/Client.cs @@ -565,7 +565,7 @@ await QueuePacketAsync(new SynchronizePlayerPositionPacket TeleportId = Player.TeleportId }); - await Player.UpdateChunksAsync(distance: server.Configuration.ViewDistance); + await Player.UpdateChunksAsync(distance: 7); await SendInfoAsync(); await this.server.EventDispatcher.ExecuteEventAsync(new PlayerJoinEventArgs(Player, this.server, DateTimeOffset.Now)); } From 77ce70457560097f7807a0036da397f8fee9ee94 Mon Sep 17 00:00:00 2001 From: "starlkytminecraft@gmail.com" Date: Fri, 23 Feb 2024 04:59:05 +0300 Subject: [PATCH 03/13] Fix minimum view distance --- Obsidian/Utilities/ServerConfiguration.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Obsidian/Utilities/ServerConfiguration.cs b/Obsidian/Utilities/ServerConfiguration.cs index 016193950..e41cf938c 100644 --- a/Obsidian/Utilities/ServerConfiguration.cs +++ b/Obsidian/Utilities/ServerConfiguration.cs @@ -51,7 +51,7 @@ public sealed class ServerConfiguration : IServerConfiguration public byte ViewDistance { get => viewDistance; - set => viewDistance = value >= 3 ? value : viewDistance; + set => viewDistance = value >= 3 ? value : (byte) 3; } public int PregenerateChunkRange { get; set; } = 15; // by default, pregenerate range from -15 to 15 From 9227f37e30ebfd99ddbb19b35e1bef043134c991 Mon Sep 17 00:00:00 2001 From: "starlkytminecraft@gmail.com" Date: Fri, 23 Feb 2024 18:33:49 +0300 Subject: [PATCH 04/13] Create a `const` for the minimum view distance. --- Obsidian/Utilities/ServerConfiguration.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Obsidian/Utilities/ServerConfiguration.cs b/Obsidian/Utilities/ServerConfiguration.cs index e41cf938c..5c0e5dfc2 100644 --- a/Obsidian/Utilities/ServerConfiguration.cs +++ b/Obsidian/Utilities/ServerConfiguration.cs @@ -51,7 +51,7 @@ public sealed class ServerConfiguration : IServerConfiguration public byte ViewDistance { get => viewDistance; - set => viewDistance = value >= 3 ? value : (byte) 3; + set => viewDistance = value >= MinimumViewDistance ? value : MinimumViewDistance; } public int PregenerateChunkRange { get; set; } = 15; // by default, pregenerate range from -15 to 15 @@ -72,6 +72,9 @@ public byte ViewDistance public int TimeTickSpeedMultiplier { get; set; } = 1; private byte viewDistance = 10; + + // Anything lower than 3 will cause weird artifacts on the client. + private const byte MinimumViewDistance = 3; } public sealed class ServerWorld From f45963215a6fa782c03e8306bb2a0f645444360b Mon Sep 17 00:00:00 2001 From: "starlkytminecraft@gmail.com" Date: Mon, 26 Feb 2024 00:54:58 +0300 Subject: [PATCH 05/13] Ignore operation cancelled exception in try/catch. Fixes #430 --- Obsidian/Services/PacketBroadcaster.cs | 2 +- Obsidian/WorldData/WorldManager.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Obsidian/Services/PacketBroadcaster.cs b/Obsidian/Services/PacketBroadcaster.cs index 7fe35cc08..331f9ec11 100644 --- a/Obsidian/Services/PacketBroadcaster.cs +++ b/Obsidian/Services/PacketBroadcaster.cs @@ -71,7 +71,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) await player.client.QueuePacketAsync(queuedPacket.Packet); } } - catch (Exception e) + catch (Exception e) when (e is not OperationCanceledException) { await this.environment.OnServerCrashAsync(this.logger, e); } diff --git a/Obsidian/WorldData/WorldManager.cs b/Obsidian/WorldData/WorldManager.cs index 58150ed3b..0c97a5969 100644 --- a/Obsidian/WorldData/WorldManager.cs +++ b/Obsidian/WorldData/WorldManager.cs @@ -57,7 +57,7 @@ protected async override Task ExecuteAsync(CancellationToken stoppingToken) await Task.WhenAll(this.worlds.Values.Cast().Select(x => x.ManageChunksAsync())); } } - catch (Exception ex) + catch (Exception ex) when (ex is not OperationCanceledException) { await this.serverEnvironment.OnServerCrashAsync(this.logger, ex); } From dd37e02525336f1dcf375f548327d549cecfd19d Mon Sep 17 00:00:00 2001 From: "starlkytminecraft@gmail.com" Date: Mon, 26 Feb 2024 00:57:03 +0300 Subject: [PATCH 06/13] Remove whitespace --- Obsidian/WorldData/WorldManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Obsidian/WorldData/WorldManager.cs b/Obsidian/WorldData/WorldManager.cs index 0c97a5969..0cc80e00a 100644 --- a/Obsidian/WorldData/WorldManager.cs +++ b/Obsidian/WorldData/WorldManager.cs @@ -57,7 +57,7 @@ protected async override Task ExecuteAsync(CancellationToken stoppingToken) await Task.WhenAll(this.worlds.Values.Cast().Select(x => x.ManageChunksAsync())); } } - catch (Exception ex) when (ex is not OperationCanceledException) + catch (Exception ex) when (ex is not OperationCanceledException) { await this.serverEnvironment.OnServerCrashAsync(this.logger, ex); } From 9b134d95944a91446ad047ad6874a8b9325cd068 Mon Sep 17 00:00:00 2001 From: "starlkytminecraft@gmail.com" Date: Tue, 27 Feb 2024 22:06:12 +0300 Subject: [PATCH 07/13] Implement player abilities packet --- Obsidian/Client.cs | 4 ++ Obsidian/Entities/Player.cs | 21 +++++- Obsidian/Net/ClientHandler.cs | 1 + .../Play/Clientbound/PlayerAbilitiesPacket.cs | 67 +++++++++++++++++++ 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 Obsidian/Net/Packets/Play/Clientbound/PlayerAbilitiesPacket.cs diff --git a/Obsidian/Client.cs b/Obsidian/Client.cs index f610edf82..c7943a33d 100644 --- a/Obsidian/Client.cs +++ b/Obsidian/Client.cs @@ -708,6 +708,10 @@ internal async Task SendPlayerInfoAsync() } await QueuePacketAsync(new PlayerInfoUpdatePacket(dict)); + await QueuePacketAsync(new PlayerAbilitiesPacket(true) + { + Abilities = Player.Abilities + }); } internal void SendPacket(IClientboundPacket packet) diff --git a/Obsidian/Entities/Player.cs b/Obsidian/Entities/Player.cs index 7ce8f1bf1..b1450d95f 100644 --- a/Obsidian/Entities/Player.cs +++ b/Obsidian/Entities/Player.cs @@ -62,7 +62,24 @@ public sealed partial class Player : Living, IPlayer public IBlock? LastClickedBlock { get; internal set; } - public Gamemode Gamemode { get; set; } + public Gamemode Gamemode + { + get => gamemode; + set + { + gamemode = value; + + Abilities = Gamemode switch + { + Gamemode.Creative => PlayerAbility.CreativeMode | PlayerAbility.AllowFlying | PlayerAbility.Invulnerable, + Gamemode.Spectator => PlayerAbility.AllowFlying | PlayerAbility.Invulnerable, + Gamemode.Survival or Gamemode.Adventure or Gamemode.Hardcore => PlayerAbility.None, + _ => throw new ArgumentOutOfRangeException(nameof(Gamemode), Gamemode, "Unknown gamemode.") + }; + } + } + + public PlayerAbility Abilities { get; internal set; } public IScoreboard? CurrentScoreboard { get; set; } @@ -115,6 +132,8 @@ internal set public IPAddress? ClientIP => (client.RemoteEndPoint as IPEndPoint)?.Address; + private Gamemode gamemode = Gamemode.Creative; + [SetsRequiredMembers] internal Player(Guid uuid, string username, Client client, World world) { diff --git a/Obsidian/Net/ClientHandler.cs b/Obsidian/Net/ClientHandler.cs index 9d29a031e..ba6952153 100644 --- a/Obsidian/Net/ClientHandler.cs +++ b/Obsidian/Net/ClientHandler.cs @@ -44,6 +44,7 @@ public void RegisterHandlers() Packets.TryAdd(0x17, new SetPlayerPositionPacket()); Packets.TryAdd(0x18, new SetPlayerPositionAndRotationPacket()); Packets.TryAdd(0x19, new SetPlayerRotationPacket()); + Packets.TryAdd(0x20, new PlayerAbilitiesPacket(false)); //Packets.TryAdd(0x15, PlayerMovement); //Packets.TryAdd(0x16, VehicleMove); //Packets.TryAdd(0x17, SteerBoat); diff --git a/Obsidian/Net/Packets/Play/Clientbound/PlayerAbilitiesPacket.cs b/Obsidian/Net/Packets/Play/Clientbound/PlayerAbilitiesPacket.cs new file mode 100644 index 000000000..11ac2d852 --- /dev/null +++ b/Obsidian/Net/Packets/Play/Clientbound/PlayerAbilitiesPacket.cs @@ -0,0 +1,67 @@ +using Obsidian.Entities; + +namespace Obsidian.Net.Packets.Play.Clientbound; + +[Flags] +public enum PlayerAbility +{ + None = 0x00, + Invulnerable = 0x01, + Flying = 0x02, + AllowFlying = 0x04, + CreativeMode = 0x08 +} + +public class PlayerAbilitiesPacket : IClientboundPacket, IServerboundPacket +{ + public PlayerAbility Abilities { get; set; } = PlayerAbility.None; + + public float FlyingSpeed { get; set; } = 0.05F; + + public float FieldOfViewModifier { get; set; } = 0.1F; + + public int Id { get; } + + public PlayerAbilitiesPacket(bool toClient) + { + Id = toClient ? 0x36 : 0x20; + } + + public void Serialize(MinecraftStream stream) + { + using var packetStream = new MinecraftStream(); + packetStream.WriteByte((byte)Abilities); + packetStream.WriteFloat(FlyingSpeed); + packetStream.WriteFloat(FieldOfViewModifier); + + stream.Lock.Wait(); + stream.WriteVarInt(Id.GetVarIntLength() + (int)packetStream.Length); + stream.WriteVarInt(Id); + packetStream.Position = 0; + packetStream.CopyTo(stream); + stream.Lock.Release(); + } + + public void Populate(MinecraftStream stream) + { + Abilities = (PlayerAbility) stream.ReadByte(); + } + + public void Populate(byte[] data) + { + using var stream = new MinecraftStream(data); + Populate(stream); + } + + public async ValueTask HandleAsync(Server server, Player player) + { + if (Abilities.HasFlag(PlayerAbility.Flying) + && !Abilities.HasFlag(PlayerAbility.AllowFlying) + && player.Gamemode is not Gamemode.Creative or Gamemode.Spectator) + { + await player.KickAsync("Cheating is not allowed!"); + } + + player.Abilities |= Abilities; + } +} From 891929dd5ef77f8cf68385d9c762b5ea6f08949f Mon Sep 17 00:00:00 2001 From: "starlkytminecraft@gmail.com" Date: Tue, 27 Feb 2024 22:08:17 +0300 Subject: [PATCH 08/13] Revert "Implement player abilities packet" This reverts commit 9b134d95944a91446ad047ad6874a8b9325cd068. --- Obsidian/Client.cs | 4 -- Obsidian/Entities/Player.cs | 21 +----- Obsidian/Net/ClientHandler.cs | 1 - .../Play/Clientbound/PlayerAbilitiesPacket.cs | 67 ------------------- 4 files changed, 1 insertion(+), 92 deletions(-) delete mode 100644 Obsidian/Net/Packets/Play/Clientbound/PlayerAbilitiesPacket.cs diff --git a/Obsidian/Client.cs b/Obsidian/Client.cs index c7943a33d..f610edf82 100644 --- a/Obsidian/Client.cs +++ b/Obsidian/Client.cs @@ -708,10 +708,6 @@ internal async Task SendPlayerInfoAsync() } await QueuePacketAsync(new PlayerInfoUpdatePacket(dict)); - await QueuePacketAsync(new PlayerAbilitiesPacket(true) - { - Abilities = Player.Abilities - }); } internal void SendPacket(IClientboundPacket packet) diff --git a/Obsidian/Entities/Player.cs b/Obsidian/Entities/Player.cs index b1450d95f..7ce8f1bf1 100644 --- a/Obsidian/Entities/Player.cs +++ b/Obsidian/Entities/Player.cs @@ -62,24 +62,7 @@ public sealed partial class Player : Living, IPlayer public IBlock? LastClickedBlock { get; internal set; } - public Gamemode Gamemode - { - get => gamemode; - set - { - gamemode = value; - - Abilities = Gamemode switch - { - Gamemode.Creative => PlayerAbility.CreativeMode | PlayerAbility.AllowFlying | PlayerAbility.Invulnerable, - Gamemode.Spectator => PlayerAbility.AllowFlying | PlayerAbility.Invulnerable, - Gamemode.Survival or Gamemode.Adventure or Gamemode.Hardcore => PlayerAbility.None, - _ => throw new ArgumentOutOfRangeException(nameof(Gamemode), Gamemode, "Unknown gamemode.") - }; - } - } - - public PlayerAbility Abilities { get; internal set; } + public Gamemode Gamemode { get; set; } public IScoreboard? CurrentScoreboard { get; set; } @@ -132,8 +115,6 @@ internal set public IPAddress? ClientIP => (client.RemoteEndPoint as IPEndPoint)?.Address; - private Gamemode gamemode = Gamemode.Creative; - [SetsRequiredMembers] internal Player(Guid uuid, string username, Client client, World world) { diff --git a/Obsidian/Net/ClientHandler.cs b/Obsidian/Net/ClientHandler.cs index ba6952153..9d29a031e 100644 --- a/Obsidian/Net/ClientHandler.cs +++ b/Obsidian/Net/ClientHandler.cs @@ -44,7 +44,6 @@ public void RegisterHandlers() Packets.TryAdd(0x17, new SetPlayerPositionPacket()); Packets.TryAdd(0x18, new SetPlayerPositionAndRotationPacket()); Packets.TryAdd(0x19, new SetPlayerRotationPacket()); - Packets.TryAdd(0x20, new PlayerAbilitiesPacket(false)); //Packets.TryAdd(0x15, PlayerMovement); //Packets.TryAdd(0x16, VehicleMove); //Packets.TryAdd(0x17, SteerBoat); diff --git a/Obsidian/Net/Packets/Play/Clientbound/PlayerAbilitiesPacket.cs b/Obsidian/Net/Packets/Play/Clientbound/PlayerAbilitiesPacket.cs deleted file mode 100644 index 11ac2d852..000000000 --- a/Obsidian/Net/Packets/Play/Clientbound/PlayerAbilitiesPacket.cs +++ /dev/null @@ -1,67 +0,0 @@ -using Obsidian.Entities; - -namespace Obsidian.Net.Packets.Play.Clientbound; - -[Flags] -public enum PlayerAbility -{ - None = 0x00, - Invulnerable = 0x01, - Flying = 0x02, - AllowFlying = 0x04, - CreativeMode = 0x08 -} - -public class PlayerAbilitiesPacket : IClientboundPacket, IServerboundPacket -{ - public PlayerAbility Abilities { get; set; } = PlayerAbility.None; - - public float FlyingSpeed { get; set; } = 0.05F; - - public float FieldOfViewModifier { get; set; } = 0.1F; - - public int Id { get; } - - public PlayerAbilitiesPacket(bool toClient) - { - Id = toClient ? 0x36 : 0x20; - } - - public void Serialize(MinecraftStream stream) - { - using var packetStream = new MinecraftStream(); - packetStream.WriteByte((byte)Abilities); - packetStream.WriteFloat(FlyingSpeed); - packetStream.WriteFloat(FieldOfViewModifier); - - stream.Lock.Wait(); - stream.WriteVarInt(Id.GetVarIntLength() + (int)packetStream.Length); - stream.WriteVarInt(Id); - packetStream.Position = 0; - packetStream.CopyTo(stream); - stream.Lock.Release(); - } - - public void Populate(MinecraftStream stream) - { - Abilities = (PlayerAbility) stream.ReadByte(); - } - - public void Populate(byte[] data) - { - using var stream = new MinecraftStream(data); - Populate(stream); - } - - public async ValueTask HandleAsync(Server server, Player player) - { - if (Abilities.HasFlag(PlayerAbility.Flying) - && !Abilities.HasFlag(PlayerAbility.AllowFlying) - && player.Gamemode is not Gamemode.Creative or Gamemode.Spectator) - { - await player.KickAsync("Cheating is not allowed!"); - } - - player.Abilities |= Abilities; - } -} From f7f354bc5e4c452ac0d2d143e06da95164ce4cbf Mon Sep 17 00:00:00 2001 From: Starlk Date: Tue, 27 Feb 2024 22:14:24 +0300 Subject: [PATCH 09/13] Update PacketBroadcaster.cs --- Obsidian/Services/PacketBroadcaster.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Obsidian/Services/PacketBroadcaster.cs b/Obsidian/Services/PacketBroadcaster.cs index 331f9ec11..7fe35cc08 100644 --- a/Obsidian/Services/PacketBroadcaster.cs +++ b/Obsidian/Services/PacketBroadcaster.cs @@ -71,7 +71,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) await player.client.QueuePacketAsync(queuedPacket.Packet); } } - catch (Exception e) when (e is not OperationCanceledException) + catch (Exception e) { await this.environment.OnServerCrashAsync(this.logger, e); } From 74a9cbadeaaa1fa9389bb50b601f6d4e5278ac97 Mon Sep 17 00:00:00 2001 From: Starlk Date: Tue, 27 Feb 2024 22:14:50 +0300 Subject: [PATCH 10/13] Update WorldManager.cs --- Obsidian/WorldData/WorldManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Obsidian/WorldData/WorldManager.cs b/Obsidian/WorldData/WorldManager.cs index 0cc80e00a..58150ed3b 100644 --- a/Obsidian/WorldData/WorldManager.cs +++ b/Obsidian/WorldData/WorldManager.cs @@ -57,7 +57,7 @@ protected async override Task ExecuteAsync(CancellationToken stoppingToken) await Task.WhenAll(this.worlds.Values.Cast().Select(x => x.ManageChunksAsync())); } } - catch (Exception ex) when (ex is not OperationCanceledException) + catch (Exception ex) { await this.serverEnvironment.OnServerCrashAsync(this.logger, ex); } From d406adb0773964152198e709946a77f7f223948b Mon Sep 17 00:00:00 2001 From: Starlk Date: Tue, 27 Feb 2024 22:15:26 +0300 Subject: [PATCH 11/13] Update Player.cs --- Obsidian/Entities/Player.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Obsidian/Entities/Player.cs b/Obsidian/Entities/Player.cs index b1450d95f..b29f5606d 100644 --- a/Obsidian/Entities/Player.cs +++ b/Obsidian/Entities/Player.cs @@ -132,7 +132,7 @@ internal set public IPAddress? ClientIP => (client.RemoteEndPoint as IPEndPoint)?.Address; - private Gamemode gamemode = Gamemode.Creative; + private Gamemode gamemode; [SetsRequiredMembers] internal Player(Guid uuid, string username, Client client, World world) From 009ae2a9ec9a7ee59c10a1c9e3210297f48b1425 Mon Sep 17 00:00:00 2001 From: Starlk Date: Tue, 27 Feb 2024 22:17:02 +0300 Subject: [PATCH 12/13] Update PlayerAbilitiesPacket.cs --- Obsidian/Net/Packets/Play/Clientbound/PlayerAbilitiesPacket.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Obsidian/Net/Packets/Play/Clientbound/PlayerAbilitiesPacket.cs b/Obsidian/Net/Packets/Play/Clientbound/PlayerAbilitiesPacket.cs index 11ac2d852..5e05c3b88 100644 --- a/Obsidian/Net/Packets/Play/Clientbound/PlayerAbilitiesPacket.cs +++ b/Obsidian/Net/Packets/Play/Clientbound/PlayerAbilitiesPacket.cs @@ -56,7 +56,7 @@ public void Populate(byte[] data) public async ValueTask HandleAsync(Server server, Player player) { if (Abilities.HasFlag(PlayerAbility.Flying) - && !Abilities.HasFlag(PlayerAbility.AllowFlying) + && !player.Abilities.HasFlag(PlayerAbility.AllowFlying) && player.Gamemode is not Gamemode.Creative or Gamemode.Spectator) { await player.KickAsync("Cheating is not allowed!"); From b54567d27c663ec320f010c8cbad2190ad09de21 Mon Sep 17 00:00:00 2001 From: "starlkytminecraft@gmail.com" Date: Tue, 27 Feb 2024 22:40:49 +0300 Subject: [PATCH 13/13] Move stuff to API --- Obsidian.API/_Interfaces/IPlayer.cs | 5 ++++- Obsidian.API/_Types/PlayerAbilities.cs | 11 +++++++++++ Obsidian/Entities/Player.cs | 1 + .../Play/Clientbound/PlayerAbilitiesPacket.cs | 13 ++----------- 4 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 Obsidian.API/_Types/PlayerAbilities.cs diff --git a/Obsidian.API/_Interfaces/IPlayer.cs b/Obsidian.API/_Interfaces/IPlayer.cs index 33eb6ec05..f7a4e90ec 100644 --- a/Obsidian.API/_Interfaces/IPlayer.cs +++ b/Obsidian.API/_Interfaces/IPlayer.cs @@ -1,4 +1,5 @@ -using System.Net; +using Obsidian.API._Types; +using System.Net; namespace Obsidian.API; @@ -21,6 +22,8 @@ public interface IPlayer : ILiving public IPAddress? ClientIP { get; } public Gamemode Gamemode { get; set; } + public PlayerAbility Abilities { get; } + public bool Sleeping { get; set; } public bool InHorseInventory { get; set; } diff --git a/Obsidian.API/_Types/PlayerAbilities.cs b/Obsidian.API/_Types/PlayerAbilities.cs new file mode 100644 index 000000000..e2d9d23c7 --- /dev/null +++ b/Obsidian.API/_Types/PlayerAbilities.cs @@ -0,0 +1,11 @@ +namespace Obsidian.API._Types; + +[Flags] +public enum PlayerAbility +{ + None = 0x00, + Invulnerable = 0x01, + Flying = 0x02, + AllowFlying = 0x04, + CreativeMode = 0x08 +} diff --git a/Obsidian/Entities/Player.cs b/Obsidian/Entities/Player.cs index b1450d95f..dbabbcf13 100644 --- a/Obsidian/Entities/Player.cs +++ b/Obsidian/Entities/Player.cs @@ -1,6 +1,7 @@ // This would be saved in a file called [playeruuid].dat which holds a bunch of NBT data. // https://wiki.vg/Map_Format using Microsoft.Extensions.Logging; +using Obsidian.API._Types; using Obsidian.API.Events; using Obsidian.API.Utilities; using Obsidian.Nbt; diff --git a/Obsidian/Net/Packets/Play/Clientbound/PlayerAbilitiesPacket.cs b/Obsidian/Net/Packets/Play/Clientbound/PlayerAbilitiesPacket.cs index 11ac2d852..211f133ee 100644 --- a/Obsidian/Net/Packets/Play/Clientbound/PlayerAbilitiesPacket.cs +++ b/Obsidian/Net/Packets/Play/Clientbound/PlayerAbilitiesPacket.cs @@ -1,17 +1,8 @@ -using Obsidian.Entities; +using Obsidian.API._Types; +using Obsidian.Entities; namespace Obsidian.Net.Packets.Play.Clientbound; -[Flags] -public enum PlayerAbility -{ - None = 0x00, - Invulnerable = 0x01, - Flying = 0x02, - AllowFlying = 0x04, - CreativeMode = 0x08 -} - public class PlayerAbilitiesPacket : IClientboundPacket, IServerboundPacket { public PlayerAbility Abilities { get; set; } = PlayerAbility.None;