3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Allow existing players to be kicked from server if in online-mode

Fixes #226
Dieser Commit ist enthalten in:
Andrew Steinborn 2019-07-19 13:25:04 -04:00
Ursprung 40c8343494
Commit 85e5fb4827
2 geänderte Dateien mit 35 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -70,6 +70,7 @@ import java.util.function.IntFunction;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import net.kyori.text.Component; import net.kyori.text.Component;
import net.kyori.text.TextComponent; import net.kyori.text.TextComponent;
import net.kyori.text.TranslatableComponent;
import net.kyori.text.serializer.gson.GsonComponentSerializer; import net.kyori.text.serializer.gson.GsonComponentSerializer;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -454,6 +455,9 @@ public class VelocityServer implements ProxyServer {
* @return {@code true} if we can register the connection, {@code false} if not * @return {@code true} if we can register the connection, {@code false} if not
*/ */
public boolean canRegisterConnection(ConnectedPlayer connection) { public boolean canRegisterConnection(ConnectedPlayer connection) {
if (configuration.isOnlineMode() && configuration.isOnlineModeKickExistingPlayers()) {
return true;
}
String lowerName = connection.getUsername().toLowerCase(Locale.US); String lowerName = connection.getUsername().toLowerCase(Locale.US);
return !(connectionsByName.containsKey(lowerName) return !(connectionsByName.containsKey(lowerName)
|| connectionsByUuid.containsKey(connection.getUniqueId())); || connectionsByUuid.containsKey(connection.getUniqueId()));
@ -466,6 +470,8 @@ public class VelocityServer implements ProxyServer {
*/ */
public boolean registerConnection(ConnectedPlayer connection) { public boolean registerConnection(ConnectedPlayer connection) {
String lowerName = connection.getUsername().toLowerCase(Locale.US); String lowerName = connection.getUsername().toLowerCase(Locale.US);
if (!this.configuration.isOnlineModeKickExistingPlayers()) {
if (connectionsByName.putIfAbsent(lowerName, connection) != null) { if (connectionsByName.putIfAbsent(lowerName, connection) != null) {
return false; return false;
} }
@ -473,6 +479,16 @@ public class VelocityServer implements ProxyServer {
connectionsByName.remove(lowerName, connection); connectionsByName.remove(lowerName, connection);
return false; return false;
} }
} else {
ConnectedPlayer existing = connectionsByUuid.get(connection.getUniqueId());
if (existing != null) {
existing.disconnect(TranslatableComponent.of("multiplayer.disconnect.duplicate_login"));
}
// We can now replace the entries as needed.
connectionsByName.put(lowerName, connection);
connectionsByUuid.put(connection.getUniqueId(), connection);
}
return true; return true;
} }

Datei anzeigen

@ -77,6 +77,11 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi
@ConfigKey("announce-forge") @ConfigKey("announce-forge")
private boolean announceForge = false; private boolean announceForge = false;
@Comment({"If enabled (default is false) and the proxy is in online mode, Velocity will kick",
"any existing player who is online if a duplicate connection attempt is made."})
@ConfigKey("kick-existing-players")
private boolean onlineModeKickExistingPlayers = false;
@Table("[servers]") @Table("[servers]")
private final Servers servers; private final Servers servers;
@ -109,7 +114,8 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi
private VelocityConfiguration(String bind, String motd, int showMaxPlayers, boolean onlineMode, private VelocityConfiguration(String bind, String motd, int showMaxPlayers, boolean onlineMode,
boolean announceForge, PlayerInfoForwarding playerInfoForwardingMode, byte[] forwardingSecret, boolean announceForge, PlayerInfoForwarding playerInfoForwardingMode, byte[] forwardingSecret,
Servers servers, ForcedHosts forcedHosts, Advanced advanced, Query query, Metrics metrics) { boolean onlineModeKickExistingPlayers, Servers servers, ForcedHosts forcedHosts,
Advanced advanced, Query query, Metrics metrics) {
this.bind = bind; this.bind = bind;
this.motd = motd; this.motd = motd;
this.showMaxPlayers = showMaxPlayers; this.showMaxPlayers = showMaxPlayers;
@ -117,6 +123,7 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi
this.announceForge = announceForge; this.announceForge = announceForge;
this.playerInfoForwardingMode = playerInfoForwardingMode; this.playerInfoForwardingMode = playerInfoForwardingMode;
this.forwardingSecret = forwardingSecret; this.forwardingSecret = forwardingSecret;
this.onlineModeKickExistingPlayers = onlineModeKickExistingPlayers;
this.servers = servers; this.servers = servers;
this.forcedHosts = forcedHosts; this.forcedHosts = forcedHosts;
this.advanced = advanced; this.advanced = advanced;
@ -425,6 +432,7 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi
toml.getBoolean("announce-forge", false), toml.getBoolean("announce-forge", false),
PlayerInfoForwarding.valueOf(forwardingModeName), PlayerInfoForwarding.valueOf(forwardingModeName),
forwardingSecret, forwardingSecret,
toml.getBoolean("kick-existing-players", false),
servers, servers,
forcedHosts, forcedHosts,
advanced, advanced,
@ -443,6 +451,10 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi
return builder.toString(); return builder.toString();
} }
public boolean isOnlineModeKickExistingPlayers() {
return onlineModeKickExistingPlayers;
}
private static class Servers { private static class Servers {
@IsMap @IsMap