diff options
author | Petr Ilin <hevav@hevav.dev> | 2023-01-16 12:57:25 +0300 |
---|---|---|
committer | Petr Ilin <hevav@hevav.dev> | 2023-01-16 12:58:14 +0300 |
commit | 51e8126e9df3e61f7bc65279b324a83922823099 (patch) | |
tree | d15557a1af737587d6d2e2b0f8b15102eb03b6c6 | |
parent | 176bd85c992b8992c57853915b1b6c2068e7e345 (diff) | |
download | LimboAuth-51e8126e9df3e61f7bc65279b324a83922823099.tar.gz LimboAuth-51e8126e9df3e61f7bc65279b324a83922823099.tar.bz2 LimboAuth-51e8126e9df3e61f7bc65279b324a83922823099.zip |
Hotfix: Legacy PluginMessages tag on legacy versions
-rw-r--r-- | src/main/java/net/elytrium/limboauth/LimboAuth.java | 14 | ||||
-rw-r--r-- | src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java | 9 |
2 files changed, 15 insertions, 8 deletions
diff --git a/src/main/java/net/elytrium/limboauth/LimboAuth.java b/src/main/java/net/elytrium/limboauth/LimboAuth.java index 1ca4286..0e88e2f 100644 --- a/src/main/java/net/elytrium/limboauth/LimboAuth.java +++ b/src/main/java/net/elytrium/limboauth/LimboAuth.java @@ -37,12 +37,16 @@ import com.velocitypowered.api.command.CommandManager; import com.velocitypowered.api.event.EventManager; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; +import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.plugin.Dependency; import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.plugin.PluginContainer; import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; +import com.velocitypowered.api.proxy.messages.ChannelIdentifier; +import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; +import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; import com.velocitypowered.api.scheduler.ScheduledTask; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import io.whitfin.siphash.SipHasher; @@ -130,6 +134,10 @@ import org.slf4j.Logger; ) public class LimboAuth { + // Architectury API appends /541f59e4256a337ea252bc482a009d46 to the channel name, that is a UUID.nameUUIDFromBytes from the TokenMessage class name + private static final ChannelIdentifier MOD_CHANNEL = MinecraftChannelIdentifier.create("limboauth", "mod/541f59e4256a337ea252bc482a009d46"); + private static final ChannelIdentifier LEGACY_MOD_CHANNEL = new LegacyChannelIdentifier("LIMBOAUTH|MOD"); + @MonotonicNonNull private static Logger LOGGER; @MonotonicNonNull @@ -652,10 +660,14 @@ public class LimboAuth { .update(Longs.toByteArray(issueTime)) .digest(); - player.sendPluginMessage(AuthSessionHandler.MOD_CHANNEL, Bytes.concat(Longs.toByteArray(issueTime), Longs.toByteArray(hash))); + player.sendPluginMessage(this.getChannelIdentifier(player), Bytes.concat(Longs.toByteArray(issueTime), Longs.toByteArray(hash))); } } + public ChannelIdentifier getChannelIdentifier(Player player) { + return player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0 ? MOD_CHANNEL : LEGACY_MOD_CHANNEL; + } + private boolean validateScheme(JsonElement jsonElement, List<String> scheme) { if (!scheme.isEmpty()) { if (!(jsonElement instanceof JsonObject)) { diff --git a/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java b/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java index e9de364..941ba1b 100644 --- a/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java +++ b/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java @@ -21,8 +21,6 @@ import at.favre.lib.crypto.bcrypt.BCrypt; import com.google.common.primitives.Longs; import com.j256.ormlite.dao.Dao; import com.velocitypowered.api.proxy.Player; -import com.velocitypowered.api.proxy.messages.ChannelIdentifier; -import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; import com.velocitypowered.proxy.protocol.packet.PluginMessage; import dev.samstevens.totp.code.CodeVerifier; import dev.samstevens.totp.code.DefaultCodeGenerator; @@ -61,9 +59,6 @@ public class AuthSessionHandler implements LimboSessionHandler { private static final CodeVerifier TOTP_CODE_VERIFIER = new DefaultCodeVerifier(new DefaultCodeGenerator(), new SystemTimeProvider()); private static final BCrypt.Verifyer HASH_VERIFIER = BCrypt.verifyer(); private static final BCrypt.Hasher HASHER = BCrypt.withDefaults(); - // Architectury API appends /541f59e4256a337ea252bc482a009d46 to the channel name, that is a UUID.nameUUIDFromBytes from the TokenMessage class name - public static final ChannelIdentifier MOD_CHANNEL = MinecraftChannelIdentifier.create("limboauth", "mod/541f59e4256a337ea252bc482a009d46"); - public static final String MOD_CHANNEL_STRING = MOD_CHANNEL.getId(); private static BossBar.Color bossbarColor; private static BossBar.Overlay bossbarOverlay; @@ -278,9 +273,9 @@ public class AuthSessionHandler implements LimboSessionHandler { // Minecraft can't handle the plugin message immediately after going to the PLAY // state, so we have to postpone sending it if (Settings.IMP.MAIN.MOD.ENABLED) { - this.proxyPlayer.sendPluginMessage(MOD_CHANNEL, new byte[0]); + this.proxyPlayer.sendPluginMessage(this.plugin.getChannelIdentifier(this.proxyPlayer), new byte[0]); } - } else if (channel.equals(MOD_CHANNEL_STRING)) { + } else if (channel.equals(this.plugin.getChannelIdentifier(this.proxyPlayer).getId())) { if (this.tokenReceived) { this.checkBruteforceAttempts(); this.proxyPlayer.disconnect(Component.empty()); |