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
|
2022-12-19 11:46:55 +01:00
|
|
|
index 00e2692dd5e2b6a17c0f5c9e149b90977afc1237..3911daf2a51da1c39adbe8486ecc8fa16093f898 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
|
2022-12-07 22:35:34 +01:00
|
|
|
@@ -60,6 +60,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
|
|
|
|
private final String serverId;
|
2022-08-08 17:25:41 +02:00
|
|
|
@Nullable
|
2022-12-07 22:35:34 +01:00
|
|
|
private ServerPlayer delayedAcceptPlayer;
|
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;
|
2022-12-07 22:35:34 +01:00
|
|
|
@@ -212,10 +213,38 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
|
|
|
|
// Paper end
|
2022-01-01 14:48:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start - validate usernames
|
|
|
|
+ public static boolean validateUsername(String in) {
|
|
|
|
+ if (in == null || in.isEmpty() || in.length() > 16) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (int i = 0, len = in.length(); i < len; ++i) {
|
|
|
|
+ char c = in.charAt(i);
|
|
|
|
+
|
2022-01-01 20:50:44 +01:00
|
|
|
+ if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (c == '_' || c == '.')) {
|
2022-01-01 14:48:17 +01:00
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ // Paper end - validate usernames
|
|
|
|
+
|
|
|
|
@Override
|
|
|
|
public void handleHello(ServerboundHelloPacket packet) {
|
|
|
|
Validate.validState(this.state == ServerLoginPacketListenerImpl.State.HELLO, "Unexpected hello packet", new Object[0]);
|
2022-06-08 14:33:46 +02:00
|
|
|
Validate.validState(ServerLoginPacketListenerImpl.isValidUsername(packet.name()), "Invalid characters in username", new Object[0]);
|
2022-01-01 14:48:17 +01:00
|
|
|
+ // Paper start - validate usernames
|
2022-06-09 10:51:45 +02:00
|
|
|
+ if (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode() && io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.performUsernameValidation) {
|
2022-06-08 14:33:46 +02:00
|
|
|
+ if (!this.iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation && !validateUsername(packet.name())) {
|
2022-01-01 14:48:17 +01:00
|
|
|
+ ServerLoginPacketListenerImpl.this.disconnect("Failed to verify username!");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end - validate usernames
|
2022-07-27 23:32:15 +02:00
|
|
|
GameProfile gameprofile = this.server.getSingleplayerProfile();
|
2022-06-08 14:33:46 +02:00
|
|
|
|
2022-12-07 22:35:34 +01:00
|
|
|
if (gameprofile != null && packet.name().equalsIgnoreCase(gameprofile.getName())) {
|
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
|
2022-12-19 11:46:55 +01:00
|
|
|
index 88e9c5faca16eeb5cafcedb811a3d9d4dba6e9ce..01404600dcf4eefe1e62e7c62edb5b0980298583 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
|
2022-12-19 11:46:55 +01:00
|
|
|
@@ -652,7 +652,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);
|
|
|
|
}
|
|
|
|
}
|