Search in sources :

Example 1 with AuthPlugin

use of com.github.games647.fastlogin.core.hooks.AuthPlugin 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 AuthPlugin

use of com.github.games647.fastlogin.core.hooks.AuthPlugin in project FastLogin by games647.

the class FastLoginBungee method registerHook.

private void registerHook() {
    try {
        List<Class<? extends AuthPlugin<ProxiedPlayer>>> hooks = Arrays.asList(BungeeAuthHook.class, BungeeCordAuthenticatorBungeeHook.class, SodionAuthHook.class);
        for (Class<? extends AuthPlugin<ProxiedPlayer>> clazz : hooks) {
            String pluginName = clazz.getSimpleName();
            pluginName = pluginName.substring(0, pluginName.length() - "Hook".length());
            // uses only member classes which uses AuthPlugin interface (skip interfaces)
            Plugin plugin = getProxy().getPluginManager().getPlugin(pluginName);
            if (plugin != null) {
                logger.info("Hooking into auth plugin: {}", pluginName);
                core.setAuthPluginHook(clazz.getDeclaredConstructor(FastLoginBungee.class).newInstance(this));
                break;
            }
        }
    } catch (ReflectiveOperationException ex) {
        logger.error("Couldn't load the auth hook class", ex);
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) AuthPlugin(com.github.games647.fastlogin.core.hooks.AuthPlugin) AuthPlugin(com.github.games647.fastlogin.core.hooks.AuthPlugin) PlatformPlugin(com.github.games647.fastlogin.core.shared.PlatformPlugin) Plugin(net.md_5.bungee.api.plugin.Plugin)

Example 3 with AuthPlugin

use of com.github.games647.fastlogin.core.hooks.AuthPlugin in project FastLogin by games647.

the class FloodgateManagement method run.

@Override
public void run() {
    core.getPlugin().getLog().info("Player {} is connecting through Geyser Floodgate.", username);
    // check if the Bedrock player is linked to a Java account
    isLinked = floodgatePlayer.getLinkedPlayer() != null;
    // if that's the case, players will be logged in via plugin messages
    if (core.getStorage() == null) {
        return;
    }
    profile = core.getStorage().loadProfile(username);
    AuthPlugin<P> authPlugin = core.getAuthPluginHook();
    try {
        // maybe Bungee without auth plugin
        if (authPlugin == null) {
            if (profile != null) {
                isRegistered = profile.isPremium();
            } else {
                isRegistered = false;
            }
        } else {
            isRegistered = authPlugin.isRegistered(username);
        }
    } catch (Exception ex) {
        core.getPlugin().getLog().error("An error has occured while checking if player {} is registered", username, ex);
        return;
    }
    // decide if checks should be made for conflicting Java player names
    if (isNameCheckRequired()) {
        // check for conflicting Premium Java name
        Optional<Profile> premiumUUID = Optional.empty();
        try {
            premiumUUID = core.getResolver().findProfile(username);
        } catch (IOException | RateLimitException e) {
            core.getPlugin().getLog().error("Could not check whether Floodgate Player {}'s name conflicts a premium Java account's name.", username, e);
            return;
        }
        // stop execution if player's name is conflicting
        if (premiumUUID.isPresent()) {
            return;
        }
    }
    if (!isRegistered && !isAutoAuthAllowed(autoRegisterFloodgate)) {
        return;
    }
    // logging in from bedrock for a second time threw an error with UUID
    if (profile == null) {
        profile = new StoredProfile(getUUID(player), username, true, getAddress(player).toString());
    }
    // start Bukkit/Bungee specific tasks
    startLogin();
}
Also used : StoredProfile(com.github.games647.fastlogin.core.StoredProfile) RateLimitException(com.github.games647.craftapi.resolver.RateLimitException) IOException(java.io.IOException) RateLimitException(com.github.games647.craftapi.resolver.RateLimitException) IOException(java.io.IOException) Profile(com.github.games647.craftapi.model.Profile) StoredProfile(com.github.games647.fastlogin.core.StoredProfile)

Example 4 with AuthPlugin

use of com.github.games647.fastlogin.core.hooks.AuthPlugin in project FastLogin by games647.

the class ForceLoginManagement method run.

@Override
public void run() {
    if (!isOnline(player)) {
        core.getPlugin().getLog().info("Player {} disconnected", player);
        return;
    }
    if (session == null) {
        core.getPlugin().getLog().info("No valid session found for {}", player);
        return;
    }
    SQLStorage storage = core.getStorage();
    StoredProfile playerProfile = session.getProfile();
    try {
        if (isOnlineMode()) {
            // premium player
            AuthPlugin<P> authPlugin = core.getAuthPluginHook();
            if (authPlugin == null) {
                // maybe only bungeecord plugin
                onForceActionSuccess(session);
            } else {
                boolean success = true;
                String playerName = getName(player);
                if (core.getConfig().get("autoLogin", true)) {
                    if (session.needsRegistration() || (core.getConfig().get("auto-register-unknown", false) && !authPlugin.isRegistered(playerName))) {
                        success = forceRegister(player);
                    } else if (!callFastLoginAutoLoginEvent(session, playerProfile).isCancelled()) {
                        success = forceLogin(player);
                    }
                }
                if (success) {
                    // update only on success to prevent corrupt data
                    if (playerProfile != null) {
                        playerProfile.setId(session.getUuid());
                        playerProfile.setPremium(true);
                        storage.save(playerProfile);
                    }
                    onForceActionSuccess(session);
                }
            }
        } else if (playerProfile != null) {
            // cracked player
            playerProfile.setId(null);
            playerProfile.setPremium(false);
            storage.save(playerProfile);
        }
    } catch (Exception ex) {
        core.getPlugin().getLog().warn("ERROR ON FORCE LOGIN of {}", getName(player), ex);
    }
}
Also used : StoredProfile(com.github.games647.fastlogin.core.StoredProfile) SQLStorage(com.github.games647.fastlogin.core.storage.SQLStorage)

Aggregations

StoredProfile (com.github.games647.fastlogin.core.StoredProfile)2 Profile (com.github.games647.craftapi.model.Profile)1 RateLimitException (com.github.games647.craftapi.resolver.RateLimitException)1 BukkitLoginSession (com.github.games647.fastlogin.bukkit.BukkitLoginSession)1 AuthPlugin (com.github.games647.fastlogin.core.hooks.AuthPlugin)1 PlatformPlugin (com.github.games647.fastlogin.core.shared.PlatformPlugin)1 SQLStorage (com.github.games647.fastlogin.core.storage.SQLStorage)1 IOException (java.io.IOException)1 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)1 Plugin (net.md_5.bungee.api.plugin.Plugin)1 Player (org.bukkit.entity.Player)1