use ip not hostname for getting geolocation

This commit is contained in:
Lee 2024-04-21 23:42:33 +01:00
parent 67efda71d2
commit a8558578f2
3 changed files with 8 additions and 8 deletions

@ -55,20 +55,20 @@ public class MaxMindService {
} }
/** /**
* Lookup the GeoIP information for the query. * Lookup the GeoIP information for the ip.
* *
* @param query The query to lookup * @param ip The query to lookup
* @return The GeoIP information * @return The GeoIP information
*/ */
public static CityResponse lookup(String query) { public static CityResponse lookup(String ip) {
if (database == null) { // The database isn't loaded, return null if (database == null) { // The database isn't loaded, return null
return null; return null;
} }
try { try {
return database.city(InetAddress.getByName(query)); return database.city(InetAddress.getByName(ip));
} catch (IOException | GeoIp2Exception e) { } catch (IOException | GeoIp2Exception e) {
log.error("Failed to lookup the GeoIP information for '{}'", query, e); log.error("Failed to lookup the GeoIP information for '{}'", ip, e);
throw new RuntimeException("Failed to lookup the GeoIP information for '%s'".formatted(query)); throw new RuntimeException("Failed to lookup the IP for '%s'".formatted(ip));
} }
} }

@ -58,7 +58,7 @@ public final class BedrockMinecraftServerPinger implements MinecraftServerPinger
throw new ResourceNotFoundException("Server '%s' didn't respond to ping".formatted(hostname)); throw new ResourceNotFoundException("Server '%s' didn't respond to ping".formatted(hostname));
} }
return BedrockMinecraftServer.create(hostname, ip, port, records, return BedrockMinecraftServer.create(hostname, ip, port, records,
MinecraftServer.GeoLocation.fromMaxMind(MaxMindService.lookup(hostname)), response); // Return the server MinecraftServer.GeoLocation.fromMaxMind(MaxMindService.lookup(ip)), 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));

@ -53,7 +53,7 @@ public final class JavaMinecraftServerPinger implements MinecraftServerPinger<Ja
packetStatusInStart.process(inputStream, outputStream); packetStatusInStart.process(inputStream, outputStream);
JavaServerStatusToken token = Main.GSON.fromJson(packetStatusInStart.getResponse(), JavaServerStatusToken.class); JavaServerStatusToken token = Main.GSON.fromJson(packetStatusInStart.getResponse(), JavaServerStatusToken.class);
return JavaMinecraftServer.create(hostname, ip, port, records, return JavaMinecraftServer.create(hostname, ip, port, records,
MinecraftServer.GeoLocation.fromMaxMind(MaxMindService.lookup(hostname)), token); MinecraftServer.GeoLocation.fromMaxMind(MaxMindService.lookup(ip)), token);
} }
} catch (IOException ex) { } catch (IOException ex) {
if (ex instanceof UnknownHostException) { if (ex instanceof UnknownHostException) {