Search in sources :

Example 6 with RateLimitException

use of com.github.games647.craftapi.resolver.RateLimitException 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 7 with RateLimitException

use of com.github.games647.craftapi.resolver.RateLimitException in project CraftAPI by games647.

the class MojangResolver method findProfile.

@Override
public Optional<Profile> findProfile(String name) throws IOException, RateLimitException {
    Optional<Profile> optProfile = cache.getByName(name);
    if (optProfile.isPresent() || !validNamePredicate.test(name)) {
        return optProfile;
    }
    String url = UUID_URL + name;
    HttpURLConnection conn = getConnection(url);
    int responseCode = conn.getResponseCode();
    if (responseCode == RateLimitException.RATE_LIMIT_RESPONSE_CODE) {
        if (conn.usingProxy()) {
            throw new RateLimitException();
        }
        conn = getProxyConnection(url);
        responseCode = conn.getResponseCode();
    }
    if (responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
        return Optional.empty();
    }
    // todo: print errorstream on IOException
    Profile profile = readJson(conn.getInputStream(), Profile.class);
    cache.add(profile);
    return Optional.of(profile);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Profile(com.github.games647.craftapi.model.Profile)

Aggregations

Profile (com.github.games647.craftapi.model.Profile)3 HttpURLConnection (java.net.HttpURLConnection)3 NotPremiumException (com.github.games647.changeskin.core.NotPremiumException)2 RateLimitException (com.github.games647.changeskin.core.RateLimitException)2 RateLimitException (com.github.games647.craftapi.resolver.RateLimitException)2 StoredProfile (com.github.games647.fastlogin.core.StoredProfile)2 IOException (java.io.IOException)2 UUID (java.util.UUID)2 GameProfile (com.github.games647.changeskin.core.model.GameProfile)1 SkinModel (com.github.games647.changeskin.core.model.skin.SkinModel)1 SkinProperty (com.github.games647.craftapi.model.skin.SkinProperty)1 Textures (com.github.games647.craftapi.model.skin.Textures)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 Proxy (java.net.Proxy)1 Configuration (net.md_5.bungee.config.Configuration)1