Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
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;
import java.io.IOException;
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;
Expand All @@ -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;
}

/**
Expand All @@ -41,7 +44,7 @@ public class MojangApiService {
*/
public Optional<UUID> fetchUuidByName(String username) {
try {
HttpURLConnection conn = openGet(PROFILE_URL + username);
HttpURLConnection conn = openGet(settings.getProperty(PremiumSettings.ACCOUNT_SERVER) + username);
int code = conn.getResponseCode();
Comment on lines 46 to 48
if (code == HttpURLConnection.HTTP_NO_CONTENT || code == HttpURLConnection.HTTP_NOT_FOUND) {
return Optional.empty();
Expand Down Expand Up @@ -70,7 +73,9 @@ public Optional<UUID> fetchUuidByName(String username) {
*/
public Optional<UUID> 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");
Comment on lines +76 to +78
HttpURLConnection conn = openGet(url);
int code = conn.getResponseCode();
if (code == HttpURLConnection.HTTP_NO_CONTENT || code == HttpURLConnection.HTTP_NOT_FOUND) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
);
Comment on lines +167 to +173
}

private static boolean hasDeprecatedProperties(PropertyReader reader) {
String[] deprecatedProperties = {
"Converter.Rakamak.newPasswordHash", "Hooks.chestshop", "Hooks.legacyChestshop", "Hooks.notifications",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ public final class PremiumSettings implements SettingsHolder {
"Players must use /premium to opt in."
})
public static final Property<Boolean> ENABLE_PREMIUM =
newProperty("settings.enablePremium", false);
newProperty("settings.premium.enabled", false);

@Comment("Profile url used for premium verification.")
public static final Property<String> ACCOUNT_SERVER =
newProperty("settings.premium.accountServer", "https://api.mojang.com/users/profiles/minecraft/");

@Comment("Session server used for premium verification.")
public static final Property<String> SESSION_SERVER =
newProperty("settings.premium.sessionServer", "https://sessionserver.mojang.com");
Comment on lines +28 to +30

private PremiumSettings() {
}
Expand Down