[1.16] Optimize NetworkManager exception handling (#3819)

This commit is contained in:
Andrew Steinborn 2020-07-06 00:27:37 -04:00
parent 5d595d8e4a
commit 7a714e6e13
3 changed files with 94 additions and 1 deletions

File diff suppressed because one or more lines are too long

View file

@ -55,7 +55,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
this.packetListener = packetlistener;
}
+ // Paper start
+ private EntityPlayer getPlayer() {
+ EntityPlayer getPlayer() {
+ if (packetListener instanceof PlayerConnection) {
+ return ((PlayerConnection) packetListener).player;
+ } else {

View file

@ -0,0 +1,71 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Andrew Steinborn <git@steinborn.me>
Date: Sun, 5 Jul 2020 22:38:18 -0400
Subject: [PATCH] Optimize NetworkManager Exception Handling
diff --git a/src/main/java/net/minecraft/server/EnumProtocol.java b/src/main/java/net/minecraft/server/EnumProtocol.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/EnumProtocol.java
+++ b/src/main/java/net/minecraft/server/EnumProtocol.java
@@ -0,0 +0,0 @@ public enum EnumProtocol {
@Nullable
public Packet<?> a(int i) {
+ if (i < 0 || i >= this.b.size()) return null; // Paper
Supplier<? extends Packet<T>> supplier = (Supplier) this.b.get(i);
return supplier != null ? (Packet) supplier.get() : null;
diff --git a/src/main/java/net/minecraft/server/PacketSplitter.java b/src/main/java/net/minecraft/server/PacketSplitter.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/PacketSplitter.java
+++ b/src/main/java/net/minecraft/server/PacketSplitter.java
@@ -0,0 +0,0 @@ import java.util.List;
public class PacketSplitter extends ByteToMessageDecoder {
+ private final byte[] lenBuf = new byte[3]; // Paper
public PacketSplitter() {}
protected void decode(ChannelHandlerContext channelhandlercontext, ByteBuf bytebuf, List<Object> list) throws Exception {
+ // Paper start - if channel is not active just discard the packet
+ if (!channelhandlercontext.channel().isActive()) {
+ bytebuf.skipBytes(bytebuf.readableBytes());
+ return;
+ }
+ // Paper end
bytebuf.markReaderIndex();
- byte[] abyte = new byte[3];
+ // Paper start - reuse temporary length buffer
+ byte[] abyte = lenBuf;
+ java.util.Arrays.fill(abyte, (byte) 0);
+ // Paper end
for (int i = 0; i < abyte.length; ++i) {
if (!bytebuf.isReadable()) {
diff --git a/src/main/java/net/minecraft/server/PlayerConnectionUtils.java b/src/main/java/net/minecraft/server/PlayerConnectionUtils.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/PlayerConnectionUtils.java
+++ b/src/main/java/net/minecraft/server/PlayerConnectionUtils.java
@@ -0,0 +0,0 @@ public class PlayerConnectionUtils {
try (Timing ignored = timing.startTiming()) { // Paper - timings
packet.a(t0);
} // Paper - timings
+ // Paper start
+ catch (Exception e) {
+ NetworkManager networkmanager = t0.a();
+ if (networkmanager.getPlayer() != null) {
+ LOGGER.error("Error whilst processing packet {} for {}[{}]", packet, networkmanager.getPlayer().getName(), networkmanager.getSocketAddress(), e);
+ } else {
+ LOGGER.error("Error whilst processing packet {} for connection from {}", packet, networkmanager.getSocketAddress(), e);
+ }
+ ChatComponentText error = new ChatComponentText("Packet processing error");
+ networkmanager.sendPacket(new PacketPlayOutKickDisconnect(error), (future) -> {
+ networkmanager.close(error);
+ });
+ networkmanager.stopReading();
+ }
+ // Paper end
} else {
PlayerConnectionUtils.LOGGER.debug("Ignoring packet due to disconnection: " + packet);
}