Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/GeyserMC/Geyser into serv…
Browse files Browse the repository at this point in the history
…er-inventory
  • Loading branch information
Camotoy committed Jan 22, 2021
2 parents 787e6fe + 5a8604f commit 3dc5890
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 49 deletions.
2 changes: 1 addition & 1 deletion bootstrap/bungeecord/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.4-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ public PlayerEntity getPlayerEntity(UUID uuid) {
return playerEntities.get(uuid);
}

public void removePlayerEntity(UUID uuid) {
playerEntities.remove(uuid);
public PlayerEntity removePlayerEntity(UUID uuid) {
return playerEntities.remove(uuid);
}

public void addBossBar(UUID uuid, BossBar bossBar) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@

package org.geysermc.connector.network.translators.java.entity.player;

import com.github.steveice10.mc.protocol.data.game.PlayerListEntry;
import com.github.steveice10.mc.protocol.data.game.PlayerListEntryAction;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerPlayerListEntryPacket;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.PlayerListPacket;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.entity.player.PlayerEntity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.skin.SkinManager;

import com.github.steveice10.mc.protocol.data.game.PlayerListEntry;
import com.github.steveice10.mc.protocol.data.game.PlayerListEntryAction;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerPlayerListEntryPacket;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.PlayerListPacket;

@Translator(packet = ServerPlayerListEntryPacket.class)
public class JavaPlayerListEntryTranslator extends PacketTranslator<ServerPlayerListEntryPacket> {
@Override
Expand All @@ -57,9 +56,6 @@ public void translate(ServerPlayerListEntryPacket packet, GeyserSession session)
if (self) {
// Entity is ourself
playerEntity = session.getPlayerEntity();
//TODO: playerEntity.setProfile(entry.getProfile()); seems to help with online mode skins but needs more testing to ensure Floodgate skins aren't overwritten
SkinManager.requestAndHandleSkinAndCape(playerEntity, session, skinAndCape ->
GeyserConnector.getInstance().getLogger().debug("Loaded Local Bedrock Java Skin Data"));
} else {
playerEntity = session.getEntityCache().getPlayerEntity(entry.getProfile().getId());
}
Expand All @@ -74,27 +70,35 @@ public void translate(ServerPlayerListEntryPacket packet, GeyserSession session)
Vector3f.ZERO,
Vector3f.ZERO
);
}

session.getEntityCache().addPlayerEntity(playerEntity);
session.getEntityCache().addPlayerEntity(playerEntity);
} else {
playerEntity.setProfile(entry.getProfile());
}

playerEntity.setProfile(entry.getProfile());
playerEntity.setPlayerList(true);
playerEntity.setValid(true);

PlayerListPacket.Entry playerListEntry = SkinManager.buildCachedEntry(session, playerEntity);
// We'll send our own PlayerListEntry in requestAndHandleSkinAndCape
// But we need to send other player's entries so they show up in the player list
// without processing their skin information - that'll be processed when they spawn in
if (self) {
SkinManager.requestAndHandleSkinAndCape(playerEntity, session, skinAndCape ->
GeyserConnector.getInstance().getLogger().debug("Loaded Local Bedrock Java Skin Data for " + session.getClientData().getUsername()));
} else {
playerEntity.setValid(true);
PlayerListPacket.Entry playerListEntry = SkinManager.buildCachedEntry(session, playerEntity);

translate.getEntries().add(playerListEntry);
translate.getEntries().add(playerListEntry);
}
break;
case REMOVE_PLAYER:
PlayerEntity entity = session.getEntityCache().getPlayerEntity(entry.getProfile().getId());
// As the player entity is no longer present, we can remove the entry
PlayerEntity entity = session.getEntityCache().removePlayerEntity(entry.getProfile().getId());
if (entity != null) {
// Just remove the entity's player list status
// Don't despawn the entity - the Java server will also take care of that.
entity.setPlayerList(false);
}
// As the player entity is no longer present, we can remove the entry
session.getEntityCache().removePlayerEntity(entry.getProfile().getId());
if (entity == session.getPlayerEntity()) {
// If removing ourself we use our AuthData UUID
translate.getEntries().add(new PlayerListPacket.Entry(session.getAuthData().getUUID()));
Expand All @@ -105,7 +109,7 @@ public void translate(ServerPlayerListEntryPacket packet, GeyserSession session)
}
}

if (packet.getAction() == PlayerListEntryAction.REMOVE_PLAYER || session.getUpstream().isInitialized()) {
if (!translate.getEntries().isEmpty() && (packet.getAction() == PlayerListEntryAction.REMOVE_PLAYER || session.getUpstream().isInitialized())) {
session.sendUpstreamPacket(translate);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.common.AuthType;
import org.geysermc.connector.entity.player.PlayerEntity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.session.auth.BedrockClientData;
Expand All @@ -47,6 +46,9 @@

public class SkinManager {

/**
* Builds a Bedrock player list entry from our existing, cached Bedrock skin information
*/
public static PlayerListPacket.Entry buildCachedEntry(GeyserSession session, PlayerEntity playerEntity) {
GameProfileData data = GameProfileData.from(playerEntity.getProfile());
SkinProvider.Cape cape = SkinProvider.getCachedCape(data.getCapeUrl());
Expand All @@ -70,27 +72,31 @@ public static PlayerListPacket.Entry buildCachedEntry(GeyserSession session, Pla
);
}

/**
* With all the information needed, build a Bedrock player entry with translated skin information.
*/
public static PlayerListPacket.Entry buildEntryManually(GeyserSession session, UUID uuid, String username, long geyserId,
String skinId, byte[] skinData,
String capeId, byte[] capeData,
SkinProvider.SkinGeometry geometry) {
SerializedSkin serializedSkin = SerializedSkin.of(
skinId, geometry.getGeometryName(), ImageData.of(skinData), Collections.emptyList(),
ImageData.of(capeData), geometry.getGeometryData(), "", true, false, !capeId.equals(SkinProvider.EMPTY_CAPE.getCapeId()), capeId, skinId
ImageData.of(capeData), geometry.getGeometryData(), "", true, false,
!capeId.equals(SkinProvider.EMPTY_CAPE.getCapeId()), capeId, skinId
);

// This attempts to find the xuid of the player so profile images show up for xbox accounts
// This attempts to find the XUID of the player so profile images show up for Xbox accounts
String xuid = "";
GeyserSession player = GeyserConnector.getInstance().getPlayerByUuid(uuid);
GeyserSession playerSession = GeyserConnector.getInstance().getPlayerByUuid(uuid);

if (player != null) {
xuid = player.getAuthData().getXboxUUID();
if (playerSession != null) {
xuid = playerSession.getAuthData().getXboxUUID();
}

PlayerListPacket.Entry entry;

// If we are building a PlayerListEntry for our own session we use our AuthData UUID instead of the Java UUID
// as bedrock expects to get back its own provided uuid
// as Bedrock expects to get back its own provided UUID
if (session.getPlayerEntity().getUuid().equals(uuid)) {
entry = new PlayerListPacket.Entry(session.getAuthData().getUUID());
} else {
Expand Down Expand Up @@ -134,12 +140,13 @@ public static void requestAndHandleSkinAndCape(PlayerEntity entity, GeyserSessio
geometry, entity.getUuid()
), geometry, 3);

boolean isDeadmau5 = "deadmau5".equals(entity.getUsername());
// Not a bedrock player check for ears
if (geometry.isFailed() && SkinProvider.ALLOW_THIRD_PARTY_EARS) {
if (geometry.isFailed() && (SkinProvider.ALLOW_THIRD_PARTY_EARS || isDeadmau5)) {
boolean isEars;

// Its deadmau5, gotta support his skin :)
if (entity.getUuid().toString().equals("1e18d5ff-643d-45c8-b509-43b8461d8614")) {
if (isDeadmau5) {
isEars = true;
} else {
// Get the ears texture for the player
Expand Down Expand Up @@ -185,7 +192,6 @@ public static void requestAndHandleSkinAndCape(PlayerEntity entity, GeyserSessio
playerRemovePacket.setAction(PlayerListPacket.Action.REMOVE);
playerRemovePacket.getEntries().add(updatedEntry);
session.sendUpstreamPacket(playerRemovePacket);

}
}
} catch (Exception e) {
Expand Down Expand Up @@ -238,20 +244,20 @@ public static class GameProfileData {
* @return The built GameProfileData
*/
public static GameProfileData from(GameProfile profile) {
// Fallback to the offline mode of working it out
boolean isAlex = (Math.abs(profile.getId().hashCode() % 2) == 1);

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

// TODO: Remove try/catch here
if (skinProperty == null) {
// Likely offline mode
return loadBedrockOrOfflineSkin(profile);
}
JsonNode skinObject = GeyserConnector.JSON_MAPPER.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().replace("http://", "https://");

isAlex = skinTexture.has("metadata");
boolean isAlex = skinTexture.has("metadata");

String capeUrl = null;
if (textures.has("CAPE")) {
Expand All @@ -261,20 +267,30 @@ public static GameProfileData from(GameProfile profile) {

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
String skinUrl = isAlex ? SkinProvider.EMPTY_SKIN_ALEX.getTextureUrl() : SkinProvider.EMPTY_SKIN.getTextureUrl();
if ("steve".equals(skinUrl) || "alex".equals(skinUrl)) {
GeyserSession session = GeyserConnector.getInstance().getPlayerByUuid(profile.getId());
GeyserConnector.getInstance().getLogger().debug("Something went wrong while processing skin for " + profile.getName() + ": " + exception.getMessage());
return loadBedrockOrOfflineSkin(profile);
}
}

if (session != null) {
skinUrl = session.getClientData().getSkinId();
}
/**
* @return default skin with default cape when texture data is invalid, or the Bedrock player's skin if this
* is a Bedrock player.
*/
private static GameProfileData loadBedrockOrOfflineSkin(GameProfile profile) {
// Fallback to the offline mode of working it out
boolean isAlex = (Math.abs(profile.getId().hashCode() % 2) == 1);

String skinUrl = isAlex ? SkinProvider.EMPTY_SKIN_ALEX.getTextureUrl() : SkinProvider.EMPTY_SKIN.getTextureUrl();
String capeUrl = SkinProvider.EMPTY_CAPE.getTextureUrl();
if ("steve".equals(skinUrl) || "alex".equals(skinUrl)) {
GeyserSession session = GeyserConnector.getInstance().getPlayerByUuid(profile.getId());

if (session != null) {
skinUrl = session.getClientData().getSkinId();
capeUrl = session.getClientData().getCapeId();
}
return new GameProfileData(skinUrl, SkinProvider.EMPTY_CAPE.getTextureUrl(), isAlex);
}
return new GameProfileData(skinUrl, capeUrl, isAlex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public static void showMicrosoftAuthenticationWindow(GeyserSession session) {
*/
public static void showMicrosoftCodeWindow(GeyserSession session, MsaAuthenticationService.MsCodeResponse response) {
ModalFormWindow msaCodeWindow = new ModalFormWindow("%xbox.signin", "%xbox.signin.website\n%xbox.signin.url\n%xbox.signin.enterCode\n" +
response.user_code, "Done", "%menu.disconnect");
response.user_code, "%gui.done", "%menu.disconnect");
session.sendForm(msaCodeWindow, LoginEncryptionUtils.AUTH_MSA_CODE_FORM_ID);
}

Expand Down

0 comments on commit 3dc5890

Please sign in to comment.