summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTravis Watkins <amaranth@ubuntu.com>2012-11-17 11:48:22 -0600
committerTravis Watkins <amaranth@ubuntu.com>2012-11-17 11:48:22 -0600
commit558411692a5995c91687ea6ca90cc9a26ada60ca (patch)
tree673da00e8ce8908aea36ef23d1711b94f895d28c /src
parent9add7d3000c15268a0b277aabc224c2acf86cc06 (diff)
downloadcraftbukkit-558411692a5995c91687ea6ca90cc9a26ada60ca.tar
craftbukkit-558411692a5995c91687ea6ca90cc9a26ada60ca.tar.gz
craftbukkit-558411692a5995c91687ea6ca90cc9a26ada60ca.tar.lz
craftbukkit-558411692a5995c91687ea6ca90cc9a26ada60ca.tar.xz
craftbukkit-558411692a5995c91687ea6ca90cc9a26ada60ca.zip
Don't wait for main thread when processing commands.
In order to correctly handle disconnects for invalid chat we setup a Waitable and pass it to the main thread then wait for it to be processed. However, commands are also chat packets and they are already on the main thread. In this case, waiting will deadlock the server so we should just do a normal disconnect.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/net/minecraft/server/NetServerHandler.java96
1 files changed, 54 insertions, 42 deletions
diff --git a/src/main/java/net/minecraft/server/NetServerHandler.java b/src/main/java/net/minecraft/server/NetServerHandler.java
index 831ad7ed..a6e64031 100644
--- a/src/main/java/net/minecraft/server/NetServerHandler.java
+++ b/src/main/java/net/minecraft/server/NetServerHandler.java
@@ -794,22 +794,26 @@ public class NetServerHandler extends NetHandler {
if (s.length() > 100) {
// CraftBukkit start
- Waitable waitable = new Waitable() {
- @Override
- protected Object evaluate() {
- NetServerHandler.this.disconnect("Chat message too long");
- return null;
- }
- };
+ if (packet3chat.a_()) {
+ Waitable waitable = new Waitable() {
+ @Override
+ protected Object evaluate() {
+ NetServerHandler.this.disconnect("Chat message too long");
+ return null;
+ }
+ };
- this.minecraftServer.processQueue.add(waitable);
+ this.minecraftServer.processQueue.add(waitable);
- try {
- waitable.get();
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- } catch (ExecutionException e) {
- throw new RuntimeException(e);
+ try {
+ waitable.get();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ } catch (ExecutionException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ this.disconnect("Chat message too long");
}
// CraftBukkit end
} else {
@@ -818,22 +822,26 @@ public class NetServerHandler extends NetHandler {
for (int i = 0; i < s.length(); ++i) {
if (!SharedConstants.isAllowedChatCharacter(s.charAt(i))) {
// CraftBukkit start
- Waitable waitable = new Waitable() {
- @Override
- protected Object evaluate() {
- NetServerHandler.this.disconnect("Illegal characters in chat");
- return null;
- }
- };
+ if (packet3chat.a_()) {
+ Waitable waitable = new Waitable() {
+ @Override
+ protected Object evaluate() {
+ NetServerHandler.this.disconnect("Illegal characters in chat");
+ return null;
+ }
+ };
- this.minecraftServer.processQueue.add(waitable);
+ this.minecraftServer.processQueue.add(waitable);
- try {
- waitable.get();
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- } catch (ExecutionException e) {
- throw new RuntimeException(e);
+ try {
+ waitable.get();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ } catch (ExecutionException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ this.disconnect("Illegal characters in chat");
}
// CraftBukkit end
return;
@@ -851,22 +859,26 @@ 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
// CraftBukkit start
- Waitable waitable = new Waitable() {
- @Override
- protected Object evaluate() {
- NetServerHandler.this.disconnect("disconnect.spam");
- return null;
- }
- };
+ if (packet3chat.a_()) {
+ Waitable waitable = new Waitable() {
+ @Override
+ protected Object evaluate() {
+ NetServerHandler.this.disconnect("disconnect.spam");
+ return null;
+ }
+ };
- this.minecraftServer.processQueue.add(waitable);
+ this.minecraftServer.processQueue.add(waitable);
- try {
- waitable.get();
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- } catch (ExecutionException e) {
- throw new RuntimeException(e);
+ try {
+ waitable.get();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ } catch (ExecutionException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ this.disconnect("disconnect.spam");
}
// CraftBukkit end
}