Search in sources :

Example 1 with InboundConnection

use of com.velocitypowered.api.proxy.InboundConnection in project FastLogin by games647.

the class ConnectListener method onPreLogin.

@Subscribe
public void onPreLogin(PreLoginEvent preLoginEvent, Continuation continuation) {
    if (!preLoginEvent.getResult().isAllowed()) {
        return;
    }
    InboundConnection connection = preLoginEvent.getConnection();
    if (!rateLimiter.tryAcquire()) {
        plugin.getLog().warn("Simple Anti-Bot join limit - Ignoring {}", connection);
        return;
    }
    String username = preLoginEvent.getUsername();
    plugin.getLog().info("Incoming login request for {} from {}", username, connection.getRemoteAddress());
    Runnable asyncPremiumCheck = new AsyncPremiumCheck(plugin, connection, username, continuation, preLoginEvent);
    plugin.getScheduler().runAsync(asyncPremiumCheck);
}
Also used : InboundConnection(com.velocitypowered.api.proxy.InboundConnection) AsyncPremiumCheck(com.github.games647.fastlogin.velocity.task.AsyncPremiumCheck) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 2 with InboundConnection

use of com.velocitypowered.api.proxy.InboundConnection in project Floodgate by GeyserMC.

the class VelocityListener method onPreLogin.

@Subscribe(order = PostOrder.EARLY)
public void onPreLogin(PreLoginEvent event) {
    FloodgatePlayer player = null;
    String kickMessage;
    try {
        InboundConnection connection = event.getConnection();
        if (INITIAL_CONNECTION_DELEGATE != null) {
            // Velocity 3.1.0 added LoginInboundConnection which is used in the login state,
            // but that class doesn't have a Channel field. However, it does have
            // InitialInboundConnection as a field
            connection = getCastedValue(connection, INITIAL_CONNECTION_DELEGATE);
        }
        Object mcConnection = getValue(connection, INITIAL_MINECRAFT_CONNECTION);
        Channel channel = getCastedValue(mcConnection, CHANNEL);
        player = channel.attr(playerAttribute).get();
        kickMessage = channel.attr(kickMessageAttribute).get();
    } catch (Exception exception) {
        logger.error("Failed get the FloodgatePlayer from the player's channel", exception);
        kickMessage = "Failed to get the FloodgatePlayer from the players's Channel";
    }
    if (kickMessage != null) {
        event.setResult(PreLoginEvent.PreLoginComponentResult.denied(Component.text(kickMessage)));
        return;
    }
    if (player != null) {
        event.setResult(PreLoginEvent.PreLoginComponentResult.forceOfflineMode());
        playerCache.put(event.getConnection(), player);
    }
}
Also used : FloodgatePlayer(org.geysermc.floodgate.api.player.FloodgatePlayer) Channel(io.netty.channel.Channel) InboundConnection(com.velocitypowered.api.proxy.InboundConnection) Subscribe(com.velocitypowered.api.event.Subscribe)

Aggregations

Subscribe (com.velocitypowered.api.event.Subscribe)2 InboundConnection (com.velocitypowered.api.proxy.InboundConnection)2 AsyncPremiumCheck (com.github.games647.fastlogin.velocity.task.AsyncPremiumCheck)1 Channel (io.netty.channel.Channel)1 FloodgatePlayer (org.geysermc.floodgate.api.player.FloodgatePlayer)1