From 67c2b37337d0b8a5634e40af0d528b0736de56c3 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Fri, 10 Jul 2020 00:50:08 +0100 Subject: [PATCH] Fix version checking on older Java versions (#926) * Fix version checking on older Java versions We add a useragent header to stop cloudflare blocking the default Java useragent * Explain why we need the user agent Co-authored-by: Camotoy <20743703+DoctorMacc@users.noreply.github.com> --- .../geysermc/connector/command/defaults/VersionCommand.java | 5 +++-- .../src/main/java/org/geysermc/connector/utils/WebUtils.java | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/command/defaults/VersionCommand.java b/connector/src/main/java/org/geysermc/connector/command/defaults/VersionCommand.java index 7dd59712..50527968 100644 --- a/connector/src/main/java/org/geysermc/connector/command/defaults/VersionCommand.java +++ b/connector/src/main/java/org/geysermc/connector/command/defaults/VersionCommand.java @@ -29,6 +29,7 @@ import com.github.steveice10.mc.protocol.MinecraftConstants; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.command.CommandSender; import org.geysermc.connector.command.GeyserCommand; +import org.geysermc.connector.common.ChatColor; import org.geysermc.connector.utils.FileUtils; import org.geysermc.connector.utils.LanguageUtils; import org.geysermc.connector.utils.WebUtils; @@ -63,7 +64,7 @@ public class VersionCommand extends GeyserCommand { if (buildXML.startsWith("")) { int latestBuildNum = Integer.parseInt(buildXML.replaceAll("<(\\\\)?(/)?buildNumber>", "").trim()); int buildNum = Integer.parseInt(gitProp.getProperty("git.build.number")); - if (latestBuildNum != buildNum) { + if (latestBuildNum == buildNum) { sender.sendMessage(LanguageUtils.getLocaleStringLog("geyser.commands.version.no_updates")); } else { sender.sendMessage(LanguageUtils.getLocaleStringLog("geyser.commands.version.outdated", (latestBuildNum - buildNum), "http://ci.geysermc.org/")); @@ -73,7 +74,7 @@ public class VersionCommand extends GeyserCommand { } } catch (IOException | AssertionError | NumberFormatException e) { GeyserConnector.getInstance().getLogger().error(LanguageUtils.getLocaleStringLog("geyser.commands.version.failed"), e); - sender.sendMessage(LanguageUtils.getLocaleStringLog("geyser.commands.version.failed")); + sender.sendMessage(ChatColor.RED + LanguageUtils.getLocaleStringLog("geyser.commands.version.failed")); } } } diff --git a/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java b/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java index 7a1a0215..c29b95e8 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java @@ -25,6 +25,8 @@ package org.geysermc.connector.utils; +import org.geysermc.connector.GeyserConnector; + import java.io.*; import java.net.HttpURLConnection; import java.net.URL; @@ -47,6 +49,7 @@ public class WebUtils { url = new URL(reqURL); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); + con.setRequestProperty("User-Agent", "Geyser-" + GeyserConnector.getInstance().getPlatformType().toString() + "/" + GeyserConnector.VERSION); // Otherwise Java 8 fails on checking updates BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine;