Skip to content

Commit

Permalink
Cleanup old code and remove improved login for now
Browse files Browse the repository at this point in the history
  • Loading branch information
bundabrg committed Jan 22, 2021
1 parent 450d2ec commit 0fedbb6
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ public Entity(long entityId, long geyserId, EntityType entityType, Vector3f posi
}

public void spawnEntity(GeyserSession session) {
if (!session.getUpstream().isInitialized()) {
return;
}

AddEntityPacket addEntityPacket = new AddEntityPacket();
addEntityPacket.setIdentifier(entityType.getIdentifier());
addEntityPacket.setRuntimeEntityId(geyserId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public class PlayerEntity extends LivingEntity {
private GameProfile profile;
private UUID uuid;
private String username;
private String displayName;
private boolean playerList = true; // Player is in the player list

/**
Expand All @@ -87,9 +86,6 @@ public PlayerEntity(GameProfile gameProfile, long entityId, long geyserId, Vecto

@Override
public void spawnEntity(GeyserSession session) {
if (!session.getUpstream().isInitialized())
return;

AddPlayerPacket addPlayerPacket = new AddPlayerPacket();
addPlayerPacket.setUuid(uuid);
addPlayerPacket.setUsername(username);
Expand Down Expand Up @@ -121,7 +117,7 @@ public void sendPlayer(GeyserSession session) {
if (session.getEntityCache().getPlayerEntity(uuid) == null)
return;

if (session.getEntityCache().getEntityByGeyserId(geyserId) == null) {
if (session.getUpstream().isInitialized() && session.getEntityCache().getEntityByGeyserId(geyserId) == null) {
session.getEntityCache().spawnEntity(this);
} else {
spawnEntity(session);
Expand Down Expand Up @@ -341,12 +337,4 @@ public void updateBedrockAttributes(GeyserSession session) { // TODO: Don't use
updateAttributesPacket.setAttributes(attributes);
session.sendUpstreamPacket(updateAttributesPacket);
}

/**
* Returns the DisplayName if set, otherwise the Username
* @return Name of player entity
*/
public String getName() {
return displayName == null ? username : displayName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,6 @@ public boolean handle(SetLocalPlayerAsInitializedPacket packet) {
LanguageUtils.loadGeyserLocale(session.getLocale());

if (!session.isLoggedIn() && !session.isLoggingIn() && session.getConnector().getAuthType() == AuthType.ONLINE) {
PlayStatusPacket playStatusPacket = new PlayStatusPacket();
playStatusPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
session.sendUpstreamPacket(playStatusPacket);

// TODO it is safer to key authentication on something that won't change (UUID, not username)
if (!couldLoginUserByName(session.getAuthData().getName())) {
LoginEncryptionUtils.showLoginWindow(session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,8 @@ public GeyserSession(GeyserConnector connector, BedrockServerSession bedrockServ
}

public void connect(RemoteServer remoteServer) {
this.remoteServer = remoteServer;

PlayerListPacket playerListPacket = new PlayerListPacket();
playerListPacket.setAction(PlayerListPacket.Action.ADD);
playerListPacket.getEntries().add(SkinManager.buildCachedEntry(this, playerEntity));
sendUpstreamPacket(playerListPacket);

startGame();
this.remoteServer = remoteServer;

// Set the hardcoded shield ID to the ID we just defined in StartGamePacket
upstream.getSession().getHardcodedBlockingId().set(ItemRegistry.SHIELD.getBedrockId());
Expand All @@ -424,6 +418,10 @@ public void connect(RemoteServer remoteServer) {
creativePacket.setContents(ItemRegistry.CREATIVE_ITEMS);
sendUpstreamPacket(creativePacket);

PlayStatusPacket playStatusPacket = new PlayStatusPacket();
playStatusPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
sendUpstreamPacket(playStatusPacket);

UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();
attributesPacket.setRuntimeEntityId(getPlayerEntity().getGeyserId());
List<AttributeData> attributes = new ArrayList<>();
Expand All @@ -443,11 +441,6 @@ public void connect(RemoteServer remoteServer) {
// Ensure client doesn't try and do anything funky; the server handles this for us
gamerulePacket.getGameRules().add(new GameRuleData<>("spawnradius", 0));
sendUpstreamPacket(gamerulePacket);

// Spawn the player
PlayStatusPacket playStatusPacket = new PlayStatusPacket();
playStatusPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
sendUpstreamPacket(playStatusPacket);
}

public void login() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ public boolean cacheEntity(Entity entity) {
if (!entityIdTranslations.containsKey(entity.getEntityId())) {
entityIdTranslations.put(entity.getEntityId(), entity.getGeyserId());
entities.put(entity.getGeyserId(), entity);

if (session.getUpstream().isInitialized())
return true;
return true;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ public void translate(ServerJoinGamePacket packet, GeyserSession session) {
session.sendUpstreamPacket(playerGameTypePacket);
session.setGameMode(packet.getGameMode());

// SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
// entityDataPacket.setRuntimeEntityId(entity.getGeyserId());
// entityDataPacket.getMetadata().putAll(entity.getMetadata());
// session.sendUpstreamPacket(entityDataPacket);
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
entityDataPacket.setRuntimeEntityId(entity.getGeyserId());
entityDataPacket.getMetadata().putAll(entity.getMetadata());
session.sendUpstreamPacket(entityDataPacket);

// Send if client should show respawn screen
GameRulesChangedPacket gamerulePacket = new GameRulesChangedPacket();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
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.utils.LocaleUtils;
import org.geysermc.connector.skin.SkinManager;

@Translator(packet = ServerPlayerListEntryPacket.class)
Expand Down Expand Up @@ -86,7 +85,7 @@ public void translate(ServerPlayerListEntryPacket packet, GeyserSession session)
SkinManager.requestAndHandleSkinAndCape(playerEntity, session, skinAndCape ->
GeyserConnector.getInstance().getLogger().debug("Loaded Local Bedrock Java Skin Data for " + session.getClientData().getUsername()));
} else {
playerEntity.setDisplayName(entry.getDisplayName() != null ? LocaleUtils.getLocaleString(entry.getDisplayName().toString(), session.getClientData().getLanguageCode()) : null);
playerEntity.setValid(true);
PlayerListPacket.Entry playerListEntry = SkinManager.buildCachedEntry(session, playerEntity);

translate.getEntries().add(playerListEntry);
Expand All @@ -110,8 +109,8 @@ public void translate(ServerPlayerListEntryPacket packet, GeyserSession session)
}
}

// if (!translate.getEntries().isEmpty() && (packet.getAction() == PlayerListEntryAction.REMOVE_PLAYER || session.getUpstream().isInitialized())) {
if (!translate.getEntries().isEmpty() && (packet.getAction() == PlayerListEntryAction.REMOVE_PLAYER || session.getUpstream().isInitialized())) {
session.sendUpstreamPacket(translate);
// }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket;
import com.nukkitx.protocol.bedrock.packet.RespawnPacket;
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
import org.geysermc.connector.entity.player.PlayerEntity;
Expand All @@ -47,13 +46,6 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator<Serve

@Override
public void translate(ServerPlayerPositionRotationPacket packet, GeyserSession session) {
if (!session.getUpstream().isInitialized()) {
// Spawn the player
PlayStatusPacket playStatusPacket = new PlayStatusPacket();
playStatusPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
session.sendUpstreamPacket(playStatusPacket);
}

if (!session.isLoggedIn())
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.data.inventory.ContainerType;
import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public static void requestAndHandleSkinAndCape(PlayerEntity entity, GeyserSessio
PlayerListPacket.Entry updatedEntry = buildEntryManually(
session,
entity.getUuid(),
entity.getName(),
entity.getUsername(),
entity.getGeyserId(),
skin.getTextureUrl(),
skin.getSkinData(),
Expand Down Expand Up @@ -291,7 +291,7 @@ private static GameProfileData loadBedrockOrOfflineSkin(GameProfile profile) {
if ("steve".equals(skinUrl) || "alex".equals(skinUrl)) {
GeyserSession session = GeyserConnector.getInstance().getPlayerByUuid(profile.getId());

if (session.getPlayerEntity().getUuid() != null && session != null) {
if (session != null) {
skinUrl = session.getClientData().getSkinId();
capeUrl = session.getClientData().getCapeId();
}
Expand Down

0 comments on commit 0fedbb6

Please sign in to comment.