summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorWesley Wolfe <weswolf@aol.com>2012-11-16 01:31:53 -0600
committerTravis Watkins <amaranth@ubuntu.com>2012-11-16 15:56:13 -0600
commit6466aa1d257ba9395b0e02011f08e1f4b3777407 (patch)
tree5a4a7bcfe6a51e0ff54d3f79f21ecf4ce9350791 /src/main
parent82c8cf42341a439972dfde9bb144c004dce17fd1 (diff)
downloadcraftbukkit-6466aa1d257ba9395b0e02011f08e1f4b3777407.tar
craftbukkit-6466aa1d257ba9395b0e02011f08e1f4b3777407.tar.gz
craftbukkit-6466aa1d257ba9395b0e02011f08e1f4b3777407.tar.lz
craftbukkit-6466aa1d257ba9395b0e02011f08e1f4b3777407.tar.xz
craftbukkit-6466aa1d257ba9395b0e02011f08e1f4b3777407.zip
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.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/net/minecraft/server/NetServerHandler.java63
1 files changed, 59 insertions, 4 deletions
diff --git a/src/main/java/net/minecraft/server/NetServerHandler.java b/src/main/java/net/minecraft/server/NetServerHandler.java
index c05c9c5f..86b6ad1c 100644
--- a/src/main/java/net/minecraft/server/NetServerHandler.java
+++ b/src/main/java/net/minecraft/server/NetServerHandler.java
@@ -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 {