mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-30 12:11:35 +01:00
parent
c45369311e
commit
cbb35324c1
@ -21,7 +21,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
public void handleHello(ServerboundHelloPacket packet) {
|
public void handleHello(ServerboundHelloPacket packet) {
|
||||||
Validate.validState(this.state == ServerLoginPacketListenerImpl.State.HELLO, "Unexpected hello packet", new Object[0]);
|
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]);
|
- 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();
|
this.requestedUsername = packet.name();
|
||||||
GameProfile gameprofile = this.server.getSingleplayerProfile();
|
GameProfile gameprofile = this.server.getSingleplayerProfile();
|
||||||
|
|
||||||
@ -43,18 +49,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
--- a/src/main/java/net/minecraft/util/StringUtil.java
|
--- a/src/main/java/net/minecraft/util/StringUtil.java
|
||||||
+++ b/src/main/java/net/minecraft/util/StringUtil.java
|
+++ b/src/main/java/net/minecraft/util/StringUtil.java
|
||||||
@@ -0,0 +0,0 @@ public class StringUtil {
|
@@ -0,0 +0,0 @@ public class StringUtil {
|
||||||
|
return name.length() <= 16 && name.chars().filter(c -> c <= 32 || c >= 127).findAny().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isValidPlayerName(String name) {
|
+ // Paper start - Username validation
|
||||||
- return name.length() <= 16 && name.chars().filter(c -> c <= 32 || c >= 127).findAny().isEmpty();
|
+ public static boolean isReasonablePlayerName(final String name) {
|
||||||
+ // Paper start - username validation overriding
|
+ if (name.isEmpty() || name.length() > 16) {
|
||||||
+ if (name == null || name.isEmpty() || name.length() > 16) {
|
|
||||||
+ return false;
|
+ return false;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ for (int i = 0, len = name.length(); i < len; ++i) {
|
+ 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 == '.')) {
|
+ if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (c == '_' || c == '.')) {
|
||||||
+ continue;
|
+ continue;
|
||||||
+ }
|
+ }
|
||||||
@ -63,7 +68,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ return true;
|
+ return true;
|
||||||
+ // Paper end - username validation overriding
|
+ }
|
||||||
}
|
+ // Paper end - Username validation
|
||||||
|
+
|
||||||
public static String filterText(String string) {
|
public static String filterText(String string) {
|
||||||
|
return filterText(string, false);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user