Paper/CraftBukkit-Patches/0032-Filter-Invalid-Names.patch

29 lines
1.2 KiB
Diff

From 814cb42764064d0a31a56ff09f9ac8e28d3a9f8d Mon Sep 17 00:00:00 2001
From: Benjamin James Harrison-Sims <tehrainbowguy@gmail.com>
Date: Sun, 14 Apr 2013 21:19:57 +0500
Subject: [PATCH] Filter Invalid Names
diff --git a/src/main/java/net/minecraft/server/Packet2Handshake.java b/src/main/java/net/minecraft/server/Packet2Handshake.java
index 1e7bad0..f25afb6 100644
--- a/src/main/java/net/minecraft/server/Packet2Handshake.java
+++ b/src/main/java/net/minecraft/server/Packet2Handshake.java
@@ -14,11 +14,14 @@ public class Packet2Handshake extends Packet {
public Packet2Handshake() {}
+ public static final java.util.regex.Pattern validName = java.util.regex.Pattern.compile("^[a-zA-Z0-9_-]{2,16}$");
public void a(DataInput datainput) throws IOException { // CraftBukkit - throws IOException
this.a = datainput.readByte();
this.b = a(datainput, 16);
this.c = a(datainput, 255);
this.d = datainput.readInt();
+ // Spigot: TODO: md_5 hates this
+ if(!validName.matcher(this.b).matches()) throw new IOException("Invalid name!"); // Spigot
}
public void a(DataOutput dataoutput) throws IOException { // CraftBukkit - throws IOException
--
1.8.1.2