We don't have to add handshake data when Floodgate is integrated

This commit is contained in:
Tim203 2023-10-12 19:54:22 +02:00
parent a894ce9824
commit cdd0f9a75e
No known key found for this signature in database
7 changed files with 33 additions and 16 deletions

View File

@ -29,9 +29,9 @@ import com.mojang.authlib.GameProfile;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.geysermc.api.connection.Connection;
import org.geysermc.floodgate.spigot.util.ClassNames;
import org.geysermc.geyser.floodgate.IntegratedFloodgateProvider;
import org.geysermc.geyser.session.GeyserSession;
import javax.annotation.Nonnull;
@ -42,7 +42,7 @@ public final class SpigotHybridChannelHandler extends ChannelInboundHandlerAdapt
@Override
public void channelRead(@Nonnull ChannelHandlerContext ctx, @Nonnull Object packet) throws Exception {
GeyserSession session = ctx.channel().attr(IntegratedFloodgateProvider.SESSION_KEY).get();
Connection session = ctx.channel().attr(IntegratedFloodgateProvider.SESSION_KEY).get();
// TODO generify this code within Floodgate
if (ClassNames.LOGIN_START_PACKET.isInstance(packet)) {
Object networkManager = ctx.channel().pipeline().get("packet_handler");

View File

@ -65,8 +65,8 @@ import org.geysermc.geyser.erosion.UnixSocketClientListener;
import org.geysermc.geyser.event.GeyserEventBus;
import org.geysermc.geyser.extension.GeyserExtensionManager;
import org.geysermc.geyser.floodgate.FloodgateProvider;
import org.geysermc.geyser.floodgate.IntegratedFloodgateProvider;
import org.geysermc.geyser.floodgate.NoFloodgateProvider;
import org.geysermc.geyser.floodgate.ProxyFloodgateProvider;
import org.geysermc.geyser.level.WorldManager;
import org.geysermc.geyser.network.netty.GeyserServer;
import org.geysermc.geyser.registry.BlockRegistries;
@ -165,8 +165,8 @@ public class GeyserImpl implements GeyserApi {
floodgatePlatform.load();
floodgatePlatform.enable();
// this.floodgatePlatform = floodgatePlatform.isProxy() ? new ProxyFloodgateProvider(floodgatePlatform) : new IntegratedFloodgateProvider(floodgatePlatform);
// this.floodgateProvider = new IntegratedFloodgateProvider(floodgatePlatform);
this.floodgateProvider = new ProxyFloodgateProvider(floodgatePlatform);
this.floodgateProvider = new IntegratedFloodgateProvider(floodgatePlatform);
// this.floodgateProvider = new ProxyFloodgateProvider(floodgatePlatform);
} else {
this.floodgateProvider = new NoFloodgateProvider();
Geyser.set(this);

View File

@ -25,23 +25,30 @@
package org.geysermc.geyser.floodgate;
import io.micronaut.core.type.Argument;
import io.micronaut.inject.qualifiers.Qualifiers;
import io.netty.util.AttributeKey;
import org.geysermc.api.connection.Connection;
import org.geysermc.floodgate.core.FloodgatePlatform;
import org.geysermc.floodgate.core.connection.ConnectionManager;
import org.geysermc.floodgate.core.skin.SkinApplier;
import org.geysermc.floodgate.core.skin.SkinDataImpl;
import org.geysermc.geyser.session.GeyserSession;
public class IntegratedFloodgateProvider implements FloodgateProvider {
// TODO This will probably end up as its own class.
public static final AttributeKey<GeyserSession> SESSION_KEY = AttributeKey.valueOf("geyser-session");
public static final AttributeKey<Connection> SESSION_KEY = AttributeKey.valueOf("floodgate-player");
private final SkinApplier skinApplier;
private final ConnectionManager connectionManager;
public IntegratedFloodgateProvider(FloodgatePlatform platform) {
skinApplier = platform.getBean(SkinApplier.class);
connectionManager = platform.getBean(ConnectionManager.class);
var connectionAttribute = platform.getBean(
Argument.of(AttributeKey.class, Connection.class),
Qualifiers.byName("connectionAttribute")
);
if (connectionAttribute.id() != SESSION_KEY.id()) {
throw new IllegalStateException("Session key doesn't match Floodgate's key!");
}
}
@Override
@ -51,7 +58,6 @@ public class IntegratedFloodgateProvider implements FloodgateProvider {
@Override
public String onClientIntention(GeyserSession session) {
connectionManager.addConnection(session);
return null;
}
}

View File

@ -28,9 +28,9 @@ package org.geysermc.geyser.network.netty;
import io.netty.channel.local.LocalChannel;
import io.netty.channel.local.LocalServerChannel;
import io.netty.util.Attribute;
import org.geysermc.api.connection.Connection;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.floodgate.IntegratedFloodgateProvider;
import org.geysermc.geyser.session.GeyserSession;
/**
* If the incoming channel if an instance of LocalChannelWithRemoteAddress, this server creates a LocalChannelWrapper
@ -45,8 +45,8 @@ public class LocalServerChannelWrapper extends LocalServerChannel {
channel.wrapper().remoteAddress(((LocalChannelWithRemoteAddress) peer).spoofedRemoteAddress());
if (GeyserImpl.getInstance().getFloodgateProvider() instanceof IntegratedFloodgateProvider) {
Attribute<GeyserSession> attribute = peer.attr(IntegratedFloodgateProvider.SESSION_KEY);
GeyserSession session = attribute.get();
Attribute<Connection> attribute = peer.attr(IntegratedFloodgateProvider.SESSION_KEY);
Connection session = attribute.get();
// Garbage collect since it's no longer relevant for the PacketLib side.
attribute.set(null);
channel.attr(IntegratedFloodgateProvider.SESSION_KEY).set(session);

View File

@ -38,6 +38,7 @@ import io.netty.channel.*;
import io.netty.channel.unix.PreferredDirectByteBufAllocator;
import io.netty.handler.codec.haproxy.*;
import io.netty.util.Attribute;
import org.geysermc.api.connection.Connection;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.floodgate.IntegratedFloodgateProvider;
import org.geysermc.geyser.session.GeyserSession;
@ -99,7 +100,7 @@ public final class LocalSession extends TcpSession {
addHAProxySupport(pipeline);
if (GeyserImpl.getInstance().getFloodgateProvider() instanceof IntegratedFloodgateProvider) {
Attribute<GeyserSession> attribute = channel.attr(IntegratedFloodgateProvider.SESSION_KEY);
Attribute<Connection> attribute = channel.attr(IntegratedFloodgateProvider.SESSION_KEY);
attribute.set(session);
}
}

View File

@ -101,6 +101,7 @@ import org.checkerframework.checker.index.qual.NonNegative;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.common.returnsreceiver.qual.This;
import org.checkerframework.common.value.qual.IntRange;
import org.cloudburstmc.math.vector.Vector2f;
import org.cloudburstmc.math.vector.Vector2i;
@ -242,6 +243,8 @@ public class GeyserSession extends FloodgateConnection implements GeyserConnecti
@Setter
private List<String> certChainData;
private LinkedPlayer linkedPlayer;
@NotNull
@Setter
private AbstractGeyserboundPacketHandler erosionHandler;
@ -1973,7 +1976,7 @@ public class GeyserSession extends FloodgateConnection implements GeyserConnecti
@Override
public @MonotonicNonNull LinkedPlayer linkedPlayer() {
return null; //todo
return linkedPlayer;
}
@SuppressWarnings("ConstantConditions") // Need to enforce the parameter annotations
@ -1991,6 +1994,12 @@ public class GeyserSession extends FloodgateConnection implements GeyserConnecti
return true;
}
@Override
public @This FloodgateConnection linkedPlayer(@Nullable LinkedPlayer linkedPlayer) {
this.linkedPlayer = linkedPlayer;
return this;
}
@Override
public @NonNull CompletableFuture<@Nullable GeyserEntity> entityByJavaId(@NonNegative int javaId) {
CompletableFuture<GeyserEntity> future = new CompletableFuture<>();

View File

@ -0,0 +1 @@
platform.integrated=true