mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 10:35:38 +01:00
[1.16] Optimize NetworkManager exception handling (#3819)
This commit is contained in:
parent
802b94f3d5
commit
da15798cab
File diff suppressed because one or more lines are too long
@ -28,7 +28,7 @@ and then catch exceptions and close if they fire.
|
||||
Part of this commit was authored by: Spottedleaf
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java
|
||||
index c84ee96cbed69cca311dd546e562a5322a03fd20..bd33f85cfe00cda72efb871f1fc11bebfb0ce700 100644
|
||||
index c84ee96cbed69cca311dd546e562a5322a03fd20..d5cc2af83a1c08db969bfb8a832e450a71dd845e 100644
|
||||
--- a/src/main/java/net/minecraft/server/NetworkManager.java
|
||||
+++ b/src/main/java/net/minecraft/server/NetworkManager.java
|
||||
@@ -65,6 +65,10 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet<?>> {
|
||||
@ -55,7 +55,7 @@ index c84ee96cbed69cca311dd546e562a5322a03fd20..bd33f85cfe00cda72efb871f1fc11beb
|
||||
this.packetListener = packetlistener;
|
||||
}
|
||||
+ // Paper start
|
||||
+ private EntityPlayer getPlayer() {
|
||||
+ EntityPlayer getPlayer() {
|
||||
+ if (packetListener instanceof PlayerConnection) {
|
||||
+ return ((PlayerConnection) packetListener).player;
|
||||
+ } else {
|
||||
|
@ -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 d384b1e857a5fe21a93e6fb956a2bfd777d92de3..ec3c8ec6a7c0a835d0bab9872d0ead68b2ff54df 100644
|
||||
--- a/src/main/java/net/minecraft/server/EnumProtocol.java
|
||||
+++ b/src/main/java/net/minecraft/server/EnumProtocol.java
|
||||
@@ -128,6 +128,7 @@ 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 cdaa8be90d16b0e9e2f92a3e2ed120b856feab54..2aaa8770edfd8acc6861c23176e405863858b275 100644
|
||||
--- a/src/main/java/net/minecraft/server/PacketSplitter.java
|
||||
+++ b/src/main/java/net/minecraft/server/PacketSplitter.java
|
||||
@@ -9,11 +9,21 @@ 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 eb3269e0ea3ce33d08e9eee3bca7cf434921e991..7ea293f38dedd6066601d94adbe175a31c502e1f 100644
|
||||
--- a/src/main/java/net/minecraft/server/PlayerConnectionUtils.java
|
||||
+++ b/src/main/java/net/minecraft/server/PlayerConnectionUtils.java
|
||||
@@ -22,6 +22,21 @@ 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user