DNS records shouldnt be NonNull
All checks were successful
Deploy API / docker (17, 3.8.5) (push) Successful in 1m45s

This commit is contained in:
Braydon 2024-04-22 23:44:19 -04:00
parent 52ff61c554
commit 2261bde6cb
5 changed files with 16 additions and 13 deletions

@ -64,9 +64,9 @@ public class MinecraftServer {
@EqualsAndHashCode.Include private final int port; @EqualsAndHashCode.Include private final int port;
/** /**
* The DNS records resolved for this server. * The DNS records resolved for this server, null if none.
*/ */
@NonNull private final DNSRecord[] records; private final DNSRecord[] records;
/** /**
* The Geo location of this server, null if unknown. * The Geo location of this server, null if unknown.

@ -55,7 +55,7 @@ public final class BedrockMinecraftServer extends MinecraftServer {
@NonNull private final GameMode gamemode; @NonNull private final GameMode gamemode;
private BedrockMinecraftServer(@NonNull String id, @NonNull String hostname, String ip, int port, GeoLocation geo, private BedrockMinecraftServer(@NonNull String id, @NonNull String hostname, String ip, int port, GeoLocation geo,
@NonNull DNSRecord[] records, @NonNull Edition edition, @NonNull Version version, DNSRecord[] records, @NonNull Edition edition, @NonNull Version version,
@NonNull Players players, @NonNull MOTD motd, @NonNull GameMode gamemode) { @NonNull Players players, @NonNull MOTD motd, @NonNull GameMode gamemode) {
super(hostname, ip, port, records, geo, players, motd); super(hostname, ip, port, records, geo, players, motd);
this.id = id; this.id = id;
@ -70,13 +70,12 @@ public final class BedrockMinecraftServer extends MinecraftServer {
* @param hostname the hostname of the server * @param hostname the hostname of the server
* @param ip the IP address of the server * @param ip the IP address of the server
* @param port the port of the server * @param port the port of the server
* @param records the DNS records of the server * @param records the DNS records of the server, if any
* @param token the status token * @param token the status token
* @return the Bedrock Minecraft server * @return the Bedrock Minecraft server
*/ */
@NonNull @NonNull
public static BedrockMinecraftServer create(@NonNull String hostname, String ip, int port, public static BedrockMinecraftServer create(@NonNull String hostname, String ip, int port, DNSRecord[] records, @NonNull String token) {
@NonNull DNSRecord[] records, @NonNull String token) {
String[] split = token.split(";"); // Split the token String[] split = token.split(";"); // Split the token
Edition edition = Edition.valueOf(split[0]); Edition edition = Edition.valueOf(split[0]);
Version version = new Version(Integer.parseInt(split[2]), split[3]); Version version = new Version(Integer.parseInt(split[2]), split[3]);

@ -123,7 +123,7 @@ public final class JavaMinecraftServer extends MinecraftServer {
*/ */
private boolean mojangBanned; private boolean mojangBanned;
private JavaMinecraftServer(@NonNull String hostname, String ip, int port, @NonNull DNSRecord[] records, GeoLocation geo, private JavaMinecraftServer(@NonNull String hostname, String ip, int port, DNSRecord[] records, GeoLocation geo,
@NonNull Version version, @NonNull Players players, @NonNull MOTD motd, Favicon favicon, @NonNull Version version, @NonNull Players players, @NonNull MOTD motd, Favicon favicon,
String software, Plugin[] plugins, ModInfo modInfo, ForgeData forgeData, String world, String software, Plugin[] plugins, ModInfo modInfo, ForgeData forgeData, String world,
boolean queryEnabled, boolean previewsChat, boolean enforcesSecureChat, boolean preventsChatReports, boolean queryEnabled, boolean previewsChat, boolean enforcesSecureChat, boolean preventsChatReports,
@ -149,13 +149,13 @@ public final class JavaMinecraftServer extends MinecraftServer {
* @param hostname the hostname of the server * @param hostname the hostname of the server
* @param ip the IP address of the server * @param ip the IP address of the server
* @param port the port of the server * @param port the port of the server
* @param records the DNS records of the server * @param records the DNS records of the server, if any
* @param statusToken the status token * @param statusToken the status token
* @param challengeStatusToken the challenge status token, null if none * @param challengeStatusToken the challenge status token, null if none
* @return the Java Minecraft server * @return the Java Minecraft server
*/ */
@NonNull @NonNull
public static JavaMinecraftServer create(@NonNull String hostname, String ip, int port, @NonNull DNSRecord[] records, public static JavaMinecraftServer create(@NonNull String hostname, String ip, int port, DNSRecord[] records,
@NonNull JavaServerStatusToken statusToken, JavaServerChallengeStatusToken challengeStatusToken) { @NonNull JavaServerStatusToken statusToken, JavaServerChallengeStatusToken challengeStatusToken) {
String motdString = statusToken.getDescription() instanceof String ? (String) statusToken.getDescription() : null; String motdString = statusToken.getDescription() instanceof String ? (String) statusToken.getDescription() : null;
if (motdString == null) { // Not a string motd, convert from Json if (motdString == null) { // Not a string motd, convert from Json

@ -30,7 +30,6 @@ import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy; import jakarta.annotation.PreDestroy;
import lombok.*; import lombok.*;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import me.braydon.mc.common.EnvironmentUtils;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.codehaus.plexus.archiver.tar.TarGZipUnArchiver; import org.codehaus.plexus.archiver.tar.TarGZipUnArchiver;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;

@ -438,9 +438,10 @@ public final class MojangService {
throw new BadRequestException("Invalid port defined"); throw new BadRequestException("Invalid port defined");
} }
} }
String cacheKey = "%s-%s".formatted(platform.name(), lookupHostname.replace(":", "-"));
// Check the cache for the server // Check the cache for the server
Optional<CachedMinecraftServer> cached = minecraftServerCache.findById("%s-%s".formatted(platform.name(), lookupHostname)); Optional<CachedMinecraftServer> cached = minecraftServerCache.findById(cacheKey);
if (cached.isPresent()) { // Respond with the cache if present if (cached.isPresent()) { // Respond with the cache if present
log.info("Found server in cache: {}", hostname); log.info("Found server in cache: {}", hostname);
return cached.get(); return cached.get();
@ -466,7 +467,11 @@ public final class MojangService {
CityResponse geo = null; // The server's Geo location CityResponse geo = null; // The server's Geo location
try { try {
log.info("Looking up Geo location data for {}...", ip); log.info("Looking up Geo location data for {}...", ip);
geo = maxMindService.lookupCity(InetAddress.getByName(ip)); // Get the Geo location
InetAddress address = InetAddress.getByName(ip);
if (!address.isAnyLocalAddress()) { // Get the Geo location
geo = maxMindService.lookupCity(address);
}
} catch (Exception ex) { } catch (Exception ex) {
log.error("Failed looking up Geo location data for %s:".formatted(ip), ex); log.error("Failed looking up Geo location data for %s:".formatted(ip), ex);
} }
@ -481,7 +486,7 @@ public final class MojangService {
} }
CachedMinecraftServer minecraftServer = new CachedMinecraftServer( CachedMinecraftServer minecraftServer = new CachedMinecraftServer(
platform.name() + "-" + lookupHostname, response, System.currentTimeMillis() cacheKey, response, System.currentTimeMillis()
); );
// Get the blocked status of the Java server // Get the blocked status of the Java server