From 157077b0efad614e6684a0a490ffd86c1ad54f7a Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Sat, 28 Jan 2023 21:04:25 +0100 Subject: [PATCH] Payload Overload - Potential fix for players getting kicked while merging very large track networks --- .../content/logistics/trains/TrackGraphSync.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/TrackGraphSync.java b/src/main/java/com/simibubi/create/content/logistics/trains/TrackGraphSync.java index 2c52fe585..dfd5d0e36 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/TrackGraphSync.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/TrackGraphSync.java @@ -54,22 +54,26 @@ public class TrackGraphSync { public void nodeAdded(TrackGraph graph, TrackNode node) { flushGraphPacket(graph); currentGraphSyncPacket.addedNodes.put(node.getNetId(), Pair.of(node.getLocation(), node.getNormal())); + currentPayload++; } public void edgeAdded(TrackGraph graph, TrackNode node1, TrackNode node2, TrackEdge edge) { flushGraphPacket(graph); currentGraphSyncPacket.addedEdges .add(Pair.of(Couple.create(node1.getNetId(), node2.getNetId()), edge.getTurn())); + currentPayload++; } public void pointAdded(TrackGraph graph, TrackEdgePoint point) { flushGraphPacket(graph); currentGraphSyncPacket.addedEdgePoints.add(point); + currentPayload++; } public void pointRemoved(TrackGraph graph, TrackEdgePoint point) { flushGraphPacket(graph); currentGraphSyncPacket.removedEdgePoints.add(point.getId()); + currentPayload++; } public void nodeRemoved(TrackGraph graph, TrackNode node) { @@ -120,12 +124,14 @@ public class TrackGraphSync { public void edgeDataChanged(TrackGraph graph, TrackNode node1, TrackNode node2, TrackEdge edge) { flushGraphPacket(graph); currentGraphSyncPacket.syncEdgeData(node1, node2, edge); + currentPayload++; } public void edgeDataChanged(TrackGraph graph, TrackNode node1, TrackNode node2, TrackEdge edge, TrackEdge edge2) { flushGraphPacket(graph); currentGraphSyncPacket.syncEdgeData(node1, node2, edge); currentGraphSyncPacket.syncEdgeData(node2, node1, edge2); + currentPayload++; } public void sendFullGraphTo(TrackGraph graph, ServerPlayer player) { @@ -190,6 +196,7 @@ public class TrackGraphSync { // private TrackGraphSyncPacket currentGraphSyncPacket; + private int currentPayload; private void flushGraphPacket() { flushGraphPacket(null, 0); @@ -201,14 +208,17 @@ public class TrackGraphSync { private void flushGraphPacket(@Nullable UUID graphId, int netId) { if (currentGraphSyncPacket != null) { - if (currentGraphSyncPacket.graphId.equals(graphId)) + if (currentGraphSyncPacket.graphId.equals(graphId) && currentPayload < 1000) return; queuedPackets.add(currentGraphSyncPacket); currentGraphSyncPacket = null; + currentPayload = 0; } - if (graphId != null) + if (graphId != null) { currentGraphSyncPacket = new TrackGraphSyncPacket(graphId, netId); + currentPayload = 0; + } } }