Search in sources :

Example 21 with StoredProfile

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

the class AsyncToggleMessage method activatePremium.

private void activatePremium() {
    StoredProfile playerProfile = core.getStorage().loadProfile(targetPlayer);
    if (playerProfile.isPremium()) {
        sendMessage("already-exists");
        return;
    }
    playerProfile.setPremium(true);
    core.getStorage().save(playerProfile);
    PremiumToggleReason reason = (!isPlayerSender || !sender.getName().equalsIgnoreCase(playerProfile.getName())) ? PremiumToggleReason.COMMAND_OTHER : PremiumToggleReason.COMMAND_SELF;
    core.getPlugin().getProxy().getPluginManager().callEvent(new BungeeFastLoginPremiumToggleEvent(playerProfile, reason));
    sendMessage("add-premium");
}
Also used : StoredProfile(com.github.games647.fastlogin.core.StoredProfile) PremiumToggleReason(com.github.games647.fastlogin.core.shared.event.FastLoginPremiumToggleEvent.PremiumToggleReason) BungeeFastLoginPremiumToggleEvent(com.github.games647.fastlogin.bungee.event.BungeeFastLoginPremiumToggleEvent)

Example 22 with StoredProfile

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

the class ConnectListener method onGameprofileRequest.

@Subscribe
public void onGameprofileRequest(GameProfileRequestEvent event) {
    if (event.isOnlineMode()) {
        LoginSession session = plugin.getSession().get(event.getConnection().getRemoteAddress());
        UUID verifiedUUID = event.getGameProfile().getId();
        String verifiedUsername = event.getUsername();
        session.setUuid(verifiedUUID);
        session.setVerifiedUsername(verifiedUsername);
        StoredProfile playerProfile = session.getProfile();
        playerProfile.setId(verifiedUUID);
        if (!plugin.getCore().getConfig().get("premiumUuid", true)) {
            UUID offlineUUID = UUIDAdapter.generateOfflineId(playerProfile.getName());
            event.setGameProfile(event.getGameProfile().withId(offlineUUID));
            plugin.getLog().info("Overridden UUID from {} to {} (based of {}) on {}", verifiedUUID, offlineUUID, verifiedUsername, event.getConnection());
        }
        if (!plugin.getCore().getConfig().get("forwardSkin", true)) {
            event.setGameProfile(event.getGameProfile().withProperties(removeSkin(event.getGameProfile().getProperties())));
        }
    }
}
Also used : VelocityLoginSession(com.github.games647.fastlogin.velocity.VelocityLoginSession) LoginSession(com.github.games647.fastlogin.core.shared.LoginSession) StoredProfile(com.github.games647.fastlogin.core.StoredProfile) UUID(java.util.UUID) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 23 with StoredProfile

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

the class AsyncToggleMessage method activatePremium.

private void activatePremium() {
    StoredProfile playerProfile = core.getStorage().loadProfile(targetPlayer);
    if (playerProfile.isPremium()) {
        sendMessage("already-exists");
        return;
    }
    playerProfile.setPremium(true);
    core.getStorage().save(playerProfile);
    PremiumToggleReason reason = (!isPlayerSender || !senderName.equalsIgnoreCase(playerProfile.getName())) ? PremiumToggleReason.COMMAND_OTHER : PremiumToggleReason.COMMAND_SELF;
    core.getPlugin().getProxy().getEventManager().fire(new VelocityFastLoginPremiumToggleEvent(playerProfile, reason));
    sendMessage("add-premium");
}
Also used : StoredProfile(com.github.games647.fastlogin.core.StoredProfile) VelocityFastLoginPremiumToggleEvent(com.github.games647.fastlogin.velocity.event.VelocityFastLoginPremiumToggleEvent) PremiumToggleReason(com.github.games647.fastlogin.core.shared.event.FastLoginPremiumToggleEvent.PremiumToggleReason)

Example 24 with StoredProfile

use of com.github.games647.fastlogin.core.StoredProfile 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 25 with StoredProfile

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