diff --git a/src/main/java/io/akarin/server/misc/CheckedConcurrentLinkedQueue.java b/src/main/java/io/akarin/server/misc/CheckedConcurrentLinkedQueue.java index 06dfd23c9..ec11da021 100644 --- a/src/main/java/io/akarin/server/misc/CheckedConcurrentLinkedQueue.java +++ b/src/main/java/io/akarin/server/misc/CheckedConcurrentLinkedQueue.java @@ -327,7 +327,7 @@ public class CheckedConcurrentLinkedQueue extends AbstractQueue * @throws NullPointerException if the specified element is null */ public boolean offer(E e) { - checkNotNull(e); + //checkNotNull(e); final Node newNode = new Node(e); for (Node t = tail, p = t;;) { diff --git a/src/main/java/net/minecraft/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java index 9c1ee1399..be70697dc 100644 --- a/src/main/java/net/minecraft/server/NetworkManager.java +++ b/src/main/java/net/minecraft/server/NetworkManager.java @@ -165,33 +165,72 @@ public class NetworkManager extends SimpleChannelInboundHandler> { this.packetListener = packetlistener; } - public void sendPacket(Packet packet) { + public final void sendPacket(Packet packet) { // Akarin - add final this.sendPacket(packet, (GenericFutureListener) null); } // Akarin start - public void sendPacket(Packet... packets) { + public final void sendPacket(Packet packet0, Packet packet1) { if (this.isConnected()) { // why send packet to whom not connected? this.j.readLock().lock(); try { // Send queued packets this.sendPacketQueueUnsafe(); // Dispatch or queue new packets - for (Packet packet : packets) { - boolean dispatch = packet instanceof PacketStatusOutPong || packet instanceof PacketStatusOutServerInfo || (packet instanceof PacketPlayOutMapChunk && ((PacketPlayOutMapChunk) packet).isReady()); - if (dispatch) - this.dispatchPacket(packet, null); - else { - this.packetQueue.add(new QueuedPacket(packet, null)); - } - } + this.packetQueue.offer(new QueuedPacket(packet0, null)); + this.packetQueue.offer(new QueuedPacket(packet1, null)); } finally { this.j.readLock().unlock(); } } } - private void sendPacketQueueUnsafe() { + public final void sendPacket(Packet packet0, Packet packet1, Packet packet2) { + if (this.isConnected()) { // why send packet to whom not connected? + this.j.readLock().lock(); + try { + // Send queued packets + this.sendPacketQueueUnsafe(); + // Dispatch or queue new packets + this.packetQueue.offer(new QueuedPacket(packet0, null)); + this.packetQueue.offer(new QueuedPacket(packet1, null)); + this.packetQueue.offer(new QueuedPacket(packet2, null)); + } finally { + this.j.readLock().unlock(); + } + } + } + + public final void sendPacket(Packet packet0, Packet packet1, Packet packet2, Packet packet3, Packet packet4, Packet packet5, Packet packet6) { + if (this.isConnected()) { // why send packet to whom not connected? + this.j.readLock().lock(); + try { + // Send queued packets + this.sendPacketQueueUnsafe(); + // Dispatch or queue new packets + this.packetQueue.offer(new QueuedPacket(packet0, null)); + this.packetQueue.offer(new QueuedPacket(packet1, null)); + this.packetQueue.offer(new QueuedPacket(packet2, null)); + this.packetQueue.offer(new QueuedPacket(packet3, null)); + this.packetQueue.offer(new QueuedPacket(packet4, null)); + this.packetQueue.offer(new QueuedPacket(packet5, null)); + this.packetQueue.offer(new QueuedPacket(packet6, null)); + } finally { + this.j.readLock().unlock(); + } + } + } + + private final void dispatchOrQueuePacketUnsafe(Packet packet) { + boolean dispatch = packet instanceof PacketStatusOutPong || packet instanceof PacketStatusOutServerInfo || (packet instanceof PacketPlayOutMapChunk && ((PacketPlayOutMapChunk) packet).isReady()); + if (dispatch) + this.dispatchPacket(packet, null); + else { + this.packetQueue.offer(new QueuedPacket(packet, null)); + } + } + + private final void sendPacketQueueUnsafe() { while (!this.packetQueue.isEmpty()) { QueuedPacket queuedPacket = this.packetQueue.poll(packet -> packet != null && @@ -203,7 +242,7 @@ public class NetworkManager extends SimpleChannelInboundHandler> { } } // Akarin end - public void sendPacket(Packet packet, @Nullable GenericFutureListener> genericfuturelistener) { + public final void sendPacket(Packet packet, @Nullable GenericFutureListener> genericfuturelistener) { // Akarin - add final if (this.isConnected() /*&& this.sendPacketQueue() && !(packet instanceof PacketPlayOutMapChunk && !((PacketPlayOutMapChunk) packet).isReady())*/) { // Paper - Async-Anti-Xray - Add chunk packets which are not ready or all packets if the packet queue contains chunk packets which are not ready to the packet queue and send the packets later in the right order // Akarin //this.o(); // Paper - Async-Anti-Xray - Move to if statement (this.sendPacketQueue()) // Akarin start @@ -212,12 +251,7 @@ public class NetworkManager extends SimpleChannelInboundHandler> { // Send queued packets this.sendPacketQueueUnsafe(); // Dispatch or queue new packets - boolean dispatch = packet instanceof PacketStatusOutPong || packet instanceof PacketStatusOutServerInfo || (packet instanceof PacketPlayOutMapChunk && ((PacketPlayOutMapChunk) packet).isReady()); - if (dispatch) - this.dispatchPacket(packet, genericfuturelistener); - else { - this.packetQueue.add(new QueuedPacket(packet, genericfuturelistener)); - } + this.dispatchOrQueuePacketUnsafe(packet); } finally { this.j.readLock().unlock(); } diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java index 7f2a497df..fce7720ef 100644 --- a/src/main/java/net/minecraft/server/PlayerConnection.java +++ b/src/main/java/net/minecraft/server/PlayerConnection.java @@ -1465,7 +1465,7 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable { } - public void a(IChatBaseComponent ichatbasecomponent) { + public final void a(IChatBaseComponent ichatbasecomponent) { // Akarin - add final // CraftBukkit start - Rarely it would send a disconnect line twice if (this.processedDisconnect) { return; @@ -1497,25 +1497,59 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable { this.a(packet, (GenericFutureListener) null); } // Akarin start - public void sendPacket(Packet... packets) { + public final void sendPacket(Packet packet0, Packet packet1) { if (this.processedDisconnect) return; - + try { - this.networkManager.sendPacket(packets); + this.networkManager.sendPacket(packet0, packet1); } catch (Throwable throwable) { CrashReport crashreport = CrashReport.a(throwable, "Sending packet"); CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Packet being sent"); crashreportsystemdetails.a("Packet classes", () -> { - return Lists.newArrayList(packets).toString(); + return Lists.newArrayList(packet0.getClass().getName(), packet1.getClass().getName()).toString(); + }); + throw new ReportedException(crashreport); + } + } + + public final void sendPacket(Packet packet0, Packet packet1, Packet packet2) { + if (this.processedDisconnect) + return; + + try { + this.networkManager.sendPacket(packet0, packet1, packet2); + } catch (Throwable throwable) { + CrashReport crashreport = CrashReport.a(throwable, "Sending packet"); + CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Packet being sent"); + + crashreportsystemdetails.a("Packet classes", () -> { + return Lists.newArrayList(packet0.getClass().getName(), packet1.getClass().getName(), packet2.getClass().getName()).toString(); + }); + throw new ReportedException(crashreport); + } + } + + public final void sendPacket(Packet packet0, Packet packet1, Packet packet2, Packet packet3, Packet packet4, Packet packet5, Packet packet6) { + if (this.processedDisconnect) + return; + + try { + this.networkManager.sendPacket(packet0, packet1, packet2, packet3, packet4, packet5, packet6); + } catch (Throwable throwable) { + CrashReport crashreport = CrashReport.a(throwable, "Sending packet"); + CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Packet being sent"); + + crashreportsystemdetails.a("Packet classes", () -> { + return Lists.newArrayList(packet0.getClass().getName(), packet1.getClass().getName(), packet2.getClass().getName(), packet3.getClass().getName(), packet4.getClass().getName(), packet5.getClass().getName(), packet6.getClass().getName()).toString(); }); throw new ReportedException(crashreport); } } // Akarin end - public void a(Packet packet, @Nullable GenericFutureListener> genericfuturelistener) { + public final void a(Packet packet, @Nullable GenericFutureListener> genericfuturelistener) { // Akarin - add final if (packet instanceof PacketPlayOutChat) { PacketPlayOutChat packetplayoutchat = (PacketPlayOutChat) packet; EntityHuman.EnumChatVisibility entityhuman_enumchatvisibility = this.player.getChatFlags(); diff --git a/work/Paper b/work/Paper index 988887d2b..c3c889523 160000 --- a/work/Paper +++ b/work/Paper @@ -1 +1 @@ -Subproject commit 988887d2b053d4ef34935b7671cc20d2c7eb920a +Subproject commit c3c889523fb08d918fe94f1ebecc06345f2f4b74