Search in sources :

Example 6 with StoredProfile

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

the class JoinManagement method checkNameChange.

private boolean checkNameChange(S source, String username, Profile profile) {
    // user not exists in the db
    if (core.getConfig().get("nameChangeCheck", false)) {
        StoredProfile storedProfile = core.getStorage().loadProfile(profile.getId());
        if (storedProfile != null) {
            // uuid exists in the database
            core.getPlugin().getLog().info("GameProfile {} changed it's username", profile);
            // update the username to the new one in the database
            storedProfile.setPlayerName(username);
            requestPremiumLogin(source, storedProfile, username, false);
            return true;
        }
    }
    return false;
}
Also used : StoredProfile(com.github.games647.fastlogin.core.StoredProfile)

Example 7 with StoredProfile

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

the class JoinManagement method onLogin.

public void onLogin(String username, S source) {
    core.getPlugin().getLog().info("Handling player {}", username);
    StoredProfile profile = core.getStorage().loadProfile(username);
    if (profile == null) {
        return;
    }
    // check if the player is connecting through Bedrock Edition
    if (bedrockService != null && bedrockService.isBedrockConnection(username)) {
        // perform Bedrock specific checks and skip Java checks, if they are not needed
        if (bedrockService.performChecks(username, source)) {
            return;
        }
    }
    callFastLoginPreLoginEvent(username, source, profile);
    Configuration config = core.getConfig();
    String ip = source.getAddress().getAddress().getHostAddress();
    profile.setLastIp(ip);
    try {
        if (profile.isSaved()) {
            if (profile.isPremium()) {
                core.getPlugin().getLog().info("Requesting premium login for registered player: {}", username);
                requestPremiumLogin(source, profile, username, true);
            } else {
                if (isValidUsername(source, profile)) {
                    startCrackedSession(source, profile, username);
                }
            }
        } else {
            if (core.getPendingLogin().remove(ip + username) != null && config.get("secondAttemptCracked", false)) {
                core.getPlugin().getLog().info("Second attempt login -> cracked {}", username);
                // first login request failed so make a cracked session
                startCrackedSession(source, profile, username);
                return;
            }
            Optional<Profile> premiumUUID = Optional.empty();
            if (config.get("nameChangeCheck", false) || config.get("autoRegister", false)) {
                premiumUUID = core.getResolver().findProfile(username);
            }
            if (!premiumUUID.isPresent() || (!checkNameChange(source, username, premiumUUID.get()) && !checkPremiumName(source, username, profile))) {
                // nothing detected the player as premium -> start a cracked session
                if (core.getConfig().get("switchMode", false)) {
                    source.kick(core.getMessage("switch-kick-message"));
                    return;
                }
                startCrackedSession(source, profile, username);
            }
        }
    } catch (RateLimitException rateLimitEx) {
        core.getPlugin().getLog().error("Mojang's rate limit reached for {}. The public IPv4 address of this" + " server issued more than 600 Name -> UUID requests within 10 minutes. After those 10" + " minutes we can make requests again.", username);
    } catch (Exception ex) {
        core.getPlugin().getLog().error("Failed to check premium state for {}", username, ex);
        core.getPlugin().getLog().error("Failed to check premium state of {}", username, ex);
    }
}
Also used : StoredProfile(com.github.games647.fastlogin.core.StoredProfile) Configuration(net.md_5.bungee.config.Configuration) RateLimitException(com.github.games647.craftapi.resolver.RateLimitException) Profile(com.github.games647.craftapi.model.Profile) StoredProfile(com.github.games647.fastlogin.core.StoredProfile) RateLimitException(com.github.games647.craftapi.resolver.RateLimitException)

Example 8 with StoredProfile

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

the class CrackedCommand method onCrackedSelf.

private void onCrackedSelf(CommandSender sender, Command cmd, String[] args) {
    if (isConsole(sender)) {
        return;
    }
    if (forwardCrackedCommand(sender, sender.getName())) {
        return;
    }
    if (plugin.getBungeeManager().isEnabled()) {
        sendBungeeActivateMessage(sender, sender.getName(), false);
        plugin.getCore().sendLocaleMessage("wait-on-proxy", sender);
    } else {
        // todo: load async if
        StoredProfile profile = plugin.getCore().getStorage().loadProfile(sender.getName());
        if (profile.isPremium()) {
            plugin.getCore().sendLocaleMessage("remove-premium", sender);
            profile.setPremium(false);
            profile.setId(null);
            plugin.getScheduler().runAsync(() -> {
                plugin.getCore().getStorage().save(profile);
                plugin.getServer().getPluginManager().callEvent(new BukkitFastLoginPremiumToggleEvent(profile, PremiumToggleReason.COMMAND_OTHER));
            });
        } else {
            plugin.getCore().sendLocaleMessage("not-premium", sender);
        }
    }
}
Also used : StoredProfile(com.github.games647.fastlogin.core.StoredProfile) BukkitFastLoginPremiumToggleEvent(com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPremiumToggleEvent)

Example 9 with StoredProfile

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

the class PremiumCommand method onPremiumOther.

private void onPremiumOther(CommandSender sender, Command command, String[] args) {
    if (!hasOtherPermission(sender, command)) {
        return;
    }
    if (forwardPremiumCommand(sender, args[0])) {
        return;
    }
    // todo: load async
    StoredProfile profile = plugin.getCore().getStorage().loadProfile(args[0]);
    if (profile == null) {
        plugin.getCore().sendLocaleMessage("player-unknown", sender);
        return;
    }
    if (profile.isPremium()) {
        plugin.getCore().sendLocaleMessage("already-exists-other", sender);
    } else {
        // todo: resolve uuid
        profile.setPremium(true);
        plugin.getScheduler().runAsync(() -> {
            plugin.getCore().getStorage().save(profile);
            plugin.getServer().getPluginManager().callEvent(new BukkitFastLoginPremiumToggleEvent(profile, PremiumToggleReason.COMMAND_OTHER));
        });
        plugin.getCore().sendLocaleMessage("add-premium-other", sender);
    }
}
Also used : StoredProfile(com.github.games647.fastlogin.core.StoredProfile) BukkitFastLoginPremiumToggleEvent(com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPremiumToggleEvent)

Example 10 with StoredProfile

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

the class NameCheckTask method callFastLoginPreLoginEvent.

@Override
public FastLoginPreLoginEvent callFastLoginPreLoginEvent(String username, ProtocolLibLoginSource source, StoredProfile profile) {
    BukkitFastLoginPreLoginEvent event = new BukkitFastLoginPreLoginEvent(username, source, profile);
    plugin.getServer().getPluginManager().callEvent(event);
    return event;
}
Also used : BukkitFastLoginPreLoginEvent(com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPreLoginEvent)

Aggregations

StoredProfile (com.github.games647.fastlogin.core.StoredProfile)17 BukkitLoginSession (com.github.games647.fastlogin.bukkit.BukkitLoginSession)4 BukkitFastLoginPremiumToggleEvent (com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPremiumToggleEvent)4 PremiumToggleReason (com.github.games647.fastlogin.core.shared.event.FastLoginPremiumToggleEvent.PremiumToggleReason)4 UUID (java.util.UUID)4 BungeeLoginSession (com.github.games647.fastlogin.bungee.BungeeLoginSession)3 VelocityLoginSession (com.github.games647.fastlogin.velocity.VelocityLoginSession)3 Profile (com.github.games647.craftapi.model.Profile)2 RateLimitException (com.github.games647.craftapi.resolver.RateLimitException)2 BukkitFastLoginPreLoginEvent (com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPreLoginEvent)2 BungeeFastLoginPremiumToggleEvent (com.github.games647.fastlogin.bungee.event.BungeeFastLoginPremiumToggleEvent)2 LoginSession (com.github.games647.fastlogin.core.shared.LoginSession)2 VelocityFastLoginPremiumToggleEvent (com.github.games647.fastlogin.velocity.event.VelocityFastLoginPremiumToggleEvent)2 BukkitFastLoginAutoLoginEvent (com.github.games647.fastlogin.bukkit.event.BukkitFastLoginAutoLoginEvent)1 FloodgateService (com.github.games647.fastlogin.core.hooks.bedrock.FloodgateService)1 SQLStorage (com.github.games647.fastlogin.core.storage.SQLStorage)1 Subscribe (com.velocitypowered.api.event.Subscribe)1 IOException (java.io.IOException)1 Instant (java.time.Instant)1 PendingConnection (net.md_5.bungee.api.connection.PendingConnection)1