Skip to content

Commit

Permalink
Revert "Integrate multi-forwarding handler for different servers (res…
Browse files Browse the repository at this point in the history
…olves #296)."

This reverts commit b266f6a.
  • Loading branch information
R00tB33rMan committed Sep 4, 2024
1 parent 07dfaa0 commit 46e9cdf
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class VelocityConfiguration implements ProxyConfig {
@Expose
private boolean preventClientProxyConnections = false;
@Expose
private PlayerInfoForwarding defaultForwardingMode = PlayerInfoForwarding.NONE;
private PlayerInfoForwarding playerInfoForwardingMode = PlayerInfoForwarding.NONE;
private byte[] forwardingSecret = generateRandomString(12).getBytes(StandardCharsets.UTF_8);
@Expose
private boolean announceForge = false;
Expand Down Expand Up @@ -121,7 +121,7 @@ private VelocityConfiguration(Servers servers, ForcedHosts forcedHosts, Advanced

private VelocityConfiguration(String bind, String motd, int showMaxPlayers, boolean onlineMode,
boolean preventClientProxyConnections, boolean announceForge,
PlayerInfoForwarding defaultForwardingMode, byte[] forwardingSecret,
PlayerInfoForwarding playerInfoForwardingMode, byte[] forwardingSecret,
boolean onlineModeKickExistingPlayers, PingPassthroughMode pingPassthrough,
boolean enablePlayerAddressLogging, Servers servers, ForcedHosts forcedHosts,
Advanced advanced, Query query, Metrics metrics, boolean forceKeyAuthentication,
Expand All @@ -134,7 +134,7 @@ private VelocityConfiguration(String bind, String motd, int showMaxPlayers, bool
this.onlineMode = onlineMode;
this.preventClientProxyConnections = preventClientProxyConnections;
this.announceForge = announceForge;
this.defaultForwardingMode = defaultForwardingMode;
this.playerInfoForwardingMode = playerInfoForwardingMode;
this.forwardingSecret = forwardingSecret;
this.onlineModeKickExistingPlayers = onlineModeKickExistingPlayers;
this.pingPassthrough = pingPassthrough;
Expand Down Expand Up @@ -180,42 +180,22 @@ public boolean validate() {
+ "receive any support!");
}

boolean requireForwardingSecret = false;
for (Map.Entry<String, PlayerInfoForwarding> entry : servers.getServerForwardingModes().entrySet()) {
switch (entry.getValue()) {
case NONE:
logger.warn("Player info forwarding is disabled for {}!"
+ " All players will appear to be connecting from the proxy and will have offline-mode UUIDs.", entry.getKey());
break;
case MODERN:
case BUNGEEGUARD:
requireForwardingSecret = true;
break;
default:
break;
}
}

switch (defaultForwardingMode) {
switch (playerInfoForwardingMode) {
case NONE:
logger.warn("Player info forwarding is disabled by default! All players will appear to be connecting "
logger.warn("Player info forwarding is disabled! All players will appear to be connecting "
+ "from the proxy and will have offline-mode UUIDs.");
break;
case MODERN:
case BUNGEEGUARD:
requireForwardingSecret = true;
if (forwardingSecret == null || forwardingSecret.length == 0) {
logger.error("You don't have a forwarding secret set. This is required for security.");
valid = false;
}
break;
default:
break;
}


if (requireForwardingSecret && (forwardingSecret == null || forwardingSecret.length == 0)) {
logger.error("You don't have a forwarding secret set. This is required for security. "
+ "See https://docs.papermc.io/velocity for more details.");
valid = false;
}

if (servers.getServers().isEmpty()) {
logger.warn("You don't have any servers configured.");
}
Expand Down Expand Up @@ -342,12 +322,8 @@ public boolean shouldPreventClientProxyConnections() {
return preventClientProxyConnections;
}

public PlayerInfoForwarding getDefaultForwardingMode() {
return defaultForwardingMode;
}

public PlayerInfoForwarding getServerForwardingMode(String server) {
return servers.getServerForwardingModes().getOrDefault(server, defaultForwardingMode);
public PlayerInfoForwarding getPlayerInfoForwardingMode() {
return playerInfoForwardingMode;
}

public byte[] getForwardingSecret() {
Expand Down Expand Up @@ -483,7 +459,7 @@ public String toString() {
.add("motd", motd)
.add("showMaxPlayers", showMaxPlayers)
.add("onlineMode", onlineMode)
.add("defaultForwardingMode", defaultForwardingMode)
.add("playerInfoForwardingMode", playerInfoForwardingMode)
.add("forwardingSecret", forwardingSecret)
.add("announceForge", announceForge)
.add("servers", servers)
Expand Down Expand Up @@ -705,7 +681,6 @@ private static class Servers {
"minigames", "127.0.0.1:30068"
);
private List<String> attemptConnectionOrder = ImmutableList.of("lobby");
private Map<String, PlayerInfoForwarding> serverForwardingModes = ImmutableMap.of();

private boolean enableDynamicFallbacks = false;

Expand All @@ -715,25 +690,9 @@ private Servers() {
private Servers(CommentedConfig config) {
if (config != null) {
Map<String, String> servers = new HashMap<>();
Map<String, PlayerInfoForwarding> serverForwardingModes = new HashMap<>();
for (UnmodifiableConfig.Entry entry : config.entrySet()) {
if (entry.getValue() instanceof String) {
servers.put(cleanServerName(entry.getKey()), entry.getValue());
} else if (entry.getValue() instanceof UnmodifiableConfig) {
UnmodifiableConfig unmodifiableConfig = entry.getValue();
String name = entry.getKey();

String address = unmodifiableConfig.get("address");
if (address == null) {
throw new IllegalArgumentException("Server " + name + " doesn't have an address!");
}

PlayerInfoForwarding mode = unmodifiableConfig.getEnum("forwarding-mode", PlayerInfoForwarding.class);
if (mode != null) {
serverForwardingModes.put(name, mode);
}

servers.put(name, address);
} else {
if (!entry.getKey().equalsIgnoreCase("try") && !entry.getKey().equalsIgnoreCase("enable-dynamic-fallbacks")) {
throw new IllegalArgumentException(
Expand All @@ -747,10 +706,9 @@ private Servers(CommentedConfig config) {
}
}

private Servers(Map<String, String> servers, List<String> attemptConnectionOrder, Map<String, PlayerInfoForwarding> serverForwardingModes) {
private Servers(Map<String, String> servers, List<String> attemptConnectionOrder) {
this.servers = servers;
this.attemptConnectionOrder = attemptConnectionOrder;
this.serverForwardingModes = ImmutableMap.copyOf(serverForwardingModes);
}

private Map<String, String> getServers() {
Expand All @@ -773,14 +731,6 @@ public void setAttemptConnectionOrder(List<String> attemptConnectionOrder) {
this.attemptConnectionOrder = attemptConnectionOrder;
}

public Map<String, PlayerInfoForwarding> getServerForwardingModes() {
return serverForwardingModes;
}

public void setServerForwardingModes(Map<String, PlayerInfoForwarding> serverForwardingModes) {
this.serverForwardingModes = serverForwardingModes;
}

/**
* TOML requires keys to match a regex of {@code [A-Za-z0-9_-]} unless it is wrapped in quotes;
* however, the TOML parser returns the key with the quotes so we need to clean the server name
Expand All @@ -798,7 +748,6 @@ public String toString() {
return "Servers{"
+ "servers=" + servers
+ ", attemptConnectionOrder=" + attemptConnectionOrder
+ ", serverForwardingModes=" + serverForwardingModes
+ '}';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public boolean handle(EncryptionRequestPacket packet) {
public boolean handle(LoginPluginMessagePacket packet) {
MinecraftConnection mc = serverConn.ensureConnected();
VelocityConfiguration configuration = server.getConfiguration();
if (configuration.getServerForwardingMode(serverConn.getServerInfo().getName()) == PlayerInfoForwarding.MODERN
if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
&& packet.getChannel().equals(PlayerDataForwarding.CHANNEL)) {

int requestedForwardingVersion = PlayerDataForwarding.MODERN_DEFAULT;
Expand Down Expand Up @@ -144,8 +144,7 @@ public boolean handle(SetCompressionPacket packet) {

@Override
public boolean handle(ServerLoginSuccessPacket packet) {
if (server.getConfiguration().getServerForwardingMode(serverConn.getServerInfo().getName()) == PlayerInfoForwarding.MODERN
&& !informationForwarded) {
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && !informationForwarded) {
resultFuture.complete(ConnectionRequestResults.forDisconnect(MODERN_IP_FORWARDING_FAILURE, serverConn.getServer()));
serverConn.disconnect();
return true;
Expand Down Expand Up @@ -204,7 +203,7 @@ public void exception(Throwable throwable) {

@Override
public void disconnected() {
if (server.getConfiguration().getServerForwardingMode(serverConn.getServerInfo().getName()) == PlayerInfoForwarding.LEGACY) {
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.LEGACY) {
resultFuture.completeExceptionally(new QuietRuntimeException(
"""
The connection to the remote server was unexpectedly closed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private String createBungeeGuardForwardingAddress(byte[] forwardingSecret) {

private void startHandshake() {
final MinecraftConnection mc = ensureConnected();
PlayerInfoForwarding forwardingMode = server.getConfiguration().getServerForwardingMode(registeredServer.getServerInfo().getName());
PlayerInfoForwarding forwardingMode = server.getConfiguration().getPlayerInfoForwardingMode();

// Initiate the handshake.
ProtocolVersion protocolVersion = proxyPlayer.getConnection().getProtocolVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class AuthSessionHandler implements MinecraftSessionHandler {
public void activated() {
// Some connection types may need to alter the game profile.
profile = mcConnection.getType().addGameProfileTokensIfRequired(profile,
server.getConfiguration().getDefaultForwardingMode());
server.getConfiguration().getPlayerInfoForwardingMode());
GameProfileRequestEvent profileRequestEvent = new GameProfileRequestEvent(inbound, profile,
onlineMode);
final GameProfile finalProfile = profile;
Expand Down Expand Up @@ -179,7 +179,7 @@ private void startLoginCompletion(ConnectedPlayer player) {
}
VelocityConfiguration configuration = server.getConfiguration();
UUID playerUniqueId = player.getUniqueId();
if (configuration.getDefaultForwardingMode() == PlayerInfoForwarding.NONE) {
if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.NONE) {
playerUniqueId = UuidUtils.generateOfflinePlayerUuid(player.getUsername());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void handleLogin(HandshakePacket handshake, InitialInboundConnection ic)

// If the proxy is configured for modern forwarding, we must deny connections from 1.12.2
// and lower, otherwise IP information will never get forwarded.
if (server.getConfiguration().getDefaultForwardingMode() == PlayerInfoForwarding.MODERN
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
&& handshake.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_13)) {
// Bump connection into correct protocol state so that we can send the disconnect packet.
connection.setState(StateRegistry.LOGIN);
Expand Down
3 changes: 0 additions & 3 deletions proxy/src/main/resources/default-velocity.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ lobby = "127.0.0.1:30066"
factions = "127.0.0.1:30067"
minigames = "127.0.0.1:30068"

# If you need a different forwarding mode, specify as shown:
minigames = { address = "127.0.0.1:30068", forwarding-mode = "MODERN" }

# In what order we should try servers when a player logs in or is kicked from a server.
try = [
"lobby"
Expand Down

0 comments on commit 46e9cdf

Please sign in to comment.