From 0e7e93353073dc36bf550de7cb352dbdd5b447de Mon Sep 17 00:00:00 2001 From: Petr Ilin Date: Mon, 16 Jan 2023 07:26:09 +0300 Subject: 1.1.1 release: Client Mod support, RegisteredPlayer refactor --- src/main/java/net/elytrium/limboauth/Settings.java | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'src/main/java/net/elytrium/limboauth/Settings.java') diff --git a/src/main/java/net/elytrium/limboauth/Settings.java b/src/main/java/net/elytrium/limboauth/Settings.java index 9a61af3..15e7db0 100644 --- a/src/main/java/net/elytrium/limboauth/Settings.java +++ b/src/main/java/net/elytrium/limboauth/Settings.java @@ -17,7 +17,13 @@ package net.elytrium.limboauth; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; import java.util.List; +import java.util.Random; +import net.elytrium.commons.config.ConfigSerializer; import net.elytrium.commons.config.YamlConfig; import net.elytrium.commons.kyori.serialization.Serializers; import net.elytrium.limboapi.api.chunk.Dimension; @@ -208,6 +214,26 @@ public class Settings extends YamlConfig { @Comment("New players will be kicked with registrations-disabled-kick message") public boolean DISABLE_REGISTRATIONS = false; + @Create + public Settings.MAIN.MOD MOD; + + @Comment({ + "Implement the automatic login using the plugin, the LimboAuth client mod and optionally using a custom launcher", + "See https://github.com/Elytrium/LimboAuth-ClientMod" + }) + public static class MOD { + + public boolean ENABLED = true; + + @Comment("Should the plugin forbid logging in without a mod") + public boolean LOGIN_ONLY_BY_MOD = false; + + @Comment("The key must be the same in the plugin config and in the server hash issuer, if you use it") + @CustomSerializer(serializerClass = MD5KeySerializer.class) + public byte[] VERIFY_KEY = null; + + } + @Create public Settings.MAIN.WORLD_COORDS WORLD_COORDS; @@ -368,6 +394,8 @@ public class Settings extends YamlConfig { public String TOTP_RECOVERY = "{PRFX} &aYour recovery codes &7(Click to copy)&a: &6{0}"; public String DESTROY_SESSION_SUCCESSFUL = "{PRFX} &eYour session is now destroyed, you'll need to log in again after reconnecting."; + + public String MOD_SESSION_EXPIRED = "{PRFX} Your session has expired, log in again."; } @Create @@ -399,4 +427,41 @@ public class Settings extends YamlConfig { public String DATABASE = "limboauth"; public String CONNECTION_PARAMETERS = "?autoReconnect=true&initialTimeout=1&useSSL=false"; } + + public static class MD5KeySerializer extends ConfigSerializer { + + private final MessageDigest md5; + private final Random random; + private String originalValue; + + public MD5KeySerializer() throws NoSuchAlgorithmException { + super(byte[].class, String.class); + this.md5 = MessageDigest.getInstance("MD5"); + this.random = new SecureRandom(); + } + + @Override + public String serialize(byte[] from) { + if (this.originalValue == null || this.originalValue.isEmpty()) { + this.originalValue = generateRandomString(24); + } + + return this.originalValue; + } + + @Override + public byte[] deserialize(String from) { + this.originalValue = from; + return this.md5.digest(from.getBytes(StandardCharsets.UTF_8)); + } + + private String generateRandomString(int length) { + String chars = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890"; + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < length; i++) { + builder.append(chars.charAt(this.random.nextInt(chars.length()))); + } + return builder.toString(); + } + } } -- cgit