Search in sources :

Example 11 with Profile

use of com.github.games647.craftapi.model.Profile 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 12 with Profile

use of com.github.games647.craftapi.model.Profile 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)

Example 13 with Profile

use of com.github.games647.craftapi.model.Profile in project FastLogin by games647.

the class NameCheckTask method requestPremiumLogin.

// Minecraft server implementation
// https://github.com/bergerkiller/CraftSource/blob/master/net.minecraft.server/LoginListener.java#L161
@Override
public void requestPremiumLogin(ProtocolLibLoginSource source, StoredProfile profile, String username, boolean registered) {
    try {
        source.enableOnlinemode();
    } catch (Exception ex) {
        plugin.getLog().error("Cannot send encryption packet. Falling back to cracked login for: {}", profile, ex);
        return;
    }
    String ip = player.getAddress().getAddress().getHostAddress();
    core.getPendingLogin().put(ip + username, new Object());
    byte[] verify = source.getVerifyToken();
    BukkitLoginSession playerSession = new BukkitLoginSession(username, verify, registered, profile);
    plugin.putSession(player.getAddress(), playerSession);
    // cancel only if the player has a paid account otherwise login as normal offline player
    synchronized (packetEvent.getAsyncMarker().getProcessingLock()) {
        packetEvent.setCancelled(true);
    }
}
Also used : BukkitLoginSession(com.github.games647.fastlogin.bukkit.BukkitLoginSession)

Example 14 with Profile

use of com.github.games647.craftapi.model.Profile in project FastLogin by games647.

the class VerifyResponseTask method verifyResponse.

private void verifyResponse(BukkitLoginSession session) {
    PrivateKey privateKey = serverKey.getPrivate();
    SecretKey loginKey;
    try {
        loginKey = EncryptionUtil.decryptSharedKey(privateKey, sharedSecret);
    } catch (GeneralSecurityException securityEx) {
        disconnect("error-kick", false, "Cannot decrypt received contents", securityEx);
        return;
    }
    try {
        if (!checkVerifyToken(session) || !enableEncryption(loginKey)) {
            return;
        }
    } catch (Exception ex) {
        disconnect("error-kick", false, "Cannot decrypt received contents", ex);
        return;
    }
    String serverId = EncryptionUtil.getServerIdHashString("", loginKey, serverKey.getPublic());
    String requestedUsername = session.getRequestUsername();
    InetSocketAddress socketAddress = player.getAddress();
    try {
        MojangResolver resolver = plugin.getCore().getResolver();
        InetAddress address = socketAddress.getAddress();
        Optional<Verification> response = resolver.hasJoined(requestedUsername, serverId, address);
        if (response.isPresent()) {
            Verification verification = response.get();
            plugin.getLog().info("Profile {} has a verified premium account", requestedUsername);
            String realUsername = verification.getName();
            if (realUsername == null) {
                disconnect("invalid-session", true, "Username field null for {}", requestedUsername);
                return;
            }
            SkinProperty[] properties = verification.getProperties();
            if (properties.length > 0) {
                session.setSkinProperty(properties[0]);
            }
            session.setVerifiedUsername(realUsername);
            session.setUuid(verification.getId());
            session.setVerified(true);
            setPremiumUUID(session.getUuid());
            receiveFakeStartPacket(realUsername);
        } else {
            // user tried to fake an authentication
            disconnect("invalid-session", true, "GameProfile {0} ({1}) tried to log in with an invalid session ServerId: {2}", session.getRequestUsername(), socketAddress, serverId);
        }
    } catch (IOException ioEx) {
        disconnect("error-kick", false, "Failed to connect to session server", ioEx);
    }
}
Also used : PrivateKey(java.security.PrivateKey) InetSocketAddress(java.net.InetSocketAddress) GeneralSecurityException(java.security.GeneralSecurityException) Verification(com.github.games647.craftapi.model.auth.Verification) IOException(java.io.IOException) SkinProperty(com.github.games647.craftapi.model.skin.SkinProperty) MojangResolver(com.github.games647.craftapi.resolver.MojangResolver) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SecretKey(javax.crypto.SecretKey) InetAddress(java.net.InetAddress)

Example 15 with Profile

use of com.github.games647.craftapi.model.Profile in project FastLogin by games647.

the class ProtocolSupportListener method requestPremiumLogin.

@Override
public void requestPremiumLogin(ProtocolLoginSource source, StoredProfile profile, String username, boolean registered) {
    source.enableOnlinemode();
    String ip = source.getAddress().getAddress().getHostAddress();
    plugin.getCore().getPendingLogin().put(ip + username, new Object());
    BukkitLoginSession playerSession = new BukkitLoginSession(username, registered, profile);
    plugin.putSession(source.getAddress(), playerSession);
}
Also used : BukkitLoginSession(com.github.games647.fastlogin.bukkit.BukkitLoginSession)

Aggregations

Profile (com.github.games647.craftapi.model.Profile)8 StoredProfile (com.github.games647.fastlogin.core.StoredProfile)7 SkinPropertyTest (com.github.games647.craftapi.model.skin.SkinPropertyTest)5 BukkitLoginSession (com.github.games647.fastlogin.bukkit.BukkitLoginSession)5 Test (org.junit.Test)5 BukkitFastLoginPremiumToggleEvent (com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPremiumToggleEvent)4 UUID (java.util.UUID)3 SkinModel (com.github.games647.changeskin.core.model.skin.SkinModel)2 SkinProperty (com.github.games647.craftapi.model.skin.SkinProperty)2 RateLimitException (com.github.games647.craftapi.resolver.RateLimitException)2 BukkitFastLoginPreLoginEvent (com.github.games647.fastlogin.bukkit.event.BukkitFastLoginPreLoginEvent)2 BungeeLoginSession (com.github.games647.fastlogin.bungee.BungeeLoginSession)2 IOException (java.io.IOException)2 ChangeSkinCore (com.github.games647.changeskin.core.ChangeSkinCore)1 SkinStorage (com.github.games647.changeskin.core.SkinStorage)1 GameProfile (com.github.games647.changeskin.core.model.GameProfile)1 UserPreference (com.github.games647.changeskin.core.model.UserPreference)1 Account (com.github.games647.changeskin.core.model.auth.Account)1 TextureType (com.github.games647.changeskin.core.model.skin.TextureType)1 SharedListener (com.github.games647.changeskin.core.shared.SharedListener)1