mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-01 20:50:41 +01:00
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.
This commit is contained in:
parent
82c8cf4234
commit
6466aa1d25
1 changed files with 59 additions and 4 deletions
|
@ -10,6 +10,7 @@ import java.util.logging.Logger;
|
|||
|
||||
// CraftBukkit start
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
|
||||
import java.util.logging.Level;
|
||||
import java.util.HashSet;
|
||||
|
@ -792,13 +793,49 @@ public class NetServerHandler extends NetHandler {
|
|||
String s = packet3chat.message;
|
||||
|
||||
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 {
|
||||
s = s.trim();
|
||||
|
||||
for (int i = 0; i < s.length(); ++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;
|
||||
}
|
||||
}
|
||||
|
@ -813,7 +850,25 @@ public class NetServerHandler extends NetHandler {
|
|||
|
||||
// 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
|
||||
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();
|
||||
} catch (InterruptedException e) {
|
||||
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());
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue