Java源码示例:com.github.steveice10.mc.auth.data.GameProfile

示例1
public GeyserSession(GeyserConnector connector, BedrockServerSession bedrockServerSession) {
    this.connector = connector;
    this.upstream = new UpstreamSession(bedrockServerSession);

    this.chunkCache = new ChunkCache(this);
    this.entityCache = new EntityCache(this);
    this.inventoryCache = new InventoryCache(this);
    this.scoreboardCache = new ScoreboardCache(this);
    this.windowCache = new WindowCache(this);

    this.playerEntity = new PlayerEntity(new GameProfile(UUID.randomUUID(), "unknown"), 1, 1, Vector3f.ZERO, Vector3f.ZERO, Vector3f.ZERO);
    this.inventory = new PlayerInventory();

    this.javaPacketCache = new DataCache<>();

    this.spawned = false;
    this.loggedIn = false;

    this.inventoryCache.getInventories().put(0, inventory);
}
 
示例2
public static PlayerListPacket.Entry buildCachedEntry(GameProfile profile, long geyserId) {
    GameProfileData data = GameProfileData.from(profile);
    SkinProvider.Cape cape = SkinProvider.getCachedCape(data.getCapeUrl());

    SkinProvider.SkinGeometry geometry = SkinProvider.SkinGeometry.getLegacy(data.isAlex());

    return buildEntryManually(
            profile.getId(),
            profile.getName(),
            geyserId,
            profile.getIdAsString(),
            SkinProvider.getCachedSkin(profile.getId()).getSkinData(),
            cape.getCapeId(),
            cape.getCapeData(),
            geometry.getGeometryName(),
            geometry.getGeometryData()
    );
}
 
示例3
/**
 * Fills in the properties of a profile.
 *
 * @param profile Profile to fill in the properties of.
 * @return The given profile, after filling in its properties.
 * @throws ProfileException If the property lookup fails.
 */
public GameProfile fillProfileProperties(GameProfile profile) throws ProfileException {
    if(profile.getId() == null) {
        return profile;
    }

    try {
        MinecraftProfileResponse response = HTTP.makeRequest(this.proxy, BASE_URL+"/profile" + "/" + UUIDSerializer.fromUUID(profile.getId()) + "?unsigned=false", null, MinecraftProfileResponse.class);
        if(response == null) {
            throw new ProfileNotFoundException("Couldn't fetch profile properties for " + profile + " as the profile does not exist.");
        }

        if(response.properties != null) {
            profile.getProperties().addAll(response.properties);
        }

        return profile;
    } catch(RequestException e) {
        throw new ProfileLookupException("Couldn't look up profile properties for " + profile + ".", e);
    }
}
 
示例4
/**
 * Selects a game profile.
 *
 * @param profile Profile to select.
 * @throws RequestException If an error occurs while making the request.
 */
public void selectGameProfile(GameProfile profile) throws RequestException {
    if(!this.loggedIn) {
        throw new RequestException("Cannot change game profile while not logged in.");
    } else if(this.selectedProfile != null) {
        throw new RequestException("Cannot change game profile when it is already selected.");
    } else if(profile != null && this.profiles.contains(profile)) {
        RefreshRequest request = new RefreshRequest(this.clientToken, this.accessToken, profile);
        RefreshResponse response = HTTP.makeRequest(this.proxy, REFRESH_URL, request, RefreshResponse.class);
        if(response.clientToken.equals(this.clientToken)) {
            this.accessToken = response.accessToken;
            this.selectedProfile = response.selectedProfile;
        } else {
            throw new RequestException("Server requested we change our client token. Don't know how to handle this!");
        }
    } else {
        throw new IllegalArgumentException("Invalid profile '" + profile + "'.");
    }
}
 
示例5
public static GameProfile readGameProfile(DataInputStream data) throws IOException {
	boolean present = data.readBoolean();
	if (!present)
		return new GameProfile(new UUID(0, 0), "<unknown>");
	UUID uuid = new UUID(data.readLong(), data.readLong());
	String name = data.readUTF();
	GameProfile profile = new GameProfile(uuid, name);
	int len = data.readUnsignedShort();
	for (int i = 0; i < len; i++) {
		TextureType type = TextureType.values()[data.readUnsignedByte()];
		TextureModel model = TextureModel.values()[data.readUnsignedByte()];
		String url = data.readUTF();
		Map<String, String> m = Maps.newHashMap();
		m.put("model", model.name().toLowerCase(Locale.ROOT));
		profile.getTextures().put(type, new Texture(url, m));
	}
	return profile;
}
 
示例6
public static void writeGameProfile(DataOutputStream data, GameProfile profile) throws IOException {
	if (profile == null) {
		data.writeBoolean(false);
		return;
	}
	data.writeBoolean(true);
	data.writeLong(profile.getId().getMostSignificantBits());
	data.writeLong(profile.getId().getLeastSignificantBits());
	data.writeUTF(profile.getName());
	data.writeShort(profile.getTextures().size());
	for (Map.Entry<TextureType, Texture> en : profile.getTextures().entrySet()) {
		data.writeByte(en.getKey().ordinal());
		data.writeByte(en.getValue().getModel().ordinal());
		data.writeUTF(en.getValue().getURL());
	}
}
 
示例7
/**
 * Fills in the properties of a profile.
 *
 * @param profile Profile to fill in the properties of.
 * @return The given profile, after filling in its properties.
 * @throws ProfileException If the property lookup fails.
 */
public GameProfile fillProfileProperties(GameProfile profile) throws ProfileException {
    if(profile.getId() == null) {
        return profile;
    }

    try {
        MinecraftProfileResponse response = HTTP.makeRequest(this.getProxy(), this.getEndpointUri(PROFILE_ENDPOINT + "/" + UUIDSerializer.fromUUID(profile.getId()), "unsigned=false"), null, MinecraftProfileResponse.class);
        if(response == null) {
            throw new ProfileNotFoundException("Couldn't fetch profile properties for " + profile + " as the profile does not exist.");
        }

        profile.setProperties(response.properties);
        return profile;
    } catch(RequestException e) {
        throw new ProfileLookupException("Couldn't look up profile properties for " + profile + ".", e);
    }
}
 
示例8
/**
 * Selects a game profile.
 *
 * @param profile Profile to select.
 * @throws RequestException If an error occurs while making the request.
 */
public void selectGameProfile(GameProfile profile) throws RequestException {
    if(!this.loggedIn) {
        throw new RequestException("Cannot change game profile while not logged in.");
    } else if(this.selectedProfile != null) {
        throw new RequestException("Cannot change game profile when it is already selected.");
    } else if(profile == null || !this.profiles.contains(profile)) {
        throw new IllegalArgumentException("Invalid profile '" + profile + "'.");
    }

    RefreshRequest request = new RefreshRequest(this.clientToken, this.accessToken, profile);
    AuthenticateRefreshResponse response = HTTP.makeRequest(this.getProxy(), this.getEndpointUri(REFRESH_ENDPOINT), request, AuthenticateRefreshResponse.class);
    if(response == null) {
        throw new RequestException("Server returned invalid response.");
    } else if(!response.clientToken.equals(this.clientToken)) {
        throw new RequestException("Server responded with incorrect client token.");
    }

    this.accessToken = response.accessToken;
    this.selectedProfile = response.selectedProfile;
}
 
示例9
public PlayerEntity(GameProfile gameProfile, long entityId, long geyserId, Vector3f position, Vector3f motion, Vector3f rotation) {
    super(entityId, geyserId, EntityType.PLAYER, position, motion, rotation);

    profile = gameProfile;
    uuid = gameProfile.getId();
    username = gameProfile.getName();
    effectCache = new EntityEffectCache();
    if (geyserId == 1) valid = true;
}
 
示例10
public static PlayerListPacket.Entry buildDefaultEntry(GameProfile profile, long geyserId) {
    return buildEntryManually(
            profile.getId(),
            profile.getName(),
            geyserId,
            profile.getIdAsString(),
            SkinProvider.STEVE_SKIN,
            SkinProvider.EMPTY_CAPE.getCapeId(),
            SkinProvider.EMPTY_CAPE.getCapeData(),
            SkinProvider.EMPTY_GEOMETRY.getGeometryName(),
            SkinProvider.EMPTY_GEOMETRY.getGeometryData()
    );
}
 
示例11
/**
 * Generate the GameProfileData from the given GameProfile
 *
 * @param profile GameProfile to build the GameProfileData from
 * @return The built GameProfileData
 */
public static GameProfileData from(GameProfile profile) {
    // Fallback to the offline mode of working it out
    boolean isAlex = ((profile.getId().hashCode() % 2) == 1);

    try {
        GameProfile.Property skinProperty = profile.getProperty("textures");

        JsonNode skinObject = new ObjectMapper().readTree(new String(Base64.getDecoder().decode(skinProperty.getValue()), StandardCharsets.UTF_8));
        JsonNode textures = skinObject.get("textures");

        JsonNode skinTexture = textures.get("SKIN");
        String skinUrl = skinTexture.get("url").asText();

        isAlex = skinTexture.has("metadata");

        String capeUrl = null;
        if (textures.has("CAPE")) {
            JsonNode capeTexture = textures.get("CAPE");
            capeUrl = capeTexture.get("url").asText();
        }

        return new GameProfileData(skinUrl, capeUrl, isAlex);
    } catch (Exception exception) {
        if (GeyserConnector.getInstance().getAuthType() != AuthType.OFFLINE) {
            GeyserConnector.getInstance().getLogger().debug("Got invalid texture data for " + profile.getName() + " " + exception.getMessage());
        }
        // return default skin with default cape when texture data is invalid
        return new GameProfileData((isAlex ? SkinProvider.EMPTY_SKIN_ALEX.getTextureUrl() : SkinProvider.EMPTY_SKIN.getTextureUrl()), SkinProvider.EMPTY_CAPE.getTextureUrl(), isAlex);
    }
}
 
示例12
/**
 * Gets the profile of the given user if they are currently logged in to the given server.
 *
 * @param name     Name of the user to get the profile of.
 * @param serverId ID of the server to check if they're logged in to.
 * @return The profile of the given user, or null if they are not logged in to the given server.
 * @throws RequestException If an error occurs while making the request.
 */
public GameProfile getProfileByServer(String name, String serverId) throws RequestException {
    HasJoinedResponse response = HTTP.makeRequest(this.proxy, BASE_URL+"/hasJoined" + "?username=" + name + "&serverId=" + serverId, null, HasJoinedResponse.class);
    if(response != null && response.id != null) {
        GameProfile result = new GameProfile(response.id, name);
        if(response.properties != null) {
            result.getProperties().addAll(response.properties);
        }

        return result;
    } else {
        return null;
    }
}
 
示例13
private void loginWithPassword() throws RequestException {
    if(this.username == null || this.username.isEmpty()) {
        throw new InvalidCredentialsException("Invalid username.");
    } else if(this.password == null || this.password.isEmpty()) {
        throw new InvalidCredentialsException("Invalid password.");
    } else {
        AuthenticationRequest request = new AuthenticationRequest(this.username, this.password, this.clientToken);
        AuthenticationResponse response = HTTP.makeRequest(this.proxy, AUTHENTICATE_URL, request, AuthenticationResponse.class);
        if(response.clientToken.equals(this.clientToken)) {
            if(response.user != null && response.user.id != null) {
                this.id = response.user.id;
            } else {
                this.id = this.username;
            }

            this.loggedIn = true;
            this.accessToken = response.accessToken;
            this.profiles = response.availableProfiles != null ? Arrays.asList(response.availableProfiles) : Collections.<GameProfile>emptyList();
            this.selectedProfile = response.selectedProfile;
            this.properties.clear();
            if(response.user != null && response.user.properties != null) {
                this.properties.addAll(response.user.properties);
            }
        } else {
            throw new RequestException("Server requested we change our client token. Don't know how to handle this!");
        }
    }
}
 
示例14
private void loginWithToken() throws RequestException {
    if(this.id == null || this.id.isEmpty()) {
        if(this.username == null || this.username.isEmpty()) {
            throw new InvalidCredentialsException("Invalid uuid and username.");
        }

        this.id = this.username;
    }

    if(this.accessToken == null || this.accessToken.equals("")) {
        throw new InvalidCredentialsException("Invalid access token.");
    } else {
        RefreshRequest request = new RefreshRequest(this.clientToken, this.accessToken, null);
        RefreshResponse response = HTTP.makeRequest(this.proxy, REFRESH_URL, request, RefreshResponse.class);
        if(response.clientToken.equals(this.clientToken)) {
            if(response.user != null && response.user.id != null) {
                this.id = response.user.id;
            } else {
                this.id = this.username;
            }

            this.loggedIn = true;
            this.accessToken = response.accessToken;
            this.profiles = response.availableProfiles != null ? Arrays.asList(response.availableProfiles) : Collections.<GameProfile>emptyList();
            this.selectedProfile = response.selectedProfile;
            this.properties.clear();
            if(response.user != null && response.user.properties != null) {
                this.properties.addAll(response.user.properties);
            }
        } else {
            throw new RequestException("Server requested we change our client token. Don't know how to handle this!");
        }
    }
}
 
示例15
private void processDelivery(Delivery delivery) throws Exception {
	BasicProperties props = delivery.getProperties();
	BasicProperties replyProps = new BasicProperties.Builder().correlationId(props.getCorrelationId()).build();
	DataInputStream data = new DataInputStream(new InflaterInputStream(new ByteArrayInputStream(delivery.getBody())));
	RenderMode mode = RenderMode.values()[data.readUnsignedByte()];
	int width = data.readUnsignedShort();
	int height = data.readUnsignedShort();
	GameProfile profile = Profiles.readGameProfile(data);
	Map<String, String[]> params = Maps.newHashMap();
	int len = data.readUnsignedShort();
	for (int i = 0; i < len; i++) {
		String key = data.readUTF();
		String[] val = new String[data.readUnsignedByte()];
		for (int v = 0; v < val.length; v++) {
			val[v] = data.readUTF();
		}
		params.put(key, val);
	}
	byte[] skinData = new byte[data.readInt()];
	data.readFully(skinData);
	BufferedImage skin = new PngImage().read(new ByteArrayInputStream(skinData), false);
	Visage.log.info("Received a job to render a "+width+"x"+height+" "+mode.name().toLowerCase()+" for "+(profile == null ? "null" : profile.getName()));
	
	RenderConfiguration conf = new RenderConfiguration(Type.fromMode(mode), Profiles.isSlim(profile), mode.isTall(), Profiles.isFlipped(profile));
	
	glClearColor(0, 0, 0, 0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	byte[] pngBys = draw(conf, width, height, profile, skin, params);
	if (Visage.trace) Visage.log.finest("Got png bytes");
	parent.channel.basicPublish("", props.getReplyTo(), replyProps, buildResponse(0, pngBys));
	if (Visage.trace) Visage.log.finest("Published response");
	parent.channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
	if (Visage.trace) Visage.log.finest("Ack'd message");
}
 
示例16
public static boolean isSlim(GameProfile profile) throws IOException {
	if (profile.getTextures().containsKey(TextureType.SKIN)) {
		Texture t = profile.getTexture(TextureType.SKIN);
		return t.getModel() == TextureModel.SLIM;
	}
	return UUIDs.isAlex(profile.getId());
}
 
示例17
/**
 * Gets the profile of the given user if they are currently logged in to the given server.
 *
 * @param name     Name of the user to get the profile of.
 * @param serverId ID of the server to check if they're logged in to.
 * @return The profile of the given user, or null if they are not logged in to the given server.
 * @throws RequestException If an error occurs while making the request.
 */
public GameProfile getProfileByServer(String name, String serverId) throws RequestException {
    HasJoinedResponse response = HTTP.makeRequest(this.getProxy(), this.getEndpointUri(HAS_JOINED_ENDPOINT, "username=" + name + "&serverId=" + serverId), null, HasJoinedResponse.class);
    if(response != null && response.id != null) {
        GameProfile result = new GameProfile(response.id, name);
        result.setProperties(response.properties);
        return result;
    } else {
        return null;
    }
}
 
示例18
public ProtocolWrapper(GameProfile profile, String accessToken) {
    super(profile, accessToken);
}
 
示例19
public ProtocolWrapper(GameProfile profile, String accessToken) {
    super(profile, accessToken);
}
 
示例20
public GameProfile getGameProfile() {
    return account.getProfile();
}
 
示例21
protected RefreshRequest(String clientToken, String accessToken, GameProfile selectedProfile) {
    this.clientToken = clientToken;
    this.accessToken = accessToken;
    this.selectedProfile = selectedProfile;
    this.requestUser = true;
}
 
示例22
public RenderResponse renderRpc(RenderMode mode, int width, int height, GameProfile profile, byte[] skin, Map<String, String[]> switches) throws RenderFailedException, NoRenderersAvailableException {
	if (mode == RenderMode.SKIN) return null;
	try {
		byte[] response = null;
		String corrId = UUID.randomUUID().toString();
		BasicProperties props = new BasicProperties.Builder().correlationId(corrId).replyTo(replyQueue).build();
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		DeflaterOutputStream defos = new DeflaterOutputStream(baos);
		DataOutputStream dos = new DataOutputStream(defos);
		dos.writeByte(mode.ordinal());
		dos.writeShort(width);
		dos.writeShort(height);
		Profiles.writeGameProfile(dos, profile);
		dos.writeShort(switches.size());
		for (Entry<String, String[]> en : switches.entrySet()) {
			dos.writeUTF(en.getKey());
			dos.writeByte(en.getValue().length);
			for (String s : en.getValue()) {
				dos.writeUTF(s);
			}
		}
		dos.writeInt(skin.length);
		dos.write(skin);
		dos.flush();
		defos.finish();
		channel.basicPublish("", config.getString("rabbitmq.queue"), props, baos.toByteArray());
		if (Visage.debug) Visage.log.finer("Requested a "+width+"x"+height+" "+mode.name().toLowerCase()+" render for "+(profile == null ? "null" : profile.getName()));
		final Object waiter = new Object();
		queuedJobs.put(corrId, new Runnable() {
			@Override
			public void run() {
				if (Visage.debug) Visage.log.finer("Got response");
				synchronized (waiter) {
					waiter.notify();
				}
			}
		});
		long start = System.currentTimeMillis();
		long timeout = config.getDuration("render.timeout", TimeUnit.MILLISECONDS);
		synchronized (waiter) {
			while (queuedJobs.containsKey(corrId) && (System.currentTimeMillis()-start) < timeout) {
				if (Visage.trace) Visage.log.finest("Waiting...");
				waiter.wait(timeout);
			}
		}
		if (queuedJobs.containsKey(corrId)) {
			if (Visage.trace) Visage.log.finest("Queue still contains this request, assuming timeout");
			queuedJobs.remove(corrId);
			throw new RenderFailedException("Request timed out");
		}
		response = responses.get(corrId);
		responses.remove(corrId);
		if (response == null)
			throw new RenderFailedException("Response was null");
		ByteArrayInputStream bais = new ByteArrayInputStream(response);
		String renderer = new DataInputStream(bais).readUTF();
		int type = bais.read();
		byte[] payload = ByteStreams.toByteArray(bais);
		if (type == 0) {
			if (Visage.trace) Visage.log.finest("Got type 0, success");
			RenderResponse resp = new RenderResponse();
			resp.renderer = renderer;
			resp.png = payload;
			Visage.log.info("Receieved a "+mode.name().toLowerCase()+" render from "+resp.renderer);
			return resp;
		} else if (type == 1) {
			if (Visage.trace) Visage.log.finest("Got type 1, failure");
			ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(payload));
			Throwable t = (Throwable)ois.readObject();
			throw new RenderFailedException("Renderer reported error", t);
		} else
			throw new RenderFailedException("Malformed response from '"+renderer+"' - unknown response id "+type);
	} catch (Exception e) {
		if (e instanceof RenderFailedException)
			throw (RenderFailedException) e;
		throw new RenderFailedException("Unexpected error", e);
	}
}
 
示例23
public static boolean isFlipped(GameProfile profile) {
	return "Dinnerbone".equals(profile.getName()) ||
			"Grumm".equals(profile.getName());
}
 
示例24
protected RefreshRequest(String clientToken, String accessToken, GameProfile selectedProfile) {
    this.clientToken = clientToken;
    this.accessToken = accessToken;
    this.selectedProfile = selectedProfile;
    this.requestUser = true;
}
 
示例25
/**
 * Joins a server.
 *
 * @param profile             Profile to join the server with.
 * @param authenticationToken Authentication token to join the server with.
 * @param serverId            ID of the server to join.
 * @throws RequestException If an error occurs while making the request.
 */
public void joinServer(GameProfile profile, String authenticationToken, String serverId) throws RequestException {
    JoinServerRequest request = new JoinServerRequest(authenticationToken, profile.getId(), serverId);
    HTTP.makeRequest(this.proxy, BASE_URL+"/join", request, null);
}
 
示例26
/**
 * Called when a profile lookup request succeeds.
 *
 * @param profile Profile resulting from the request.
 */
public void onProfileLookupSucceeded(GameProfile profile);
 
示例27
/**
 * Called when a profile lookup request fails.
 *
 * @param profile Profile that failed to be located.
 * @param e       Exception causing the failure.
 */
public void onProfileLookupFailed(GameProfile profile, Exception e);
 
示例28
/**
 * Gets the properties of the user logged in with the service.
 *
 * @return The user's properties.
 */
public List<GameProfile.Property> getProperties() {
    return this.isLoggedIn() ? new ArrayList<GameProfile.Property>(this.properties) : Collections.<GameProfile.Property>emptyList();
}
 
示例29
/**
 * Gets the available profiles of the user logged in with the service.
 *
 * @return The user's available profiles.
 */
public List<GameProfile> getAvailableProfiles() {
    return this.profiles;
}
 
示例30
/**
 * Gets the selected profile of the user logged in with the service.
 *
 * @return The user's selected profile.
 */
public GameProfile getSelectedProfile() {
    return this.selectedProfile;
}