Show proxy-wide online players in server ping (#811)
* Show proxy-wide online players in server ping * Reflow arguments in VelocityConfiguration constructor
This commit is contained in:
@@ -516,6 +516,10 @@ public final class ServerPing {
|
|||||||
*/
|
*/
|
||||||
public static final class SamplePlayer {
|
public static final class SamplePlayer {
|
||||||
|
|
||||||
|
public static final SamplePlayer ANONYMOUS = new SamplePlayer(
|
||||||
|
"Anonymous Player",
|
||||||
|
new UUID(0L, 0L)
|
||||||
|
);
|
||||||
private final String name;
|
private final String name;
|
||||||
private final UUID id;
|
private final UUID id;
|
||||||
|
|
||||||
|
@@ -78,6 +78,8 @@ public class VelocityConfiguration implements ProxyConfig {
|
|||||||
private boolean onlineModeKickExistingPlayers = false;
|
private boolean onlineModeKickExistingPlayers = false;
|
||||||
@Expose
|
@Expose
|
||||||
private PingPassthroughMode pingPassthrough = PingPassthroughMode.DISABLED;
|
private PingPassthroughMode pingPassthrough = PingPassthroughMode.DISABLED;
|
||||||
|
@Expose
|
||||||
|
private boolean samplePlayersInPing = false;
|
||||||
private final Servers servers;
|
private final Servers servers;
|
||||||
private final ForcedHosts forcedHosts;
|
private final ForcedHosts forcedHosts;
|
||||||
@Expose
|
@Expose
|
||||||
@@ -105,8 +107,9 @@ public class VelocityConfiguration implements ProxyConfig {
|
|||||||
boolean preventClientProxyConnections, boolean announceForge,
|
boolean preventClientProxyConnections, boolean announceForge,
|
||||||
PlayerInfoForwarding playerInfoForwardingMode, byte[] forwardingSecret,
|
PlayerInfoForwarding playerInfoForwardingMode, byte[] forwardingSecret,
|
||||||
boolean onlineModeKickExistingPlayers, PingPassthroughMode pingPassthrough,
|
boolean onlineModeKickExistingPlayers, PingPassthroughMode pingPassthrough,
|
||||||
boolean enablePlayerAddressLogging, Servers servers, ForcedHosts forcedHosts,
|
boolean samplePlayersInPing, boolean enablePlayerAddressLogging, Servers servers,
|
||||||
Advanced advanced, Query query, Metrics metrics, boolean forceKeyAuthentication) {
|
ForcedHosts forcedHosts, Advanced advanced, Query query, Metrics metrics,
|
||||||
|
boolean forceKeyAuthentication) {
|
||||||
this.bind = bind;
|
this.bind = bind;
|
||||||
this.motd = motd;
|
this.motd = motd;
|
||||||
this.showMaxPlayers = showMaxPlayers;
|
this.showMaxPlayers = showMaxPlayers;
|
||||||
@@ -117,6 +120,7 @@ public class VelocityConfiguration implements ProxyConfig {
|
|||||||
this.forwardingSecret = forwardingSecret;
|
this.forwardingSecret = forwardingSecret;
|
||||||
this.onlineModeKickExistingPlayers = onlineModeKickExistingPlayers;
|
this.onlineModeKickExistingPlayers = onlineModeKickExistingPlayers;
|
||||||
this.pingPassthrough = pingPassthrough;
|
this.pingPassthrough = pingPassthrough;
|
||||||
|
this.samplePlayersInPing = samplePlayersInPing;
|
||||||
this.enablePlayerAddressLogging = enablePlayerAddressLogging;
|
this.enablePlayerAddressLogging = enablePlayerAddressLogging;
|
||||||
this.servers = servers;
|
this.servers = servers;
|
||||||
this.forcedHosts = forcedHosts;
|
this.forcedHosts = forcedHosts;
|
||||||
@@ -371,6 +375,10 @@ public class VelocityConfiguration implements ProxyConfig {
|
|||||||
return pingPassthrough;
|
return pingPassthrough;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getSamplePlayersInPing() {
|
||||||
|
return samplePlayersInPing;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isPlayerAddressLoggingEnabled() {
|
public boolean isPlayerAddressLoggingEnabled() {
|
||||||
return enablePlayerAddressLogging;
|
return enablePlayerAddressLogging;
|
||||||
}
|
}
|
||||||
@@ -507,6 +515,8 @@ public class VelocityConfiguration implements ProxyConfig {
|
|||||||
final PingPassthroughMode pingPassthroughMode = config.getEnumOrElse("ping-passthrough",
|
final PingPassthroughMode pingPassthroughMode = config.getEnumOrElse("ping-passthrough",
|
||||||
PingPassthroughMode.DISABLED);
|
PingPassthroughMode.DISABLED);
|
||||||
|
|
||||||
|
final boolean samplePlayersInPing = config.getOrElse("sample-players-in-ping", false);
|
||||||
|
|
||||||
final String bind = config.getOrElse("bind", "0.0.0.0:25565");
|
final String bind = config.getOrElse("bind", "0.0.0.0:25565");
|
||||||
final int maxPlayers = config.getIntOrElse("show-max-players", 500);
|
final int maxPlayers = config.getIntOrElse("show-max-players", 500);
|
||||||
final boolean onlineMode = config.getOrElse("online-mode", true);
|
final boolean onlineMode = config.getOrElse("online-mode", true);
|
||||||
@@ -537,6 +547,7 @@ public class VelocityConfiguration implements ProxyConfig {
|
|||||||
forwardingSecret,
|
forwardingSecret,
|
||||||
kickExisting,
|
kickExisting,
|
||||||
pingPassthroughMode,
|
pingPassthroughMode,
|
||||||
|
samplePlayersInPing,
|
||||||
enablePlayerAddressLogging,
|
enablePlayerAddressLogging,
|
||||||
new Servers(serversConfig),
|
new Servers(serversConfig),
|
||||||
new ForcedHosts(forcedHostsConfig),
|
new ForcedHosts(forcedHostsConfig),
|
||||||
|
@@ -30,10 +30,12 @@ import com.velocitypowered.proxy.config.VelocityConfiguration;
|
|||||||
import com.velocitypowered.proxy.server.VelocityRegisteredServer;
|
import com.velocitypowered.proxy.server.VelocityRegisteredServer;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common utilities for handling server list ping results.
|
* Common utilities for handling server list ping results.
|
||||||
@@ -51,11 +53,27 @@ public class ServerListPingHandler {
|
|||||||
version = ProtocolVersion.MAXIMUM_VERSION;
|
version = ProtocolVersion.MAXIMUM_VERSION;
|
||||||
}
|
}
|
||||||
VelocityConfiguration configuration = server.getConfiguration();
|
VelocityConfiguration configuration = server.getConfiguration();
|
||||||
|
List<ServerPing.SamplePlayer> samplePlayers;
|
||||||
|
if (configuration.getSamplePlayersInPing()) {
|
||||||
|
List<ServerPing.SamplePlayer> unshuffledPlayers = server.getAllPlayers().stream()
|
||||||
|
.map(p -> {
|
||||||
|
if (p.getPlayerSettings().isClientListingAllowed()) {
|
||||||
|
return new ServerPing.SamplePlayer(p.getUsername(), p.getUniqueId());
|
||||||
|
} else {
|
||||||
|
return ServerPing.SamplePlayer.ANONYMOUS;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
Collections.shuffle(unshuffledPlayers);
|
||||||
|
samplePlayers = unshuffledPlayers.subList(0, Math.min(12, server.getPlayerCount()));
|
||||||
|
} else {
|
||||||
|
samplePlayers = ImmutableList.of();
|
||||||
|
}
|
||||||
return new ServerPing(
|
return new ServerPing(
|
||||||
new ServerPing.Version(version.getProtocol(),
|
new ServerPing.Version(version.getProtocol(),
|
||||||
"Velocity " + ProtocolVersion.SUPPORTED_VERSION_STRING),
|
"Velocity " + ProtocolVersion.SUPPORTED_VERSION_STRING),
|
||||||
new ServerPing.Players(server.getPlayerCount(), configuration.getShowMaxPlayers(),
|
new ServerPing.Players(server.getPlayerCount(), configuration.getShowMaxPlayers(),
|
||||||
ImmutableList.of()),
|
samplePlayers),
|
||||||
configuration.getMotd(),
|
configuration.getMotd(),
|
||||||
configuration.getFavicon().orElse(null),
|
configuration.getFavicon().orElse(null),
|
||||||
configuration.isAnnounceForge() ? ModInfo.DEFAULT : null
|
configuration.isAnnounceForge() ? ModInfo.DEFAULT : null
|
||||||
|
@@ -66,6 +66,11 @@ kick-existing-players = false
|
|||||||
# configuration is used if no servers could be contacted.
|
# configuration is used if no servers could be contacted.
|
||||||
ping-passthrough = "DISABLED"
|
ping-passthrough = "DISABLED"
|
||||||
|
|
||||||
|
# If enabled (default is false), then a sample of the online players on the proxy will be visible
|
||||||
|
# when hovering over the player count in the server list.
|
||||||
|
# This doesn't have any effect when ping passthrough is set to either "description" or "all".
|
||||||
|
sample-players-in-ping = false
|
||||||
|
|
||||||
# If not enabled (default is true) player IP addresses will be replaced by <ip address withheld> in logs
|
# If not enabled (default is true) player IP addresses will be replaced by <ip address withheld> in logs
|
||||||
enable-player-address-logging = true
|
enable-player-address-logging = true
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user