Search in sources :

Example 1 with BukkitLoginSession

use of com.github.games647.fastlogin.bukkit.BukkitLoginSession in project FastLogin by games647.

the class BungeeListener method onRegisterMessage.

private void onRegisterMessage(Player player, String playerName, InetSocketAddress address) {
    Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
        AuthPlugin<Player> authPlugin = plugin.getCore().getAuthPluginHook();
        try {
            // we need to check if the player is registered on Bukkit too
            if (authPlugin == null || !authPlugin.isRegistered(playerName)) {
                BukkitLoginSession playerSession = new BukkitLoginSession(playerName, false);
                startLoginTaskIfReady(player, playerSession);
            }
        } catch (Exception ex) {
            plugin.getLog().error("Failed to query isRegistered for player: {}", player, ex);
        }
    });
}
Also used : Player(org.bukkit.entity.Player) BukkitLoginSession(com.github.games647.fastlogin.bukkit.BukkitLoginSession)

Example 2 with BukkitLoginSession

use of com.github.games647.fastlogin.bukkit.BukkitLoginSession in project FastLogin by games647.

the class NameCheckTask method requestPremiumLogin.

// Minecraft server implementation
// https://github.com/bergerkiller/CraftSource/blob/master/net.minecraft.server/LoginListener.java#L161
@Override
public void requestPremiumLogin(ProtocolLibLoginSource source, StoredProfile profile, String username, boolean registered) {
    try {
        source.enableOnlinemode();
    } catch (Exception ex) {
        plugin.getLog().error("Cannot send encryption packet. Falling back to cracked login for: {}", profile, ex);
        return;
    }
    String ip = player.getAddress().getAddress().getHostAddress();
    core.getPendingLogin().put(ip + username, new Object());
    byte[] verify = source.getVerifyToken();
    BukkitLoginSession playerSession = new BukkitLoginSession(username, verify, registered, profile);
    plugin.putSession(player.getAddress(), playerSession);
    // cancel only if the player has a paid account otherwise login as normal offline player
    synchronized (packetEvent.getAsyncMarker().getProcessingLock()) {
        packetEvent.setCancelled(true);
    }
}
Also used : BukkitLoginSession(com.github.games647.fastlogin.bukkit.BukkitLoginSession)

Example 3 with BukkitLoginSession

use of com.github.games647.fastlogin.bukkit.BukkitLoginSession in project FastLogin by games647.

the class VerifyResponseTask method verifyResponse.

private void verifyResponse(BukkitLoginSession session) {
    PrivateKey privateKey = serverKey.getPrivate();
    SecretKey loginKey;
    try {
        loginKey = EncryptionUtil.decryptSharedKey(privateKey, sharedSecret);
    } catch (GeneralSecurityException securityEx) {
        disconnect("error-kick", false, "Cannot decrypt received contents", securityEx);
        return;
    }
    try {
        if (!checkVerifyToken(session) || !enableEncryption(loginKey)) {
            return;
        }
    } catch (Exception ex) {
        disconnect("error-kick", false, "Cannot decrypt received contents", ex);
        return;
    }
    String serverId = EncryptionUtil.getServerIdHashString("", loginKey, serverKey.getPublic());
    String requestedUsername = session.getRequestUsername();
    InetSocketAddress socketAddress = player.getAddress();
    try {
        MojangResolver resolver = plugin.getCore().getResolver();
        InetAddress address = socketAddress.getAddress();
        Optional<Verification> response = resolver.hasJoined(requestedUsername, serverId, address);
        if (response.isPresent()) {
            Verification verification = response.get();
            plugin.getLog().info("Profile {} has a verified premium account", requestedUsername);
            String realUsername = verification.getName();
            if (realUsername == null) {
                disconnect("invalid-session", true, "Username field null for {}", requestedUsername);
                return;
            }
            SkinProperty[] properties = verification.getProperties();
            if (properties.length > 0) {
                session.setSkinProperty(properties[0]);
            }
            session.setVerifiedUsername(realUsername);
            session.setUuid(verification.getId());
            session.setVerified(true);
            setPremiumUUID(session.getUuid());
            receiveFakeStartPacket(realUsername);
        } else {
            // user tried to fake an authentication
            disconnect("invalid-session", true, "GameProfile {0} ({1}) tried to log in with an invalid session ServerId: {2}", session.getRequestUsername(), socketAddress, serverId);
        }
    } catch (IOException ioEx) {
        disconnect("error-kick", false, "Failed to connect to session server", ioEx);
    }
}
Also used : PrivateKey(java.security.PrivateKey) InetSocketAddress(java.net.InetSocketAddress) GeneralSecurityException(java.security.GeneralSecurityException) Verification(com.github.games647.craftapi.model.auth.Verification) IOException(java.io.IOException) SkinProperty(com.github.games647.craftapi.model.skin.SkinProperty) MojangResolver(com.github.games647.craftapi.resolver.MojangResolver) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SecretKey(javax.crypto.SecretKey) InetAddress(java.net.InetAddress)

Example 4 with BukkitLoginSession

use of com.github.games647.fastlogin.bukkit.BukkitLoginSession in project FastLogin by games647.

the class ProtocolSupportListener method requestPremiumLogin.

@Override
public void requestPremiumLogin(ProtocolLoginSource source, StoredProfile profile, String username, boolean registered) {
    source.enableOnlinemode();
    String ip = source.getAddress().getAddress().getHostAddress();
    plugin.getCore().getPendingLogin().put(ip + username, new Object());
    BukkitLoginSession playerSession = new BukkitLoginSession(username, registered, profile);
    plugin.putSession(source.getAddress(), playerSession);
}
Also used : BukkitLoginSession(com.github.games647.fastlogin.bukkit.BukkitLoginSession)

Example 5 with BukkitLoginSession

use of com.github.games647.fastlogin.bukkit.BukkitLoginSession in project FastLogin by games647.

the class ConnectionListener method delayForceLogin.

private void delayForceLogin(Player player) {
    // session exists so the player is ready for force login
    // cases: Paper (firing BungeeCord message before PlayerJoinEvent) or not running BungeeCord and already
    // having the login session from the login process
    BukkitLoginSession session = plugin.getSession(player.getAddress());
    if (session == null) {
        // Floodgate players usually don't have a session at this point
        // exception: if force login by bungee message had been delayed
        FloodgateService floodgateService = plugin.getFloodgateService();
        if (floodgateService != null) {
            FloodgatePlayer floodgatePlayer = floodgateService.getBedrockPlayer(player.getUniqueId());
            if (floodgatePlayer != null) {
                Runnable floodgateAuthTask = new FloodgateAuthTask(plugin.getCore(), player, floodgatePlayer);
                Bukkit.getScheduler().runTaskAsynchronously(plugin, floodgateAuthTask);
                return;
            }
        }
        String sessionId = plugin.getSessionId(player.getAddress());
        plugin.getLog().info("No on-going login session for player: {} with ID {}. ", player, sessionId);
        plugin.getLog().info("Setups using Minecraft proxies will start delayed " + "when the command from the proxy is received");
    } else {
        Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session);
        Bukkit.getScheduler().runTaskAsynchronously(plugin, forceLoginTask);
    }
    plugin.getBungeeManager().markJoinEventFired(player);
}
Also used : ForceLoginTask(com.github.games647.fastlogin.bukkit.task.ForceLoginTask) FloodgatePlayer(org.geysermc.floodgate.api.player.FloodgatePlayer) FloodgateService(com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService) BukkitLoginSession(com.github.games647.fastlogin.bukkit.BukkitLoginSession) FloodgateAuthTask(com.github.games647.fastlogin.bukkit.task.FloodgateAuthTask)

Aggregations

BukkitLoginSession (com.github.games647.fastlogin.bukkit.BukkitLoginSession)10 InetSocketAddress (java.net.InetSocketAddress)2 Player (org.bukkit.entity.Player)2 EventHandler (org.bukkit.event.EventHandler)2 Verification (com.github.games647.craftapi.model.auth.Verification)1 SkinProperty (com.github.games647.craftapi.model.skin.SkinProperty)1 MojangResolver (com.github.games647.craftapi.resolver.MojangResolver)1 FloodgateAuthTask (com.github.games647.fastlogin.bukkit.task.FloodgateAuthTask)1 ForceLoginTask (com.github.games647.fastlogin.bukkit.task.ForceLoginTask)1 FloodgateService (com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 InetAddress (java.net.InetAddress)1 GeneralSecurityException (java.security.GeneralSecurityException)1 PrivateKey (java.security.PrivateKey)1 SecretKey (javax.crypto.SecretKey)1 FloodgatePlayer (org.geysermc.floodgate.api.player.FloodgatePlayer)1