230 lines
11 KiB
Diff
230 lines
11 KiB
Diff
From 2185d2838759bc55fae480b75a9067350b6f5086 Mon Sep 17 00:00:00 2001
|
|
From: Poweruser <poweruser.rs@hotmail.com>
|
|
Date: Sat, 28 May 2016 06:31:24 +0200
|
|
Subject: [PATCH] Only one thread for async chat messages
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java
|
|
index f815eebbf..6e69b7326 100644
|
|
--- a/src/main/java/net/minecraft/server/NetworkManager.java
|
|
+++ b/src/main/java/net/minecraft/server/NetworkManager.java
|
|
@@ -73,6 +73,16 @@ public class NetworkManager extends SimpleChannelInboundHandler {
|
|
}
|
|
// Spigot End
|
|
|
|
+ // Poweruser start
|
|
+ private boolean lockDownIncomingTraffic = false;
|
|
+
|
|
+ protected boolean lockDownIncomingTraffic() {
|
|
+ boolean oldValue = this.lockDownIncomingTraffic;
|
|
+ this.lockDownIncomingTraffic = true;
|
|
+ return oldValue;
|
|
+ }
|
|
+ // Poweruser end
|
|
+
|
|
public static final GenericFutureListener[] emptyListenerArray = new GenericFutureListener[0]; // Poweruser
|
|
|
|
public NetworkManager(boolean flag) {
|
|
@@ -115,7 +125,7 @@ public class NetworkManager extends SimpleChannelInboundHandler {
|
|
}
|
|
|
|
protected void a(ChannelHandlerContext channelhandlercontext, Packet packet) {
|
|
- if (this.m.isOpen()) {
|
|
+ if (this.m.isOpen() && !this.lockDownIncomingTraffic) { // Poweruser
|
|
if (packet.a()) {
|
|
packet.handle(this.o);
|
|
} else {
|
|
@@ -197,6 +207,11 @@ public class NetworkManager extends SimpleChannelInboundHandler {
|
|
// CraftBukkit end
|
|
|
|
// Poweruser start
|
|
+ if(this.lockDownIncomingTraffic) {
|
|
+ this.k.clear();
|
|
+ break;
|
|
+ }
|
|
+
|
|
CustomTimingsHandler packetHandlerTimer = SpigotTimings.getPacketHandlerTimings(packet);
|
|
packetHandlerTimer.startTiming();
|
|
try {
|
|
diff --git a/src/main/java/net/minecraft/server/PacketPlayInChat.java b/src/main/java/net/minecraft/server/PacketPlayInChat.java
|
|
index 6146e7a70..ebbfa8695 100644
|
|
--- a/src/main/java/net/minecraft/server/PacketPlayInChat.java
|
|
+++ b/src/main/java/net/minecraft/server/PacketPlayInChat.java
|
|
@@ -3,6 +3,7 @@ package net.minecraft.server;
|
|
import java.io.IOException; // CraftBukkit
|
|
|
|
import net.frozenorb.ThreadingManager; // Poweruser
|
|
+import net.frozenorb.ThreadingManager.TaskQueueWorker; // Poweruser
|
|
|
|
public class PacketPlayInChat extends Packet {
|
|
|
|
@@ -45,12 +46,20 @@ public class PacketPlayInChat extends Packet {
|
|
}
|
|
// CraftBukkit end
|
|
|
|
+ private static TaskQueueWorker taskQueue; // Poweruser
|
|
// Spigot Start
|
|
public void handle(final PacketListener packetlistener)
|
|
{
|
|
if ( a() )
|
|
{
|
|
- ThreadingManager.submit( new Runnable() // Poweruser
|
|
+ // Poweruser start
|
|
+ TaskQueueWorker worker = taskQueue;
|
|
+ if(worker == null) {
|
|
+ taskQueue = worker = ThreadingManager.createTaskQueue();
|
|
+ }
|
|
+
|
|
+ worker.queueTask(new Runnable() // Poweruser
|
|
+ // Poweruser end
|
|
{
|
|
|
|
@Override
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
index 90725d6cb..a3c0917ce 100644
|
|
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
@@ -900,23 +900,21 @@ public class PlayerConnection implements PacketPlayInListener {
|
|
if (!SharedConstants.isAllowedChatCharacter(s.charAt(i))) {
|
|
// CraftBukkit start - threadsafety
|
|
if (packetplayinchat.a()) {
|
|
- Waitable waitable = new Waitable() {
|
|
- @Override
|
|
- protected Object evaluate() {
|
|
- PlayerConnection.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);
|
|
+ // Poweruser start
|
|
+ if(!this.networkManager.lockDownIncomingTraffic()) {
|
|
+ Runnable runnable = new Runnable() {
|
|
+ @Override
|
|
+ public void run() {
|
|
+ try {
|
|
+ PlayerConnection.this.disconnect("Illegal characters in chat");
|
|
+ } catch (Exception e) {
|
|
+ c.warn(e.toString());
|
|
+ }
|
|
+ }
|
|
+ };
|
|
+ this.minecraftServer.processQueue.add(runnable);
|
|
}
|
|
+ // Poweruser end
|
|
} else {
|
|
this.disconnect("Illegal characters in chat");
|
|
}
|
|
@@ -976,23 +974,21 @@ public class PlayerConnection implements PacketPlayInListener {
|
|
// this.chatThrottle += 20;
|
|
if (counted && chatSpamField.addAndGet(this, 20) > 200 && !this.minecraftServer.getPlayerList().isOp(this.player.getProfile())) {
|
|
if (packetplayinchat.a()) {
|
|
- Waitable waitable = new Waitable() {
|
|
- @Override
|
|
- protected Object evaluate() {
|
|
- PlayerConnection.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);
|
|
+ // Poweruser start
|
|
+ if(!this.networkManager.lockDownIncomingTraffic()) {
|
|
+ Runnable runnable = new Runnable() {
|
|
+ @Override
|
|
+ public void run() {
|
|
+ try {
|
|
+ PlayerConnection.this.disconnect("disconnect.spam");
|
|
+ } catch (Exception e) {
|
|
+ c.warn(e.toString());
|
|
+ }
|
|
+ }
|
|
+ };
|
|
+ this.minecraftServer.processQueue.add(runnable);
|
|
}
|
|
+ // Poweruser end
|
|
} else {
|
|
this.disconnect("disconnect.spam");
|
|
}
|
|
@@ -1020,40 +1016,38 @@ public class PlayerConnection implements PacketPlayInListener {
|
|
// Evil plugins still listening to deprecated event
|
|
final PlayerChatEvent queueEvent = new PlayerChatEvent(player, event.getMessage(), event.getFormat(), event.getRecipients());
|
|
queueEvent.setCancelled(event.isCancelled());
|
|
- Waitable waitable = new Waitable() {
|
|
+ // Poweruser start
|
|
+ Runnable runnable = new Runnable() {
|
|
@Override
|
|
- protected Object evaluate() {
|
|
- org.bukkit.Bukkit.getPluginManager().callEvent(queueEvent);
|
|
-
|
|
- if (queueEvent.isCancelled()) {
|
|
- return null;
|
|
- }
|
|
+ public void run() {
|
|
+ try {
|
|
+ org.bukkit.Bukkit.getPluginManager().callEvent(queueEvent);
|
|
|
|
- String message = String.format(queueEvent.getFormat(), queueEvent.getPlayer().getDisplayName(), queueEvent.getMessage());
|
|
- PlayerConnection.this.minecraftServer.console.sendMessage(message);
|
|
- if (((LazyPlayerSet) queueEvent.getRecipients()).isLazy()) {
|
|
- for (Object player : PlayerConnection.this.minecraftServer.getPlayerList().players) {
|
|
- ((EntityPlayer) player).sendMessage(CraftChatMessage.fromString(message));
|
|
+ if (queueEvent.isCancelled()) {
|
|
+ return;
|
|
}
|
|
- } else {
|
|
- for (Player player : queueEvent.getRecipients()) {
|
|
- player.sendMessage(message);
|
|
+
|
|
+ String message = String.format(queueEvent.getFormat(), queueEvent.getPlayer().getDisplayName(), queueEvent.getMessage());
|
|
+ PlayerConnection.this.minecraftServer.console.sendMessage(message);
|
|
+ if (((LazyPlayerSet) queueEvent.getRecipients()).isLazy()) {
|
|
+ for (Object player : PlayerConnection.this.minecraftServer.getPlayerList().players) {
|
|
+ ((EntityPlayer) player).sendMessage(CraftChatMessage.fromString(message));
|
|
+ }
|
|
+ } else {
|
|
+ for (Player player : queueEvent.getRecipients()) {
|
|
+ player.sendMessage(message);
|
|
+ }
|
|
}
|
|
+ } catch (Exception e) {
|
|
+ c.warn(e.toString());
|
|
}
|
|
- return null;
|
|
}};
|
|
if (async) {
|
|
- minecraftServer.processQueue.add(waitable);
|
|
+ minecraftServer.processQueue.add(runnable);
|
|
} else {
|
|
- waitable.run();
|
|
- }
|
|
- try {
|
|
- waitable.get();
|
|
- } catch (InterruptedException e) {
|
|
- Thread.currentThread().interrupt(); // This is proper habit for java. If we aren't handling it, pass it on!
|
|
- } catch (ExecutionException e) {
|
|
- throw new RuntimeException("Exception processing chat event", e.getCause());
|
|
+ runnable.run();
|
|
}
|
|
+ // Poweruser end
|
|
} else {
|
|
if (event.isCancelled()) {
|
|
return;
|
|
--
|
|
2.13.3
|
|
|