Skip to content

Commit

Permalink
possible fix for mysql [untested]
Browse files Browse the repository at this point in the history
  • Loading branch information
mdxd44 committed Dec 28, 2023
1 parent 1dbca38 commit 6638ba4
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/main/java/net/elytrium/limboauth/LimboAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 6638ba4

Please sign in to comment.