2022-01-01 14:48:17 +01:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Sat, 1 Jan 2022 05:19:37 -0800
Subject: [PATCH] Validate usernames
diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
2024-04-25 23:21:18 +02:00
index b968026728b8b4e549eed9fa9b43919c6c19eb7a..c44a15fc358c28345302b1bf37fc4b111a77fe0e 100644
2022-01-01 14:48:17 +01:00
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
2024-04-24 18:15:59 +02:00
@@ -83,6 +83,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
2022-12-07 22:35:34 +01:00
private final String serverId;
2024-04-24 18:15:59 +02:00
private final boolean transferred;
2023-09-22 17:08:04 +02:00
private ServerPlayer player; // CraftBukkit
2022-01-18 04:52:47 +01:00
+ public boolean iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation = false; // Paper - username validation overriding
2024-04-24 18:15:59 +02:00
public ServerLoginPacketListenerImpl(MinecraftServer server, Connection connection, boolean transferred) {
2022-01-18 04:52:47 +01:00
this.state = ServerLoginPacketListenerImpl.State.HELLO;
2024-04-24 18:15:59 +02:00
@@ -164,7 +165,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
2022-01-01 14:48:17 +01:00
@Override
public void handleHello(ServerboundHelloPacket packet) {
Validate.validState(this.state == ServerLoginPacketListenerImpl.State.HELLO, "Unexpected hello packet", new Object[0]);
2024-04-24 18:15:59 +02:00
- Validate.validState(StringUtil.isValidPlayerName(packet.name()), "Invalid characters in username", new Object[0]);
+ if (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode() && io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.performUsernameValidation && !this.iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation) Validate.validState(StringUtil.isValidPlayerName(packet.name()), "Invalid characters in username", new Object[0]); // Paper - config username validation
2023-09-22 17:08:04 +02:00
this.requestedUsername = packet.name();
2022-07-27 23:32:15 +02:00
GameProfile gameprofile = this.server.getSingleplayerProfile();
2022-06-08 14:33:46 +02:00
2022-01-01 14:48:17 +01:00
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
2024-04-25 22:34:46 +02:00
index d7bbdcc97745246718c92c9aba56d9f926897975..7406784899ba5f3575adf1ffe5e5d85ab430a841 100644
2022-01-01 14:48:17 +01:00
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
2024-04-24 18:15:59 +02:00
@@ -676,7 +676,7 @@ public abstract class PlayerList {
2022-01-01 14:48:17 +01:00
for (int i = 0; i < this.players.size(); ++i) {
entityplayer = (ServerPlayer) this.players.get(i);
- if (entityplayer.getUUID().equals(uuid)) {
2022-06-09 10:51:45 +02:00
+ if (entityplayer.getUUID().equals(uuid) || (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode() && entityplayer.getGameProfile().getName().equalsIgnoreCase(gameprofile.getName()))) { // Paper - validate usernames
2022-01-01 14:48:17 +01:00
list.add(entityplayer);
}
}
2024-04-24 18:15:59 +02:00
diff --git a/src/main/java/net/minecraft/util/StringUtil.java b/src/main/java/net/minecraft/util/StringUtil.java
index d3fc549a08993376c76c4ebebb788fea3f4ddf69..ae7ef47446c15b8a6878dd2d31b60cd0670eaf83 100644
--- a/src/main/java/net/minecraft/util/StringUtil.java
+++ b/src/main/java/net/minecraft/util/StringUtil.java
@@ -64,7 +64,23 @@ public class StringUtil {
2023-12-07 02:26:58 +01:00
}
2024-04-24 18:15:59 +02:00
public static boolean isValidPlayerName(String name) {
- return name.length() <= 16 && name.chars().filter(c -> c <= 32 || c >= 127).findAny().isEmpty();
2024-01-18 22:00:40 +01:00
+ // Paper start - username validation overriding
2023-12-07 02:26:58 +01:00
+ if (name == null || name.isEmpty() || name.length() > 16) {
+ return false;
+ }
+
+ for (int i = 0, len = name.length(); i < len; ++i) {
+ char c = name.charAt(i);
+
+ if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (c == '_' || c == '.')) {
+ continue;
+ }
+
+ return false;
+ }
+
+ return true;
2024-01-18 22:00:40 +01:00
+ // Paper end - username validation overriding
2023-12-07 02:26:58 +01:00
}
2024-04-24 18:15:59 +02:00
public static String filterText(String string) {