mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-28 03:56:59 -05:00
Fix split packet transformer splitting into wrong parts, minus 10 more bytes for safety (#270)
This commit is contained in:
@@ -179,7 +179,7 @@ public class SplitPacketTransformer implements PacketTransformer {
|
||||
|
||||
@Override
|
||||
public void outbound(NetworkManager.Side side, ResourceLocation id, FriendlyByteBuf buf, TransformationSink sink) {
|
||||
int maxSize = (side == NetworkManager.Side.C2S ? 32767 : 1048576) - 1 - 10;
|
||||
int maxSize = (side == NetworkManager.Side.C2S ? 32767 : 1048576) - 1 - 20;
|
||||
if (buf.readableBytes() <= maxSize) {
|
||||
ByteBuf stateBuf = Unpooled.buffer(1);
|
||||
stateBuf.writeByte(ONLY);
|
||||
@@ -187,7 +187,7 @@ public class SplitPacketTransformer implements PacketTransformer {
|
||||
sink.accept(side, id, packetBuffer);
|
||||
} else {
|
||||
int partSize = maxSize - 4;
|
||||
int parts = Math.round(buf.readableBytes() / (float) partSize);
|
||||
int parts = (int) Math.ceil(buf.readableBytes() / (float) partSize);
|
||||
for (int i = 0; i < parts; i++) {
|
||||
FriendlyByteBuf packetBuffer = new FriendlyByteBuf(Unpooled.buffer());
|
||||
if (i == 0) {
|
||||
|
||||
@@ -41,7 +41,7 @@ public interface TestModNet {
|
||||
// An example Server to Client message
|
||||
MessageType SYNC_DATA = NET.registerS2C("sync_data", SyncDataMessage::new);
|
||||
ResourceLocation BIG_DATA = new ResourceLocation(TestMod.MOD_ID, "big_data");
|
||||
String BIG_STRING = StringUtils.repeat('a', 60000);
|
||||
String BIG_STRING = StringUtils.repeat('a', 100000);
|
||||
|
||||
static void initialize() {
|
||||
NetworkManager.registerReceiver(NetworkManager.Side.C2S, BIG_DATA, Collections.singletonList(new SplitPacketTransformer()), (buf, context) -> {
|
||||
|
||||
Reference in New Issue
Block a user