mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 14:38:53 +00:00
Add timeout to network messages
This commit is contained in:
1 parent
98931c1900
commit
d368befabd
2 files changed
+9
-7
No files matched your search
@@ -109,16 +109,16 @@ public class RequestManager {
|
|||||||
MessagePayload.withTeleportRequest(request),
|
MessagePayload.withTeleportRequest(request),
|
||||||
Message.RelayType.MESSAGE,
|
Message.RelayType.MESSAGE,
|
||||||
plugin.getSettings().clusterId))
|
plugin.getSettings().clusterId))
|
||||||
.thenApply(message -> {
|
.orTimeout(3, TimeUnit.SECONDS)
|
||||||
if (message.payload.teleportRequest == null) {
|
.exceptionally(throwable -> null)
|
||||||
|
.thenApply(reply -> {
|
||||||
|
if (reply == null || reply.payload.teleportRequest == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the message was ignored by the recipient, return false
|
// If the message was ignored by the recipient, return false
|
||||||
return message.payload.teleportRequest.status == TeleportRequest.RequestStatus.PENDING;
|
return reply.payload.teleportRequest.status == TeleportRequest.RequestStatus.PENDING;
|
||||||
})
|
}).join();
|
||||||
.orTimeout(3, TimeUnit.SECONDS)
|
|
||||||
.exceptionally(throwable -> false).join();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return CompletableFuture.supplyAsync(() -> false);
|
return CompletableFuture.supplyAsync(() -> false);
|
||||||
|
|||||||
@@ -165,8 +165,10 @@ public class TeleportManager {
|
|||||||
MessagePayload.withPosition(position),
|
MessagePayload.withPosition(position),
|
||||||
Message.RelayType.MESSAGE,
|
Message.RelayType.MESSAGE,
|
||||||
plugin.getSettings().clusterId))
|
plugin.getSettings().clusterId))
|
||||||
|
.orTimeout(3, TimeUnit.SECONDS)
|
||||||
|
.exceptionally(throwable -> null)
|
||||||
.thenApply(result -> {
|
.thenApply(result -> {
|
||||||
if (result.payload.teleportResult == null) {
|
if (result == null || result.payload.teleportResult == null) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
return Optional.of(result.payload.teleportResult);
|
return Optional.of(result.payload.teleportResult);
|
||||||
|
|||||||
Reference in new issue
Block a user