diff --git a/gradle.properties b/gradle.properties index 1837683..acb5727 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ loader_version=0.10.6+build.214 fabric_version=0.25.1+build.416-1.16 # Mod Properties -mod_version = 1.7.1 +mod_version = 1.7.2 maven_group = org.samo_lego archives_base_name = simpleauth diff --git a/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerAdvancementTracker.java b/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerAdvancementTracker.java index 61a7581..a141c4a 100644 --- a/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerAdvancementTracker.java +++ b/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerAdvancementTracker.java @@ -30,7 +30,7 @@ public class MixinPlayerAdvancementTracker { @Inject(method = "load(Lnet/minecraft/server/ServerAdvancementLoader;)V", at = @At("HEAD")) private void startMigratingOfflineAdvancements(ServerAdvancementLoader advancementLoader, CallbackInfo ci) { - if(config.experimental.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) this.owner).isUsingMojangAccount() && !this.advancementFile.isFile()) { + if(config.main.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) this.owner).isUsingMojangAccount() && !this.advancementFile.isFile()) { // Migrate String playername = owner.getGameProfile().getName(); this.advancementFile = new File(this.advancementFile.getParent(), PlayerEntity.getOfflinePlayerUuid(playername).toString() + ".json"); @@ -39,7 +39,7 @@ public class MixinPlayerAdvancementTracker { @Inject(method = "load(Lnet/minecraft/server/ServerAdvancementLoader;)V", at = @At("TAIL")) private void endMigratingOfflineAdvancements(ServerAdvancementLoader advancementLoader, CallbackInfo ci) { - if(config.experimental.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) this.owner).isUsingMojangAccount()) { + if(config.main.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) this.owner).isUsingMojangAccount()) { this.advancementFile = new File(this.advancementFile.getParent(), owner.getUuid() + ".json"); } } diff --git a/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerManager.java b/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerManager.java index 784d5c1..4579633 100644 --- a/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerManager.java +++ b/src/main/java/org/samo_lego/simpleauth/mixin/MixinPlayerManager.java @@ -66,7 +66,7 @@ public abstract class MixinPlayerManager { ordinal = 1 ) private File migrateOfflineStats(File file, PlayerEntity player) { - if(config.experimental.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) player).isUsingMojangAccount()) { + if(config.main.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) player).isUsingMojangAccount()) { String playername = player.getGameProfile().getName(); file = new File(file.getParent(), PlayerEntity.getOfflinePlayerUuid(playername) + ".json"); } @@ -83,7 +83,7 @@ public abstract class MixinPlayerManager { ) private void migrateOfflineStats(PlayerEntity player, CallbackInfoReturnable cir, UUID uUID, ServerStatHandler serverStatHandler, File serverStatsDir, File playerStatFile) { File onlineFile = new File(serverStatsDir, uUID + ".json"); - if(config.experimental.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) player).isUsingMojangAccount() && !onlineFile.exists()) { + if(config.main.premiumAutologin && !config.experimental.forceoOfflineUuids && ((PlayerAuth) player).isUsingMojangAccount() && !onlineFile.exists()) { ((ServerStatHandlerAccessor) serverStatHandler).setFile(onlineFile); } } diff --git a/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerLoginNetworkHandler.java b/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerLoginNetworkHandler.java index 6fa1ac6..e199e54 100644 --- a/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerLoginNetworkHandler.java +++ b/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerLoginNetworkHandler.java @@ -44,7 +44,7 @@ public abstract class MixinServerLoginNetworkHandler { */ @Inject(method = "tick()V", at = @At("HEAD"), cancellable = true) private void preTick(CallbackInfo ci) { - if (this.acceptCrackedPlayer && config.experimental.premiumAutologin) { + if (this.acceptCrackedPlayer && config.main.premiumAutologin) { ((ServerLoginNetworkHandler) (Object) this).acceptPlayer(); if (this.loginTicks++ == 600) @@ -77,12 +77,12 @@ public abstract class MixinServerLoginNetworkHandler { cancellable = true ) private void checkPremium(LoginHelloC2SPacket packet, CallbackInfo ci) { - if(config.experimental.premiumAutologin) { + if(config.main.premiumAutologin) { try { String playername = packet.getProfile().getName().toLowerCase(); Pattern pattern = Pattern.compile("^[a-z0-9_]{3,16}$"); Matcher matcher = pattern.matcher(playername); - if(playerCacheMap.containsKey(PlayerEntity.getOfflinePlayerUuid(playername).toString()) || !matcher.matches()) { + if(playerCacheMap.containsKey(PlayerEntity.getOfflinePlayerUuid(playername).toString()) || !matcher.matches() || config.main.forcedOfflinePlayers.contains(playername)) { // Player definitely doesn't have a mojang account this.acceptCrackedPlayer = true; diff --git a/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayerEntity.java b/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayerEntity.java index 1dbbce7..9ae0115 100644 --- a/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayerEntity.java +++ b/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerPlayerEntity.java @@ -162,7 +162,7 @@ public class MixinServerPlayerEntity implements PlayerAuth { @Override public boolean canSkipAuth() { // We ask CarpetHelper class since it has the imports needed - return (this.isRunningCarpet && isPlayerCarpetFake(this.player)) || (isUsingMojangAccount() && config.experimental.premiumAutologin); + return (this.isRunningCarpet && isPlayerCarpetFake(this.player)) || (isUsingMojangAccount() && config.main.premiumAutologin); } /** diff --git a/src/main/java/org/samo_lego/simpleauth/mixin/MixinWorldSaveHandler.java b/src/main/java/org/samo_lego/simpleauth/mixin/MixinWorldSaveHandler.java index 3651d48..1f4508d 100644 --- a/src/main/java/org/samo_lego/simpleauth/mixin/MixinWorldSaveHandler.java +++ b/src/main/java/org/samo_lego/simpleauth/mixin/MixinWorldSaveHandler.java @@ -75,7 +75,7 @@ public class MixinWorldSaveHandler { private CompoundTag migratePlayerData(CompoundTag compoundTag, PlayerEntity player) { // Checking for offline player data only if online doesn't exist yet String playername = player.getGameProfile().getName().toLowerCase(); - if(config.experimental.premiumAutologin && mojangAccountNamesCache.contains(playername) && !this.fileExists) { + if(config.main.premiumAutologin && mojangAccountNamesCache.contains(playername) && !this.fileExists) { if(config.experimental.debugMode) logInfo("Migrating data for " + playername); File file = new File(this.playerDataDir, PlayerEntity.getOfflinePlayerUuid(player.getGameProfile().getName()) + ".dat"); diff --git a/src/main/java/org/samo_lego/simpleauth/storage/AuthConfig.java b/src/main/java/org/samo_lego/simpleauth/storage/AuthConfig.java index 14c91e3..1a87bf6 100644 --- a/src/main/java/org/samo_lego/simpleauth/storage/AuthConfig.java +++ b/src/main/java/org/samo_lego/simpleauth/storage/AuthConfig.java @@ -22,6 +22,9 @@ import com.google.gson.GsonBuilder; import java.io.*; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import static org.samo_lego.simpleauth.SimpleAuth.serverProp; import static org.samo_lego.simpleauth.utils.SimpleLogger.logError; @@ -150,6 +153,28 @@ public class AuthConfig { public boolean useSsl = true; } + /** + * Whether players who have a valid session should skip the authentication process. + * You have to set online-mode to true in server.properties! + * (cracked players will still be able to enter, but they'll need to login) + * + * This protects premium usernames from being stolen, since cracked players + * with name that is found in Mojang database, are kicked. + */ + public boolean premiumAutologin = false; + + /** + * Contains a list of lower case (!) player names + * that should always be treated as offline. + * + * Used when AuthConfig#premiumAutoLogin is enabled + * and you have some players that want to use username, + * that is already taken. + */ + public ArrayList forcedOfflinePlayers = new ArrayList<>(Arrays.asList( + "" + )); + } public static class LangConfig { public String enterPassword = "ยง6You need to enter your password!"; @@ -236,15 +261,6 @@ public class AuthConfig { * @see wiki */ public boolean useBCryptLibrary = false; - /** - * Whether players who have a valid session should skip the authentication process. - * You have to set online-mode to true in server.properties! - * (cracked players will still be able to enter, but they'll need to login) - * - * This protects premium usernames from being stolen, since cracked players - * with name that is found in Mojang database, are kicked. - */ - public boolean premiumAutologin = false; /** * Whether to modify player uuids to offline style. * Note: this should be used only if you had your server @@ -284,9 +300,9 @@ public class AuthConfig { logInfo("Server is in offline mode, forceoOfflineUuids option is irrelevant. Setting it to false."); config.experimental.forceoOfflineUuids = false; } - if(config.experimental.premiumAutologin) { + if(config.main.premiumAutologin) { logError("You cannot use server in offline mode and premiumAutologin! Disabling the latter."); - config.experimental.premiumAutologin = false; + config.main.premiumAutologin = false; } } } catch (IOException e) {