Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
}

setGroup("net.elytrium")
setVersion("1.1.14")
setVersion("1.2.0-SNAPSHOT-4")

java {
setSourceCompatibility(JavaVersion.VERSION_17)
Expand Down Expand Up @@ -58,8 +58,8 @@ dependencies {
implementation("at.favre.lib:bcrypt:0.9.0")
implementation("dev.samstevens.totp:totp:1.7.1")

implementation("com.j256.ormlite:ormlite-jdbc:6.1")
implementation("de.mkammerer:argon2-jvm-nolibs:2.11")
implementation("com.zaxxer:HikariCP:6.2.1")

implementation("io.whitfin:siphash:2.0.0")

Expand All @@ -84,7 +84,6 @@ shadowJar {
exclude("META-INF/*.txt")
exclude("google/protobuf/**")
exclude("com/google/protobuf/**")
exclude("com/j256/ormlite/**/*.txt")
exclude("com/mysql/cj/x/**")
exclude("com/mysql/cj/xdevapi/**")
exclude("com/sun/jna/aix-ppc*/**")
Expand All @@ -106,7 +105,6 @@ shadowJar {
minimize()

relocate("at.favre.lib", "net.elytrium.limboauth.thirdparty.at.favre.lib")
relocate("com.j256.ormlite", "net.elytrium.limboauth.thirdparty.com.j256.ormlite")
relocate("com.sun.jna", "net.elytrium.limboauth.thirdparty.com.sun.jna") {
exclude("com.sun.jna.Native") // For compatibility with native methods.
}
Expand Down
1 change: 1 addition & 0 deletions lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lombok.accessors.chain=true
277 changes: 67 additions & 210 deletions src/main/java/net/elytrium/limboauth/LimboAuth.java

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions src/main/java/net/elytrium/limboauth/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,20 @@
import net.elytrium.limboapi.api.file.BuiltInWorldFileType;
import net.elytrium.limboapi.api.player.GameMode;
import net.elytrium.limboauth.command.CommandPermissionState;
import net.elytrium.limboauth.dependencies.DatabaseLibrary;
import net.elytrium.limboauth.data.DataProvider;
import net.elytrium.limboauth.migration.MigrationHash;
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.title.Title;
import net.kyori.adventure.util.Ticks;

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 java.util.concurrent.ThreadLocalRandom;

public class Settings extends YamlConfig {

@Ignore
Expand Down Expand Up @@ -512,8 +520,8 @@ public static class STRINGS {
@Comment("Database settings")
public static class DATABASE {

@Comment("Database type: mariadb, mysql, postgresql, sqlite or h2.")
public DatabaseLibrary STORAGE_TYPE = DatabaseLibrary.H2;
@Comment("Database type: mariadb, mysql, postgresql.")
public DataProvider STORAGE_TYPE = DataProvider.MYSQL;

@Comment("Settings for Network-based database (like MySQL, PostgreSQL): ")
public String HOSTNAME = "127.0.0.1:3306";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public LongDatabaseEndpoint(LimboAuth plugin, String type, String username, long

public LongDatabaseEndpoint(LimboAuth plugin, String type, Function<RegisteredPlayer, Long> function) {
super(plugin, type, username -> {
RegisteredPlayer player = AuthSessionHandler.fetchInfo(plugin.getPlayerDao(), username);
RegisteredPlayer player = AuthSessionHandler.fetchInfo(plugin.getPlayerRepository(), username);
if (player == null) {
return Long.MIN_VALUE;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public StringDatabaseEndpoint(LimboAuth plugin, String type, String username, St

public StringDatabaseEndpoint(LimboAuth plugin, String type, Function<RegisteredPlayer, String> function) {
super(plugin, type, username -> {
RegisteredPlayer player = AuthSessionHandler.fetchInfo(plugin.getPlayerDao(), username);
RegisteredPlayer player = AuthSessionHandler.fetchInfo(plugin.getPlayerRepository(), username);
if (player == null) {
return "";
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@

package net.elytrium.limboauth.command;

import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.UpdateBuilder;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.proxy.Player;
import java.sql.SQLException;
import java.util.Locale;
import net.elytrium.commons.kyori.serialization.Serializer;
import net.elytrium.limboauth.LimboAuth;
import net.elytrium.limboauth.Settings;
import net.elytrium.limboauth.event.ChangePasswordEvent;
import net.elytrium.limboauth.handler.AuthSessionHandler;
import net.elytrium.limboauth.model.DataAccessRuntimeException;
import net.elytrium.limboauth.model.RegisteredPlayer;
import net.elytrium.limboauth.model.SQLRuntimeException;
import net.elytrium.limboauth.repository.RegisteredPlayerRepository;
import net.elytrium.limboauth.repository.exception.DataAccessException;
import net.kyori.adventure.text.Component;

import java.util.Locale;

public class ChangePasswordCommand extends RatelimitedCommand {

private final LimboAuth plugin;
private final Dao<RegisteredPlayer, String> playerDao;
private final RegisteredPlayerRepository registeredPlayerRepository;

private final boolean needOldPass;
private final Component notRegistered;
Expand All @@ -46,9 +46,9 @@ public class ChangePasswordCommand extends RatelimitedCommand {
private final Component usage;
private final Component notPlayer;

public ChangePasswordCommand(LimboAuth plugin, Dao<RegisteredPlayer, String> playerDao) {
public ChangePasswordCommand(LimboAuth plugin, RegisteredPlayerRepository registeredPlayerRepository) {
this.plugin = plugin;
this.playerDao = playerDao;
this.registeredPlayerRepository = registeredPlayerRepository;

Serializer serializer = LimboAuth.getSerializer();
this.needOldPass = Settings.IMP.MAIN.CHANGE_PASSWORD_NEED_OLD_PASSWORD;
Expand All @@ -64,7 +64,7 @@ public ChangePasswordCommand(LimboAuth plugin, Dao<RegisteredPlayer, String> pla
public void execute(CommandSource source, String[] args) {
if (source instanceof Player) {
String usernameLowercase = ((Player) source).getUsername().toLowerCase(Locale.ROOT);
RegisteredPlayer player = AuthSessionHandler.fetchInfoLowercased(this.playerDao, usernameLowercase);
RegisteredPlayer player = AuthSessionHandler.fetchInfoLowercased(this.registeredPlayerRepository, usernameLowercase);

if (player == null) {
source.sendMessage(this.notRegistered);
Expand All @@ -79,7 +79,7 @@ public void execute(CommandSource source, String[] args) {
return;
}

if (!AuthSessionHandler.checkPassword(args[0], player, this.playerDao)) {
if (!AuthSessionHandler.checkPassword(args[0], player, this.registeredPlayerRepository)) {
source.sendMessage(this.wrongPassword);
return;
}
Expand All @@ -93,20 +93,17 @@ public void execute(CommandSource source, String[] args) {
final String newPassword = needOldPass ? args[1] : args[0];
final String newHash = RegisteredPlayer.genHash(newPassword);

UpdateBuilder<RegisteredPlayer, String> updateBuilder = this.playerDao.updateBuilder();
updateBuilder.where().eq(RegisteredPlayer.LOWERCASE_NICKNAME_FIELD, usernameLowercase);
updateBuilder.updateColumnValue(RegisteredPlayer.HASH_FIELD, newHash);
updateBuilder.update();
registeredPlayerRepository.updateHash(usernameLowercase, newHash);

this.plugin.removePlayerFromCacheLowercased(usernameLowercase);

this.plugin.getServer().getEventManager().fireAndForget(
new ChangePasswordEvent(player, needOldPass ? args[0] : null, oldHash, newPassword, newHash));

source.sendMessage(this.successful);
} catch (SQLException e) {
} catch (DataAccessException e) {
source.sendMessage(this.errorOccurred);
throw new SQLRuntimeException(e);
throw new DataAccessRuntimeException(e);
}
} else {
source.sendMessage(this.notPlayer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,41 @@

package net.elytrium.limboauth.command;

import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.UpdateBuilder;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.proxy.ProxyServer;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.List;
import java.util.Locale;
import net.elytrium.commons.kyori.serialization.Serializer;
import net.elytrium.commons.velocity.commands.SuggestUtils;
import net.elytrium.limboauth.LimboAuth;
import net.elytrium.limboauth.Settings;
import net.elytrium.limboauth.event.ChangePasswordEvent;
import net.elytrium.limboauth.handler.AuthSessionHandler;
import net.elytrium.limboauth.model.DataAccessRuntimeException;
import net.elytrium.limboauth.model.RegisteredPlayer;
import net.elytrium.limboauth.model.SQLRuntimeException;
import net.elytrium.limboauth.repository.RegisteredPlayerRepository;
import net.elytrium.limboauth.repository.exception.DataAccessException;
import net.kyori.adventure.text.Component;

import java.text.MessageFormat;
import java.util.List;
import java.util.Locale;

public class ForceChangePasswordCommand extends RatelimitedCommand {

private final LimboAuth plugin;
private final ProxyServer server;
private final Dao<RegisteredPlayer, String> playerDao;
private final RegisteredPlayerRepository registeredPlayerRepository;

private final String message;
private final String successful;
private final String notSuccessful;
private final String notRegistered;
private final Component usage;

public ForceChangePasswordCommand(LimboAuth plugin, ProxyServer server, Dao<RegisteredPlayer, String> playerDao) {
public ForceChangePasswordCommand(LimboAuth plugin, ProxyServer server, RegisteredPlayerRepository registeredPlayerRepository) {
this.plugin = plugin;
this.server = server;
this.playerDao = playerDao;
this.registeredPlayerRepository = registeredPlayerRepository;

this.message = Settings.IMP.MAIN.STRINGS.FORCE_CHANGE_PASSWORD_MESSAGE;
this.successful = Settings.IMP.MAIN.STRINGS.FORCE_CHANGE_PASSWORD_SUCCESSFUL;
Expand All @@ -74,7 +74,7 @@ public void execute(CommandSource source, String[] args) {

Serializer serializer = LimboAuth.getSerializer();
try {
RegisteredPlayer registeredPlayer = AuthSessionHandler.fetchInfoLowercased(this.playerDao, nicknameLowercased);
RegisteredPlayer registeredPlayer = AuthSessionHandler.fetchInfoLowercased(this.registeredPlayerRepository, nicknameLowercased);

if (registeredPlayer == null) {
source.sendMessage(serializer.deserialize(MessageFormat.format(this.notRegistered, nickname)));
Expand All @@ -84,10 +84,7 @@ public void execute(CommandSource source, String[] args) {
final String oldHash = registeredPlayer.getHash();
final String newHash = RegisteredPlayer.genHash(newPassword);

UpdateBuilder<RegisteredPlayer, String> updateBuilder = this.playerDao.updateBuilder();
updateBuilder.where().eq(RegisteredPlayer.LOWERCASE_NICKNAME_FIELD, nicknameLowercased);
updateBuilder.updateColumnValue(RegisteredPlayer.HASH_FIELD, newHash);
updateBuilder.update();
this.registeredPlayerRepository.updateHash(nicknameLowercased, newHash);

this.plugin.removePlayerFromCacheLowercased(nicknameLowercased);
this.server.getPlayer(nickname)
Expand All @@ -96,9 +93,9 @@ public void execute(CommandSource source, String[] args) {
this.plugin.getServer().getEventManager().fireAndForget(new ChangePasswordEvent(registeredPlayer, null, oldHash, newPassword, newHash));

source.sendMessage(serializer.deserialize(MessageFormat.format(this.successful, nickname)));
} catch (SQLException e) {
} catch (DataAccessException e) {
source.sendMessage(serializer.deserialize(MessageFormat.format(this.notSuccessful, nickname)));
throw new SQLRuntimeException(e);
throw new DataAccessRuntimeException(e);
}
} else {
source.sendMessage(this.usage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,34 @@

package net.elytrium.limboauth.command;

import com.j256.ormlite.dao.Dao;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.Locale;
import net.elytrium.commons.kyori.serialization.Serializer;
import net.elytrium.limboauth.LimboAuth;
import net.elytrium.limboauth.Settings;
import net.elytrium.limboauth.model.DataAccessRuntimeException;
import net.elytrium.limboauth.model.RegisteredPlayer;
import net.elytrium.limboauth.model.SQLRuntimeException;
import net.elytrium.limboauth.repository.RegisteredPlayerRepository;
import net.elytrium.limboauth.repository.exception.DataAccessException;
import net.kyori.adventure.text.Component;

import java.text.MessageFormat;
import java.util.Locale;

public class ForceRegisterCommand extends RatelimitedCommand {

private final LimboAuth plugin;
private final Dao<RegisteredPlayer, String> playerDao;
private final RegisteredPlayerRepository registeredPlayerRepository;

private final String successful;
private final String notSuccessful;
private final Component usage;
private final Component takenNickname;
private final Component incorrectNickname;

public ForceRegisterCommand(LimboAuth plugin, Dao<RegisteredPlayer, String> playerDao) {
public ForceRegisterCommand(LimboAuth plugin, RegisteredPlayerRepository registeredPlayerRepository) {
this.plugin = plugin;
this.playerDao = playerDao;
this.registeredPlayerRepository = registeredPlayerRepository;

this.successful = Settings.IMP.MAIN.STRINGS.FORCE_REGISTER_SUCCESSFUL;
this.notSuccessful = Settings.IMP.MAIN.STRINGS.FORCE_REGISTER_NOT_SUCCESSFUL;
Expand All @@ -66,18 +67,18 @@ public void execute(CommandSource source, String[] args) {
}

String lowercaseNickname = nickname.toLowerCase(Locale.ROOT);
if (this.playerDao.idExists(lowercaseNickname)) {
if (this.registeredPlayerRepository.getByLowercaseName(lowercaseNickname).isPresent()) {
source.sendMessage(this.takenNickname);
return;
}

RegisteredPlayer player = new RegisteredPlayer(nickname, "", "").setPassword(password);
this.playerDao.create(player);
this.registeredPlayerRepository.createIfNotExists(player);

source.sendMessage(serializer.deserialize(MessageFormat.format(this.successful, nickname)));
} catch (SQLException e) {
} catch (DataAccessException e) {
source.sendMessage(serializer.deserialize(MessageFormat.format(this.notSuccessful, nickname)));
throw new SQLRuntimeException(e);
throw new DataAccessRuntimeException(e);
}
} else {
source.sendMessage(this.usage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,38 @@

package net.elytrium.limboauth.command;

import com.j256.ormlite.dao.Dao;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.proxy.ProxyServer;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.List;
import java.util.Locale;
import net.elytrium.commons.kyori.serialization.Serializer;
import net.elytrium.commons.velocity.commands.SuggestUtils;
import net.elytrium.limboauth.LimboAuth;
import net.elytrium.limboauth.Settings;
import net.elytrium.limboauth.event.AuthUnregisterEvent;
import net.elytrium.limboauth.model.RegisteredPlayer;
import net.elytrium.limboauth.model.SQLRuntimeException;
import net.elytrium.limboauth.model.DataAccessRuntimeException;
import net.elytrium.limboauth.repository.RegisteredPlayerRepository;
import net.elytrium.limboauth.repository.exception.DataAccessException;
import net.kyori.adventure.text.Component;

import java.text.MessageFormat;
import java.util.List;
import java.util.Locale;

public class ForceUnregisterCommand extends RatelimitedCommand {

private final LimboAuth plugin;
private final ProxyServer server;
private final Dao<RegisteredPlayer, String> playerDao;
private final RegisteredPlayerRepository registeredPlayerRepository;

private final Component kick;
private final String successful;
private final String notSuccessful;
private final Component usage;

public ForceUnregisterCommand(LimboAuth plugin, ProxyServer server, Dao<RegisteredPlayer, String> playerDao) {
public ForceUnregisterCommand(LimboAuth plugin, ProxyServer server, RegisteredPlayerRepository registeredPlayerRepository) {
this.plugin = plugin;
this.server = server;
this.playerDao = playerDao;
this.registeredPlayerRepository = registeredPlayerRepository;

Serializer serializer = LimboAuth.getSerializer();
this.kick = serializer.deserialize(Settings.IMP.MAIN.STRINGS.FORCE_UNREGISTER_KICK);
Expand All @@ -71,13 +71,13 @@ public void execute(CommandSource source, String[] args) {
Serializer serializer = LimboAuth.getSerializer();
try {
this.plugin.getServer().getEventManager().fireAndForget(new AuthUnregisterEvent(playerNick));
this.playerDao.deleteById(usernameLowercased);
this.registeredPlayerRepository.deleteByLowercaseName(usernameLowercased);
this.plugin.removePlayerFromCacheLowercased(usernameLowercased);
this.server.getPlayer(playerNick).ifPresent(player -> player.disconnect(this.kick));
source.sendMessage(serializer.deserialize(MessageFormat.format(this.successful, playerNick)));
} catch (SQLException e) {
} catch (DataAccessException e) {
source.sendMessage(serializer.deserialize(MessageFormat.format(this.notSuccessful, playerNick)));
throw new SQLRuntimeException(e);
throw new DataAccessRuntimeException(e);
}
} else {
source.sendMessage(this.usage);
Expand Down
Loading