aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0663-Validate-usernames.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patches/server/0663-Validate-usernames.patch')
-rw-r--r--patches/server/0663-Validate-usernames.patch35
1 files changed, 21 insertions, 14 deletions
diff --git a/patches/server/0663-Validate-usernames.patch b/patches/server/0663-Validate-usernames.patch
index 51eedf4f14..d3b04f3950 100644
--- a/patches/server/0663-Validate-usernames.patch
+++ b/patches/server/0663-Validate-usernames.patch
@@ -5,7 +5,7 @@ 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
-index b968026728b8b4e549eed9fa9b43919c6c19eb7a..c44a15fc358c28345302b1bf37fc4b111a77fe0e 100644
+index b968026728b8b4e549eed9fa9b43919c6c19eb7a..9bcded0466f3b10fafd709edc44c60f85cb48b7f 100644
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
@@ -83,6 +83,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
@@ -16,12 +16,18 @@ index b968026728b8b4e549eed9fa9b43919c6c19eb7a..c44a15fc358c28345302b1bf37fc4b11
public ServerLoginPacketListenerImpl(MinecraftServer server, Connection connection, boolean transferred) {
this.state = ServerLoginPacketListenerImpl.State.HELLO;
-@@ -164,7 +165,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
+@@ -164,7 +165,13 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
@Override
public void handleHello(ServerboundHelloPacket packet) {
Validate.validState(this.state == ServerLoginPacketListenerImpl.State.HELLO, "Unexpected hello packet", new Object[0]);
- 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
++ // Paper start - Validate usernames
++ if (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode()
++ && io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.performUsernameValidation
++ && !this.iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation) {
++ Validate.validState(StringUtil.isReasonablePlayerName(packet.name()), "Invalid characters in username", new Object[0]);
++ }
++ // Paper end - Validate usernames
this.requestedUsername = packet.name();
GameProfile gameprofile = this.server.getSingleplayerProfile();
@@ -39,22 +45,21 @@ index d7bbdcc97745246718c92c9aba56d9f926897975..7406784899ba5f3575adf1ffe5e5d85a
}
}
diff --git a/src/main/java/net/minecraft/util/StringUtil.java b/src/main/java/net/minecraft/util/StringUtil.java
-index d3fc549a08993376c76c4ebebb788fea3f4ddf69..ae7ef47446c15b8a6878dd2d31b60cd0670eaf83 100644
+index d3fc549a08993376c76c4ebebb788fea3f4ddf69..0bd191acb9596d3aa21c337230d26f09d26f6888 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 {
+@@ -67,6 +67,25 @@ public class StringUtil {
+ return name.length() <= 16 && name.chars().filter(c -> c <= 32 || c >= 127).findAny().isEmpty();
}
- public static boolean isValidPlayerName(String name) {
-- return name.length() <= 16 && name.chars().filter(c -> c <= 32 || c >= 127).findAny().isEmpty();
-+ // Paper start - username validation overriding
-+ if (name == null || name.isEmpty() || name.length() > 16) {
++ // Paper start - Username validation
++ public static boolean isReasonablePlayerName(final String name) {
++ if (name.isEmpty() || name.length() > 16) {
+ return false;
+ }
+
+ for (int i = 0, len = name.length(); i < len; ++i) {
-+ char c = name.charAt(i);
-+
++ final char c = name.charAt(i);
+ if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (c == '_' || c == '.')) {
+ continue;
+ }
@@ -63,7 +68,9 @@ index d3fc549a08993376c76c4ebebb788fea3f4ddf69..ae7ef47446c15b8a6878dd2d31b60cd0
+ }
+
+ return true;
-+ // Paper end - username validation overriding
- }
-
++ }
++ // Paper end - Username validation
++
public static String filterText(String string) {
+ return filterText(string, false);
+ }