diff --git a/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java b/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java index 88fe44000..ec5d35a50 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java @@ -22,7 +22,7 @@ public class ServerPing { this(version, players, description, favicon, Modinfo.DEFAULT); } - public ServerPing(Version version, @Nullable Players players, Component description, @Nullable Favicon favicon, Modinfo modinfo) { + public ServerPing(Version version, @Nullable Players players, Component description, @Nullable Favicon favicon, @Nullable Modinfo modinfo) { this.version = Preconditions.checkNotNull(version, "version"); this.players = players; this.description = Preconditions.checkNotNull(description, "description"); @@ -46,6 +46,10 @@ public class ServerPing { return Optional.ofNullable(favicon); } + public Optional getModinfo() { + return Optional.ofNullable(modinfo); + } + @Override public String toString() { return "ServerPing{" + @@ -59,11 +63,16 @@ public class ServerPing { public Builder asBuilder() { Builder builder = new Builder(); builder.version = version; - builder.onlinePlayers = players.online; - builder.maximumPlayers = players.max; - builder.samplePlayers.addAll(players.sample); + if (players != null) { + builder.onlinePlayers = players.online; + builder.maximumPlayers = players.max; + builder.samplePlayers.addAll(players.sample); + } else { + builder.nullOutPlayers = true; + } builder.description = description; builder.favicon = favicon; + builder.nullOutModinfo = modinfo == null; return builder; } @@ -83,6 +92,7 @@ public class ServerPing { private Component description; private Favicon favicon; private boolean nullOutPlayers; + private boolean nullOutModinfo; private Builder() { @@ -123,6 +133,11 @@ public class ServerPing { return this; } + public Builder notModCompatible() { + this.nullOutModinfo = true; + return this; + } + public Builder nullPlayers() { this.nullOutPlayers = true; return this; @@ -140,7 +155,7 @@ public class ServerPing { public ServerPing build() { return new ServerPing(version, nullOutPlayers ? null : new Players(onlinePlayers, maximumPlayers, samplePlayers), description, favicon, - new Modinfo(mods)); + nullOutModinfo ? null : new Modinfo(mods)); } public Version getVersion() { @@ -182,6 +197,7 @@ public class ServerPing { ", description=" + description + ", favicon=" + favicon + ", nullOutPlayers=" + nullOutPlayers + + ", nullOutModinfo=" + nullOutModinfo + '}'; } } 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 2a7e214ac..470e064f8 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java @@ -1,5 +1,6 @@ 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.util.Favicon; @@ -48,7 +49,7 @@ public class VelocityConfiguration extends AnnotatedConfig { @Comment({ "Should we forward IP addresses and other data to backend servers?", "Available options:", - "- \"none\": No forwarding will be done. All players will appear to be Should we forward IP addresses and other data to backend servers?connecting from the proxy", + "- \"none\": No forwarding will be done. All players will appear to be connecting from the proxy", " and will have offline-mode UUIDs.", "- \"legacy\": Forward player IPs and UUIDs in BungeeCord-compatible fashion. Use this if you run", " servers using Minecraft 1.12 or lower.", @@ -62,6 +63,10 @@ public class VelocityConfiguration extends AnnotatedConfig { @ConfigKey("forwarding-secret") private byte[] forwardingSecret = generateRandomString(12).getBytes(StandardCharsets.UTF_8); + @Comment("Announce whether or not your server supports Forge/FML. If you run a modded server, we suggest turning this on.") + @ConfigKey("announce-forge") + private boolean announceForge = false; + @Table("[servers]") private final Servers servers; @@ -83,12 +88,13 @@ public class VelocityConfiguration extends AnnotatedConfig { } private VelocityConfiguration(String bind, String motd, int showMaxPlayers, boolean onlineMode, - PlayerInfoForwarding playerInfoForwardingMode, byte[] forwardingSecret, Servers servers, - Advanced advanced, Query query) { + boolean announceForge, PlayerInfoForwarding playerInfoForwardingMode, byte[] forwardingSecret, + Servers servers, Advanced advanced, Query query) { this.bind = bind; this.motd = motd; this.showMaxPlayers = showMaxPlayers; this.onlineMode = onlineMode; + this.announceForge = announceForge; this.playerInfoForwardingMode = playerInfoForwardingMode; this.forwardingSecret = forwardingSecret; this.servers = servers; @@ -263,54 +269,26 @@ public class VelocityConfiguration extends AnnotatedConfig { return favicon; } - private void setBind(String bind) { - this.bind = bind; - } - - private void setMotd(String motd) { - this.motd = motd; - } - - private void setShowMaxPlayers(int showMaxPlayers) { - this.showMaxPlayers = showMaxPlayers; - } - - private void setOnlineMode(boolean onlineMode) { - this.onlineMode = onlineMode; - } - - private void setPlayerInfoForwardingMode(PlayerInfoForwarding playerInfoForwardingMode) { - this.playerInfoForwardingMode = playerInfoForwardingMode; - } - - private void setForwardingSecret(byte[] forwardingSecret) { - this.forwardingSecret = forwardingSecret; - } - - private void setMotdAsComponent(Component motdAsComponent) { - this.motdAsComponent = motdAsComponent; - } - - private void setFavicon(Favicon favicon) { - this.favicon = favicon; + public boolean isAnnounceForge() { + return announceForge; } @Override public String toString() { - - return "VelocityConfiguration{" - + "bind='" + bind + '\'' - + ", motd='" + motd + '\'' - + ", showMaxPlayers=" + showMaxPlayers - + ", onlineMode=" + onlineMode - + ", playerInfoForwardingMode=" + playerInfoForwardingMode - + ", forwardingSecret=" + ByteBufUtil.hexDump(forwardingSecret) - + ", servers=" + servers - + ", advanced=" + advanced - + ", query=" + query - + ", motdAsComponent=" + motdAsComponent - + ", favicon=" + favicon - + '}'; + return MoreObjects.toStringHelper(this) + .add("configVersion", configVersion) + .add("bind", bind) + .add("motd", motd) + .add("showMaxPlayers", showMaxPlayers) + .add("onlineMode", onlineMode) + .add("playerInfoForwardingMode", playerInfoForwardingMode) + .add("forwardingSecret", forwardingSecret) + .add("announceForge", announceForge) + .add("servers", servers) + .add("advanced", advanced) + .add("query", query) + .add("favicon", favicon) + .toString(); } public static VelocityConfiguration read(Path path) throws IOException { @@ -335,6 +313,7 @@ public class VelocityConfiguration extends AnnotatedConfig { toml.getString("motd", "&3A Velocity Server"), toml.getLong("show-max-players", 500L).intValue(), toml.getBoolean("online-mode", true), + toml.getBoolean("announce-forge", false), PlayerInfoForwarding.valueOf(toml.getString("player-info-forwarding-mode", "MODERN").toUpperCase()), forwardingSecret, servers, diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java index b6b2dafe5..54899d2a1 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java @@ -108,6 +108,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { new ServerPing.Version(ProtocolConstants.MAXIMUM_GENERIC_VERSION, "Velocity " + ProtocolConstants.SUPPORTED_GENERIC_VERSION_STRING), new ServerPing.Players(server.getPlayerCount(), configuration.getShowMaxPlayers(), ImmutableList.of()), configuration.getMotdComponent(), + null, null ); ProxyPingEvent event = new ProxyPingEvent(new LegacyInboundConnection(connection), ping); 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 863c32e59..ccc53a8ac 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 @@ -48,7 +48,8 @@ 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(), + configuration.isAnnounceForge() ? ServerPing.Modinfo.DEFAULT : null ); ProxyPingEvent event = new ProxyPingEvent(inboundWrapper, initialPing);