diff --git a/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java b/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java index 66e08a7..811747c 100644 --- a/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java +++ b/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java @@ -36,7 +36,7 @@ import static org.samo_lego.simpleauth.utils.SimpleLogger.logInfo; public class SimpleAuth implements DedicatedServerModInitializer { - public static SimpleAuthDatabase DB = new SimpleAuthDatabase(); + public static final SimpleAuthDatabase DB = new SimpleAuthDatabase(); public static final ExecutorService THREADPOOL = Executors.newCachedThreadPool(); @@ -45,19 +45,19 @@ public class SimpleAuth implements DedicatedServerModInitializer { * It's cleared on server stop in order to save some interactions with database during runtime. * Stores their data as {@link org.samo_lego.simpleauth.storage.PlayerCache PlayerCache} object. */ - public static HashMap playerCacheMap = new HashMap<>(); + public static final HashMap playerCacheMap = new HashMap<>(); /** * HashSet of player names that have Mojang accounts. * If player is saved in here, they will be treated as online-mode ones. */ - public static HashSet mojangAccountNamesCache = new HashSet<>(); + public static final HashSet mojangAccountNamesCache = new HashSet<>(); // Getting game directory public static final Path gameDirectory = FabricLoader.getInstance().getGameDir(); // Server properties - public static Properties serverProp = new Properties(); + public static final Properties serverProp = new Properties(); /** * Config of the SimpleAuth mod. diff --git a/src/main/java/org/samo_lego/simpleauth/commands/LogoutCommand.java b/src/main/java/org/samo_lego/simpleauth/commands/LogoutCommand.java index 7e975f9..d9dac8c 100644 --- a/src/main/java/org/samo_lego/simpleauth/commands/LogoutCommand.java +++ b/src/main/java/org/samo_lego/simpleauth/commands/LogoutCommand.java @@ -23,7 +23,7 @@ public class LogoutCommand { private static int logout(ServerCommandSource serverCommandSource) throws CommandSyntaxException { ServerPlayerEntity player = serverCommandSource.getPlayer(); - if(mojangAccountNamesCache.contains(player.getGameProfile().getName().toLowerCase())) { + if(!mojangAccountNamesCache.contains(player.getGameProfile().getName().toLowerCase())) { ((PlayerAuth) player).setAuthenticated(false); player.sendMessage(new LiteralText(config.lang.successfulLogout), false); } 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 d2076ba..ba4db49 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,6 @@ public class MixinPlayerAdvancementTracker { @Inject(method = "load(Lnet/minecraft/server/ServerAdvancementLoader;)V", at = @At("HEAD")) private void startMigratingOfflineAdvancements(ServerAdvancementLoader advancementLoader, CallbackInfo ci) { - System.out.println(this.advancementFile.isFile()); if(config.experimental.premiumAutologin && ((PlayerAuth) this.owner).isUsingMojangAccount() && !this.advancementFile.isFile()) { // Migrate String playername = owner.getGameProfile().getName().toLowerCase(); 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 7e33ad7..a31d868 100644 --- a/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerLoginNetworkHandler.java +++ b/src/main/java/org/samo_lego/simpleauth/mixin/MixinServerLoginNetworkHandler.java @@ -21,13 +21,15 @@ import static org.samo_lego.simpleauth.SimpleAuth.*; import static org.samo_lego.simpleauth.utils.SimpleLogger.logError; @Mixin(ServerLoginNetworkHandler.class) -public class MixinServerLoginNetworkHandler { +public abstract class MixinServerLoginNetworkHandler { @Shadow private GameProfile profile; @Shadow private int loginTicks; + @Shadow protected abstract GameProfile toOfflineProfile(GameProfile profile); + /** * Fake state of current player. */ @@ -49,6 +51,13 @@ public class MixinServerLoginNetworkHandler { } } + @Inject(method = "acceptPlayer()V", at = @At("HEAD")) + private void acceptPlayer(CallbackInfo ci) { + if(config.experimental.forceoOfflineUuids) { + this.profile = this.toOfflineProfile(this.profile); + } + } + /** * Checks whether the player has purchased an account. * If so, server is presented as online, and continues as in normal-online mode. 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 30064ad..3fe71ff 100644 --- a/src/main/java/org/samo_lego/simpleauth/storage/AuthConfig.java +++ b/src/main/java/org/samo_lego/simpleauth/storage/AuthConfig.java @@ -25,6 +25,7 @@ import java.nio.charset.StandardCharsets; import static org.samo_lego.simpleauth.SimpleAuth.serverProp; import static org.samo_lego.simpleauth.utils.SimpleLogger.logError; +import static org.samo_lego.simpleauth.utils.SimpleLogger.logInfo; public class AuthConfig { private static final Gson gson = new GsonBuilder() @@ -230,9 +231,15 @@ public class AuthConfig { new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8) )) { config = gson.fromJson(fileReader, AuthConfig.class); - if(config.experimental.premiumAutologin && !Boolean.parseBoolean(serverProp.getProperty("online-mode"))) { - logError("You cannot use server in offline mode and premiumAutologin! Disabling the latter."); - config.experimental.premiumAutologin = false; + if(!Boolean.parseBoolean(serverProp.getProperty("online-mode"))) { + if(config.experimental.forceoOfflineUuids) { + logInfo("Server is in offline mode, forceoOfflineUuids option is irrelevant. Setting it to false."); + config.experimental.forceoOfflineUuids = false; + } + if(config.experimental.premiumAutologin) { + logError("You cannot use server in offline mode and premiumAutologin! Disabling the latter."); + config.experimental.premiumAutologin = false; + } } } catch (IOException e) { throw new RuntimeException("[SimpleAuth] Problem occurred when trying to load config: ", e); diff --git a/src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java b/src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java index 0c5b17b..526af00 100644 --- a/src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java +++ b/src/main/java/org/samo_lego/simpleauth/storage/PlayerCache.java @@ -60,7 +60,7 @@ public class PlayerCache { public float pitch; } - public PlayerCache.LastLocation lastLocation = new PlayerCache.LastLocation(); + public final PlayerCache.LastLocation lastLocation = new PlayerCache.LastLocation(); private static final Gson gson = new Gson(); diff --git a/src/main/java/org/samo_lego/simpleauth/storage/SimpleAuthDatabase.java b/src/main/java/org/samo_lego/simpleauth/storage/SimpleAuthDatabase.java index 020a406..6b551f2 100644 --- a/src/main/java/org/samo_lego/simpleauth/storage/SimpleAuthDatabase.java +++ b/src/main/java/org/samo_lego/simpleauth/storage/SimpleAuthDatabase.java @@ -64,6 +64,7 @@ public class SimpleAuthDatabase { * @param data data to put inside database * @return true if operation was successful, otherwise false */ + @Deprecated public boolean registerUser(String uuid, String data) { try { if(!this.isUserRegistered(uuid)) { @@ -111,6 +112,7 @@ public class SimpleAuthDatabase { * @param uuid uuid of the player to update data for * @param data data to put inside database */ + @Deprecated public void updateUserData(String uuid, String data) { try { levelDBStore.put(bytes("UUID:" + uuid), bytes("data:" + data)); diff --git a/src/main/java/org/samo_lego/simpleauth/utils/AuthHelper.java b/src/main/java/org/samo_lego/simpleauth/utils/AuthHelper.java index cd39534..1eaa013 100644 --- a/src/main/java/org/samo_lego/simpleauth/utils/AuthHelper.java +++ b/src/main/java/org/samo_lego/simpleauth/utils/AuthHelper.java @@ -1,10 +1,5 @@ package org.samo_lego.simpleauth.utils; -import com.google.gson.JsonElement; -import com.google.gson.JsonNull; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import org.samo_lego.simpleauth.SimpleAuth; import org.samo_lego.simpleauth.utils.hashing.HasherArgon2; import org.samo_lego.simpleauth.utils.hashing.HasherBCrypt; @@ -12,9 +7,6 @@ import static org.samo_lego.simpleauth.SimpleAuth.config; import static org.samo_lego.simpleauth.SimpleAuth.playerCacheMap; public class AuthHelper { - // Json parser - private static final JsonParser parser = new JsonParser(); - /** * Checks password of user *