Skip to content

Commit

Permalink
Support plugin message in configuration stage (#1096)
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 authored Oct 27, 2023
1 parent 277be8f commit 660160e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.regex.Pattern;
import net.kyori.adventure.text.Component;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -193,10 +192,7 @@ public boolean handle(PluginMessage packet) {
PluginMessageUtil.rewriteMinecraftBrand(packet, server.getVersion(),
serverConn.getPlayer().getProtocolVersion()));
} else {
// TODO: Change this so its usable for mod loaders
serverConn.disconnect();
resultFuture.complete(ConnectionRequestResults.forDisconnect(
Component.translatable("multiplayer.disconnect.missing_tags"), serverConn.getServer()));
serverConn.getPlayer().getConnection().write(packet.retain());
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.velocitypowered.proxy.connection.client;

import com.velocitypowered.api.event.player.PlayerClientBrandEvent;
import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
Expand All @@ -25,9 +26,11 @@
import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.packet.ClientSettings;
import com.velocitypowered.proxy.protocol.packet.KeepAlive;
import com.velocitypowered.proxy.protocol.packet.PingIdentify;
import com.velocitypowered.proxy.protocol.packet.PluginMessage;
import com.velocitypowered.proxy.protocol.packet.ResourcePackResponse;
import com.velocitypowered.proxy.protocol.packet.config.FinishedUpdate;
import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
import io.netty.buffer.ByteBuf;
import java.util.concurrent.CompletableFuture;
import net.kyori.adventure.text.Component;
Expand Down Expand Up @@ -105,6 +108,31 @@ public boolean handle(FinishedUpdate packet) {
return true;
}

@Override
public boolean handle(PluginMessage packet) {
VelocityServerConnection serverConn = player.getConnectionInFlight();
if (serverConn != null) {
if (PluginMessageUtil.isMcBrand(packet)) {
String brand = PluginMessageUtil.readBrandMessage(packet.content());
server.getEventManager().fireAndForget(new PlayerClientBrandEvent(player, brand));
player.setClientBrand(brand);
// Client sends `minecraft:brand` packet immediately after Login,
// but at this time the backend server may not be ready, just discard it.
} else {
serverConn.ensureConnected().write(packet.retain());
}
}
return true;
}

@Override
public boolean handle(PingIdentify packet) {
if (player.getConnectionInFlight() != null) {
player.getConnectionInFlight().ensureConnected().write(packet);
}
return true;
}

@Override
public void handleGeneric(MinecraftPacket packet) {
VelocityServerConnection serverConnection = player.getConnectedServer();
Expand Down

0 comments on commit 660160e

Please sign in to comment.