From 6638ba405fb429552ba52b0d01f0143062e25c7e Mon Sep 17 00:00:00 2001 From: mdxd44 Date: Thu, 28 Dec 2023 09:45:28 +0900 Subject: [PATCH] possible fix for mysql [untested] --- .../net/elytrium/limboauth/LimboAuth.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/elytrium/limboauth/LimboAuth.java b/src/main/java/net/elytrium/limboauth/LimboAuth.java index a6db4d96..3b206ac9 100644 --- a/src/main/java/net/elytrium/limboauth/LimboAuth.java +++ b/src/main/java/net/elytrium/limboauth/LimboAuth.java @@ -27,6 +27,7 @@ import com.j256.ormlite.dao.DaoManager; import com.j256.ormlite.dao.GenericRawResults; import com.j256.ormlite.db.DatabaseType; +import com.j256.ormlite.field.DatabaseFieldConfig; import com.j256.ormlite.field.FieldType; import com.j256.ormlite.stmt.QueryBuilder; import com.j256.ormlite.stmt.UpdateBuilder; @@ -54,6 +55,9 @@ import io.whitfin.siphash.SipHasher; import java.io.File; import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.InetAddress; import java.net.URI; import java.net.URISyntaxException; @@ -78,6 +82,7 @@ import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import java.util.function.Function; +import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -321,11 +326,33 @@ public void reload() { this.nicknameValidationPattern = Pattern.compile(Settings.IMP.MAIN.ALLOWED_NICKNAME_REGEX); try { - TableUtils.createTableIfNotExists(this.connectionSource, RegisteredPlayer.class); this.playerDao = DaoManager.createDao(this.connectionSource, RegisteredPlayer.class); + + // fuck ormlite + if (!this.connectionSource.getDatabaseType().isCreateIndexIfNotExistsSupported()) { + Field fieldConfigField = FieldType.class.getDeclaredField("fieldConfig"); + fieldConfigField.setAccessible(true); + for (FieldType fieldType : this.playerDao.getTableInfo().getFieldTypes()) { + if (fieldType.getIndexName() != null) { + ((DatabaseFieldConfig) fieldConfigField.get(fieldType)).setIndex(false); + } + } + } + + Method doCreateTable = TableUtils.class.getDeclaredMethod("doCreateTable", Dao.class, boolean.class); + doCreateTable.setAccessible(true); + doCreateTable.invoke(null, this.playerDao, true); + + Matcher format = Pattern.compile("%s") + .matcher("declare continue handler for sqlstate '42000' begin end; create index `AUTH_%s_idx` on `AUTH`(`%s`);"); + this.playerDao.executeRawNoArgs(format.replaceAll(RegisteredPlayer.PREMIUM_UUID_FIELD)); + this.playerDao.executeRawNoArgs(format.replaceAll(RegisteredPlayer.IP_FIELD)); + this.migrateDb(this.playerDao); } catch (SQLException e) { throw new SQLRuntimeException(e); + } catch (NoSuchFieldException | InvocationTargetException | IllegalAccessException | NoSuchMethodException e) { + throw new ReflectionException(e); } CommandManager manager = this.server.getCommandManager();