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-10-23 22:52:43 +02:00
|
|
|
index 1e4b288f20153ce0c91fabf164c5c8320c90ba7d..cb5dd77892283a1aaec45434fb99bb7f08ee5394 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-09-15 21:39:53 +02:00
|
|
|
@@ -90,6 +90,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-09-15 21:39:53 +02:00
|
|
|
@@ -171,7 +172,13 @@ 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]);
|
2024-04-28 18:25:20 +02:00
|
|
|
+ // 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
|
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
|
Rework async chunk api implementation
Firstly, the old methods all routed to the CompletableFuture method.
However, the CF method could not guarantee that if the caller
was off-main that the future would be "completed" on-main. Since
the callback methods used the CF one, this meant that the callback
methods did not guarantee that the callbacks were to be called on
the main thread.
Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb)
so that the methods with the callback are guaranteed to invoke
the callback on the main thread. The CF behavior remains unchanged;
it may still appear to complete on main if invoked off-main.
Secondly, remove the scheduleOnMain invocation in the async
chunk completion. This unnecessarily delays the callback
by 1 tick.
Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which
will load chunks within an area. This method is provided as a helper
as keeping all chunks loaded within an area can be complicated to
implement for plugins (due to the lacking ticket API), and is
already implemented internally anyways.
Fourthly, remove the ticket addition that occured with getChunkAt
and getChunkAtAsync. The ticket addition may delay the unloading
of the chunk unnecessarily. It also fixes a very rare timing bug
where the future/callback would be completed after the chunk
unloads.
2024-11-19 07:34:32 +01:00
|
|
|
index 05d2f3c26d10169f6cf43bcb6c48db5d27b5cbac..3a0e0196f5bfa554b23fff9ff1a18a189b36452e 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-10-27 18:11:15 +01:00
|
|
|
@@ -627,7 +627,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
|
2024-10-23 22:52:43 +02:00
|
|
|
index e588bd7ef0616dc88ce4c0feeeabadc29dcaa550..6c33002dc8bbb3759c3156302ab7d1f26ce5e8ee 100644
|
2024-04-24 18:15:59 +02:00
|
|
|
--- a/src/main/java/net/minecraft/util/StringUtil.java
|
|
|
|
+++ b/src/main/java/net/minecraft/util/StringUtil.java
|
2024-04-28 18:25:20 +02:00
|
|
|
@@ -67,6 +67,25 @@ public class StringUtil {
|
|
|
|
return name.length() <= 16 && name.chars().filter(c -> c <= 32 || c >= 127).findAny().isEmpty();
|
2023-12-07 02:26:58 +01:00
|
|
|
}
|
|
|
|
|
2024-04-28 18:25:20 +02:00
|
|
|
+ // Paper start - Username validation
|
|
|
|
+ public static boolean isReasonablePlayerName(final String name) {
|
|
|
|
+ if (name.isEmpty() || name.length() > 16) {
|
2023-12-07 02:26:58 +01:00
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (int i = 0, len = name.length(); i < len; ++i) {
|
2024-04-28 18:25:20 +02:00
|
|
|
+ final char c = name.charAt(i);
|
2023-12-07 02:26:58 +01:00
|
|
|
+ if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (c == '_' || c == '.')) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return true;
|
2024-04-28 18:25:20 +02:00
|
|
|
+ }
|
|
|
|
+ // Paper end - Username validation
|
|
|
|
+
|
2024-04-24 18:15:59 +02:00
|
|
|
public static String filterText(String string) {
|
2024-04-28 18:25:20 +02:00
|
|
|
return filterText(string, false);
|
|
|
|
}
|