Split packets when sending items over network (#107)

Packets are now split into smaller chunks when sent. The packet
size is adjustable in the config.
This commit is contained in:
firenoo authored and GitHub committed 2023-03-23 17:14:14 +01:00
1 parent 6a244c12c4
commit 9c2ef02383
12 files changed
+316 -181

No files matched your search

@@ -25,13 +25,16 @@ public class GuiFluidMonitor extends FCGuiMonitor<IAEFluidStack> {
this.repo = new FluidRepo(getScrollBar(), this);
}
public void postUpdate(final List<IAEFluidStack> list) {
@Override
public void postUpdate(final List<IAEFluidStack> list, boolean resort) {
for (final IAEFluidStack is : list) {
IAEItemStack stack = AEItemStack.create(ItemFluidDrop.newDisplayStack(is.getFluidStack()));
stack.setStackSize(is.getStackSize());
this.repo.postUpdate(stack);
}
this.repo.updateView();
if (resort) {
this.repo.updateView();
}
this.setScrollBar();
}
@@ -22,11 +22,14 @@ public class GuiItemMonitor extends FCGuiMonitor<IAEItemStack> {
this.repo = new ItemRepo(getScrollBar(), this);
}
public void postUpdate(final List<IAEItemStack> list) {
@Override
public void postUpdate(final List<IAEItemStack> list, boolean resort) {
for (final IAEItemStack is : list) {
this.repo.postUpdate(is);
}
this.repo.updateView();
if (resort) {
this.repo.updateView();
}
this.setScrollBar();
}
@@ -107,7 +107,7 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
offsetY = y;
}
public abstract void postUpdate(final List<T> list);
public abstract void postUpdate(final List<T> list, boolean resort);
protected void setScrollBar() {
this.getScrollBar().setTop(18).setLeft(175).setHeight(this.rows * 18 - 2);
@@ -43,7 +43,7 @@ import com.glodblock.github.client.gui.container.base.FCContainerMonitor;
import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.network.CPacketFluidUpdate;
import com.glodblock.github.network.SPacketFluidUpdate;
import com.glodblock.github.network.SPacketMEInventoryUpdate;
import com.glodblock.github.network.SPacketMEFluidInvUpdate;
import com.glodblock.github.util.Util;
public class ContainerFluidMonitor extends FCContainerMonitor<IAEFluidStack> {
@@ -126,46 +126,51 @@ public class ContainerFluidMonitor extends FCContainerMonitor<IAEFluidStack> {
protected void processItemList() {
if (!this.fluids.isEmpty()) {
final IItemList<IAEFluidStack> monitorCache = this.monitor.getStorageList();
final SPacketMEInventoryUpdate piu = new SPacketMEInventoryUpdate(true);
SPacketMEFluidInvUpdate packet = new SPacketMEFluidInvUpdate();
for (final IAEFluidStack is : this.fluids) {
final IAEFluidStack send = monitorCache.findPrecise(is);
if (send == null) {
is.setStackSize(0);
piu.appendFluid(is);
} else {
piu.appendFluid(send);
try {
if (send != null) {
packet.appendFluid(send);
} else {
is.setStackSize(0);
packet.appendFluid(is);
}
} catch (BufferOverflowException e) {
for (final Object c : this.crafters) {
FluidCraft.proxy.netHandler.sendTo(packet, (EntityPlayerMP) c);
}
packet = new SPacketMEFluidInvUpdate();
if (send != null) {
packet.appendFluid(send);
} else {
is.setStackSize(0);
packet.appendFluid(is);
}
}
}
if (!piu.isEmpty()) {
this.fluids.resetStatus();
for (final Object c : this.crafters) {
if (c instanceof EntityPlayer) {
FluidCraft.proxy.netHandler.sendTo(piu, (EntityPlayerMP) c);
}
}
for (final Object c : this.crafters) {
FluidCraft.proxy.netHandler.sendTo(packet, (EntityPlayerMP) c);
}
}
}
@Override
protected void queueInventory(final ICrafting c) {
if (Platform.isServer() && c instanceof EntityPlayer && this.monitor != null) {
SPacketMEInventoryUpdate piu = new SPacketMEInventoryUpdate(true);
if (Platform.isServer() && c instanceof EntityPlayerMP && this.monitor != null) {
final IItemList<IAEFluidStack> monitorCache = this.monitor.getStorageList();
for (final IAEFluidStack send : monitorCache) {
SPacketMEFluidInvUpdate packet = new SPacketMEFluidInvUpdate();
for (final IAEFluidStack is : monitorCache) {
try {
piu.appendFluid(send);
} catch (final BufferOverflowException boe) {
FluidCraft.proxy.netHandler.sendTo(piu, (EntityPlayerMP) c);
piu = new SPacketMEInventoryUpdate(true);
piu.appendFluid(send);
packet.appendFluid(is);
} catch (BufferOverflowException e) {
FluidCraft.proxy.netHandler.sendTo(packet, (EntityPlayerMP) c);
packet = new SPacketMEFluidInvUpdate();
packet.appendFluid(is);
}
}
FluidCraft.proxy.netHandler.sendTo(piu, (EntityPlayerMP) c);
FluidCraft.proxy.netHandler.sendTo(packet, (EntityPlayerMP) c);
}
}
@@ -27,7 +27,7 @@ import appeng.util.Platform;
import com.glodblock.github.FluidCraft;
import com.glodblock.github.client.gui.container.base.FCContainerMonitor;
import com.glodblock.github.network.SPacketMEInventoryUpdate;
import com.glodblock.github.network.SPacketMEItemInvUpdate;
public class ContainerItemMonitor extends FCContainerMonitor<IAEItemStack> {
@@ -95,46 +95,55 @@ public class ContainerItemMonitor extends FCContainerMonitor<IAEItemStack> {
protected void processItemList() {
if (!this.items.isEmpty()) {
final IItemList<IAEItemStack> monitorCache = this.monitor.getStorageList();
final SPacketMEInventoryUpdate piu = new SPacketMEInventoryUpdate();
SPacketMEItemInvUpdate packet = new SPacketMEItemInvUpdate();
for (final IAEItemStack is : this.items) {
final IAEItemStack send = monitorCache.findPrecise(is);
if (send == null) {
is.setStackSize(0);
piu.appendItem(is);
} else {
piu.appendItem(send);
}
}
if (!piu.isEmpty()) {
this.items.resetStatus();
for (final Object c : this.crafters) {
if (c instanceof EntityPlayer) {
FluidCraft.proxy.netHandler.sendTo(piu, (EntityPlayerMP) c);
try {
if (send != null) {
packet.appendItem(send);
} else {
is.setStackSize(0);
packet.appendItem(is);
}
} catch (BufferOverflowException e) {
for (final Object c : this.crafters) {
if (c instanceof EntityPlayerMP) {
FluidCraft.proxy.netHandler.sendTo(packet, (EntityPlayerMP) c);
}
}
packet = new SPacketMEItemInvUpdate();
if (send != null) {
packet.appendItem(send);
} else {
is.setStackSize(0);
packet.appendItem(is);
}
}
}
for (final Object c : this.crafters) {
if (c instanceof EntityPlayerMP) {
FluidCraft.proxy.netHandler.sendTo(packet, (EntityPlayerMP) c);
}
}
this.items.resetStatus();
}
}
@Override
protected void queueInventory(final ICrafting c) {
if (Platform.isServer() && c instanceof EntityPlayer && this.monitor != null) {
SPacketMEInventoryUpdate piu = new SPacketMEInventoryUpdate();
final IItemList<IAEItemStack> monitorCache = this.monitor.getStorageList();
for (final IAEItemStack send : monitorCache) {
SPacketMEItemInvUpdate packet = new SPacketMEItemInvUpdate();
for (final IAEItemStack is : monitorCache) {
try {
piu.appendItem(send);
} catch (final BufferOverflowException boe) {
FluidCraft.proxy.netHandler.sendTo(piu, (EntityPlayerMP) c);
piu = new SPacketMEInventoryUpdate();
piu.appendItem(send);
packet.appendItem(is);
} catch (BufferOverflowException e) {
FluidCraft.proxy.netHandler.sendTo(packet, (EntityPlayerMP) c);
packet = new SPacketMEItemInvUpdate();
packet.appendItem(is);
}
}
FluidCraft.proxy.netHandler.sendTo(piu, (EntityPlayerMP) c);
FluidCraft.proxy.netHandler.sendTo(packet, (EntityPlayerMP) c);
}
}