From c3549e483cc7864c40e80e9bda10d2faa72432b7 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Thu, 6 Feb 2014 10:57:01 -0600 Subject: [PATCH] Fixed Bug with Terminal Scroll Bar and Searching. Switched to Reactive Packet size protection. --- client/gui/implementations/GuiMEMonitorable.java | 1 + .../implementations/ContainerMEMonitorable.java | 13 +++++++++---- core/sync/packets/PacketMEInventoryUpdate.java | 12 ++++++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/client/gui/implementations/GuiMEMonitorable.java b/client/gui/implementations/GuiMEMonitorable.java index 161e2accd..ddcb42f75 100644 --- a/client/gui/implementations/GuiMEMonitorable.java +++ b/client/gui/implementations/GuiMEMonitorable.java @@ -167,6 +167,7 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource { repo.searchString = this.searchField.getText(); repo.updateView(); + setScrollBar(); } else { diff --git a/container/implementations/ContainerMEMonitorable.java b/container/implementations/ContainerMEMonitorable.java index 347672d6f..6edc02c65 100644 --- a/container/implementations/ContainerMEMonitorable.java +++ b/container/implementations/ContainerMEMonitorable.java @@ -1,6 +1,7 @@ package appeng.container.implementations; import java.io.IOException; +import java.nio.BufferOverflowException; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; @@ -136,14 +137,18 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IMEMonito for (IAEItemStack send : monitorCache) { - if ( piu.getLength() > 20000 ) + try + { + piu.appendItem( send ); + } + catch (BufferOverflowException boe) { Packet p = piu.getPacket(); PacketDispatcher.sendPacketToPlayer( p, (Player) c ); - piu = new PacketMEInventoryUpdate(); - } - piu.appendItem( send ); + piu = new PacketMEInventoryUpdate(); + piu.appendItem( send ); + } } Packet p = piu.getPacket(); diff --git a/core/sync/packets/PacketMEInventoryUpdate.java b/core/sync/packets/PacketMEInventoryUpdate.java index 7bf84952f..b8f364dab 100644 --- a/core/sync/packets/PacketMEInventoryUpdate.java +++ b/core/sync/packets/PacketMEInventoryUpdate.java @@ -4,6 +4,7 @@ import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.nio.BufferOverflowException; import java.util.LinkedList; import java.util.List; @@ -26,6 +27,7 @@ public class PacketMEInventoryUpdate extends AppEngPacket // output... final private ByteArrayOutputStream bytes; final private DataOutputStream data; + int lastSize = 0; boolean empty = true; // input. @@ -59,7 +61,9 @@ public class PacketMEInventoryUpdate extends AppEngPacket public Packet250CustomPayload getPacket() { isChunkDataPacket = false; - configureWrite( bytes.toByteArray() ); + byte[] dataOut = new byte[lastSize]; + System.arraycopy( bytes.toByteArray(), 0, dataOut, 0, lastSize ); + configureWrite( dataOut ); return super.getPacket(); } @@ -71,10 +75,14 @@ public class PacketMEInventoryUpdate extends AppEngPacket data.writeInt( getPacketID() ); } - public void appendItem(IAEItemStack is) throws IOException + public void appendItem(IAEItemStack is) throws IOException, BufferOverflowException { is.writeToPacket( data ); empty = false; + if ( bytes.size() > 20000 ) + throw new BufferOverflowException(); + else + lastSize = bytes.size(); } public int getLength()