This commit is contained in:
Jake Potrebic
2022-08-05 15:58:34 -07:00
parent 522db24de0
commit 2782b0c375
20 changed files with 108 additions and 124 deletions

View File

@@ -105,7 +105,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
this.send(packet, (PacketSendListener) null);
}
public void send(Packet<?> packet, @Nullable PacketSendListener packetsendlistener) {
public void send(Packet<?> packet, @Nullable PacketSendListener callbacks) {
- if (this.isConnected()) {
- this.flushQueue();
+ // Paper start - handle oversized packets better
@@ -118,16 +118,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ net.minecraft.server.MCUtil.isMainThread() && packet.isReady() && this.queue.isEmpty() &&
+ (packet.getExtraPackets() == null || packet.getExtraPackets().isEmpty())
+ ))) {
this.sendPacket(packet, packetsendlistener);
this.sendPacket(packet, callbacks);
- } else {
- this.queue.add(new Connection.PacketHolder(packet, packetsendlistener));
- this.queue.add(new Connection.PacketHolder(packet, callbacks));
+ return;
}
+ // write the packets to the queue, then flush - antixray hooks there already
+ java.util.List<Packet> extraPackets = InnerUtil.buildExtraPackets(packet);
+ boolean hasExtraPackets = extraPackets != null && !extraPackets.isEmpty();
+ if (!hasExtraPackets) {
+ this.queue.add(new Connection.PacketHolder(packet, packetsendlistener));
+ this.queue.add(new Connection.PacketHolder(packet, callbacks));
+ } else {
+ java.util.List<Connection.PacketHolder> packets = new java.util.ArrayList<>(1 + extraPackets.size());
+ packets.add(new Connection.PacketHolder(packet, null)); // delay the future listener until the end of the extra packets
@@ -135,7 +135,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ for (int i = 0, len = extraPackets.size(); i < len;) {
+ Packet extra = extraPackets.get(i);
+ boolean end = ++i == len;
+ packets.add(new Connection.PacketHolder(extra, end ? packetsendlistener : null)); // append listener to the end
+ packets.add(new Connection.PacketHolder(extra, end ? callbacks : null)); // append listener to the end
+ }
+ this.queue.addAll(packets); // atomic
+ }
@@ -143,7 +143,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper end
}
private void sendPacket(Packet<?> packet, @Nullable PacketSendListener packetsendlistener) {
private void sendPacket(Packet<?> packet, @Nullable PacketSendListener callbacks) {
@@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
this.setProtocol(packetState);
}
@@ -159,7 +159,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper end
ChannelFuture channelfuture = this.channel.writeAndFlush(packet);
if (packetsendlistener != null) {
if (callbacks != null) {
@@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
});