diff options
Diffstat (limited to 'src/main/java/net')
3 files changed, 32 insertions, 3 deletions
diff --git a/src/main/java/net/elytrium/limboauth/LimboAuth.java b/src/main/java/net/elytrium/limboauth/LimboAuth.java index 46b0864..b9f6453 100644 --- a/src/main/java/net/elytrium/limboauth/LimboAuth.java +++ b/src/main/java/net/elytrium/limboauth/LimboAuth.java @@ -135,6 +135,7 @@ public class LimboAuth { private final Map<String, CachedPremiumUser> premiumCache = new ConcurrentHashMap<>(); private final Map<UUID, Runnable> postLoginTasks = new ConcurrentHashMap<>(); private final Set<String> unsafePasswords = new HashSet<>(); + private final Set<String> forcedPreviously = Collections.synchronizedSet(new HashSet<>()); private final HttpClient client = HttpClient.newHttpClient(); @@ -156,6 +157,7 @@ public class LimboAuth { private Title loginFloodgateTitle; private Component registrationsDisabledKick; private Component nicknameInvalidKick; + private Component reconnectKick; private ScheduledTask purgeCacheTask; private ScheduledTask purgePremiumCacheTask; @@ -251,6 +253,7 @@ public class LimboAuth { } this.nicknameInvalidKick = SERIALIZER.deserialize(Settings.IMP.MAIN.STRINGS.NICKNAME_INVALID_KICK); + this.reconnectKick = SERIALIZER.deserialize(Settings.IMP.MAIN.STRINGS.RECONNECT_KICK); this.registrationsDisabledKick = SERIALIZER.deserialize(Settings.IMP.MAIN.STRINGS.REGISTRATIONS_DISABLED_KICK); if (Settings.IMP.MAIN.CHECK_PASSWORD_STRENGTH) { @@ -471,6 +474,11 @@ public class LimboAuth { } public void authPlayer(Player player) { + if (this.isForcedPreviously(player.getUsername()) && this.isPremium(player.getUsername())) { + player.disconnect(this.reconnectKick); + return; + } + boolean isFloodgate = !Settings.IMP.MAIN.FLOODGATE_NEED_AUTH && this.floodgateApi.isFloodgatePlayer(player.getUniqueId()); String nickname = player.getUsername(); if (!this.nicknameValidationPattern.matcher((isFloodgate) ? nickname.substring(this.floodgateApi.getPrefixLength()) : nickname).matches()) { @@ -763,6 +771,18 @@ public class LimboAuth { } } + public void saveForceOfflineMode(String nickname) { + this.forcedPreviously.add(nickname); + } + + public void unsetForcedPreviously(String nickname) { + this.forcedPreviously.remove(nickname); + } + + public boolean isForcedPreviously(String nickname) { + return this.forcedPreviously.contains(nickname); + } + public Map<UUID, Runnable> getPostLoginTasks() { return this.postLoginTasks; } diff --git a/src/main/java/net/elytrium/limboauth/Settings.java b/src/main/java/net/elytrium/limboauth/Settings.java index e258da7..0dac249 100644 --- a/src/main/java/net/elytrium/limboauth/Settings.java +++ b/src/main/java/net/elytrium/limboauth/Settings.java @@ -262,6 +262,7 @@ public class Settings extends YamlConfig { public String WRONG_PASSWORD = "{PRFX} &cPassword is wrong!"; public String NICKNAME_INVALID_KICK = "{PRFX}{NL}&cYour nickname contains forbidden characters. Please, change your nickname!"; + public String RECONNECT_KICK = "{PRFX}{NL}&cReconnect to the server to verify your account!"; @Comment("6 hours by default in ip-limit-valid-time") public String IP_LIMIT_KICK = "{PRFX}{NL}{NL}&cYour IP has reached max registered accounts. If this is an error, restart your router, or wait about 6 hours."; diff --git a/src/main/java/net/elytrium/limboauth/listener/AuthListener.java b/src/main/java/net/elytrium/limboauth/listener/AuthListener.java index a96a88d..d1f85c2 100644 --- a/src/main/java/net/elytrium/limboauth/listener/AuthListener.java +++ b/src/main/java/net/elytrium/limboauth/listener/AuthListener.java @@ -21,6 +21,7 @@ import com.j256.ormlite.dao.Dao; import com.j256.ormlite.stmt.UpdateBuilder; import com.velocitypowered.api.event.PostOrder; import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.connection.PostLoginEvent; import com.velocitypowered.api.event.connection.PreLoginEvent; import com.velocitypowered.api.event.player.GameProfileRequestEvent; @@ -52,15 +53,22 @@ public class AuthListener { @Subscribe public void onPreLoginEvent(PreLoginEvent event) { if (!event.getResult().isForceOfflineMode()) { - if (!this.plugin.isPremium(event.getUsername())) { - event.setResult(PreLoginEvent.PreLoginComponentResult.forceOfflineMode()); - } else { + if (this.plugin.isPremium(event.getUsername())) { event.setResult(PreLoginEvent.PreLoginComponentResult.forceOnlineMode()); + } else { + event.setResult(PreLoginEvent.PreLoginComponentResult.forceOfflineMode()); } + } else { + this.plugin.saveForceOfflineMode(event.getUsername()); } } @Subscribe + public void onProxyDisconnect(DisconnectEvent event) { + this.plugin.unsetForcedPreviously(event.getPlayer().getUsername()); + } + + @Subscribe public void onPostLogin(PostLoginEvent event) { Map<UUID, Runnable> postLoginTasks = this.plugin.getPostLoginTasks(); UUID uuid = event.getPlayer().getUniqueId(); |