don't throw an error on geo lookup error

This commit is contained in:
Lee 2024-04-22 22:06:11 +01:00
parent a8558578f2
commit ff79372ead
4 changed files with 13 additions and 5 deletions

@ -58,7 +58,7 @@ public final class BedrockMinecraftServer extends MinecraftServer {
Edition edition = Edition.valueOf(split[0]);
Version version = new Version(Integer.parseInt(split[2]), split[3]);
Players players = new Players(Integer.parseInt(split[4]), Integer.parseInt(split[5]), null);
MOTD motd = MOTD.create(split[1] + "\n" + split[7]);
MOTD motd = MOTD.create(hostname, Platform.BEDROCK, split[1] + "\n" + split[7]);
GameMode gameMode = new GameMode(split[8], split.length > 9 ? Integer.parseInt(split[9]) : -1);
return new BedrockMinecraftServer(
split[6],

@ -97,7 +97,7 @@ public final class JavaMinecraftServer extends MinecraftServer {
hostname,
ip,
port,
MinecraftServer.MOTD.create(motdString),
MinecraftServer.MOTD.create(hostname, Platform.JAVA, motdString),
token.getPlayers(),
location,
records,

@ -4,6 +4,7 @@ import com.maxmind.geoip2.model.CityResponse;
import io.micrometer.common.lang.NonNull;
import lombok.*;
import xyz.mcutils.backend.common.ColorUtils;
import xyz.mcutils.backend.config.Config;
import xyz.mcutils.backend.model.dns.DNSRecord;
import xyz.mcutils.backend.service.pinger.MinecraftServerPinger;
import xyz.mcutils.backend.service.pinger.impl.BedrockMinecraftServerPinger;
@ -100,6 +101,11 @@ public class MinecraftServer {
*/
private final String[] html;
/**
* The URL to the server preview image.
*/
private final String preview;
/**
* Create a new MOTD from a raw string.
*
@ -107,12 +113,14 @@ public class MinecraftServer {
* @return the new motd
*/
@NonNull
public static MOTD create(@NonNull String raw) {
public static MOTD create(@NonNull String hostname, @NonNull Platform platform, @NonNull String raw) {
String[] rawLines = raw.split("\n"); // The raw lines
return new MOTD(
rawLines,
Arrays.stream(rawLines).map(ColorUtils::stripColor).toArray(String[]::new),
Arrays.stream(rawLines).map(ColorUtils::toHTML).toArray(String[]::new)
Arrays.stream(rawLines).map(ColorUtils::toHTML).toArray(String[]::new),
Config.INSTANCE.getWebPublicUrl() + "/server/%s/preview/%s".formatted(
platform.name().toLowerCase(),hostname)
);
}
}

@ -68,7 +68,7 @@ public class MaxMindService {
return database.city(InetAddress.getByName(ip));
} catch (IOException | GeoIp2Exception e) {
log.error("Failed to lookup the GeoIP information for '{}'", ip, e);
throw new RuntimeException("Failed to lookup the IP for '%s'".formatted(ip));
return null;
}
}