From aa34977f3ea5e3bf26242e421b33abdb0ba064b6 Mon Sep 17 00:00:00 2001 From: Crypnotic Date: Sun, 30 Sep 2018 19:12:55 -0500 Subject: [PATCH] Added ProxyConfig interface and implemented in VelocityConfiguration --- .../api/proxy/ProxyServer.java | 7 ++ .../api/proxy/config/ProxyConfig.java | 103 ++++++++++++++++++ .../proxy/config/VelocityConfiguration.java | 7 +- .../backend/VelocityServerConnection.java | 1 - .../client/LoginSessionHandler.java | 1 - .../client/StatusSessionHandler.java | 2 +- 6 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 api/src/main/java/com/velocitypowered/api/proxy/config/ProxyConfig.java diff --git a/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java b/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java index 11bf095ff..9c6a2daf6 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java @@ -4,6 +4,7 @@ import com.velocitypowered.api.command.CommandManager; import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.event.EventManager; import com.velocitypowered.api.plugin.PluginManager; +import com.velocitypowered.api.proxy.config.ProxyConfig; import com.velocitypowered.api.proxy.messages.ChannelRegistrar; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.ServerInfo; @@ -124,4 +125,10 @@ public interface ProxyServer { * @return the address the proxy is bound to */ InetSocketAddress getBoundAddress(); + + /** + * Gets the {@link ProxyConfig} instance. + * @return the proxy config + * */ + ProxyConfig getConfiguration(); } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/config/ProxyConfig.java b/api/src/main/java/com/velocitypowered/api/proxy/config/ProxyConfig.java new file mode 100644 index 000000000..85cbaa30d --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/proxy/config/ProxyConfig.java @@ -0,0 +1,103 @@ +package com.velocitypowered.api.proxy.config; + +import com.velocitypowered.api.util.Favicon; +import net.kyori.text.Component; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + * Provides an interface to a proxy configuration + */ +public interface ProxyConfig { + /** + * Whether GameSpy 4 queries are accepted by the proxy + * @return queries enabled + */ + boolean isQueryEnabled(); + + /** + * Get the port GameSpy 4 queries are accepted on + * @return the query port + */ + int getQueryPort(); + + /** + * Get the map name reported to GameSpy 4 query services + * @return the map name + */ + String getQueryMap(); + + /** + * Get the MOTD component shown in the tab list + * @return the motd component + */ + Component getMotdComponent(); + + /** + * Get the maximum players shown in the tab list + * @return max players + */ + int getShowMaxPlayers(); + + /** + * Get whether the proxy is online mode. This determines if players are authenticated with Mojang servers. + * @return online mode enabled + */ + boolean isOnlineMode(); + + /** + * Get a Map of all servers registered on this proxy + * @return registered servers map + */ + Map getServers(); + + /** + * Get the order of servers that players will be connected to + * @return connection order list + */ + List getAttemptConnectionOrder(); + + /** + * Get the minimum compression threshold for packets + * @return the compression threshold + */ + int getCompressionThreshold(); + + /** + * Get the level of compression that packets will be compressed to + * @return the compression level + */ + int getCompressionLevel(); + + /** + * Get the limit for how long a player must wait to log back in + * @return the login rate limit (in milliseconds) + */ + int getLoginRatelimit(); + + /** + * Get the proxy favicon shown in the tablist + * @return optional favicon + */ + Optional getFavicon(); + + /** + * Get whether this proxy displays that it supports Forge/FML + * @return forge announce enabled + */ + boolean isAnnounceForge(); + + /** + * Get how long this proxy will wait until performing a read timeout + * @return connection timeout (in milliseconds) + */ + int getConnectTimeout(); + + /** + * Get how long this proxy will wait until performing a read timeout + * @return read timeout (in milliseconds) + */ + int getReadTimeout(); +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java index 3be6d2eb1..f42cd28ce 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java @@ -3,6 +3,7 @@ package com.velocitypowered.proxy.config; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; import com.moandjiezana.toml.Toml; +import com.velocitypowered.api.proxy.config.ProxyConfig; import com.velocitypowered.api.util.Favicon; import com.velocitypowered.proxy.util.AddressUtil; import net.kyori.text.Component; @@ -18,7 +19,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.*; -public class VelocityConfiguration extends AnnotatedConfig { +public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfig { @Comment("Config version. Do not change this") @ConfigKey("config-version") @@ -263,8 +264,8 @@ public class VelocityConfiguration extends AnnotatedConfig { return advanced.getLoginRatelimit(); } - public Favicon getFavicon() { - return favicon; + public Optional getFavicon() { + return Optional.ofNullable(favicon); } public boolean isAnnounceForge() { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java index d4ceb7402..40718cd30 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java @@ -21,7 +21,6 @@ import com.velocitypowered.proxy.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.ServerLogin; import com.velocitypowered.proxy.server.VelocityRegisteredServer; import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelInitializer; import io.netty.handler.timeout.ReadTimeoutHandler; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java index ed942a40c..6111f8d27 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java @@ -15,7 +15,6 @@ import com.velocitypowered.proxy.config.PlayerInfoForwarding; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.VelocityConstants; -import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.packet.*; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java index a172ec254..0ccd87511 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java @@ -41,7 +41,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler { new ServerPing.Version(shownVersion, "Velocity " + ProtocolConstants.SUPPORTED_GENERIC_VERSION_STRING), new ServerPing.Players(server.getPlayerCount(), configuration.getShowMaxPlayers(), ImmutableList.of()), configuration.getMotdComponent(), - configuration.getFavicon(), + configuration.getFavicon().orElse(null), configuration.isAnnounceForge() ? ServerPing.ModInfo.DEFAULT : null );