geforkt von Mirrors/Paper
Use synchronous calls and wait for chat disconnect. Fixes BUKKIT-2946
When invalid chat is detected we currently drop the connection with no hint as to why as anything else is not allowed while we're off the main thread. To give valid disconnect reasons and fire proper events instead pass these off to the main thread and wait for it to process them.
Dieser Commit ist enthalten in:
Ursprung
82c8cf4234
Commit
6466aa1d25
@ -10,6 +10,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
|
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -792,13 +793,49 @@ public class NetServerHandler extends NetHandler {
|
|||||||
String s = packet3chat.message;
|
String s = packet3chat.message;
|
||||||
|
|
||||||
if (s.length() > 100) {
|
if (s.length() > 100) {
|
||||||
this.networkManager.a("Chat message too long"); // CraftBukkit disconnect client asynchronously
|
// CraftBukkit start
|
||||||
|
Waitable waitable = new Waitable() {
|
||||||
|
@Override
|
||||||
|
protected Object evaluate() {
|
||||||
|
NetServerHandler.this.disconnect("Chat message too long");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.minecraftServer.processQueue.add(waitable);
|
||||||
|
|
||||||
|
try {
|
||||||
|
waitable.get();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
// CraftBukkit end
|
||||||
} else {
|
} else {
|
||||||
s = s.trim();
|
s = s.trim();
|
||||||
|
|
||||||
for (int i = 0; i < s.length(); ++i) {
|
for (int i = 0; i < s.length(); ++i) {
|
||||||
if (!SharedConstants.isAllowedChatCharacter(s.charAt(i))) {
|
if (!SharedConstants.isAllowedChatCharacter(s.charAt(i))) {
|
||||||
this.networkManager.a("Illegal characters in chat"); // CraftBukkit disconnect client asynchronously
|
// CraftBukkit start
|
||||||
|
Waitable waitable = new Waitable() {
|
||||||
|
@Override
|
||||||
|
protected Object evaluate() {
|
||||||
|
NetServerHandler.this.disconnect("Illegal characters in chat");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.minecraftServer.processQueue.add(waitable);
|
||||||
|
|
||||||
|
try {
|
||||||
|
waitable.get();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
// CraftBukkit end
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -813,7 +850,25 @@ public class NetServerHandler extends NetHandler {
|
|||||||
|
|
||||||
// This section stays because it is only applicable to packets
|
// This section stays because it is only applicable to packets
|
||||||
if (chatSpamField.addAndGet(this, 20) > 200 && !this.minecraftServer.getServerConfigurationManager().isOp(this.player.name)) { // CraftBukkit use thread-safe spam
|
if (chatSpamField.addAndGet(this, 20) > 200 && !this.minecraftServer.getServerConfigurationManager().isOp(this.player.name)) { // CraftBukkit use thread-safe spam
|
||||||
this.networkManager.a("disconnect.spam"); // CraftBukkit disconnect client asynchronously
|
// CraftBukkit start
|
||||||
|
Waitable waitable = new Waitable() {
|
||||||
|
@Override
|
||||||
|
protected Object evaluate() {
|
||||||
|
NetServerHandler.this.disconnect("disconnect.spam");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.minecraftServer.processQueue.add(waitable);
|
||||||
|
|
||||||
|
try {
|
||||||
|
waitable.get();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
// CraftBukkit end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -874,7 +929,7 @@ public class NetServerHandler extends NetHandler {
|
|||||||
waitable.get();
|
waitable.get();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt(); // This is proper habit for java. If we aren't handling it, pass it on!
|
Thread.currentThread().interrupt(); // This is proper habit for java. If we aren't handling it, pass it on!
|
||||||
} catch (java.util.concurrent.ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
throw new RuntimeException("Exception processing chat event", e.getCause());
|
throw new RuntimeException("Exception processing chat event", e.getCause());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren