Search in sources :

Example 1 with FloodgateService

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

the class FastLoginBungee method onEnable.

@Override
public void onEnable() {
    logger = CommonUtil.initializeLoggerService(getLogger());
    scheduler = new AsyncScheduler(logger, task -> getProxy().getScheduler().runAsync(this, task));
    core = new FastLoginCore<>(this);
    core.load();
    if (!core.setupDatabase()) {
        return;
    }
    if (isPluginInstalled("floodgate")) {
        floodgateService = new FloodgateService(FloodgateApi.getInstance(), core);
    }
    if (isPluginInstalled("Geyser-BungeeCord")) {
        geyserService = new GeyserService(GeyserImpl.getInstance(), core);
    }
    // events
    PluginManager pluginManager = getProxy().getPluginManager();
    ConnectListener connectListener = new ConnectListener(this, core.getRateLimiter());
    pluginManager.registerListener(this, connectListener);
    pluginManager.registerListener(this, new PluginMessageListener(this));
    // this is required to listen to incoming messages from the server
    getProxy().registerChannel(NamespaceKey.getCombined(getName(), ChangePremiumMessage.CHANGE_CHANNEL));
    getProxy().registerChannel(NamespaceKey.getCombined(getName(), SuccessMessage.SUCCESS_CHANNEL));
    registerHook();
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) AsyncScheduler(com.github.games647.fastlogin.core.AsyncScheduler) Arrays(java.util.Arrays) FloodgateService(com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService) BungeeCordAuthenticatorBungeeHook(com.github.games647.fastlogin.bungee.hook.BungeeCordAuthenticatorBungeeHook) AuthPlugin(com.github.games647.fastlogin.core.hooks.AuthPlugin) SuccessMessage(com.github.games647.fastlogin.core.message.SuccessMessage) BedrockService(com.github.games647.fastlogin.core.hooks.bedrock.BedrockService) ConcurrentMap(java.util.concurrent.ConcurrentMap) TextComponent(net.md_5.bungee.api.chat.TextComponent) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) GroupedThreadFactory(net.md_5.bungee.api.scheduler.GroupedThreadFactory) PluginMessageListener(com.github.games647.fastlogin.bungee.listener.PluginMessageListener) FastLoginCore(com.github.games647.fastlogin.core.shared.FastLoginCore) GeyserService(com.github.games647.fastlogin.core.hooks.bedrock.GeyserService) GeyserImpl(org.geysermc.geyser.GeyserImpl) ThreadFactory(java.util.concurrent.ThreadFactory) BungeeAuthHook(com.github.games647.fastlogin.bungee.hook.BungeeAuthHook) Path(java.nio.file.Path) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) ChannelMessage(com.github.games647.fastlogin.core.message.ChannelMessage) CommandSender(net.md_5.bungee.api.CommandSender) FloodgateApi(org.geysermc.floodgate.api.FloodgateApi) Logger(org.slf4j.Logger) SodionAuthHook(com.github.games647.fastlogin.bungee.hook.SodionAuthHook) CommonUtil(com.github.games647.fastlogin.core.CommonUtil) NamespaceKey(com.github.games647.fastlogin.core.message.NamespaceKey) PlatformPlugin(com.github.games647.fastlogin.core.shared.PlatformPlugin) List(java.util.List) ConnectListener(com.github.games647.fastlogin.bungee.listener.ConnectListener) PendingConnection(net.md_5.bungee.api.connection.PendingConnection) Server(net.md_5.bungee.api.connection.Server) ByteStreams(com.google.common.io.ByteStreams) ChangePremiumMessage(com.github.games647.fastlogin.core.message.ChangePremiumMessage) Plugin(net.md_5.bungee.api.plugin.Plugin) MapMaker(com.google.common.collect.MapMaker) PluginManager(net.md_5.bungee.api.plugin.PluginManager) PluginManager(net.md_5.bungee.api.plugin.PluginManager) AsyncScheduler(com.github.games647.fastlogin.core.AsyncScheduler) FloodgateService(com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService) GeyserService(com.github.games647.fastlogin.core.hooks.bedrock.GeyserService) PluginMessageListener(com.github.games647.fastlogin.bungee.listener.PluginMessageListener) ConnectListener(com.github.games647.fastlogin.bungee.listener.ConnectListener)

Example 2 with FloodgateService

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

Example 3 with FloodgateService

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

the class FastLoginBukkit method onEnable.

@Override
public void onEnable() {
    core = new FastLoginCore<>(this);
    core.load();
    if (getServer().getOnlineMode()) {
        // we need to require offline to prevent a loginSession request for an offline player
        logger.error("Server has to be in offline mode");
        setEnabled(false);
        return;
    }
    if (!initializeFloodgate()) {
        setEnabled(false);
    }
    bungeeManager = new BungeeManager(this);
    bungeeManager.initialize();
    PluginManager pluginManager = getServer().getPluginManager();
    if (bungeeManager.isEnabled()) {
        markInitialized();
    } else {
        if (!core.setupDatabase()) {
            setEnabled(false);
            return;
        }
        if (pluginManager.isPluginEnabled("ProtocolSupport")) {
            pluginManager.registerEvents(new ProtocolSupportListener(this, core.getRateLimiter()), this);
        } else if (pluginManager.isPluginEnabled("ProtocolLib")) {
            ProtocolLibListener.register(this, core.getRateLimiter());
            if (isPluginInstalled("floodgate")) {
                if (getConfig().getBoolean("floodgatePrefixWorkaround")) {
                    ManualNameChange.register(this, floodgateService);
                    logger.info("Floodgate prefix injection workaround has been enabled.");
                    logger.info("If you have problems joining the server, try disabling it in the configuration.");
                } else {
                    logger.warn("We have detected that you are runnging FastLogin alongside Floodgate and ProtocolLib.");
                    logger.warn("Currently there is an issue with FastLogin that prevents Floodgate name prefixes from showing up " + "when it is together used with ProtocolLib.");
                    logger.warn("If you would like to use Floodgate name prefixes, you can enable an experimental workaround by changing " + "the value 'floodgatePrefixWorkaround' to true in config.yml.");
                    logger.warn("For more information visit https://github.com/games647/FastLogin/issues/493");
                }
            }
            // if server is using paper - we need to set the skin at pre login anyway, so no need for this listener
            if (!PaperLib.isPaper() && getConfig().getBoolean("forwardSkin")) {
                pluginManager.registerEvents(new SkinApplyListener(this), this);
            }
        } else {
            logger.warn("Either ProtocolLib or ProtocolSupport have to be installed if you don't use BungeeCord");
            setEnabled(false);
            return;
        }
    }
    // delay dependency setup because we load the plugin very early where plugins are initialized yet
    getServer().getScheduler().runTaskLater(this, new DelayedAuthHook(this), 5L);
    pluginManager.registerEvents(new ConnectionListener(this), this);
    // if server is using paper - we need to add one more listener to correct the user cache usage
    if (PaperLib.isPaper()) {
        pluginManager.registerEvents(new PaperCacheListener(this), this);
    }
    // register commands using a unique name
    Optional.ofNullable(getCommand("premium")).ifPresent(c -> c.setExecutor(new PremiumCommand(this)));
    Optional.ofNullable(getCommand("cracked")).ifPresent(c -> c.setExecutor(new CrackedCommand(this)));
    if (pluginManager.isPluginEnabled("PlaceholderAPI")) {
        premiumPlaceholder = new PremiumPlaceholder(this);
        premiumPlaceholder.register();
    }
    dependencyWarnings();
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) PremiumCommand(com.github.games647.fastlogin.bukkit.command.PremiumCommand) ProtocolSupportListener(com.github.games647.fastlogin.bukkit.listener.protocolsupport.ProtocolSupportListener) SkinApplyListener(com.github.games647.fastlogin.bukkit.listener.protocollib.SkinApplyListener) CrackedCommand(com.github.games647.fastlogin.bukkit.command.CrackedCommand) ConnectionListener(com.github.games647.fastlogin.bukkit.listener.ConnectionListener) PaperCacheListener(com.github.games647.fastlogin.bukkit.listener.PaperCacheListener) DelayedAuthHook(com.github.games647.fastlogin.bukkit.task.DelayedAuthHook)

Example 4 with FloodgateService

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

the class ConnectListener method onServerConnected.

@EventHandler
public void onServerConnected(ServerConnectedEvent serverConnectedEvent) {
    ProxiedPlayer player = serverConnectedEvent.getPlayer();
    Server server = serverConnectedEvent.getServer();
    FloodgateService floodgateService = plugin.getFloodgateService();
    if (floodgateService != null) {
        FloodgatePlayer floodgatePlayer = floodgateService.getBedrockPlayer(player.getUniqueId());
        if (floodgatePlayer != null) {
            Runnable floodgateAuthTask = new FloodgateAuthTask(plugin.getCore(), player, floodgatePlayer, server);
            plugin.getScheduler().runAsync(floodgateAuthTask);
            return;
        }
    }
    BungeeLoginSession session = plugin.getSession().get(player.getPendingConnection());
    if (session == null) {
        return;
    }
    // delay sending force command, because Paper will process the login event asynchronously
    // In this case it means that the force command (plugin message) is already received and processed while
    // player is still in the login phase and reported to be offline.
    Runnable loginTask = new ForceLoginTask(plugin.getCore(), player, server, session);
    plugin.getScheduler().runAsync(loginTask);
}
Also used : ForceLoginTask(com.github.games647.fastlogin.bungee.task.ForceLoginTask) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) FloodgatePlayer(org.geysermc.floodgate.api.player.FloodgatePlayer) FloodgateService(com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService) Server(net.md_5.bungee.api.connection.Server) BungeeLoginSession(com.github.games647.fastlogin.bungee.BungeeLoginSession) FloodgateAuthTask(com.github.games647.fastlogin.bungee.task.FloodgateAuthTask) EventHandler(net.md_5.bungee.event.EventHandler)

Example 5 with FloodgateService

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

the class PluginMessageListener method onSuccessMessage.

private void onSuccessMessage(ProxiedPlayer forPlayer) {
    boolean shouldPersist = forPlayer.getPendingConnection().isOnlineMode();
    FloodgateService floodgateService = plugin.getFloodgateService();
    if (!shouldPersist && floodgateService != null) {
        // always save floodgate players to lock this username
        shouldPersist = floodgateService.isBedrockPlayer(forPlayer.getUniqueId());
    }
    if (shouldPersist) {
        // bukkit module successfully received and force logged in the user
        // update only on success to prevent corrupt data
        BungeeLoginSession loginSession = plugin.getSession().get(forPlayer.getPendingConnection());
        StoredProfile playerProfile = loginSession.getProfile();
        loginSession.setRegistered(true);
        if (!loginSession.isAlreadySaved()) {
            playerProfile.setPremium(true);
            plugin.getCore().getStorage().save(playerProfile);
            loginSession.setAlreadySaved(true);
        }
    }
}
Also used : StoredProfile(com.github.games647.fastlogin.core.StoredProfile) FloodgateService(com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService) BungeeLoginSession(com.github.games647.fastlogin.bungee.BungeeLoginSession)

Aggregations

FloodgateService (com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService)4 BungeeLoginSession (com.github.games647.fastlogin.bungee.BungeeLoginSession)2 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)2 Server (net.md_5.bungee.api.connection.Server)2 FloodgatePlayer (org.geysermc.floodgate.api.player.FloodgatePlayer)2 BukkitLoginSession (com.github.games647.fastlogin.bukkit.BukkitLoginSession)1 CrackedCommand (com.github.games647.fastlogin.bukkit.command.CrackedCommand)1 PremiumCommand (com.github.games647.fastlogin.bukkit.command.PremiumCommand)1 ConnectionListener (com.github.games647.fastlogin.bukkit.listener.ConnectionListener)1 PaperCacheListener (com.github.games647.fastlogin.bukkit.listener.PaperCacheListener)1 SkinApplyListener (com.github.games647.fastlogin.bukkit.listener.protocollib.SkinApplyListener)1 ProtocolSupportListener (com.github.games647.fastlogin.bukkit.listener.protocolsupport.ProtocolSupportListener)1 DelayedAuthHook (com.github.games647.fastlogin.bukkit.task.DelayedAuthHook)1 FloodgateAuthTask (com.github.games647.fastlogin.bukkit.task.FloodgateAuthTask)1 ForceLoginTask (com.github.games647.fastlogin.bukkit.task.ForceLoginTask)1 BungeeAuthHook (com.github.games647.fastlogin.bungee.hook.BungeeAuthHook)1 BungeeCordAuthenticatorBungeeHook (com.github.games647.fastlogin.bungee.hook.BungeeCordAuthenticatorBungeeHook)1 SodionAuthHook (com.github.games647.fastlogin.bungee.hook.SodionAuthHook)1 ConnectListener (com.github.games647.fastlogin.bungee.listener.ConnectListener)1 PluginMessageListener (com.github.games647.fastlogin.bungee.listener.PluginMessageListener)1