From e7c895116037cfec7b4c7ee9af8779e5ea091b58 Mon Sep 17 00:00:00 2001 From: ItsNature Date: Fri, 10 Jul 2026 02:21:52 +0200 Subject: [PATCH] Add `TransferModule#ping` validation & increase `PingRequest` timeout to 10s --- .../apollo/module/transfer/PingRequest.java | 11 +++++++++++ .../apollo/module/transfer/TransferModule.java | 12 ++++++++++++ .../lunarclient/apollo/roundtrip/ApolloRequest.java | 10 ++++++++++ .../apollo/roundtrip/ApolloRoundtripManager.java | 5 +++-- .../apollo/module/transfer/TransferModuleImpl.java | 13 ++++++++++++- docs/developers/modules/transfer.mdx | 2 ++ example/bukkit/json/src/main/resources/plugin.yml | 2 ++ example/bukkit/proto/src/main/resources/plugin.yml | 2 ++ 8 files changed, 54 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/com/lunarclient/apollo/module/transfer/PingRequest.java b/api/src/main/java/com/lunarclient/apollo/module/transfer/PingRequest.java index 27640400..3b305bd3 100644 --- a/api/src/main/java/com/lunarclient/apollo/module/transfer/PingRequest.java +++ b/api/src/main/java/com/lunarclient/apollo/module/transfer/PingRequest.java @@ -45,4 +45,15 @@ public final class PingRequest extends ApolloRequest { */ List serverIps; + /** + * Returns the timeout for ping requests, in milliseconds. + * + * @return the request timeout, in milliseconds + * @since 1.2.9 + */ + @Override + public long getTimeoutMillis() { + return 10_000L; + } + } diff --git a/api/src/main/java/com/lunarclient/apollo/module/transfer/TransferModule.java b/api/src/main/java/com/lunarclient/apollo/module/transfer/TransferModule.java index 2d033f4d..39b08ed8 100644 --- a/api/src/main/java/com/lunarclient/apollo/module/transfer/TransferModule.java +++ b/api/src/main/java/com/lunarclient/apollo/module/transfer/TransferModule.java @@ -42,6 +42,14 @@ @ModuleDefinition(id = "transfer", name = "Transfer") public abstract class TransferModule extends ApolloModule { + /** + * The maximum amount of server IPs the client will ping + * for a single {@link PingRequest}. + * + * @since 1.2.9 + */ + public static final int MAX_PINGS_PER_PACKET = 10; + @Override public Collection getSupportedPlatforms() { return Arrays.asList(ApolloPlatform.Kind.SERVER, ApolloPlatform.Kind.PROXY); @@ -55,6 +63,8 @@ public Collection getSupportedPlatforms() { * @param player the player * @param serverIps all server IPs to ping * @return future to be listened to for errors/success + * @throws IllegalArgumentException if no server IPs or more than + * {@value #MAX_PINGS_PER_PACKET} server IPs are provided * @since 1.0.0 */ public Future ping(ApolloPlayer player, List serverIps) { @@ -85,6 +95,8 @@ public Future transfer(ApolloPlayer player, String serverIp) { * @param player the player * @param request the ping request * @return future to be listened to for errors/success + * @throws IllegalArgumentException if no server IPs or more than + * {@value #MAX_PINGS_PER_PACKET} server IPs are provided * @since 1.0.0 */ public abstract Future ping(ApolloPlayer player, PingRequest request); diff --git a/api/src/main/java/com/lunarclient/apollo/roundtrip/ApolloRequest.java b/api/src/main/java/com/lunarclient/apollo/roundtrip/ApolloRequest.java index 372d8ae3..f5bb25b9 100644 --- a/api/src/main/java/com/lunarclient/apollo/roundtrip/ApolloRequest.java +++ b/api/src/main/java/com/lunarclient/apollo/roundtrip/ApolloRequest.java @@ -67,4 +67,14 @@ public ApolloRequest() { this.sentTime = System.currentTimeMillis(); } + /** + * Returns the time to wait for a response, in milliseconds. + * + * @return the request timeout, in milliseconds + * @since 1.2.9 + */ + public long getTimeoutMillis() { + return TIMEOUT; + } + } diff --git a/api/src/main/java/com/lunarclient/apollo/roundtrip/ApolloRoundtripManager.java b/api/src/main/java/com/lunarclient/apollo/roundtrip/ApolloRoundtripManager.java index f0d5bce8..31771c4c 100644 --- a/api/src/main/java/com/lunarclient/apollo/roundtrip/ApolloRoundtripManager.java +++ b/api/src/main/java/com/lunarclient/apollo/roundtrip/ApolloRoundtripManager.java @@ -119,13 +119,14 @@ public void registerListener(ApolloRequest request this.paginationManager.handleTimeout(packetId); if (listener != null) { - Throwable error = new Throwable("Timeout exceeded!"); + Throwable error = new Throwable("Timeout exceeded! No " + request.getClass().getSimpleName() + + " response received within " + request.getTimeoutMillis() + "ms"); future.handleFailure(error); } } catch (Exception e) { e.printStackTrace(); } - }, ApolloRequest.TIMEOUT, TimeUnit.MILLISECONDS); + }, request.getTimeoutMillis(), TimeUnit.MILLISECONDS); this.listeners.put(packetId, (UncertainFuture) future); } diff --git a/common/src/main/java/com/lunarclient/apollo/module/transfer/TransferModuleImpl.java b/common/src/main/java/com/lunarclient/apollo/module/transfer/TransferModuleImpl.java index 6971cf56..febd0109 100644 --- a/common/src/main/java/com/lunarclient/apollo/module/transfer/TransferModuleImpl.java +++ b/common/src/main/java/com/lunarclient/apollo/module/transfer/TransferModuleImpl.java @@ -53,9 +53,20 @@ public TransferModuleImpl() { @Override public Future ping(@NonNull ApolloPlayer player, @NonNull PingRequest request) { + List serverIps = request.getServerIps(); + + if (serverIps == null || serverIps.isEmpty()) { + throw new IllegalArgumentException("PingRequest must contain at least 1 server IP!"); + } + + if (serverIps.size() > MAX_PINGS_PER_PACKET) { + throw new IllegalArgumentException("PingRequest supports up to " + MAX_PINGS_PER_PACKET + + " server IPs, got " + serverIps.size() + "!"); + } + com.lunarclient.apollo.transfer.v1.PingRequest requestProto = com.lunarclient.apollo.transfer.v1.PingRequest.newBuilder() .setRequestId(ByteString.copyFromUtf8(request.getRequestId().toString())) - .addAllServerIps(request.getServerIps()) + .addAllServerIps(serverIps) .build(); return ((AbstractApolloPlayer) player).sendRoundTripPacket(request, requestProto); diff --git a/docs/developers/modules/transfer.mdx b/docs/developers/modules/transfer.mdx index b2ea55b0..b099d973 100644 --- a/docs/developers/modules/transfer.mdx +++ b/docs/developers/modules/transfer.mdx @@ -119,6 +119,7 @@ public void transferExample(Player viewer) { You can provide up to `10` different addresses per ping packet. + Requests with more addresses are rejected with an `IllegalArgumentException`. @@ -209,6 +210,7 @@ public void transferExample(Player player) { You can provide up to `10` different addresses per ping packet. + Addresses beyond the first `10` are reported as `STATUS_TIMED_OUT` instead of being pinged. ```java diff --git a/example/bukkit/json/src/main/resources/plugin.yml b/example/bukkit/json/src/main/resources/plugin.yml index 334fe2a4..a1976db1 100644 --- a/example/bukkit/json/src/main/resources/plugin.yml +++ b/example/bukkit/json/src/main/resources/plugin.yml @@ -52,6 +52,8 @@ commands: description: "Pay Now!" richpresence: description: "Rich Presence!" + serverlink: + description: "Server Links!" saturation: description: "Saturation!" serverrule: diff --git a/example/bukkit/proto/src/main/resources/plugin.yml b/example/bukkit/proto/src/main/resources/plugin.yml index f74f917e..cdb5f82d 100644 --- a/example/bukkit/proto/src/main/resources/plugin.yml +++ b/example/bukkit/proto/src/main/resources/plugin.yml @@ -52,6 +52,8 @@ commands: description: "Pay Now!" richpresence: description: "Rich Presence!" + serverlink: + description: "Server Links!" saturation: description: "Saturation!" serverrule: