fix bedrock invalid server pinging
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m36s

This commit is contained in:
Lee 2024-04-17 20:51:48 +01:00
parent 5fbab2c0ec
commit cbfaa867a9
2 changed files with 5 additions and 5 deletions

@ -1,5 +1,6 @@
package xyz.mcutils.backend.common; package xyz.mcutils.backend.common;
import com.google.gson.JsonObject;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode; import org.springframework.http.HttpStatusCode;

@ -10,10 +10,7 @@ import xyz.mcutils.backend.model.server.BedrockMinecraftServer;
import xyz.mcutils.backend.service.pinger.MinecraftServerPinger; import xyz.mcutils.backend.service.pinger.MinecraftServerPinger;
import java.io.IOException; import java.io.IOException;
import java.net.DatagramSocket; import java.net.*;
import java.net.InetSocketAddress;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
/** /**
* The {@link MinecraftServerPinger} for pinging * The {@link MinecraftServerPinger} for pinging
@ -56,11 +53,13 @@ public final class BedrockMinecraftServerPinger implements MinecraftServerPinger
throw new ResourceNotFoundException("Server didn't respond to ping"); throw new ResourceNotFoundException("Server didn't respond to ping");
} }
return BedrockMinecraftServer.create(hostname, ip, port, records, response); // Return the server return BedrockMinecraftServer.create(hostname, ip, port, records, response); // Return the server
} catch (IOException ex) { } catch (IOException ex ) {
if (ex instanceof UnknownHostException) { if (ex instanceof UnknownHostException) {
throw new BadRequestException("Unknown hostname: %s".formatted(hostname)); throw new BadRequestException("Unknown hostname: %s".formatted(hostname));
} else if (ex instanceof SocketTimeoutException) { } else if (ex instanceof SocketTimeoutException) {
throw new ResourceNotFoundException(ex); throw new ResourceNotFoundException(ex);
} else if (ex instanceof SocketException) {
throw new BadRequestException("An error occurred pinging %s:%s".formatted(hostname, port));
} }
log.error("An error occurred pinging %s:%s:".formatted(hostname, port), ex); log.error("An error occurred pinging %s:%s:".formatted(hostname, port), ex);
} }