diff options
author | Petr Ilin <hevav@hevav.dev> | 2023-01-02 03:50:55 +0300 |
---|---|---|
committer | Petr Ilin <hevav@hevav.dev> | 2023-01-02 03:50:55 +0300 |
commit | 2e6d82892032e0021eafeefda6de03774932602b (patch) | |
tree | f9b30638be8ece04cbca408f7a0815f3c0586c19 | |
parent | 19481c26987bed0c90f0f3014bb117d343dc0a15 (diff) | |
download | LimboAuth-2e6d82892032e0021eafeefda6de03774932602b.tar.gz LimboAuth-2e6d82892032e0021eafeefda6de03774932602b.tar.bz2 LimboAuth-2e6d82892032e0021eafeefda6de03774932602b.zip |
isPremiumByIdentifiedKey check. Works on 1.19+
-rw-r--r-- | build.gradle | 5 | ||||
-rw-r--r-- | config/spotbugs/suppressions.xml | 3 | ||||
-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 |
4 files changed, 57 insertions, 3 deletions
diff --git a/build.gradle b/build.gradle index d2f7bf8..c007452 100644 --- a/build.gradle +++ b/build.gradle @@ -42,8 +42,13 @@ dependencies { compileOnly("net.elytrium:limboapi-api:1.0.7") compileOnly("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT") + compileOnly("com.velocitypowered:velocity-proxy:3.1.2-SNAPSHOT") // From Elytrium Repo. annotationProcessor("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT") + // Needs for some velocity methods. + compileOnly("io.netty:netty-codec:4.1.77.Final") + compileOnly("io.netty:netty-handler:4.1.77.Final") + compileOnly("org.geysermc.floodgate:api:2.1.1-SNAPSHOT") implementation("at.favre.lib:bcrypt:0.9.0") diff --git a/config/spotbugs/suppressions.xml b/config/spotbugs/suppressions.xml index 9e62805..b1eb939 100644 --- a/config/spotbugs/suppressions.xml +++ b/config/spotbugs/suppressions.xml @@ -17,4 +17,7 @@ <Match> <Bug pattern="DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED"/> </Match> + <Match> + <Bug pattern="THROWS_METHOD_THROWS_CLAUSE_THROWABLE"/> + </Match> </FindBugsFilter> 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); + } + } } |