Velocity 1.20.2 Support but NOT Forge 1.20.2 support. Also compatible with Protocolize and Geyser

This commit is contained in:
Brent P 2023-10-12 13:55:56 -04:00
parent 4510f15ebb
commit 594aa4ccea
7 changed files with 30 additions and 15 deletions

@ -1 +1 @@
Subproject commit 19abb9094e581bc4d21107e839901e5d68090b19
Subproject commit eb594fc799281ff418dc2c161c2d8a8eb0c89a19

View File

@ -23,6 +23,7 @@ import com.velocitypowered.proxy.protocol.packet.brigadier.ArgumentIdentifier;
import com.velocitypowered.proxy.protocol.packet.brigadier.ArgumentPropertyRegistry;
import com.velocitypowered.proxy.protocol.packet.brigadier.ArgumentPropertySerializer;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import org.adde0109.ambassador.velocity.VelocityBackendChannelInitializer;
import org.adde0109.ambassador.velocity.VelocityServerChannelInitializer;
@ -39,7 +40,7 @@ import java.util.concurrent.TimeUnit;
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_19;
import static com.velocitypowered.proxy.protocol.packet.brigadier.ArgumentIdentifier.mapSet;
@Plugin(id = "ambassador", name = "Ambassador", version = "1.4.2-beta", authors = {"adde0109"})
@Plugin(id = "ambassador", name = "Ambassador", version = "1.4.2-beta-unofficial", authors = {"adde0109"})
public class Ambassador {
public ProxyServer server;
@ -103,11 +104,13 @@ public class Ambassador {
Field cmField = VelocityServer.class.getDeclaredField("cm");
cmField.setAccessible(true);
ChannelInitializer<?> original = ((ConnectionManager) cmField.get(server)).getServerChannelInitializer().get();
((ConnectionManager) cmField.get(server)).getServerChannelInitializer().set(new VelocityServerChannelInitializer(original,(VelocityServer) server));
ConnectionManager connectionManager = (ConnectionManager) cmField.get(server);
ChannelInitializer<?> originalBackend = ((ConnectionManager) cmField.get(server)).getBackendChannelInitializer().get();
((ConnectionManager) cmField.get(server)).getBackendChannelInitializer().set(new VelocityBackendChannelInitializer(originalBackend,(VelocityServer) server));
ChannelInitializer<Channel> original = connectionManager.getServerChannelInitializer().get();
connectionManager.getServerChannelInitializer().set(new VelocityServerChannelInitializer(original, (VelocityServer) server));
ChannelInitializer<Channel> originalBackend = connectionManager.getBackendChannelInitializer().get();
connectionManager.getBackendChannelInitializer().set(new VelocityBackendChannelInitializer(originalBackend, (VelocityServer) server, logger));
Method argumentRegistry = ArgumentPropertyRegistry.class.getDeclaredMethod("register", ArgumentIdentifier.class, Class.class, ArgumentPropertySerializer.class);
argumentRegistry.setAccessible(true);

View File

@ -6,6 +6,7 @@ import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.network.Connections;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.packet.AvailableCommands;
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage;
import com.velocitypowered.proxy.protocol.packet.PluginMessage;
@ -75,6 +76,8 @@ public enum VelocityForgeBackendConnectionPhase implements BackendConnectionPhas
}
}
message.retain();
// dirty hack for 1.20.2 velocity!
player.getConnection().setState(StateRegistry.LOGIN);
player.getConnection().write(message);
//Forge server
//To avoid unnecessary resets, we wait until we get the handshake even if we know that we should
@ -109,7 +112,7 @@ public enum VelocityForgeBackendConnectionPhase implements BackendConnectionPhas
if (message.getChannel().equals("ambassador:commands")) {
AvailableCommands packet = new AvailableCommands();
packet.decode(message.content(), ProtocolUtils.Direction.CLIENTBOUND,server.getConnection().getProtocolVersion());
server.getConnection().getSessionHandler().handle(packet);
server.getConnection().getActiveSessionHandler().handle(packet);
return true;
}
return false;

View File

@ -61,7 +61,7 @@ public enum VelocityForgeClientConnectionPhase implements ClientConnectionPhase
//Don't handle anything from the server until the reset has completed.
//player.getConnectionInFlight().getConnection().getChannel().config().setAutoRead(false);
if (connection.getState() == StateRegistry.PLAY) {
if (connection.getState() == StateRegistry.PLAY || connection.getState() == StateRegistry.CONFIG) {
connection.write(new PluginMessage("fml:handshake", Unpooled.wrappedBuffer(ForgeHandshakeUtils.generatePluginResetPacket())));
connection.setState(StateRegistry.LOGIN);
} else {

View File

@ -7,22 +7,27 @@ import io.netty.channel.ChannelInitializer;
import org.adde0109.ambassador.forge.ForgeConstants;
import org.adde0109.ambassador.velocity.backend.FMLMarkerAdder;
import org.adde0109.ambassador.velocity.backend.VelocityForgeBackendHandshakeHandler;
import org.slf4j.Logger;
import java.lang.reflect.Method;
public class VelocityBackendChannelInitializer extends BackendChannelInitializer {
private Method INIT_CHANNEL;
private final Method INIT_CHANNEL;
private final ChannelInitializer<?> delegate;
private final ChannelInitializer<Channel> delegate;
private final VelocityServer server;
public VelocityBackendChannelInitializer(ChannelInitializer<?> delegate, VelocityServer server) {
private final Logger logger;
public VelocityBackendChannelInitializer(ChannelInitializer<Channel> delegate, VelocityServer server, Logger logger) {
super(server);
this.delegate = delegate;
this.server = server;
this.logger = logger;
try {
logger.info("Respecting the previous registered BackendChannelInitializer: " + delegate.getClass().getName());
INIT_CHANNEL = delegate.getClass().getDeclaredMethod("initChannel", Channel.class);
INIT_CHANNEL.setAccessible(true);
} catch (ReflectiveOperationException e) {
@ -33,7 +38,8 @@ public class VelocityBackendChannelInitializer extends BackendChannelInitializer
@Override
protected void initChannel(Channel ch) {
try {
INIT_CHANNEL.invoke(delegate,ch);
logger.info("Calling the underlying backend channel initializer: " + delegate.getClass().getName());
INIT_CHANNEL.invoke(delegate, ch);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}

View File

@ -5,6 +5,7 @@ import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler;
import com.velocitypowered.proxy.network.Connections;
import com.velocitypowered.proxy.network.ServerChannelInitializer;
import com.velocitypowered.proxy.protocol.StateRegistry;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer;
@ -42,8 +43,8 @@ public class VelocityServerChannelInitializer extends ServerChannelInitializer {
if (ch.pipeline().get(MinecraftConnection.class) == null)
super.initChannel(ch);
MinecraftConnection handler = ch.pipeline().get(MinecraftConnection.class);
HandshakeSessionHandler originalSessionHandler = (HandshakeSessionHandler) handler.getSessionHandler();
handler.setSessionHandler(new VelocityHandshakeSessionHandler(originalSessionHandler, handler, server));
HandshakeSessionHandler originalSessionHandler = (HandshakeSessionHandler) handler.getActiveSessionHandler();
handler.setActiveSessionHandler(StateRegistry.HANDSHAKE, new VelocityHandshakeSessionHandler(originalSessionHandler, handler, server));
}
}
}

View File

@ -5,6 +5,7 @@ import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.backend.LoginSessionHandler;
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
import com.velocitypowered.proxy.network.Connections;
import com.velocitypowered.proxy.protocol.StateRegistry;
import io.netty.channel.*;
import org.adde0109.ambassador.forge.ForgeFMLConnectionType;
import org.jetbrains.annotations.NotNull;
@ -25,7 +26,8 @@ public class VelocityForgeBackendHandshakeHandler extends ChannelInboundHandlerA
ctx.pipeline().remove(this);
if (serverConnection.getPlayer().getConnection().getType() instanceof ForgeFMLConnectionType) {
connection.setSessionHandler(new ForgeLoginSessionHandler((LoginSessionHandler) connection.getSessionHandler(),serverConnection,server));
ForgeLoginSessionHandler forgeLoginSessionHandler = new ForgeLoginSessionHandler((LoginSessionHandler) connection.getActiveSessionHandler(), serverConnection,server);
connection.setActiveSessionHandler(StateRegistry.LOGIN, forgeLoginSessionHandler);
}
ctx.pipeline().fireChannelActive();