fix: Add timeout for GeyserBungeePingPassthrough#getPingInformation

Signed-off-by: ByteExceptionM <git@byteexception.eu>
This commit is contained in:
ByteExceptionM 2024-07-14 10:04:34 +02:00
parent 93b0a61265
commit d2813eff97
No known key found for this signature in database
GPG key ID: B98E6CFA80D07CEF
2 changed files with 15 additions and 3 deletions

View file

@ -43,6 +43,8 @@ import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
@AllArgsConstructor @AllArgsConstructor
public class GeyserBungeePingPassthrough implements IGeyserPingPassthrough, Listener { public class GeyserBungeePingPassthrough implements IGeyserPingPassthrough, Listener {
@ -59,7 +61,17 @@ public class GeyserBungeePingPassthrough implements IGeyserPingPassthrough, List
future.complete(event); future.complete(event);
} }
})); }));
ProxyPingEvent event = future.join();
ProxyPingEvent event;
try {
event = future.get(100, TimeUnit.MILLISECONDS);
} catch (Throwable cause) {
proxyServer.getLogger().log(Level.SEVERE, "Failed to get ping information for " + inetSocketAddress, cause);
return null;
}
ServerPing response = event.getResponse(); ServerPing response = event.getResponse();
return new GeyserPingInfo( return new GeyserPingInfo(
response.getDescriptionComponent().toLegacyText(), response.getDescriptionComponent().toLegacyText(),

View file

@ -35,10 +35,10 @@ import java.net.InetSocketAddress;
public interface IGeyserPingPassthrough { public interface IGeyserPingPassthrough {
/** /**
* Get the MOTD of the server displayed on the multiplayer screen * Get the ping information, including the MOTD and player count, from the server
* *
* @param inetSocketAddress the ip address of the client pinging the server * @param inetSocketAddress the ip address of the client pinging the server
* @return string of the MOTD * @return the ping information
*/ */
@Nullable @Nullable
GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress); GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress);