Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,15 @@ public final class PingRequest extends ApolloRequest<PingResponse> {
*/
List<String> 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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ApolloPlatform.Kind> getSupportedPlatforms() {
return Arrays.asList(ApolloPlatform.Kind.SERVER, ApolloPlatform.Kind.PROXY);
Expand All @@ -55,6 +63,8 @@ public Collection<ApolloPlatform.Kind> 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<PingResponse> ping(ApolloPlayer player, List<String> serverIps) {
Expand Down Expand Up @@ -85,6 +95,8 @@ public Future<TransferResponse> 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<PingResponse> ping(ApolloPlayer player, PingRequest request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,14 @@ public <T extends ApolloResponse> void registerListener(ApolloRequest<T> 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<ApolloResponse>) future);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,20 @@ public TransferModuleImpl() {

@Override
public Future<PingResponse> ping(@NonNull ApolloPlayer player, @NonNull PingRequest request) {
List<String> 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);
Expand Down
2 changes: 2 additions & 0 deletions docs/developers/modules/transfer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public void transferExample(Player viewer) {

<Callout type="info">
You can provide up to `10` different addresses per ping packet.
Requests with more addresses are rejected with an `IllegalArgumentException`.
</Callout>


Expand Down Expand Up @@ -209,6 +210,7 @@ public void transferExample(Player player) {

<Callout type="info">
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.
</Callout>

```java
Expand Down
2 changes: 2 additions & 0 deletions example/bukkit/json/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ commands:
description: "Pay Now!"
richpresence:
description: "Rich Presence!"
serverlink:
description: "Server Links!"
saturation:
description: "Saturation!"
serverrule:
Expand Down
2 changes: 2 additions & 0 deletions example/bukkit/proto/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ commands:
description: "Pay Now!"
richpresence:
description: "Rich Presence!"
serverlink:
description: "Server Links!"
saturation:
description: "Saturation!"
serverrule:
Expand Down
Loading