diff --git a/build.gradle b/build.gradle index 6f9d8b8d..b53e98b3 100644 --- a/build.gradle +++ b/build.gradle @@ -102,11 +102,11 @@ modrinth { token.set(System.getenv("MODRINTH_TOKEN")) projectId.set("aZj58GfX") versionNumber.set("${project.version}") - versionName = "[1.20] ${project.version}" + versionName = "[1.20, 1.20.1] ${project.version}" versionType = "beta" changelog.set("Release notes and Changelog: \nhttps://github.com/NikitaCartes/EasyAuth/releases/tag/${project.version}") uploadFile = remapJar - gameVersions.addAll("1.20") + gameVersions.addAll("1.20", "1.20.1") loaders = ["fabric", "quilt"] dependencies { required.project("P7dR8mSH") // Fabric API @@ -130,9 +130,10 @@ curseforge { addGameVersion("Java 17") addGameVersion("1.20") + addGameVersion("1.20.1") mainArtifact(remapJar) { - displayName = "[1.20] ${project.version}" + displayName = "[1.20, 1.20.1] ${project.version}" relations { requiredDependency("fabric-api") embeddedLibrary 'server-translation-api' diff --git a/gradle.properties b/gradle.properties index 76b259ec..f051d9c5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ # Mod mod_name=EasyAuth mod_id=easyauth -mod_version=3.0.0-16 +mod_version=3.0.0-17 # Fabric minecraft_version=1.20 diff --git a/src/main/java/xyz/nikitacartes/easyauth/commands/AuthCommand.java b/src/main/java/xyz/nikitacartes/easyauth/commands/AuthCommand.java index 7887ddc9..dca7a993 100644 --- a/src/main/java/xyz/nikitacartes/easyauth/commands/AuthCommand.java +++ b/src/main/java/xyz/nikitacartes/easyauth/commands/AuthCommand.java @@ -13,9 +13,6 @@ import xyz.nikitacartes.easyauth.storage.AuthConfig; import xyz.nikitacartes.easyauth.storage.PlayerCache; import xyz.nikitacartes.easyauth.storage.database.DBApiException; -import xyz.nikitacartes.easyauth.storage.database.LevelDB; -import xyz.nikitacartes.easyauth.storage.database.MongoDB; -import xyz.nikitacartes.easyauth.storage.database.MySQL; import xyz.nikitacartes.easyauth.utils.AuthHelper; import xyz.nikitacartes.easyauth.utils.TranslationHelper; @@ -364,6 +361,7 @@ private static int addPlayerToForcedOffline(ServerCommandSource source, String p THREADPOOL.submit(() -> { config.main.forcedOfflinePlayers.add(player.toLowerCase(Locale.ROOT)); + config.experimental.verifiedOnlinePlayer.remove(player.toLowerCase(Locale.ROOT)); config.save(new File("./mods/EasyAuth/config.json")); }); diff --git a/src/main/java/xyz/nikitacartes/easyauth/mixin/ServerLoginNetworkHandlerMixin.java b/src/main/java/xyz/nikitacartes/easyauth/mixin/ServerLoginNetworkHandlerMixin.java index 76306644..0761bd8e 100644 --- a/src/main/java/xyz/nikitacartes/easyauth/mixin/ServerLoginNetworkHandlerMixin.java +++ b/src/main/java/xyz/nikitacartes/easyauth/mixin/ServerLoginNetworkHandlerMixin.java @@ -19,6 +19,7 @@ import java.util.regex.Pattern; import static xyz.nikitacartes.easyauth.EasyAuth.*; +import static xyz.nikitacartes.easyauth.utils.EasyLogger.LogDebug; import static xyz.nikitacartes.easyauth.utils.EasyLogger.LogError; @Mixin(ServerLoginNetworkHandler.class) @@ -60,22 +61,33 @@ private void acceptPlayer(CallbackInfo ci) { private void checkPremium(LoginHelloC2SPacket packet, CallbackInfo ci) { if (config.main.premiumAutologin) { try { - // Todo: use config String playername = packet.name().toLowerCase(); Pattern pattern = Pattern.compile("^[a-z0-9_]{3,16}$"); Matcher matcher = pattern.matcher(playername); + if (config.main.forcedOfflinePlayers.contains(playername)) { + LogDebug("Player " + playername + " is forced to be offline"); + mojangAccountNamesCache.remove(playername); + state = ServerLoginNetworkHandler.State.READY_TO_ACCEPT; + + this.profile = new GameProfile(null, packet.name()); + ci.cancel(); + return; + } if (mojangAccountNamesCache.contains(playername) || config.experimental.verifiedOnlinePlayer.contains(playername)) { + LogDebug("Player " + playername + " is cached as online player. Authentication continues as vanilla"); mojangAccountNamesCache.add(playername); return; } - if ((playerCacheMap.containsKey(Uuids.getOfflinePlayerUuid(playername).toString()) || !matcher.matches() || config.main.forcedOfflinePlayers.contains(playername))) { + if ((playerCacheMap.containsKey(Uuids.getOfflinePlayerUuid(playername).toString()) || !matcher.matches())) { // Player definitely doesn't have a mojang account + LogDebug("Player " + playername + " is cached as offline player"); state = ServerLoginNetworkHandler.State.READY_TO_ACCEPT; this.profile = new GameProfile(null, packet.name()); ci.cancel(); } else { // Checking account status from API + LogDebug("Checking player " + playername + " for premium status"); HttpsURLConnection httpsURLConnection = (HttpsURLConnection) new URL("https://api.mojang.com/users/profiles/minecraft/" + playername).openConnection(); httpsURLConnection.setRequestMethod("GET"); httpsURLConnection.setConnectTimeout(5000); @@ -85,7 +97,7 @@ private void checkPremium(LoginHelloC2SPacket packet, CallbackInfo ci) { if (response == HttpURLConnection.HTTP_OK) { // Player has a Mojang account httpsURLConnection.disconnect(); - + LogDebug("Player " + playername + " has a Mojang account"); // Caches the request mojangAccountNamesCache.add(playername); @@ -95,6 +107,7 @@ private void checkPremium(LoginHelloC2SPacket packet, CallbackInfo ci) { } else if (response == HttpURLConnection.HTTP_NO_CONTENT || response == HttpURLConnection.HTTP_NOT_FOUND) { // Player doesn't have a Mojang account httpsURLConnection.disconnect(); + LogDebug("Player " + playername + " doesn't have a Mojang account"); state = ServerLoginNetworkHandler.State.READY_TO_ACCEPT; this.profile = new GameProfile(null, packet.name()); diff --git a/src/main/java/xyz/nikitacartes/easyauth/storage/AuthConfig.java b/src/main/java/xyz/nikitacartes/easyauth/storage/AuthConfig.java index c74c6f14..fca66da4 100644 --- a/src/main/java/xyz/nikitacartes/easyauth/storage/AuthConfig.java +++ b/src/main/java/xyz/nikitacartes/easyauth/storage/AuthConfig.java @@ -29,13 +29,11 @@ import java.io.*; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Collections; import java.util.regex.Pattern; import static xyz.nikitacartes.easyauth.EasyAuth.serverProp; import static xyz.nikitacartes.easyauth.EasyAuth.DB; -import static xyz.nikitacartes.easyauth.utils.EasyLogger.LogError; -import static xyz.nikitacartes.easyauth.utils.EasyLogger.LogInfo; +import static xyz.nikitacartes.easyauth.utils.EasyLogger.*; public class AuthConfig { private static final Gson gson = new GsonBuilder() @@ -66,9 +64,13 @@ public static AuthConfig load(File file) { config.experimental.forcedOfflineUuids = false; } if (config.main.premiumAutologin) { - LogInfo("You cannot use server in offline mode and premiumAutologin! Disabling the latter."); + LogWarn("You cannot use server in offline mode and premiumAutologin! Disabling the latter."); config.main.premiumAutologin = false; } + } else { + if (!config.main.premiumAutologin) { + LogWarn("With online-mode enabled and premiumAutoLogin disabled, offline players will not be able to join."); + } } if (config.experimental.enableServerSideTranslation && !FabricLoader.getInstance().isModLoaded("server_translations_api")) { config.experimental.enableServerSideTranslation = false; @@ -211,7 +213,7 @@ public static class MainConfig { * This protects premium usernames from being stolen, since cracked players * with name that is found in Mojang database, are kicked. */ - public boolean premiumAutologin = false; + public boolean premiumAutologin = true; /** * Whether bedrock players should skip the authentication process. * You have to set online-mode to true in server.properties! diff --git a/src/main/java/xyz/nikitacartes/easyauth/utils/EasyLogger.java b/src/main/java/xyz/nikitacartes/easyauth/utils/EasyLogger.java index 28663001..d8b73703 100644 --- a/src/main/java/xyz/nikitacartes/easyauth/utils/EasyLogger.java +++ b/src/main/java/xyz/nikitacartes/easyauth/utils/EasyLogger.java @@ -35,18 +35,14 @@ public static void LogWarn(String message, Throwable e) { } public static void LogDebug(String message) { - if (config == null) { - log(Level.DEBUG, message); - } else if (config.experimental.debugMode) { - log(Level.DEBUG, message); + if (config != null && config.experimental.debugMode) { + log(Level.INFO, "[DEBUG]: " + message); } } public static void LogDebug(String message, Throwable e) { - if (config == null) { - log(Level.DEBUG, message); - } else if (config.experimental.debugMode) { - log(Level.DEBUG, message, e); + if (config != null && config.experimental.debugMode) { + log(Level.INFO, "[DEBUG]: " + message, e); } }