From 1a4929d8b53549b3d8d31d72a13fb7b499618230 Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Mon, 22 Apr 2024 20:57:33 -0400 Subject: [PATCH] Identify server software if querying is enabled --- .../mc/model/server/JavaMinecraftServer.java | 20 +++++++---- .../token/JavaServerChallengeStatusToken.java | 12 +++++-- .../me/braydon/mc/service/MaxMindService.java | 36 +++++++++++++++++++ .../impl/JavaMinecraftServerPinger.java | 8 +++++ API/src/main/resources/application.yml | 5 +++ 5 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 API/src/main/java/me/braydon/mc/service/MaxMindService.java diff --git a/API/src/main/java/me/braydon/mc/model/server/JavaMinecraftServer.java b/API/src/main/java/me/braydon/mc/model/server/JavaMinecraftServer.java index 49aaf9c..bcc3f0c 100644 --- a/API/src/main/java/me/braydon/mc/model/server/JavaMinecraftServer.java +++ b/API/src/main/java/me/braydon/mc/model/server/JavaMinecraftServer.java @@ -56,6 +56,11 @@ public final class JavaMinecraftServer extends MinecraftServer { */ private final Favicon favicon; + /** + * The software of this server, present if query is on. + */ + private final String software; + /** * The plugins on this server, present if * query is on and plugins are present. @@ -119,11 +124,13 @@ public final class JavaMinecraftServer extends MinecraftServer { private boolean mojangBanned; private JavaMinecraftServer(@NonNull String hostname, String ip, int port, @NonNull DNSRecord[] records, @NonNull Version version, - @NonNull Players players, @NonNull MOTD motd, Favicon favicon, Plugin[] plugins, ModInfo modInfo, ForgeData forgeData, - String world, boolean queryEnabled, boolean previewsChat, boolean enforcesSecureChat, boolean preventsChatReports, boolean mojangBanned) { + @NonNull Players players, @NonNull MOTD motd, Favicon favicon, String software, Plugin[] plugins, + ModInfo modInfo, ForgeData forgeData, String world, boolean queryEnabled, boolean previewsChat, + boolean enforcesSecureChat, boolean preventsChatReports, boolean mojangBanned) { super(hostname, ip, port, records, players, motd); this.version = version; this.favicon = favicon; + this.software = software; this.plugins = plugins; this.modInfo = modInfo; this.forgeData = forgeData; @@ -153,6 +160,7 @@ public final class JavaMinecraftServer extends MinecraftServer { if (motdString == null) { // Not a string motd, convert from Json motdString = new TextComponent(ComponentSerializer.parse(AppConfig.GSON.toJson(statusToken.getDescription()))).toLegacyText(); } + String software = challengeStatusToken == null ? null : challengeStatusToken.getSoftware(); // The server software // Get the plugins from the challenge token Plugin[] plugins = null; @@ -163,12 +171,12 @@ public final class JavaMinecraftServer extends MinecraftServer { } plugins = list.toArray(new Plugin[0]); } - String world = challengeStatusToken == null ? null : challengeStatusToken.getMap(); + String world = challengeStatusToken == null ? null : challengeStatusToken.getMap(); // The main server world return new JavaMinecraftServer(hostname, ip, port, records, statusToken.getVersion().detailedCopy(), Players.create(statusToken.getPlayers()), - MOTD.create(motdString), Favicon.create(statusToken.getFavicon(), hostname), plugins, statusToken.getModInfo(), statusToken.getForgeData(), - world, challengeStatusToken != null, statusToken.isPreviewsChat(), statusToken.isEnforcesSecureChat(), - statusToken.isPreventsChatReports(), false + MOTD.create(motdString), Favicon.create(statusToken.getFavicon(), hostname), software, plugins, statusToken.getModInfo(), + statusToken.getForgeData(), world, challengeStatusToken != null, statusToken.isPreviewsChat(), + statusToken.isEnforcesSecureChat(), statusToken.isPreventsChatReports(), false ); } diff --git a/API/src/main/java/me/braydon/mc/model/token/JavaServerChallengeStatusToken.java b/API/src/main/java/me/braydon/mc/model/token/JavaServerChallengeStatusToken.java index 26b148c..a138ae7 100644 --- a/API/src/main/java/me/braydon/mc/model/token/JavaServerChallengeStatusToken.java +++ b/API/src/main/java/me/braydon/mc/model/token/JavaServerChallengeStatusToken.java @@ -44,6 +44,11 @@ public final class JavaServerChallengeStatusToken { */ @NonNull private final String map; + /** + * The software of this server. + */ + @NonNull private final String software; + /** * The plugins of this server. */ @@ -58,11 +63,14 @@ public final class JavaServerChallengeStatusToken { */ @NonNull public static JavaServerChallengeStatusToken create(@NonNull Map rawData) { + String[] splitPlugins = rawData.get("plugins").split(": "); + String software = splitPlugins[0]; // The server software + Map plugins = new HashMap<>(); - for (String plugin : rawData.get("plugins").split(": ")[1].split("; ")) { + for (String plugin : splitPlugins[1].split("; ")) { String[] split = plugin.split(" "); plugins.put(split[0], split[1]); } - return new JavaServerChallengeStatusToken(rawData.get("map"), plugins); + return new JavaServerChallengeStatusToken(rawData.get("map"), software, plugins); } } \ No newline at end of file diff --git a/API/src/main/java/me/braydon/mc/service/MaxMindService.java b/API/src/main/java/me/braydon/mc/service/MaxMindService.java new file mode 100644 index 0000000..8c71667 --- /dev/null +++ b/API/src/main/java/me/braydon/mc/service/MaxMindService.java @@ -0,0 +1,36 @@ +/* + * MIT License + * + * Copyright (c) 2024 Braydon (Rainnny). + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package me.braydon.mc.service; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +/** + * @author Braydon + */ +@Service +public final class MaxMindService { + @Value("${maxmind.license}") + private String license; +} \ No newline at end of file diff --git a/API/src/main/java/me/braydon/mc/service/pinger/impl/JavaMinecraftServerPinger.java b/API/src/main/java/me/braydon/mc/service/pinger/impl/JavaMinecraftServerPinger.java index df093b4..99a52e4 100644 --- a/API/src/main/java/me/braydon/mc/service/pinger/impl/JavaMinecraftServerPinger.java +++ b/API/src/main/java/me/braydon/mc/service/pinger/impl/JavaMinecraftServerPinger.java @@ -139,6 +139,14 @@ public final class JavaMinecraftServerPinger implements MinecraftServerPinger