diff options
Diffstat (limited to 'src/main/java/net/elytrium')
-rw-r--r-- | src/main/java/net/elytrium/limboauth/Settings.java | 6 | ||||
-rw-r--r-- | src/main/java/net/elytrium/limboauth/listener/AuthListener.java | 46 |
2 files changed, 49 insertions, 3 deletions
diff --git a/src/main/java/net/elytrium/limboauth/Settings.java b/src/main/java/net/elytrium/limboauth/Settings.java index 6c07ade..9f50164 100644 --- a/src/main/java/net/elytrium/limboauth/Settings.java +++ b/src/main/java/net/elytrium/limboauth/Settings.java @@ -59,8 +59,12 @@ public class Settings extends YamlConfig { public int MAX_PASSWORD_LENGTH = 71; public boolean CHECK_PASSWORD_STRENGTH = true; public String UNSAFE_PASSWORDS_FILE = "unsafe_passwords.txt"; + @Comment({ + "Players with premium nicknames should register/auth if this option is enabled", + "Players with premium nicknames must login with a premium Minecraft account if this option is disabled", + }) public boolean ONLINE_MODE_NEED_AUTH = true; - @Comment("Needs floodgate plugin.") + @Comment("Needs floodgate plugin if disabled.") public boolean FLOODGATE_NEED_AUTH = true; @Comment("TOTALLY disables hybrid auth feature") public boolean FORCE_OFFLINE_MODE = false; diff --git a/src/main/java/net/elytrium/limboauth/listener/AuthListener.java b/src/main/java/net/elytrium/limboauth/listener/AuthListener.java index de69023..ca7f031 100644 --- a/src/main/java/net/elytrium/limboauth/listener/AuthListener.java +++ b/src/main/java/net/elytrium/limboauth/listener/AuthListener.java @@ -25,11 +25,20 @@ 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; +import com.velocitypowered.api.proxy.InboundConnection; import com.velocitypowered.api.util.UuidUtils; +import com.velocitypowered.proxy.connection.MinecraftConnection; +import com.velocitypowered.proxy.connection.client.InitialInboundConnection; +import com.velocitypowered.proxy.connection.client.InitialLoginSessionHandler; +import com.velocitypowered.proxy.connection.client.LoginInboundConnection; +import com.velocitypowered.proxy.protocol.packet.ServerLogin; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; import java.sql.SQLException; import java.util.Map; import java.util.UUID; import java.util.concurrent.TimeUnit; +import net.elytrium.java.commons.reflection.ReflectionException; import net.elytrium.limboapi.api.event.LoginLimboRegisterEvent; import net.elytrium.limboauth.LimboAuth; import net.elytrium.limboauth.Settings; @@ -40,6 +49,9 @@ import net.elytrium.limboauth.model.RegisteredPlayer; // TODO: Customizable events priority public class AuthListener { + private static final MethodHandle DELEGATE_FIELD; + private static final MethodHandle LOGIN_FIELD; + private final LimboAuth plugin; private final Dao<RegisteredPlayer, String> playerDao; private final FloodgateApiHolder floodgateApi; @@ -51,9 +63,9 @@ public class AuthListener { } @Subscribe - public void onPreLoginEvent(PreLoginEvent event) { + public void onPreLoginEvent(PreLoginEvent event) throws Throwable { if (!event.getResult().isForceOfflineMode()) { - if (this.plugin.isPremium(event.getUsername())) { + if (this.isPremiumByIdentifiedKey(event.getConnection()) || this.plugin.isPremium(event.getUsername())) { event.setResult(PreLoginEvent.PreLoginComponentResult.forceOnlineMode()); } else { event.setResult(PreLoginEvent.PreLoginComponentResult.forceOfflineMode()); @@ -63,6 +75,25 @@ public class AuthListener { } } + private boolean isPremiumByIdentifiedKey(InboundConnection inbound) throws Throwable { + LoginInboundConnection inboundConnection = (LoginInboundConnection) inbound; + InitialInboundConnection initialInbound = (InitialInboundConnection) DELEGATE_FIELD.invokeExact(inboundConnection); + MinecraftConnection connection = initialInbound.getConnection(); + InitialLoginSessionHandler handler = (InitialLoginSessionHandler) connection.getSessionHandler(); + + ServerLogin packet = (ServerLogin) LOGIN_FIELD.invokeExact(handler); + if (packet == null) { + return false; + } + + UUID holder = packet.getHolderUuid(); + if (holder == null) { + return false; + } + + return holder.version() != 3; + } + @Subscribe public void onProxyDisconnect(DisconnectEvent event) { this.plugin.unsetForcedPreviously(event.getPlayer().getUsername()); @@ -138,4 +169,15 @@ public class AuthListener { event.setGameProfile(event.getOriginalProfile().withName(Settings.IMP.MAIN.ONLINE_MODE_PREFIX + event.getUsername())); } } + + static { + try { + DELEGATE_FIELD = MethodHandles.privateLookupIn(LoginInboundConnection.class, MethodHandles.lookup()) + .findGetter(LoginInboundConnection.class, "delegate", InitialInboundConnection.class); + LOGIN_FIELD = MethodHandles.privateLookupIn(InitialLoginSessionHandler.class, MethodHandles.lookup()) + .findGetter(InitialLoginSessionHandler.class, "login", ServerLogin.class); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new ReflectionException(e); + } + } } |