Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Client brand not sent to backend when reconnecting back from limbo #177

Closed
metabrixkt opened this issue Dec 15, 2024 · 0 comments · Fixed by #178
Closed

[BUG] Client brand not sent to backend when reconnecting back from limbo #177

metabrixkt opened this issue Dec 15, 2024 · 0 comments · Fixed by #178
Labels
bug Something isn't working

Comments

@metabrixkt
Copy link
Contributor

The bug

Velocity doesn't send the client brand to the backend when reconnecting back from limbo.

Related code in LimboAPI:

// Rollback original CONFIG handler
this.connection.setActiveSessionHandler(StateRegistry.CONFIG,
new ClientConfigSessionHandler(this.plugin.getServer(), this.player));

This happens because Velocity expects ClientConfigSessionHandler's private String brandChannel field to be set in ClientConfigSessionHandler#handle(PluginMessageEvent) during initial configuration — the client sends the brand only during its first configuration that comes right after the login phase. The issue isn't present when changing servers because Velocity reuses the same ClientConfigSessionHandler after one was created: https://github.com/PaperMC/Velocity/blob/4aa9ee77351531430019b4725427c5d9e5bed913/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java#L397-L399

Expected behavior

LimboAPI follows Velocity behavior for configuration phase and reuses the same ClientConfigSessionHandler; or, at least, preserves the brandChannel field.

Proposed fix

diff --git a/plugin/src/main/java/net/elytrium/limboapi/injection/login/LoginTasksQueue.java b/plugin/src/main/java/net/elytrium/limboapi/injection/login/LoginTasksQueue.java
index bc027db..be00a88 100644
--- a/plugin/src/main/java/net/elytrium/limboapi/injection/login/LoginTasksQueue.java
+++ b/plugin/src/main/java/net/elytrium/limboapi/injection/login/LoginTasksQueue.java
@@ -89,7 +89,7 @@ public class LoginTasksQueue {
   private static final BiConsumer<Object, MinecraftConnection> MC_CONNECTION_SETTER;
   private static final MethodHandle CONNECT_TO_INITIAL_SERVER_METHOD;
   private static final MethodHandle SET_CLIENT_BRAND;
-  private static final BiConsumer<ClientConfigSessionHandler, String> BRAND_CHANNEL_SETTER;
+  public static final BiConsumer<ClientConfigSessionHandler, String> BRAND_CHANNEL_SETTER;
 
   private final LimboAPI plugin;
   private final Object handler;
diff --git a/plugin/src/main/java/net/elytrium/limboapi/server/LimboPlayerImpl.java b/plugin/src/main/java/net/elytrium/limboapi/server/LimboPlayerImpl.java
index f26767f..cc16a49 100644
--- a/plugin/src/main/java/net/elytrium/limboapi/server/LimboPlayerImpl.java
+++ b/plugin/src/main/java/net/elytrium/limboapi/server/LimboPlayerImpl.java
@@ -43,6 +43,7 @@ import net.elytrium.limboapi.api.protocol.item.ItemComponentMap;
 import net.elytrium.limboapi.api.protocol.packets.data.AbilityFlags;
 import net.elytrium.limboapi.api.protocol.packets.data.MapData;
 import net.elytrium.limboapi.api.protocol.packets.data.MapPalette;
+import net.elytrium.limboapi.injection.login.LoginTasksQueue;
 import net.elytrium.limboapi.protocol.packets.s2c.ChangeGameStatePacket;
 import net.elytrium.limboapi.protocol.packets.s2c.MapDataPacket;
 import net.elytrium.limboapi.protocol.packets.s2c.PlayerAbilitiesPacket;
@@ -299,8 +300,9 @@ public class LimboPlayerImpl implements LimboPlayer {
     if (this.connection.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_20_2) >= 0) {
       this.sessionHandler.disconnectToConfig(() -> {
         // Rollback original CONFIG handler
-        this.connection.setActiveSessionHandler(StateRegistry.CONFIG,
-            new ClientConfigSessionHandler(this.plugin.getServer(), this.player));
+        ClientConfigSessionHandler handler = new ClientConfigSessionHandler(this.plugin.getServer(), this.player);
+        LoginTasksQueue.BRAND_CHANNEL_SETTER.accept(handler, "minecraft:brand");
+        this.connection.setActiveSessionHandler(StateRegistry.CONFIG, handler);
         this.player.createConnectionRequest(server).fireAndForget();
       });
     } else {

going to PR that soon

Server info

Additional info

This seems to have been a bug ever since the configuration phase was added in Minecraft 1.20.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant