Search in sources :

Example 1 with VelocityConfiguration

use of com.velocitypowered.proxy.config.VelocityConfiguration in project LimboAPI by Elytrium.

the class LoginListener method hookLoginSession.

public void hookLoginSession(GameProfileRequestEvent event) throws IllegalAccessException {
    // Changing mcConnection to the closed one. For what? To break the "initializePlayer"
    // method (which checks mcConnection.isActive()) and to override it. :)
    InitialInboundConnection inbound = (InitialInboundConnection) delegate.get(event.getConnection());
    MinecraftConnection connection = inbound.getConnection();
    LoginSessionHandler handler = (LoginSessionHandler) connection.getSessionHandler();
    loginConnectionField.set(handler, closed);
    if (connection.isClosed()) {
        return;
    }
    connection.eventLoop().execute(() -> {
        try {
            // Initiate a regular connection and move over to it.
            ConnectedPlayer player = ctor.newInstance(this.server, event.getGameProfile(), connection, event.getConnection().getVirtualHost().orElse(null), this.onlineMode.contains(event.getUsername()));
            if (!this.server.canRegisterConnection(player)) {
                player.disconnect0(Component.translatable("velocity.error.already-connected-proxy", NamedTextColor.RED), true);
                return;
            }
            if (connection.isClosed()) {
                return;
            }
            // Completing the Login process
            int threshold = this.server.getConfiguration().getCompressionThreshold();
            if (threshold >= 0 && connection.getProtocolVersion().compareTo(MINECRAFT_1_8) >= 0) {
                connection.write(new SetCompression(threshold));
                if (connection.isClosed()) {
                    return;
                }
                connection.setCompressionThreshold(threshold);
            }
            VelocityConfiguration configuration = this.server.getConfiguration();
            UUID playerUniqueId = player.getUniqueId();
            if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.NONE) {
                playerUniqueId = UuidUtils.generateOfflinePlayerUuid(player.getUsername());
            }
            ServerLoginSuccess success = new ServerLoginSuccess();
            success.setUsername(player.getUsername());
            success.setUuid(playerUniqueId);
            connection.write(success);
            this.plugin.setInitialID(player, playerUniqueId);
            connection.setState(StateRegistry.PLAY);
            this.server.getEventManager().fire(new LoginLimboRegisterEvent(player)).thenAcceptAsync(limboEvent -> {
                LoginTasksQueue queue = new LoginTasksQueue(this.plugin, handler, this.server, player, inbound, limboEvent.getCallbacks());
                this.plugin.addLoginQueue(player, queue);
                queue.next();
            }, connection.eventLoop());
        } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }
    });
}
Also used : LoginSessionHandler(com.velocitypowered.proxy.connection.client.LoginSessionHandler) ServerLoginSuccess(com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess) ClosedMinecraftConnection(net.elytrium.limboapi.injection.dummy.ClosedMinecraftConnection) MinecraftConnection(com.velocitypowered.proxy.connection.MinecraftConnection) ConnectedPlayer(com.velocitypowered.proxy.connection.client.ConnectedPlayer) InvocationTargetException(java.lang.reflect.InvocationTargetException) VelocityConfiguration(com.velocitypowered.proxy.config.VelocityConfiguration) LoginLimboRegisterEvent(net.elytrium.limboapi.api.event.LoginLimboRegisterEvent) SetCompression(com.velocitypowered.proxy.protocol.packet.SetCompression) InitialInboundConnection(com.velocitypowered.proxy.connection.client.InitialInboundConnection) UUID(java.util.UUID)

Aggregations

VelocityConfiguration (com.velocitypowered.proxy.config.VelocityConfiguration)1 MinecraftConnection (com.velocitypowered.proxy.connection.MinecraftConnection)1 ConnectedPlayer (com.velocitypowered.proxy.connection.client.ConnectedPlayer)1 InitialInboundConnection (com.velocitypowered.proxy.connection.client.InitialInboundConnection)1 LoginSessionHandler (com.velocitypowered.proxy.connection.client.LoginSessionHandler)1 ServerLoginSuccess (com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess)1 SetCompression (com.velocitypowered.proxy.protocol.packet.SetCompression)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 UUID (java.util.UUID)1 LoginLimboRegisterEvent (net.elytrium.limboapi.api.event.LoginLimboRegisterEvent)1 ClosedMinecraftConnection (net.elytrium.limboapi.injection.dummy.ClosedMinecraftConnection)1