From 6248ae2088e1d1c928891f314bb77e31b74b76f7 Mon Sep 17 00:00:00 2001 From: "starlkytminecraft@gmail.com" Date: Thu, 22 Feb 2024 00:35:48 +0300 Subject: [PATCH 1/4] 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 2/4] 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 3/4] 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 4/4] 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