diff --git a/authme-core/src/main/java/fr/xephi/authme/service/MojangApiService.java b/authme-core/src/main/java/fr/xephi/authme/service/MojangApiService.java index dffa3d734..767c84ad5 100644 --- a/authme-core/src/main/java/fr/xephi/authme/service/MojangApiService.java +++ b/authme-core/src/main/java/fr/xephi/authme/service/MojangApiService.java @@ -3,6 +3,8 @@ import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.output.ConsoleLoggerFactory; import fr.xephi.authme.util.UuidUtils; +import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.settings.properties.PremiumSettings; import javax.inject.Inject; import java.io.BufferedReader; @@ -10,6 +12,7 @@ import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; +import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.Optional; import java.util.UUID; @@ -21,16 +24,16 @@ */ public class MojangApiService { - private static final String PROFILE_URL = "https://api.mojang.com/users/profiles/minecraft/"; - private static final String HAS_JOINED_URL = - "https://sessionserver.mojang.com/session/minecraft/hasJoined"; private static final Pattern UUID_PATTERN = Pattern.compile("\"id\"\\s*:\\s*\"([0-9a-fA-F]{32})\""); private final ConsoleLogger logger = ConsoleLoggerFactory.get(MojangApiService.class); + private Settings settings; + @Inject - MojangApiService() { + MojangApiService(Settings settings) { + this.settings = settings; } /** @@ -41,7 +44,7 @@ public class MojangApiService { */ public Optional fetchUuidByName(String username) { try { - HttpURLConnection conn = openGet(PROFILE_URL + username); + HttpURLConnection conn = openGet(settings.getProperty(PremiumSettings.ACCOUNT_SERVER) + username); int code = conn.getResponseCode(); if (code == HttpURLConnection.HTTP_NO_CONTENT || code == HttpURLConnection.HTTP_NOT_FOUND) { return Optional.empty(); @@ -70,7 +73,9 @@ public Optional fetchUuidByName(String username) { */ public Optional hasJoined(String username, String serverHash) { try { - String url = HAS_JOINED_URL + "?username=" + username + "&serverId=" + serverHash; + String url = settings.getProperty(PremiumSettings.SESSION_SERVER) + + "?username=" + URLEncoder.encode(username, "UTF-8") + + "&serverId=" + URLEncoder.encode(serverHash, "UTF-8"); HttpURLConnection conn = openGet(url); int code = conn.getResponseCode(); if (code == HttpURLConnection.HTTP_NO_CONTENT || code == HttpURLConnection.HTTP_NOT_FOUND) { diff --git a/authme-core/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java b/authme-core/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java index f9c689ab9..2243836c5 100644 --- a/authme-core/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java +++ b/authme-core/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java @@ -15,6 +15,7 @@ import fr.xephi.authme.security.HashAlgorithm; import fr.xephi.authme.settings.properties.DatabaseSettings; import fr.xephi.authme.settings.properties.PluginSettings; +import fr.xephi.authme.settings.properties.PremiumSettings; import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.util.StringUtils; @@ -93,6 +94,7 @@ protected boolean performMigrations(PropertyReader reader, ConfigurationData con | moveSaltColumnConfigWithOtherColumnConfigs(reader, configurationData) | migrateTimeoutToLoginAndRegisterTimeout(reader, configurationData) | migrateDialogSettings(reader, configurationData) + | migratePremiumSetting(reader, configurationData) || hasDeprecatedProperties(reader); } @@ -154,6 +156,23 @@ private static boolean migrateDialogSettings(PropertyReader reader, Configuratio RegistrationSettings.PRE_JOIN_LOGIN_CANCEL_KICKS, reader, configData); } + /** + * Migrates the old {@code settings.enablePremium} setting to the new + * {@code settings.premium.enabled} path. + * + * @param reader The property reader + * @param configData Configuration data + * @return True if the configuration has changed, false otherwise + */ + private static boolean migratePremiumSetting(PropertyReader reader, ConfigurationData configData) { + return moveProperty( + newProperty("settings.enablePremium", false), + PremiumSettings.ENABLE_PREMIUM, + reader, + configData + ); + } + private static boolean hasDeprecatedProperties(PropertyReader reader) { String[] deprecatedProperties = { "Converter.Rakamak.newPasswordHash", "Hooks.chestshop", "Hooks.legacyChestshop", "Hooks.notifications", diff --git a/authme-core/src/main/java/fr/xephi/authme/settings/properties/PremiumSettings.java b/authme-core/src/main/java/fr/xephi/authme/settings/properties/PremiumSettings.java index e6a87e281..cc0f672b9 100644 --- a/authme-core/src/main/java/fr/xephi/authme/settings/properties/PremiumSettings.java +++ b/authme-core/src/main/java/fr/xephi/authme/settings/properties/PremiumSettings.java @@ -19,7 +19,15 @@ public final class PremiumSettings implements SettingsHolder { "Players must use /premium to opt in." }) public static final Property ENABLE_PREMIUM = - newProperty("settings.enablePremium", false); + newProperty("settings.premium.enabled", false); + + @Comment("Profile url used for premium verification.") + public static final Property ACCOUNT_SERVER = + newProperty("settings.premium.accountServer", "https://api.mojang.com/users/profiles/minecraft/"); + + @Comment("Session server used for premium verification.") + public static final Property SESSION_SERVER = + newProperty("settings.premium.sessionServer", "https://sessionserver.mojang.com"); private PremiumSettings() { }