From bb41c0f9eef7c47de8edcd62ae76c6d71cb61a26 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Mon, 19 Apr 2021 22:18:18 -0400 Subject: [PATCH] Add an option for setting Bedrock compression level (#2128) --- .../connector/configuration/GeyserConfiguration.java | 2 ++ .../configuration/GeyserJacksonConfiguration.java | 7 +++++++ .../connector/network/ConnectorServerEventHandler.java | 1 + connector/src/main/resources/config.yml | 3 +++ 4 files changed, 13 insertions(+) diff --git a/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java b/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java index 652ec1339..b6af30fed 100644 --- a/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java +++ b/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java @@ -111,6 +111,8 @@ public interface GeyserConfiguration { String getServerName(); + int getCompressionLevel(); + boolean isEnableProxyProtocol(); List getProxyProtocolWhitelistedIPs(); diff --git a/connector/src/main/java/org/geysermc/connector/configuration/GeyserJacksonConfiguration.java b/connector/src/main/java/org/geysermc/connector/configuration/GeyserJacksonConfiguration.java index e9adfe12b..f8b652e53 100644 --- a/connector/src/main/java/org/geysermc/connector/configuration/GeyserJacksonConfiguration.java +++ b/connector/src/main/java/org/geysermc/connector/configuration/GeyserJacksonConfiguration.java @@ -147,6 +147,13 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration @JsonProperty("server-name") private String serverName = GeyserConnector.NAME; + @JsonProperty("compression-level") + private int compressionLevel = 6; + + public int getCompressionLevel() { + return Math.max(-1, Math.min(compressionLevel, 9)); + } + @JsonProperty("enable-proxy-protocol") private boolean enableProxyProtocol = false; diff --git a/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java b/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java index bd5030a8b..554ae9504 100644 --- a/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java @@ -159,6 +159,7 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler { @Override public void onSessionCreation(BedrockServerSession bedrockServerSession) { bedrockServerSession.setLogging(true); + bedrockServerSession.setCompressionLevel(connector.getConfig().getBedrock().getCompressionLevel()); bedrockServerSession.setPacketHandler(new UpstreamPacketHandler(connector, new GeyserSession(connector, bedrockServerSession))); // Set the packet codec to default just in case we need to send disconnect packets. bedrockServerSession.setPacketCodec(BedrockProtocol.DEFAULT_BEDROCK_CODEC); diff --git a/connector/src/main/resources/config.yml b/connector/src/main/resources/config.yml index 6ccddd401..c81bfc675 100644 --- a/connector/src/main/resources/config.yml +++ b/connector/src/main/resources/config.yml @@ -23,6 +23,9 @@ bedrock: motd2: "Another Geyser server." # The Server Name that will be sent to Minecraft: Bedrock Edition clients. This is visible in both the pause menu and the settings menu. server-name: "Geyser" + # How much to compress network traffic to the Bedrock client. The higher the number, the more CPU usage used, but + # the smaller the bandwidth used. Does not have any effect below -1 or above 9. Set to -1 to disable. + compression-level: 6 # Whether to enable PROXY protocol or not for clients. You DO NOT WANT this feature unless you run UDP reverse proxy # in front of your Geyser instance. enable-proxy-protocol: false