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-01-22 21:04:08 +01:00
index d4658328eeecb1c9e3e25eec14dea07e9e2a8b74..ebda34825bbd10145a81d54c345e31c2a4fb5de4 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
2023-12-06 17:00:26 +01:00
@@ -63,6 +63,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
2023-09-23 00:33:14 +02:00
public GameProfile authenticatedProfile; // Paper - public
2022-12-07 22:35:34 +01:00
private final String serverId;
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
public ServerLoginPacketListenerImpl(MinecraftServer server, Connection connection) {
this.state = ServerLoginPacketListenerImpl.State.HELLO;
2023-12-07 02:26:58 +01:00
@@ -137,7 +138,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]);
2023-12-07 02:26:58 +01:00
- Validate.validState(Player.isValidUsername(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(Player.isValidUsername(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-01-24 15:57:53 +01:00
index edeec3dd7887fbde9456e39c023d4a2dd9b6ffc5..f66f7e8070cbe7628a6e4ae69418fb863f684fae 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-01-23 14:34:17 +01:00
@@ -678,7 +678,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);
}
}
2023-12-07 02:26:58 +01:00
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
2024-01-24 11:45:17 +01:00
index c6a4252979da274ec5c3c6d95548c18e12977c3b..2b68edde9fa03aa04793d3a44dd6edbdbeaf6722 100644
2023-12-07 02:26:58 +01:00
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
2024-01-24 11:45:17 +01:00
@@ -2330,9 +2330,23 @@ public abstract class Player extends LivingEntity {
2023-12-07 02:26:58 +01:00
}
public static boolean isValidUsername(String name) {
- return name.length() > 16 ? false : name.chars().filter((i) -> {
- return i <= 32 || i >= 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
}
public static float getPickRange(boolean creative) {