Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Allow setting forwarding mode separately for different servers
Dieser Commit ist enthalten in:
Ursprung
350ea7f31e
Commit
52ffca95f4
@ -70,7 +70,7 @@ public class VelocityConfiguration implements ProxyConfig {
|
|||||||
@Expose
|
@Expose
|
||||||
private boolean preventClientProxyConnections = false;
|
private boolean preventClientProxyConnections = false;
|
||||||
@Expose
|
@Expose
|
||||||
private PlayerInfoForwarding playerInfoForwardingMode = PlayerInfoForwarding.NONE;
|
private PlayerInfoForwarding defaultPlayerInfoForwardingMode = PlayerInfoForwarding.NONE;
|
||||||
private byte[] forwardingSecret = generateRandomString(12).getBytes(StandardCharsets.UTF_8);
|
private byte[] forwardingSecret = generateRandomString(12).getBytes(StandardCharsets.UTF_8);
|
||||||
@Expose
|
@Expose
|
||||||
private boolean announceForge = false;
|
private boolean announceForge = false;
|
||||||
@ -113,7 +113,7 @@ public class VelocityConfiguration implements ProxyConfig {
|
|||||||
this.onlineMode = onlineMode;
|
this.onlineMode = onlineMode;
|
||||||
this.preventClientProxyConnections = preventClientProxyConnections;
|
this.preventClientProxyConnections = preventClientProxyConnections;
|
||||||
this.announceForge = announceForge;
|
this.announceForge = announceForge;
|
||||||
this.playerInfoForwardingMode = playerInfoForwardingMode;
|
this.defaultPlayerInfoForwardingMode = playerInfoForwardingMode;
|
||||||
this.forwardingSecret = forwardingSecret;
|
this.forwardingSecret = forwardingSecret;
|
||||||
this.onlineModeKickExistingPlayers = onlineModeKickExistingPlayers;
|
this.onlineModeKickExistingPlayers = onlineModeKickExistingPlayers;
|
||||||
this.pingPassthrough = pingPassthrough;
|
this.pingPassthrough = pingPassthrough;
|
||||||
@ -151,22 +151,40 @@ public class VelocityConfiguration implements ProxyConfig {
|
|||||||
+ "receive any support!");
|
+ "receive any support!");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (playerInfoForwardingMode) {
|
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 " + entry.getKey() + "!"
|
||||||
|
+ " All players will appear to be connecting from the proxy and will have offline-mode UUIDs.");
|
||||||
|
break;
|
||||||
|
case MODERN:
|
||||||
|
case BUNGEEGUARD:
|
||||||
|
requireForwardingSecret = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (defaultPlayerInfoForwardingMode) {
|
||||||
case NONE:
|
case NONE:
|
||||||
logger.warn("Player info forwarding is disabled! All players will appear to be connecting "
|
logger.warn("Player info forwarding is disabled by default! All players will appear to be connecting "
|
||||||
+ "from the proxy and will have offline-mode UUIDs.");
|
+ "from the proxy and will have offline-mode UUIDs.");
|
||||||
break;
|
break;
|
||||||
case MODERN:
|
case MODERN:
|
||||||
case BUNGEEGUARD:
|
case BUNGEEGUARD:
|
||||||
if (forwardingSecret == null || forwardingSecret.length == 0) {
|
requireForwardingSecret = true;
|
||||||
logger.error("You don't have a forwarding secret set. This is required for security.");
|
|
||||||
valid = false;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (requireForwardingSecret && (forwardingSecret == null || forwardingSecret.length == 0)) {
|
||||||
|
logger.error("You don't have a forwarding secret set. This is required for security.");
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (servers.getServers().isEmpty()) {
|
if (servers.getServers().isEmpty()) {
|
||||||
logger.warn("You don't have any servers configured.");
|
logger.warn("You don't have any servers configured.");
|
||||||
}
|
}
|
||||||
@ -293,8 +311,12 @@ public class VelocityConfiguration implements ProxyConfig {
|
|||||||
return preventClientProxyConnections;
|
return preventClientProxyConnections;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerInfoForwarding getPlayerInfoForwardingMode() {
|
public PlayerInfoForwarding getDefaultPlayerInfoForwardingMode() {
|
||||||
return playerInfoForwardingMode;
|
return defaultPlayerInfoForwardingMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerInfoForwarding getServerPlayerInfoForwardingMode(String server) {
|
||||||
|
return servers.getServerForwardingModes().getOrDefault(server, defaultPlayerInfoForwardingMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getForwardingSecret() {
|
public byte[] getForwardingSecret() {
|
||||||
@ -414,7 +436,7 @@ public class VelocityConfiguration implements ProxyConfig {
|
|||||||
.add("motd", motd)
|
.add("motd", motd)
|
||||||
.add("showMaxPlayers", showMaxPlayers)
|
.add("showMaxPlayers", showMaxPlayers)
|
||||||
.add("onlineMode", onlineMode)
|
.add("onlineMode", onlineMode)
|
||||||
.add("playerInfoForwardingMode", playerInfoForwardingMode)
|
.add("defaultPlayerInfoForwardingMode", defaultPlayerInfoForwardingMode)
|
||||||
.add("forwardingSecret", forwardingSecret)
|
.add("forwardingSecret", forwardingSecret)
|
||||||
.add("announceForge", announceForge)
|
.add("announceForge", announceForge)
|
||||||
.add("servers", servers)
|
.add("servers", servers)
|
||||||
@ -572,6 +594,7 @@ public class VelocityConfiguration implements ProxyConfig {
|
|||||||
"minigames", "127.0.0.1:30068"
|
"minigames", "127.0.0.1:30068"
|
||||||
);
|
);
|
||||||
private List<String> attemptConnectionOrder = ImmutableList.of("lobby");
|
private List<String> attemptConnectionOrder = ImmutableList.of("lobby");
|
||||||
|
private Map<String, PlayerInfoForwarding> serverForwardingModes = ImmutableMap.of();
|
||||||
|
|
||||||
private Servers() {
|
private Servers() {
|
||||||
}
|
}
|
||||||
@ -579,9 +602,25 @@ public class VelocityConfiguration implements ProxyConfig {
|
|||||||
private Servers(CommentedConfig config) {
|
private Servers(CommentedConfig config) {
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
Map<String, String> servers = new HashMap<>();
|
Map<String, String> servers = new HashMap<>();
|
||||||
|
Map<String, PlayerInfoForwarding> serverForwardingModes = new HashMap<>();
|
||||||
for (UnmodifiableConfig.Entry entry : config.entrySet()) {
|
for (UnmodifiableConfig.Entry entry : config.entrySet()) {
|
||||||
if (entry.getValue() instanceof String) {
|
if (entry.getValue() instanceof String) {
|
||||||
servers.put(cleanServerName(entry.getKey()), entry.getValue());
|
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 {
|
} else {
|
||||||
if (!entry.getKey().equalsIgnoreCase("try")) {
|
if (!entry.getKey().equalsIgnoreCase("try")) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
@ -591,12 +630,14 @@ public class VelocityConfiguration implements ProxyConfig {
|
|||||||
}
|
}
|
||||||
this.servers = ImmutableMap.copyOf(servers);
|
this.servers = ImmutableMap.copyOf(servers);
|
||||||
this.attemptConnectionOrder = config.getOrElse("try", attemptConnectionOrder);
|
this.attemptConnectionOrder = config.getOrElse("try", attemptConnectionOrder);
|
||||||
|
this.serverForwardingModes = ImmutableMap.copyOf(serverForwardingModes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Servers(Map<String, String> servers, List<String> attemptConnectionOrder) {
|
private Servers(Map<String, String> servers, List<String> attemptConnectionOrder, Map<String, PlayerInfoForwarding> serverForwardingModes) {
|
||||||
this.servers = servers;
|
this.servers = servers;
|
||||||
this.attemptConnectionOrder = attemptConnectionOrder;
|
this.attemptConnectionOrder = attemptConnectionOrder;
|
||||||
|
this.serverForwardingModes = serverForwardingModes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String> getServers() {
|
private Map<String, String> getServers() {
|
||||||
@ -615,6 +656,14 @@ public class VelocityConfiguration implements ProxyConfig {
|
|||||||
this.attemptConnectionOrder = 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;
|
* 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
|
* however, the TOML parser returns the key with the quotes so we need to clean the server name
|
||||||
@ -632,6 +681,7 @@ public class VelocityConfiguration implements ProxyConfig {
|
|||||||
return "Servers{"
|
return "Servers{"
|
||||||
+ "servers=" + servers
|
+ "servers=" + servers
|
||||||
+ ", attemptConnectionOrder=" + attemptConnectionOrder
|
+ ", attemptConnectionOrder=" + attemptConnectionOrder
|
||||||
|
+ ", serverForwardingModes=" + serverForwardingModes
|
||||||
+ '}';
|
+ '}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
public boolean handle(LoginPluginMessagePacket packet) {
|
public boolean handle(LoginPluginMessagePacket packet) {
|
||||||
MinecraftConnection mc = serverConn.ensureConnected();
|
MinecraftConnection mc = serverConn.ensureConnected();
|
||||||
VelocityConfiguration configuration = server.getConfiguration();
|
VelocityConfiguration configuration = server.getConfiguration();
|
||||||
if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
|
if (configuration.getServerPlayerInfoForwardingMode(serverConn.getServerInfo().getName()) == PlayerInfoForwarding.MODERN
|
||||||
&& packet.getChannel().equals(PlayerDataForwarding.CHANNEL)) {
|
&& packet.getChannel().equals(PlayerDataForwarding.CHANNEL)) {
|
||||||
|
|
||||||
int requestedForwardingVersion = PlayerDataForwarding.MODERN_DEFAULT;
|
int requestedForwardingVersion = PlayerDataForwarding.MODERN_DEFAULT;
|
||||||
@ -142,7 +142,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(ServerLoginSuccessPacket packet) {
|
public boolean handle(ServerLoginSuccessPacket packet) {
|
||||||
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
|
if (server.getConfiguration().getServerPlayerInfoForwardingMode(serverConn.getServerInfo().getName()) == PlayerInfoForwarding.MODERN
|
||||||
&& !informationForwarded) {
|
&& !informationForwarded) {
|
||||||
resultFuture.complete(ConnectionRequestResults.forDisconnect(MODERN_IP_FORWARDING_FAILURE,
|
resultFuture.complete(ConnectionRequestResults.forDisconnect(MODERN_IP_FORWARDING_FAILURE,
|
||||||
serverConn.getServer()));
|
serverConn.getServer()));
|
||||||
@ -205,7 +205,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnected() {
|
public void disconnected() {
|
||||||
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.LEGACY) {
|
if (server.getConfiguration().getServerPlayerInfoForwardingMode(serverConn.getServerInfo().getName()) == PlayerInfoForwarding.LEGACY) {
|
||||||
resultFuture.completeExceptionally(new QuietRuntimeException(
|
resultFuture.completeExceptionally(new QuietRuntimeException(
|
||||||
"""
|
"""
|
||||||
The connection to the remote server was unexpectedly closed.
|
The connection to the remote server was unexpectedly closed.
|
||||||
|
@ -163,7 +163,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
|||||||
|
|
||||||
private void startHandshake() {
|
private void startHandshake() {
|
||||||
final MinecraftConnection mc = ensureConnected();
|
final MinecraftConnection mc = ensureConnected();
|
||||||
PlayerInfoForwarding forwardingMode = server.getConfiguration().getPlayerInfoForwardingMode();
|
PlayerInfoForwarding forwardingMode = server.getConfiguration().getServerPlayerInfoForwardingMode(registeredServer.getServerInfo().getName());
|
||||||
|
|
||||||
// Initiate the handshake.
|
// Initiate the handshake.
|
||||||
ProtocolVersion protocolVersion = proxyPlayer.getConnection().getProtocolVersion();
|
ProtocolVersion protocolVersion = proxyPlayer.getConnection().getProtocolVersion();
|
||||||
|
@ -83,7 +83,7 @@ public class AuthSessionHandler implements MinecraftSessionHandler {
|
|||||||
public void activated() {
|
public void activated() {
|
||||||
// Some connection types may need to alter the game profile.
|
// Some connection types may need to alter the game profile.
|
||||||
profile = mcConnection.getType().addGameProfileTokensIfRequired(profile,
|
profile = mcConnection.getType().addGameProfileTokensIfRequired(profile,
|
||||||
server.getConfiguration().getPlayerInfoForwardingMode());
|
server.getConfiguration().getDefaultPlayerInfoForwardingMode());
|
||||||
GameProfileRequestEvent profileRequestEvent = new GameProfileRequestEvent(inbound, profile,
|
GameProfileRequestEvent profileRequestEvent = new GameProfileRequestEvent(inbound, profile,
|
||||||
onlineMode);
|
onlineMode);
|
||||||
final GameProfile finalProfile = profile;
|
final GameProfile finalProfile = profile;
|
||||||
@ -139,7 +139,7 @@ public class AuthSessionHandler implements MinecraftSessionHandler {
|
|||||||
}
|
}
|
||||||
VelocityConfiguration configuration = server.getConfiguration();
|
VelocityConfiguration configuration = server.getConfiguration();
|
||||||
UUID playerUniqueId = player.getUniqueId();
|
UUID playerUniqueId = player.getUniqueId();
|
||||||
if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.NONE) {
|
if (configuration.getDefaultPlayerInfoForwardingMode() == PlayerInfoForwarding.NONE) {
|
||||||
playerUniqueId = UuidUtils.generateOfflinePlayerUuid(player.getUsername());
|
playerUniqueId = UuidUtils.generateOfflinePlayerUuid(player.getUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
|
|||||||
|
|
||||||
// If the proxy is configured for modern forwarding, we must deny connections from 1.12.2
|
// 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.
|
// and lower, otherwise IP information will never get forwarded.
|
||||||
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
|
if (server.getConfiguration().getDefaultPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
|
||||||
&& handshake.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_13)) {
|
&& handshake.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_13)) {
|
||||||
// Bump connection into correct protocol state so that we can send the disconnect packet.
|
// Bump connection into correct protocol state so that we can send the disconnect packet.
|
||||||
connection.setState(StateRegistry.LOGIN);
|
connection.setState(StateRegistry.LOGIN);
|
||||||
|
@ -42,7 +42,7 @@ forwarding-secret-file = "forwarding.secret"
|
|||||||
|
|
||||||
# Announce whether or not your server supports Forge. If you run a modded server, we
|
# Announce whether or not your server supports Forge. If you run a modded server, we
|
||||||
# suggest turning this on.
|
# suggest turning this on.
|
||||||
#
|
#
|
||||||
# If your network runs one modpack consistently, consider using ping-passthrough = "mods"
|
# If your network runs one modpack consistently, consider using ping-passthrough = "mods"
|
||||||
# instead for a nicer display in the server list.
|
# instead for a nicer display in the server list.
|
||||||
announce-forge = false
|
announce-forge = false
|
||||||
@ -76,6 +76,9 @@ lobby = "127.0.0.1:30066"
|
|||||||
factions = "127.0.0.1:30067"
|
factions = "127.0.0.1:30067"
|
||||||
minigames = "127.0.0.1:30068"
|
minigames = "127.0.0.1:30068"
|
||||||
|
|
||||||
|
# If you need a different forwarding mode, specify it like this
|
||||||
|
modern = { address = "127.0.0.1:30069", forwarding-mode = "MODERN" }
|
||||||
|
|
||||||
# In what order we should try servers when a player logs in or is kicked from a server.
|
# In what order we should try servers when a player logs in or is kicked from a server.
|
||||||
try = [
|
try = [
|
||||||
"lobby"
|
"lobby"
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren