Search in sources :

Example 6 with ProfileProperty

use of org.spongepowered.api.profile.property.ProfileProperty in project SkinsRestorerX by DoNotSpamPls.

the class LoginListener method handle.

@Override
public void handle(Login e) {
    String name = e.getTargetUser().getName().toLowerCase();
    Collection<ProfileProperty> props = e.getProfile().getPropertyMap().get("textures");
    String skin = SkinsRestorer.getInstance().getDataRoot().getNode("Players", name).getString();
    if (skin == null || skin.isEmpty())
        skin = name;
    skin = skin.toLowerCase();
    ProfileProperty cachedTextures = null;
    try {
        cachedTextures = Sponge.getServer().getGameProfileManager().createProfileProperty("textures", SkinsRestorer.getInstance().getDataRoot().getNode("Skins", skin, "Value").getString(), SkinsRestorer.getInstance().getDataRoot().getNode("Skins", skin, "Signature").getString());
        props.clear();
        props.add(cachedTextures);
    } catch (Exception ex) {
    }
    if (cachedTextures == null) {
        Optional<String> uid = MojangAPI.getUUID(skin);
        if (!uid.isPresent())
            return;
        Optional<ProfileProperty> textures = MojangAPI.getSkinProperty(uid.get());
        if (!textures.isPresent())
            return;
        cachedTextures = textures.get();
        if (!name.equalsIgnoreCase(skin))
            SkinsRestorer.getInstance().getDataRoot().getNode("Players", name).setValue(skin);
        else
            SkinsRestorer.getInstance().getDataRoot().getNode("Players", name).setValue(null);
        SkinsRestorer.getInstance().getDataRoot().getNode("Skins", skin, "Value").setValue(textures.get().getValue());
        SkinsRestorer.getInstance().getDataRoot().getNode("Skins", skin, "Signature").setValue(textures.get().getSignature().get());
        SkinsRestorer.getInstance().saveConfigs();
        props.clear();
        props.add(cachedTextures);
        return;
    }
}
Also used : ProfileProperty(org.spongepowered.api.profile.property.ProfileProperty)

Example 7 with ProfileProperty

use of org.spongepowered.api.profile.property.ProfileProperty in project ChangeSkin by games647.

the class SpongeSkinAPI method applyProperties.

@Override
public void applyProperties(GameProfile profile, SkinModel targetSkin) {
    // remove existing skins
    profile.getPropertyMap().clear();
    if (targetSkin != null) {
        GameProfileManager profileManager = Sponge.getServer().getGameProfileManager();
        ProfileProperty profileProperty = profileManager.createProfileProperty(SkinProperty.SKIN_KEY, targetSkin.getEncodedValue(), targetSkin.getSignature());
        profile.getPropertyMap().put(SkinProperty.SKIN_KEY, profileProperty);
    }
}
Also used : ProfileProperty(org.spongepowered.api.profile.property.ProfileProperty) GameProfileManager(org.spongepowered.api.profile.GameProfileManager)

Example 8 with ProfileProperty

use of org.spongepowered.api.profile.property.ProfileProperty in project LanternServer by LanternPowered.

the class LanternProfileProperty method createPropertiesMapFromJson.

/**
 * Creates a multimap with {@link LanternProfileProperty}s from the specified {@link JsonArray}.
 *
 * @param jsonArray The json array
 * @return The multimap
 */
public static Multimap<String, ProfileProperty> createPropertiesMapFromJson(JsonArray jsonArray) {
    final Multimap<String, ProfileProperty> properties = LinkedHashMultimap.create();
    for (int i = 0; i < jsonArray.size(); i++) {
        final ProfileProperty profileProperty = createFromJson(jsonArray.get(i).getAsJsonObject());
        properties.put(profileProperty.getName(), profileProperty);
    }
    return properties;
}
Also used : ProfileProperty(org.spongepowered.api.profile.property.ProfileProperty)

Example 9 with ProfileProperty

use of org.spongepowered.api.profile.property.ProfileProperty in project LanternServer by LanternPowered.

the class HandlerEncryptionResponse method performAuth.

private void performAuth(NetworkSession session, String username, String hash, @Nullable String preventProxiesIp) {
    final String postUrl = AUTH_BASE_URL + "?username=" + username + "&serverId=" + hash + (preventProxiesIp == null ? "" : "?ip=" + preventProxiesIp);
    try {
        // Authenticate
        URLConnection connection = new URL(postUrl).openConnection();
        JsonObject json;
        try (InputStream is = connection.getInputStream()) {
            if (is.available() == 0) {
                session.disconnect(t("Invalid username or session id!"));
                return;
            }
            try {
                json = GSON.fromJson(new InputStreamReader(is), JsonObject.class);
            } catch (Exception e) {
                Lantern.getLogger().warn("Username \"{}\" failed to authenticate!", username);
                session.disconnect(t("multiplayer.disconnect.unverified_username"));
                return;
            }
        }
        final String name = json.get("name").getAsString();
        final String id = json.get("id").getAsString();
        // Parse UUID
        final UUID uuid;
        try {
            uuid = UUIDHelper.fromFlatString(id);
        } catch (IllegalArgumentException e) {
            Lantern.getLogger().error("Returned authentication UUID invalid: {}", id, e);
            session.disconnect(t("Invalid UUID."));
            return;
        }
        final Multimap<String, ProfileProperty> properties = LanternProfileProperty.createPropertiesMapFromJson(json.getAsJsonArray("properties"));
        final LanternGameProfile gameProfile = new LanternGameProfile(uuid, name, properties);
        Lantern.getLogger().info("Finished authenticating.");
        final Cause cause = Cause.of(EventContext.empty(), session, gameProfile);
        final ClientConnectionEvent.Auth event = SpongeEventFactory.createClientConnectionEventAuth(cause, session, new MessageEvent.MessageFormatter(t("multiplayer.disconnect.not_allowed_to_join")), gameProfile, false);
        Sponge.getEventManager().post(event);
        if (event.isCancelled()) {
            session.disconnect(event.isMessageCancelled() ? t("multiplayer.disconnect.generic") : event.getMessage());
        } else {
            session.messageReceived(new MessageLoginInFinish(gameProfile));
        }
    } catch (Exception e) {
        Lantern.getLogger().error("Error in authentication thread", e);
        session.disconnect(t("Internal error during authentication."));
    }
}
Also used : ProfileProperty(org.spongepowered.api.profile.property.ProfileProperty) LanternProfileProperty(org.lanternpowered.server.profile.LanternProfileProperty) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) MessageEvent(org.spongepowered.api.event.message.MessageEvent) LanternGameProfile(org.lanternpowered.server.profile.LanternGameProfile) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) JsonObject(com.google.gson.JsonObject) URLConnection(java.net.URLConnection) URL(java.net.URL) SocketException(java.net.SocketException) GeneralSecurityException(java.security.GeneralSecurityException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MessageLoginInFinish(org.lanternpowered.server.network.vanilla.message.type.login.MessageLoginInFinish) Cause(org.spongepowered.api.event.cause.Cause) UUID(java.util.UUID)

Aggregations

ProfileProperty (org.spongepowered.api.profile.property.ProfileProperty)9 JsonObject (com.google.gson.JsonObject)3 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 URL (java.net.URL)2 URLConnection (java.net.URLConnection)2 UUID (java.util.UUID)2 LanternGameProfile (org.lanternpowered.server.profile.LanternGameProfile)2 LanternProfileProperty (org.lanternpowered.server.profile.LanternProfileProperty)2 JsonArray (com.google.gson.JsonArray)1 CodecException (io.netty.handler.codec.CodecException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HttpURLConnection (java.net.HttpURLConnection)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketException (java.net.SocketException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 NetworkSession (org.lanternpowered.server.network.NetworkSession)1