Skip to content

Commit

Permalink
login Success
Browse files Browse the repository at this point in the history
  • Loading branch information
SenseiTarzan committed Aug 22, 2024
1 parent 8e60043 commit d6aca04
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 68 deletions.
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ dependencies {
}
```

| Milestone | Status |
|--------------------------------------------|--------|
| **⚒️ Construction of the server tree** ||
| **👓 Visible server** ||
| **🛜 Join server** | |
| **🎍 World loader** | 🚧 |
| **🔌Plugin loader** ||
| **⌨️ Command System** | 🚧 |
| **🔐 Permission System** | 🚧 |
| **🎈 Event System** ||
| **🖼 Scoreboard API** | 🚧 |
| **🖼 Form API** ||
| **👤 Player & Actor API** ||
| **🔩 Item API** | 🚧 |
| **🧱 Block API** | 🚧 |
| **📦 Inventory API** | 🚧 |
| **🔬 Beta Testing & Community Feedback** | 🚧 |
| **🚀 Official Release & Support** | 🚧 |
| Milestone | Status |
|------------------------------------------|--------|
| **⚒️ Construction of the server tree** | |
| **👓 Visible server** | |
| **🛜 Join server** | |
| **🎍 World loader** | 🚧 |
| **🔌Plugin loader** | |
| **⌨️ Command System** | 🚧 |
| **🔐 Permission System** | 🚧 |
| **🎈 Event System** | |
| **🖼 Scoreboard API** | 🚧 |
| **🖼 Form API** | |
| **👤 Player & Actor API** | |
| **🔩 Item API** | 🚧 |
| **🧱 Block API** | 🚧 |
| **📦 Inventory API** | 🚧 |
| **🔬 Beta Testing & Community Feedback** | 🚧 |
| **🚀 Official Release & Support** | 🚧 |

Here's a legend to guide you:
- ✅: Task is completed. Woohoo! 🎉
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
import org.cloudburstmc.protocol.bedrock.packet.*;
import org.cloudburstmc.protocol.common.PacketSignal;
import org.cloudburstmc.protocol.common.util.QuadConsumer;
import org.jose4j.jws.JsonWebSignature;
import org.sculk.Player;
import org.sculk.Server;
import org.sculk.event.player.PlayerAsyncPreLoginEvent;
import org.sculk.event.player.PlayerPreLoginEvent;
import org.sculk.network.BedrockInterface;
import org.sculk.network.session.SculkServerSession;
import org.sculk.player.PlayerLoginData;
import org.sculk.player.client.ClientChainData;
import org.sculk.scheduler.AsyncTask;

import java.util.List;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -98,9 +94,6 @@ public void onCompletion(Server server) {
} else if(loginData.isShouldLogin()) {
Exception error = null;
try {
PlayStatusPacket statusPacket = new PlayStatusPacket();
statusPacket.setStatus(PlayStatusPacket.Status.LOGIN_SUCCESS);
session.sendPacket(statusPacket);
for(Consumer<SculkServerSession> action : playerAsyncPreLoginEvent.getScheduledActions()) {
action.accept(LoginPacketHandler.this.session);
}
Expand Down
111 changes: 80 additions & 31 deletions src/main/java/org/sculk/network/handler/PreSpawnPacketHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.cloudburstmc.math.vector.Vector3i;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.protocol.bedrock.data.*;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket;
import org.cloudburstmc.protocol.bedrock.packet.StartGamePacket;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
import org.cloudburstmc.protocol.bedrock.packet.*;
import org.cloudburstmc.protocol.common.PacketSignal;
import org.cloudburstmc.protocol.common.util.OptionalBoolean;
import org.sculk.Player;
Expand Down Expand Up @@ -42,51 +42,100 @@ public PreSpawnPacketHandler(SculkServerSession session, Player player) {
@Override
public void setUp() {
StartGamePacket startGamePacket = new StartGamePacket();
startGamePacket.setUniqueEntityId(this.player.getUniqueId());
startGamePacket.setRuntimeEntityId(this.player.getRuntimeId());
startGamePacket.setPlayerGameType(GameType.CREATIVE);
startGamePacket.setPlayerPosition(Vector3f.from(0, 0, 0));
startGamePacket.setRotation(Vector2f.from(0, 0));
startGamePacket.setUniqueEntityId(0);
startGamePacket.setRuntimeEntityId(0);
startGamePacket.setPlayerGameType(GameType.DEFAULT);
startGamePacket.setPlayerPosition(Vector3f.from(0, 69, 0));
startGamePacket.setRotation(Vector2f.from(1, 1));

startGamePacket.setSeed(-1L);
startGamePacket.setDimensionId(0);
startGamePacket.setTrustingPlayers(false);
startGamePacket.setLevelGameType(GameType.CREATIVE);
startGamePacket.setDifficulty(0);
startGamePacket.setDefaultSpawn(Vector3i.from(0, 0, 0));
startGamePacket.setGeneratorId(1);
startGamePacket.setLevelGameType(GameType.SURVIVAL);
startGamePacket.setDifficulty(1);
startGamePacket.setDefaultSpawn(Vector3i.ZERO);
startGamePacket.setAchievementsDisabled(true);
startGamePacket.setDayCycleStopTime(0);
startGamePacket.setCurrentTick(-1);
startGamePacket.setEduEditionOffers(0);
startGamePacket.setEduFeaturesEnabled(false);
startGamePacket.setRainLevel(0);
startGamePacket.setLightningLevel(0);
startGamePacket.setCommandsEnabled(true);
startGamePacket.setMultiplayerGame(true);
startGamePacket.setBroadcastingToLan(true);
//NetworkUtils.gameRulesToNetwork(this.getLevel().getGameRules(), startGamePacket.getGamerules());
startGamePacket.setLevelId(""); // This is irrelevant since we have multiple levels
startGamePacket.setLevelName("world"); // We might as well use the MOTD instead of the default level name
startGamePacket.setGeneratorId(1); // 0 old, 1 infinite, 2 flat - Has no effect to my knowledge
startGamePacket.setItemDefinitions(List.of());
startGamePacket.setXblBroadcastMode(GamePublishSetting.PUBLIC);
startGamePacket.setPlatformBroadcastMode(GamePublishSetting.PUBLIC);
startGamePacket.setXblBroadcastMode(GamePublishSetting.PUBLIC);
startGamePacket.setCommandsEnabled(true);
startGamePacket.setTexturePacksRequired(false);
startGamePacket.setBonusChestEnabled(false);
startGamePacket.setStartingWithMap(false);
startGamePacket.setTrustingPlayers(true);
startGamePacket.setDefaultPlayerPermission(PlayerPermission.MEMBER);
startGamePacket.setServerChunkTickRange(4);
startGamePacket.setVanillaVersion("1.21.2"); // Temporary hack that allows player to join by disabling the new chunk columns introduced in update 1.18
startGamePacket.setPremiumWorldTemplateId("");
startGamePacket.setMultiplayerCorrelationId("");
startGamePacket.setInventoriesServerAuthoritative(true);
startGamePacket.setRewindHistorySize(0);
startGamePacket.setServerAuthoritativeBlockBreaking(false);
startGamePacket.setAuthoritativeMovementMode(AuthoritativeMovementMode.CLIENT);
startGamePacket.setServerEngine("Sculk");
startGamePacket.setPlayerPropertyData(NbtMap.EMPTY);
startGamePacket.setWorldTemplateId(new UUID(0, 0));
startGamePacket.setWorldEditor(false);
startGamePacket.setChatRestrictionLevel(ChatRestrictionLevel.NONE);
startGamePacket.setBehaviorPackLocked(false);
startGamePacket.setResourcePackLocked(false);
startGamePacket.setFromLockedWorldTemplate(false);
startGamePacket.setUsingMsaGamertagsOnly(false);
startGamePacket.setFromWorldTemplate(false);
startGamePacket.setWorldTemplateOptionLocked(false);
startGamePacket.setSpawnBiomeType(SpawnBiomeType.DEFAULT);
startGamePacket.setCustomBiomeName("");
startGamePacket.setEducationProductionId("");
startGamePacket.setForceExperimentalGameplay(OptionalBoolean.empty());

String serverName = session.getServer().getMotd();
startGamePacket.setLevelId(serverName);
startGamePacket.setLevelName(serverName);

startGamePacket.setPremiumWorldTemplateId("00000000-0000-0000-0000-000000000000");
// startGamePacket.setCurrentTick(0);
startGamePacket.setEnchantmentSeed(0);
startGamePacket.setMultiplayerCorrelationId("");

startGamePacket.getItemDefinitions().addAll(List.of());

// Needed for custom block mappings and custom skulls system
startGamePacket.getBlockProperties().addAll(List.of());

/* THANK GEYSER
// See https://learn.microsoft.com/en-us/minecraft/creator/documents/experimentalfeaturestoggle for info on each experiment
// data_driven_items (Holiday Creator Features) is needed for blocks and items
startGamePacket.getExperiments().add(new ExperimentData("data_driven_items", true));
// Needed for block properties for states
startGamePacket.getExperiments().add(new ExperimentData("upcoming_creator_features", true));
// Needed for certain molang queries used in blocks and items
startGamePacket.getExperiments().add(new ExperimentData("experimental_molang_features", true));
// Required for experimental 1.21 features
startGamePacket.getExperiments().add(new ExperimentData("updateAnnouncedLive2023", true));*/

startGamePacket.setVanillaVersion("*");
startGamePacket.setInventoriesServerAuthoritative(true);
startGamePacket.setServerEngine(""); // Do we want to fill this in?

startGamePacket.setPlayerPropertyData(NbtMap.EMPTY);
startGamePacket.setWorldTemplateId(UUID.randomUUID());

startGamePacket.setChatRestrictionLevel(ChatRestrictionLevel.NONE);

startGamePacket.setAuthoritativeMovementMode(AuthoritativeMovementMode.SERVER);
startGamePacket.setRewindHistorySize(0);
startGamePacket.setServerAuthoritativeBlockBreaking(false);

startGamePacket.setServerId("");
startGamePacket.setWorldId("");
startGamePacket.setScenarioId("");

session.sendPacket(startGamePacket);
session.sendPacket(new CreativeContentPacket());
session.sendPacket(new BiomeDefinitionListPacket());
session.sendPacket(new AvailableEntityIdentifiersPacket());
SetEntityDataPacket setEntityDataPacket = new SetEntityDataPacket();
setEntityDataPacket.setRuntimeEntityId(0);
setEntityDataPacket.getMetadata().put(EntityDataTypes.PLAYER_FLAGS, (byte) 2);
session.sendPacket(setEntityDataPacket);

SetTimePacket setTimePacket = new SetTimePacket();
setTimePacket.setTime(0);
session.sendPacket(setTimePacket);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
import org.cloudburstmc.protocol.bedrock.packet.ResourcePackStackPacket;
import org.cloudburstmc.protocol.bedrock.packet.ResourcePacksInfoPacket;
import org.cloudburstmc.protocol.common.PacketSignal;
import org.sculk.Player;
import org.sculk.network.session.SculkServerSession;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;

/*
Expand Down Expand Up @@ -42,8 +39,6 @@ public void setUp() {
}




public PacketSignal handle(ResourcePackClientResponsePacket packet) {
switch (packet.getStatus()) {
case REFUSED -> {
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/org/sculk/network/session/SculkServerSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
import org.cloudburstmc.protocol.bedrock.BedrockServerSession;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacketHandler;
import org.cloudburstmc.protocol.bedrock.packet.PlayStatusPacket;
import org.cloudburstmc.protocol.common.util.QuadConsumer;
import org.sculk.Player;
import org.sculk.Server;
import org.sculk.network.BedrockInterface;
import org.sculk.network.handler.*;
import org.sculk.player.client.ClientChainData;

import javax.annotation.Nullable;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.Objects;

/*
* ____ _ _
Expand Down Expand Up @@ -67,7 +65,7 @@ private void onSessionStartSuccess(Object e) {

private void setAuthenticationStatus(boolean authenticated, boolean authRequired, Exception error, String clientPubKey) {
if(error == null){
if(authenticated && playerInfo.getXUID() == null){
if(authenticated && Objects.requireNonNull(playerInfo).getXUID() == null){
error = new Exception("Expected XUID but none found");
}else if(clientPubKey == null){
error = new Exception("Missing client public key"); //failsafe
Expand Down Expand Up @@ -96,6 +94,7 @@ private void onServerLoginSuccess() {

private void createPlayer(Object e) {
this.server.createPlayer(this, this.playerInfo, false).thenAccept(this::onPlayerCreated).exceptionally(ex -> {
server.getLogger().throwing(ex);
this.disconnect("Failed to create player.");
return null;
});
Expand All @@ -112,19 +111,17 @@ private void notifyTerrainReady(Object e) {
PlayStatusPacket packet = new PlayStatusPacket();
packet.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
this.sendPacket(packet);
System.out.println(packet);
this.setPacketHandler(new SpawnResponsePacketHandler(this, this::onClientSpawnResponse));
}

private void onClientSpawnResponse(Object e) {
System.out.println("vvvvvvvvvvvvvvvv");
this.setPacketHandler(new InGamePacketHandler(this.getPlayer(),this));
}

@Override
public void setPacketHandler(@NonNull BedrockPacketHandler packetHandler) {
super.setPacketHandler(packetHandler);
if (packetHandler instanceof SculkPacketHandler _sculkHandler)
_sculkHandler.setUp();
super.setPacketHandler(packetHandler);
}
}

0 comments on commit d6aca04

Please sign in to comment.