Search in sources :

Example 1 with FastLoginCore

use of com.github.games647.fastlogin.core.shared.FastLoginCore in project FastLogin by games647.

the class PluginMessageListener method readMessage.

private void readMessage(Player forPlayer, String channel, byte[] data) {
    FastLoginCore<Player, CommandSource, FastLoginVelocity> core = plugin.getCore();
    ByteArrayDataInput dataInput = ByteStreams.newDataInput(data);
    if (successChannel.equals(channel)) {
        onSuccessMessage(forPlayer);
    } else if (changeChannel.equals(channel)) {
        ChangePremiumMessage changeMessage = new ChangePremiumMessage();
        changeMessage.readFrom(dataInput);
        String playerName = changeMessage.getPlayerName();
        boolean isSourceInvoker = changeMessage.isSourceInvoker();
        if (changeMessage.shouldEnable()) {
            if (playerName.equals(forPlayer.getUsername()) && plugin.getCore().getConfig().get("premium-warning", true) && !core.getPendingConfirms().contains(forPlayer.getUniqueId())) {
                String message = core.getMessage("premium-warning");
                forPlayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message));
                core.getPendingConfirms().add(forPlayer.getUniqueId());
                return;
            }
            core.getPendingConfirms().remove(forPlayer.getUniqueId());
            Runnable task = new AsyncToggleMessage(core, forPlayer, playerName, true, isSourceInvoker);
            plugin.getScheduler().runAsync(task);
        } else {
            Runnable task = new AsyncToggleMessage(core, forPlayer, playerName, false, isSourceInvoker);
            plugin.getScheduler().runAsync(task);
        }
    }
}
Also used : ChangePremiumMessage(com.github.games647.fastlogin.core.message.ChangePremiumMessage) AsyncToggleMessage(com.github.games647.fastlogin.velocity.task.AsyncToggleMessage) Player(com.velocitypowered.api.proxy.Player) FastLoginVelocity(com.github.games647.fastlogin.velocity.FastLoginVelocity) CommandSource(com.velocitypowered.api.command.CommandSource) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput)

Example 2 with FastLoginCore

use of com.github.games647.fastlogin.core.shared.FastLoginCore 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 3 with FastLoginCore

use of com.github.games647.fastlogin.core.shared.FastLoginCore in project FastLogin by games647.

the class PluginMessageListener method readMessage.

private void readMessage(ProxiedPlayer forPlayer, String channel, byte[] data) {
    FastLoginCore<ProxiedPlayer, CommandSender, FastLoginBungee> core = plugin.getCore();
    ByteArrayDataInput dataInput = ByteStreams.newDataInput(data);
    if (successChannel.equals(channel)) {
        onSuccessMessage(forPlayer);
    } else if (changeChannel.equals(channel)) {
        ChangePremiumMessage changeMessage = new ChangePremiumMessage();
        changeMessage.readFrom(dataInput);
        String playerName = changeMessage.getPlayerName();
        boolean isSourceInvoker = changeMessage.isSourceInvoker();
        if (changeMessage.shouldEnable()) {
            if (playerName.equals(forPlayer.getName()) && plugin.getCore().getConfig().get("premium-warning", true) && !core.getPendingConfirms().contains(forPlayer.getUniqueId())) {
                String message = core.getMessage("premium-warning");
                forPlayer.sendMessage(TextComponent.fromLegacyText(message));
                core.getPendingConfirms().add(forPlayer.getUniqueId());
                return;
            }
            core.getPendingConfirms().remove(forPlayer.getUniqueId());
            Runnable task = new AsyncToggleMessage(core, forPlayer, playerName, true, isSourceInvoker);
            plugin.getScheduler().runAsync(task);
        } else {
            Runnable task = new AsyncToggleMessage(core, forPlayer, playerName, false, isSourceInvoker);
            plugin.getScheduler().runAsync(task);
        }
    }
}
Also used : ChangePremiumMessage(com.github.games647.fastlogin.core.message.ChangePremiumMessage) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) AsyncToggleMessage(com.github.games647.fastlogin.bungee.task.AsyncToggleMessage) CommandSender(net.md_5.bungee.api.CommandSender) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) FastLoginBungee(com.github.games647.fastlogin.bungee.FastLoginBungee)

Example 4 with FastLoginCore

use of com.github.games647.fastlogin.core.shared.FastLoginCore 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 5 with FastLoginCore

use of com.github.games647.fastlogin.core.shared.FastLoginCore in project FastLogin by games647.

the class FastLoginVelocity method onProxyInitialization.

@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
    scheduler = new AsyncScheduler(logger, task -> server.getScheduler().buildTask(this, task).schedule());
    core = new FastLoginCore<>(this);
    core.load();
    loadOrGenerateProxyId();
    if (!core.setupDatabase() || proxyId == null) {
        return;
    }
    server.getEventManager().register(this, new ConnectListener(this, core.getRateLimiter()));
    server.getEventManager().register(this, new PluginMessageListener(this));
    server.getChannelRegistrar().register(MinecraftChannelIdentifier.create(getName(), ChangePremiumMessage.CHANGE_CHANNEL));
    server.getChannelRegistrar().register(MinecraftChannelIdentifier.create(getName(), SuccessMessage.SUCCESS_CHANNEL));
}
Also used : MinecraftChannelIdentifier(com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier) AsyncScheduler(com.github.games647.fastlogin.core.AsyncScheduler) Inject(com.google.inject.Inject) SuccessMessage(com.github.games647.fastlogin.core.message.SuccessMessage) BedrockService(com.github.games647.fastlogin.core.hooks.bedrock.BedrockService) ProxyShutdownEvent(com.velocitypowered.api.event.proxy.ProxyShutdownEvent) ConcurrentMap(java.util.concurrent.ConcurrentMap) FastLoginCore(com.github.games647.fastlogin.core.shared.FastLoginCore) ConnectListener(com.github.games647.fastlogin.velocity.listener.ConnectListener) Player(com.velocitypowered.api.proxy.Player) ProxyServer(com.velocitypowered.api.proxy.ProxyServer) ProxyInitializeEvent(com.velocitypowered.api.event.proxy.ProxyInitializeEvent) LegacyComponentSerializer(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer) Path(java.nio.file.Path) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) Plugin(com.velocitypowered.api.plugin.Plugin) ChannelMessage(com.github.games647.fastlogin.core.message.ChannelMessage) Logger(org.slf4j.Logger) Files(java.nio.file.Files) StandardOpenOption(java.nio.file.StandardOpenOption) IOException(java.io.IOException) PlatformPlugin(com.github.games647.fastlogin.core.shared.PlatformPlugin) UUID(java.util.UUID) RegisteredServer(com.velocitypowered.api.proxy.server.RegisteredServer) InetSocketAddress(java.net.InetSocketAddress) StandardCharsets(java.nio.charset.StandardCharsets) PluginMessageListener(com.github.games647.fastlogin.velocity.listener.PluginMessageListener) DataDirectory(com.velocitypowered.api.plugin.annotation.DataDirectory) List(java.util.List) ByteStreams(com.google.common.io.ByteStreams) Subscribe(com.velocitypowered.api.event.Subscribe) ChangePremiumMessage(com.github.games647.fastlogin.core.message.ChangePremiumMessage) MapMaker(com.google.common.collect.MapMaker) CommandSource(com.velocitypowered.api.command.CommandSource) Collections(java.util.Collections) AsyncScheduler(com.github.games647.fastlogin.core.AsyncScheduler) PluginMessageListener(com.github.games647.fastlogin.velocity.listener.PluginMessageListener) ConnectListener(com.github.games647.fastlogin.velocity.listener.ConnectListener) Subscribe(com.velocitypowered.api.event.Subscribe)

Aggregations

ChangePremiumMessage (com.github.games647.fastlogin.core.message.ChangePremiumMessage)4 AsyncScheduler (com.github.games647.fastlogin.core.AsyncScheduler)2 BedrockService (com.github.games647.fastlogin.core.hooks.bedrock.BedrockService)2 ChannelMessage (com.github.games647.fastlogin.core.message.ChannelMessage)2 SuccessMessage (com.github.games647.fastlogin.core.message.SuccessMessage)2 FastLoginCore (com.github.games647.fastlogin.core.shared.FastLoginCore)2 PlatformPlugin (com.github.games647.fastlogin.core.shared.PlatformPlugin)2 MapMaker (com.google.common.collect.MapMaker)2 ByteArrayDataInput (com.google.common.io.ByteArrayDataInput)2 ByteArrayDataOutput (com.google.common.io.ByteArrayDataOutput)2 ByteStreams (com.google.common.io.ByteStreams)2 CommandSource (com.velocitypowered.api.command.CommandSource)2 Player (com.velocitypowered.api.proxy.Player)2 Path (java.nio.file.Path)2 List (java.util.List)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 CommandSender (net.md_5.bungee.api.CommandSender)2 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)2 CrackedCommand (com.github.games647.fastlogin.bukkit.command.CrackedCommand)1 PremiumCommand (com.github.games647.fastlogin.bukkit.command.PremiumCommand)1