diff options
Diffstat (limited to 'src/main/java/net/elytrium/limboauth/LimboAuth.java')
-rw-r--r-- | src/main/java/net/elytrium/limboauth/LimboAuth.java | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/main/java/net/elytrium/limboauth/LimboAuth.java b/src/main/java/net/elytrium/limboauth/LimboAuth.java index 5a422e4..1ca4286 100644 --- a/src/main/java/net/elytrium/limboauth/LimboAuth.java +++ b/src/main/java/net/elytrium/limboauth/LimboAuth.java @@ -17,6 +17,8 @@ package net.elytrium.limboauth; +import com.google.common.primitives.Bytes; +import com.google.common.primitives.Longs; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; @@ -43,6 +45,7 @@ import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.scheduler.ScheduledTask; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import io.whitfin.siphash.SipHasher; import java.io.File; import java.io.IOException; import java.net.InetAddress; @@ -554,18 +557,7 @@ public class LimboAuth { } if (nicknameRegisteredPlayer == null && registeredPlayer == null && Settings.IMP.MAIN.SAVE_PREMIUM_ACCOUNTS) { - registeredPlayer = new RegisteredPlayer( - nickname, - nickname.toLowerCase(Locale.ROOT), - "", - player.getRemoteAddress().getAddress().getHostAddress(), - "", - System.currentTimeMillis(), - player.getUniqueId().toString(), - player.getUniqueId().toString(), - player.getRemoteAddress().getAddress().getHostAddress(), - System.currentTimeMillis() - ); + registeredPlayer = new RegisteredPlayer(player).setPremiumUuid(player.getUniqueId()); try { this.playerDao.create(registeredPlayer); @@ -645,11 +637,23 @@ public class LimboAuth { } public void updateLoginData(Player player) throws SQLException { + String lowercaseNickname = player.getUsername().toLowerCase(Locale.ROOT); UpdateBuilder<RegisteredPlayer, String> updateBuilder = this.playerDao.updateBuilder(); - updateBuilder.where().eq(RegisteredPlayer.LOWERCASE_NICKNAME_FIELD, player.getUsername().toLowerCase(Locale.ROOT)); + updateBuilder.where().eq(RegisteredPlayer.LOWERCASE_NICKNAME_FIELD, lowercaseNickname); updateBuilder.updateColumnValue(RegisteredPlayer.LOGIN_IP_FIELD, player.getRemoteAddress().getAddress().getHostAddress()); updateBuilder.updateColumnValue(RegisteredPlayer.LOGIN_DATE_FIELD, System.currentTimeMillis()); updateBuilder.update(); + + if (Settings.IMP.MAIN.MOD.ENABLED) { + byte[] lowercaseNicknameSerialized = lowercaseNickname.getBytes(StandardCharsets.UTF_8); + long issueTime = System.currentTimeMillis(); + long hash = SipHasher.init(Settings.IMP.MAIN.MOD.VERIFY_KEY) + .update(lowercaseNicknameSerialized) + .update(Longs.toByteArray(issueTime)) + .digest(); + + player.sendPluginMessage(AuthSessionHandler.MOD_CHANNEL, Bytes.concat(Longs.toByteArray(issueTime), Longs.toByteArray(hash))); + } } private boolean validateScheme(JsonElement jsonElement, List<String> scheme) { |