From 22a1a4d50cf183bed149f9ebeebdaad6364b07de Mon Sep 17 00:00:00 2001 From: Moulberry Date: Tue, 26 Mar 2024 13:26:59 +0800 Subject: [PATCH] Add option to increase limit for request chunk data packet --- .../java/com/moulberry/axiom/AxiomPaper.java | 11 ++++++++--- .../axiom/packet/AxiomBigPayloadHandler.java | 16 ++++++++++++++-- src/main/resources/config.yml | 3 +++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/moulberry/axiom/AxiomPaper.java b/src/main/java/com/moulberry/axiom/AxiomPaper.java index f5a7161..9bcd577 100644 --- a/src/main/java/com/moulberry/axiom/AxiomPaper.java +++ b/src/main/java/com/moulberry/axiom/AxiomPaper.java @@ -71,6 +71,7 @@ public class AxiomPaper extends JavaPlugin implements Listener { this.getLogger().warning("Invalid value for unsupported-axiom-version, expected 'kick', 'warn' or 'ignore'"); } + boolean allowLargeChunkDataRequest = this.configuration.getBoolean("allow-large-chunk-data-request"); this.logLargeBlockBufferChanges = this.configuration.getBoolean("log-large-block-buffer-changes"); List disallowedBlocks = this.configuration.getStringList("disallowed-blocks"); @@ -123,8 +124,10 @@ public class AxiomPaper extends JavaPlugin implements Listener { if (configuration.getBoolean("packet-handlers.set-editor-views")) { msg.registerIncomingPluginChannel(this, "axiom:set_editor_views", new SetEditorViewsPacketListener(this)); } - if (configuration.getBoolean("packet-handlers.request-chunk-data")) { - msg.registerIncomingPluginChannel(this, "axiom:request_chunk_data", new RequestChunkDataPacketListener(this)); + if (!allowLargeChunkDataRequest) { + if (configuration.getBoolean("packet-handlers.request-chunk-data")) { + msg.registerIncomingPluginChannel(this, "axiom:request_chunk_data", new RequestChunkDataPacketListener(this)); + } } if (configuration.getBoolean("packet-handlers.spawn-entity")) { msg.registerIncomingPluginChannel(this, "axiom:spawn_entity", new SpawnEntityPacketListener(this)); @@ -145,6 +148,8 @@ public class AxiomPaper extends JavaPlugin implements Listener { if (configuration.getBoolean("packet-handlers.set-buffer")) { SetBlockBufferPacketListener setBlockBufferPacketListener = new SetBlockBufferPacketListener(this); UploadBlueprintPacketListener uploadBlueprintPacketListener = new UploadBlueprintPacketListener(this); + RequestChunkDataPacketListener requestChunkDataPacketListener = allowLargeChunkDataRequest ? + new RequestChunkDataPacketListener(this) : null; ChannelInitializeListenerHolder.addListener(Key.key("axiom:handle_big_payload"), new ChannelInitializeListener() { @Override @@ -164,7 +169,7 @@ public class AxiomPaper extends JavaPlugin implements Listener { Connection connection = (Connection) channel.pipeline().get("packet_handler"); channel.pipeline().addBefore("decoder", "axiom-big-payload-handler", new AxiomBigPayloadHandler(payloadId, connection, setBlockBufferPacketListener, - uploadBlueprintPacketListener)); + uploadBlueprintPacketListener, requestChunkDataPacketListener)); } }); } diff --git a/src/main/java/com/moulberry/axiom/packet/AxiomBigPayloadHandler.java b/src/main/java/com/moulberry/axiom/packet/AxiomBigPayloadHandler.java index 8a36a8a..06a628c 100644 --- a/src/main/java/com/moulberry/axiom/packet/AxiomBigPayloadHandler.java +++ b/src/main/java/com/moulberry/axiom/packet/AxiomBigPayloadHandler.java @@ -16,17 +16,20 @@ public class AxiomBigPayloadHandler extends ByteToMessageDecoder { private static final ResourceLocation SET_BUFFER = new ResourceLocation("axiom", "set_buffer"); private static final ResourceLocation UPLOAD_BLUEPRINT = new ResourceLocation("axiom", "upload_blueprint"); + private static final ResourceLocation REQUEST_CHUNK_DATA = new ResourceLocation("axiom", "request_chunk_data"); private final int payloadId; private final Connection connection; private final SetBlockBufferPacketListener setBlockBuffer; private final UploadBlueprintPacketListener uploadBlueprint; + private final RequestChunkDataPacketListener requestChunkDataPacketListener; public AxiomBigPayloadHandler(int payloadId, Connection connection, SetBlockBufferPacketListener setBlockBuffer, - UploadBlueprintPacketListener uploadBlueprint) { + UploadBlueprintPacketListener uploadBlueprint, RequestChunkDataPacketListener requestChunkDataPacketListener) { this.payloadId = payloadId; this.connection = connection; this.setBlockBuffer = setBlockBuffer; this.uploadBlueprint = uploadBlueprint; + this.requestChunkDataPacketListener = requestChunkDataPacketListener; } @Override @@ -63,6 +66,15 @@ public class AxiomBigPayloadHandler extends ByteToMessageDecoder { in.skipBytes(in.readableBytes()); return; } + } else if (requestChunkDataPacketListener != null && identifier.equals(REQUEST_CHUNK_DATA)) { + ServerPlayer player = connection.getPlayer(); + if (AxiomPaper.PLUGIN.canUseAxiom(player.getBukkitEntity())) { + requestChunkDataPacketListener.onPluginMessageReceived(identifier.toString(), player.getBukkitEntity(), + buf.array()); + success = true; + in.skipBytes(in.readableBytes()); + return; + } } } } catch (Throwable ignored) { @@ -86,7 +98,7 @@ public class AxiomBigPayloadHandler extends ByteToMessageDecoder { if (evt == ConnectionEvent.COMPRESSION_THRESHOLD_SET || evt == ConnectionEvent.COMPRESSION_DISABLED) { ctx.channel().pipeline().remove("axiom-big-payload-handler"); ctx.channel().pipeline().addBefore("decoder", "axiom-big-payload-handler", - new AxiomBigPayloadHandler(payloadId, connection, setBlockBuffer, uploadBlueprint)); + new AxiomBigPayloadHandler(payloadId, connection, setBlockBuffer, uploadBlueprint, requestChunkDataPacketListener)); } super.userEventTriggered(ctx, evt); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1c97379..7273f2c 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -14,6 +14,9 @@ allow-teleport-between-worlds: true # Whether to allow clients to save/load/share blueprints through the server blueprint-sharing: false +# Allow large chunk data requests, not recommended for public servers +allow-large-chunk-data-request: false + # Action to take when a user with an incompatible Minecraft version or Axiom version joins # Valid actions are 'kick', 'warn' and 'ignore' # 'warn' will give the player a warning and disable Axiom