From 183159c85d6d71974805854bcefae662926c9694 Mon Sep 17 00:00:00 2001 From: mworzala Date: Sat, 7 Oct 2023 07:39:24 -0400 Subject: [PATCH] finish configuration phase, ish (cherry picked from commit 13edf5f863119da71cf3f07f6e71ccf5d5ec7bfd) --- .../src/main/java/net/minestom/demo/Main.java | 2 + .../java/net/minestom/demo/PlayerInit.java | 2 +- .../net/minestom/server/MinecraftServer.java | 2 +- .../net/minestom/server/entity/Player.java | 41 ++---------- .../listener/preplay/LoginListener.java | 54 ++++++++++++++-- .../server/network/NetworkBufferTypes.java | 3 +- .../server/network/PacketProcessor.java | 1 + .../server/common/ResourcePackSendPacket.java | 9 ++- .../FinishConfigurationPacket.java | 3 +- .../configuration/RegistryDataPacket.java | 27 ++++++++ .../UpdateEnabledFeaturesPacket.java | 30 +++++++++ .../server/play/ChangeGameStatePacket.java | 3 +- .../server/play/ChunkBatchFinishedPacket.java | 26 ++++++++ .../server/play/ChunkBatchStartPacket.java | 23 +++++++ .../packet/server/play/JoinGamePacket.java | 62 +++++++++++-------- .../player/PlayerSocketConnection.java | 9 ++- 16 files changed, 220 insertions(+), 77 deletions(-) create mode 100644 src/main/java/net/minestom/server/network/packet/server/configuration/RegistryDataPacket.java create mode 100644 src/main/java/net/minestom/server/network/packet/server/configuration/UpdateEnabledFeaturesPacket.java create mode 100644 src/main/java/net/minestom/server/network/packet/server/play/ChunkBatchFinishedPacket.java create mode 100644 src/main/java/net/minestom/server/network/packet/server/play/ChunkBatchStartPacket.java diff --git a/demo/src/main/java/net/minestom/demo/Main.java b/demo/src/main/java/net/minestom/demo/Main.java index bb3ee073e..24f2ac7c1 100644 --- a/demo/src/main/java/net/minestom/demo/Main.java +++ b/demo/src/main/java/net/minestom/demo/Main.java @@ -27,6 +27,8 @@ public class Main { System.setProperty("minestom.use-new-chunk-sending", "true"); System.setProperty("minestom.experiment.pose-updates", "true"); + MinecraftServer.setCompressionThreshold(0); + MinecraftServer minecraftServer = MinecraftServer.init(); BlockManager blockManager = MinecraftServer.getBlockManager(); diff --git a/demo/src/main/java/net/minestom/demo/PlayerInit.java b/demo/src/main/java/net/minestom/demo/PlayerInit.java index bc1105d91..99208d809 100644 --- a/demo/src/main/java/net/minestom/demo/PlayerInit.java +++ b/demo/src/main/java/net/minestom/demo/PlayerInit.java @@ -181,6 +181,6 @@ public class PlayerInit { .append(Component.text("ACQ TIME: " + MathUtils.round(tickMonitor.getAcquisitionTime(), 2) + "ms")); final Component footer = benchmarkManager.getCpuMonitoringMessage(); Audiences.players().sendPlayerListHeaderAndFooter(header, footer); - }).repeat(10, TimeUnit.SERVER_TICK).schedule(); + }).repeat(10, TimeUnit.SERVER_TICK);//.schedule(); } } diff --git a/src/main/java/net/minestom/server/MinecraftServer.java b/src/main/java/net/minestom/server/MinecraftServer.java index 1f2fc1b60..8947d8bfc 100644 --- a/src/main/java/net/minestom/server/MinecraftServer.java +++ b/src/main/java/net/minestom/server/MinecraftServer.java @@ -238,7 +238,7 @@ public final class MinecraftServer { * @throws IllegalStateException if this is called after the server started */ public static void setCompressionThreshold(int compressionThreshold) { - Check.stateCondition(serverProcess.isAlive(), "The compression threshold cannot be changed after the server has been started."); + Check.stateCondition(serverProcess != null && serverProcess.isAlive(), "The compression threshold cannot be changed after the server has been started."); MinecraftServer.compressionThreshold = compressionThreshold; } diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 15b3999fb..2f9e44e3d 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -263,39 +263,11 @@ public class Player extends LivingEntity implements CommandSender, Localizable, public CompletableFuture UNSAFE_init(@NotNull Instance spawnInstance) { this.dimensionType = spawnInstance.getDimensionType(); - var registry = new HashMap(); - registry.put("minecraft:chat_type", Messenger.chatRegistry()); - registry.put("minecraft:dimension_type", MinecraftServer.getDimensionTypeManager().toNBT()); - registry.put("minecraft:worldgen/biome", MinecraftServer.getBiomeManager().toNBT()); - - var damageTypeData = Registry.load(Registry.Resource.DAMAGE_TYPES); - var damageTypes = new ArrayList(); - int i = 0; - for (var entry : damageTypeData.entrySet()) { - var elem = new HashMap(); - for (var e : entry.getValue().entrySet()) { - if (e.getValue() instanceof String s) { - elem.put(e.getKey(), NBT.String(s)); - } else if (e.getValue() instanceof Double f) { - elem.put(e.getKey(), NBT.Float(f.floatValue())); - } else if (e.getValue() instanceof Integer integer) { - elem.put(e.getKey(), NBT.Int(integer)); - } - } - damageTypes.add(NBT.Compound(Map.of( - "id", NBT.Int(i++), - "name", NBT.String(entry.getKey()), - "element", NBT.Compound(elem) - ))); - } - registry.put("minecraft:damage_type", NBT.Compound(Map.of( - "type", NBT.String("minecraft:damage_type"), - "value", NBT.List(NBTType.TAG_Compound, damageTypes) - ))); - final JoinGamePacket joinGamePacket = new JoinGamePacket(getEntityId(), false, gameMode, null, - List.of(), NBT.Compound(registry), dimensionType.toString(), spawnInstance.getDimensionName(), - 0, 0, MinecraftServer.getChunkViewDistance(), MinecraftServer.getChunkViewDistance(), - false, true, false, levelFlat, deathLocation, portalCooldown); + final JoinGamePacket joinGamePacket = new JoinGamePacket( + getEntityId(), false, List.of(), 0, + MinecraftServer.getChunkViewDistance(), MinecraftServer.getChunkViewDistance(), + false, true, dimensionType.toString(), spawnInstance.getDimensionName(), + 0, gameMode, null, false, levelFlat, deathLocation, portalCooldown); sendPacket(joinGamePacket); // Server brand name @@ -364,9 +336,6 @@ public class Player extends LivingEntity implements CommandSender, Localizable, } // Recipes end - // Tags - sendPacket(TagsPacket.DEFAULT_TAGS); - // Some client updates sendPacket(getPropertiesPacket()); // Send default properties triggerStatus((byte) (24 + permissionLevel)); // Set permission level diff --git a/src/main/java/net/minestom/server/listener/preplay/LoginListener.java b/src/main/java/net/minestom/server/listener/preplay/LoginListener.java index 0b42b983c..dfe2b193c 100644 --- a/src/main/java/net/minestom/server/listener/preplay/LoginListener.java +++ b/src/main/java/net/minestom/server/listener/preplay/LoginListener.java @@ -10,6 +10,7 @@ import net.minestom.server.extras.MojangAuth; import net.minestom.server.extras.bungee.BungeeCordProxy; import net.minestom.server.extras.mojangAuth.MojangCrypt; import net.minestom.server.extras.velocity.VelocityProxy; +import net.minestom.server.message.Messenger; import net.minestom.server.network.ConnectionManager; import net.minestom.server.network.ConnectionState; import net.minestom.server.network.NetworkBuffer; @@ -17,15 +18,20 @@ import net.minestom.server.network.packet.client.login.ClientEncryptionResponseP import net.minestom.server.network.packet.client.login.ClientLoginAcknowledgedPacket; import net.minestom.server.network.packet.client.login.ClientLoginPluginResponsePacket; import net.minestom.server.network.packet.client.login.ClientLoginStartPacket; +import net.minestom.server.network.packet.server.common.TagsPacket; import net.minestom.server.network.packet.server.configuration.FinishConfigurationPacket; +import net.minestom.server.network.packet.server.configuration.RegistryDataPacket; import net.minestom.server.network.packet.server.login.EncryptionRequestPacket; import net.minestom.server.network.packet.server.login.LoginDisconnectPacket; import net.minestom.server.network.packet.server.login.LoginPluginRequestPacket; import net.minestom.server.network.player.GameProfile; import net.minestom.server.network.player.PlayerConnection; import net.minestom.server.network.player.PlayerSocketConnection; +import net.minestom.server.registry.Registry; import net.minestom.server.utils.async.AsyncUtils; import org.jetbrains.annotations.NotNull; +import org.jglrxavpok.hephaistos.nbt.NBT; +import org.jglrxavpok.hephaistos.nbt.NBTType; import javax.crypto.SecretKey; import java.math.BigInteger; @@ -35,10 +41,8 @@ import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; +import java.util.*; +import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ThreadLocalRandom; import static net.minestom.server.network.NetworkBuffer.STRING; @@ -219,7 +223,47 @@ public final class LoginListener { public static void loginAckListener(@NotNull ClientLoginAcknowledgedPacket packet, @NotNull PlayerConnection connection) { connection.setConnectionState(ConnectionState.CONFIGURATION); - connection.sendPacket(new FinishConfigurationPacket()); + CONNECTION_MANAGER.registerPlayer(connection.getPlayer()); + + // Registry data + var registry = new HashMap(); + registry.put("minecraft:chat_type", Messenger.chatRegistry()); + registry.put("minecraft:dimension_type", MinecraftServer.getDimensionTypeManager().toNBT()); + registry.put("minecraft:worldgen/biome", MinecraftServer.getBiomeManager().toNBT()); + var damageTypeData = Registry.load(Registry.Resource.DAMAGE_TYPES); + var damageTypes = new ArrayList(); + int i = 0; + for (var entry : damageTypeData.entrySet()) { + var elem = new HashMap(); + for (var e : entry.getValue().entrySet()) { + if (e.getValue() instanceof String s) { + elem.put(e.getKey(), NBT.String(s)); + } else if (e.getValue() instanceof Double f) { + elem.put(e.getKey(), NBT.Float(f.floatValue())); + } else if (e.getValue() instanceof Integer integer) { + elem.put(e.getKey(), NBT.Int(integer)); + } + } + damageTypes.add(NBT.Compound(Map.of( + "id", NBT.Int(i++), + "name", NBT.String(entry.getKey()), + "element", NBT.Compound(elem) + ))); + } + registry.put("minecraft:damage_type", NBT.Compound(Map.of( + "type", NBT.String("minecraft:damage_type"), + "value", NBT.List(NBTType.TAG_Compound, damageTypes) + ))); + connection.sendPacket(new RegistryDataPacket(NBT.Compound(registry))); + + // Tags + connection.sendPacket(TagsPacket.DEFAULT_TAGS); + + AsyncUtils.runAsync(() -> { + //todo event + + connection.sendPacket(new FinishConfigurationPacket()); + }); } } diff --git a/src/main/java/net/minestom/server/network/NetworkBufferTypes.java b/src/main/java/net/minestom/server/network/NetworkBufferTypes.java index 2c08a6604..bbb307009 100644 --- a/src/main/java/net/minestom/server/network/NetworkBufferTypes.java +++ b/src/main/java/net/minestom/server/network/NetworkBufferTypes.java @@ -240,7 +240,8 @@ final class NetworkBufferTypes { // Kotlin - https://discord.com/channels/706185253441634317/706186227493109860/1163703658341478462 buffer.write(BYTE, (byte) NBTType.TAG_End.getOrdinal()); } else { - nbtWriter.writeNamed("", value); + buffer.write(BYTE, (byte) NBTType.TAG_Compound.getOrdinal()); + nbtWriter.writeRaw(value); } } catch (IOException e) { throw new RuntimeException(e); diff --git a/src/main/java/net/minestom/server/network/PacketProcessor.java b/src/main/java/net/minestom/server/network/PacketProcessor.java index f00285bd5..be461d476 100644 --- a/src/main/java/net/minestom/server/network/PacketProcessor.java +++ b/src/main/java/net/minestom/server/network/PacketProcessor.java @@ -51,6 +51,7 @@ public class PacketProcessor { public ClientPacket process(@NotNull PlayerConnection connection, int packetId, ByteBuffer body) { final ClientPacket packet = create(connection.getConnectionState(), packetId, body); + System.out.println("PROCESS " + connection.getConnectionState() + " " + packet.getClass().getSimpleName()); final ConnectionState state = connection.getConnectionState(); switch (state) { diff --git a/src/main/java/net/minestom/server/network/packet/server/common/ResourcePackSendPacket.java b/src/main/java/net/minestom/server/network/packet/server/common/ResourcePackSendPacket.java index b18775281..107d618a7 100644 --- a/src/main/java/net/minestom/server/network/packet/server/common/ResourcePackSendPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/common/ResourcePackSendPacket.java @@ -8,6 +8,7 @@ import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; import net.minestom.server.resourcepack.ResourcePack; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.List; @@ -15,8 +16,12 @@ import java.util.function.UnaryOperator; import static net.minestom.server.network.NetworkBuffer.*; -public record ResourcePackSendPacket(String url, String hash, boolean forced, - Component prompt) implements ComponentHoldingServerPacket { +public record ResourcePackSendPacket( + @NotNull String url, + @NotNull String hash, + boolean forced, + @Nullable Component prompt +) implements ComponentHoldingServerPacket { public ResourcePackSendPacket(@NotNull NetworkBuffer reader) { this(reader.read(STRING), reader.read(STRING), reader.read(BOOLEAN), reader.read(BOOLEAN) ? reader.read(COMPONENT) : null); diff --git a/src/main/java/net/minestom/server/network/packet/server/configuration/FinishConfigurationPacket.java b/src/main/java/net/minestom/server/network/packet/server/configuration/FinishConfigurationPacket.java index 18d319731..a1b63236c 100644 --- a/src/main/java/net/minestom/server/network/packet/server/configuration/FinishConfigurationPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/configuration/FinishConfigurationPacket.java @@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.configuration; import net.minestom.server.network.ConnectionState; import net.minestom.server.network.NetworkBuffer; import net.minestom.server.network.packet.server.ServerPacket; +import net.minestom.server.network.packet.server.ServerPacketIdentifier; import org.jetbrains.annotations.NotNull; public record FinishConfigurationPacket() implements ServerPacket { @@ -17,6 +18,6 @@ public record FinishConfigurationPacket() implements ServerPacket { @Override public int getId(@NotNull ConnectionState state) { - return 2; + return ServerPacketIdentifier.CONFIGURATION_FINISH_CONFIGURATION; } } diff --git a/src/main/java/net/minestom/server/network/packet/server/configuration/RegistryDataPacket.java b/src/main/java/net/minestom/server/network/packet/server/configuration/RegistryDataPacket.java new file mode 100644 index 000000000..56e8c6c58 --- /dev/null +++ b/src/main/java/net/minestom/server/network/packet/server/configuration/RegistryDataPacket.java @@ -0,0 +1,27 @@ +package net.minestom.server.network.packet.server.configuration; + +import net.minestom.server.network.ConnectionState; +import net.minestom.server.network.NetworkBuffer; +import net.minestom.server.network.packet.server.ServerPacket; +import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import org.jetbrains.annotations.NotNull; +import org.jglrxavpok.hephaistos.nbt.NBTCompound; + +import static net.minestom.server.network.NetworkBuffer.NBT; + +public record RegistryDataPacket(@NotNull NBTCompound data) implements ServerPacket { + + public RegistryDataPacket(@NotNull NetworkBuffer buffer) { + this((NBTCompound) buffer.read(NBT)); + } + + @Override + public void write(@NotNull NetworkBuffer writer) { + writer.write(NBT, data); + } + + @Override + public int getId(@NotNull ConnectionState state) { + return ServerPacketIdentifier.CONFIGURATION_REGISTRY_DATA; + } +} diff --git a/src/main/java/net/minestom/server/network/packet/server/configuration/UpdateEnabledFeaturesPacket.java b/src/main/java/net/minestom/server/network/packet/server/configuration/UpdateEnabledFeaturesPacket.java new file mode 100644 index 000000000..c7cfe1c2d --- /dev/null +++ b/src/main/java/net/minestom/server/network/packet/server/configuration/UpdateEnabledFeaturesPacket.java @@ -0,0 +1,30 @@ +package net.minestom.server.network.packet.server.configuration; + +import net.minestom.server.network.ConnectionState; +import net.minestom.server.network.NetworkBuffer; +import net.minestom.server.network.packet.server.ServerPacket; +import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import net.minestom.server.utils.NamespaceID; +import org.jetbrains.annotations.NotNull; + +import java.util.Set; + +import static net.minestom.server.network.NetworkBuffer.STRING; + +public record UpdateEnabledFeaturesPacket(@NotNull Set features) implements ServerPacket { + + public UpdateEnabledFeaturesPacket(@NotNull NetworkBuffer buffer) { + this(Set.copyOf(buffer.readCollection((b) -> NamespaceID.from(b.read(STRING))))); + } + + @Override + public void write(@NotNull NetworkBuffer writer) { + writer.writeCollection(features, (b, feature) -> b.write(STRING, feature.asString())); + } + + @Override + public int getId(@NotNull ConnectionState state) { + return ServerPacketIdentifier.CONFIGURATION_UPDATE_ENABLED_FEATURES; + } + +} diff --git a/src/main/java/net/minestom/server/network/packet/server/play/ChangeGameStatePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/ChangeGameStatePacket.java index f1f6a4b40..05dd103ff 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/ChangeGameStatePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/ChangeGameStatePacket.java @@ -37,6 +37,7 @@ public record ChangeGameStatePacket(@NotNull Reason reason, float value) impleme THUNDER_LEVEL_CHANGE, PLAY_PUFFERFISH_STING_SOUND, PLAYER_ELDER_GUARDIAN_MOB_APPEARANCE, - ENABLE_RESPAWN_SCREEN + ENABLE_RESPAWN_SCREEN, + LIMITED_CRAFTING } } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/ChunkBatchFinishedPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/ChunkBatchFinishedPacket.java new file mode 100644 index 000000000..fc68127c5 --- /dev/null +++ b/src/main/java/net/minestom/server/network/packet/server/play/ChunkBatchFinishedPacket.java @@ -0,0 +1,26 @@ +package net.minestom.server.network.packet.server.play; + +import net.minestom.server.network.ConnectionState; +import net.minestom.server.network.NetworkBuffer; +import net.minestom.server.network.packet.server.ServerPacket; +import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import org.jetbrains.annotations.NotNull; + +import static net.minestom.server.network.NetworkBuffer.VAR_INT; + +public record ChunkBatchFinishedPacket(int batchSize) implements ServerPacket { + + public ChunkBatchFinishedPacket(@NotNull NetworkBuffer buffer) { + this(buffer.read(VAR_INT)); + } + + @Override + public void write(@NotNull NetworkBuffer writer) { + writer.write(VAR_INT, batchSize); + } + + @Override + public int getId(@NotNull ConnectionState state) { + return ServerPacketIdentifier.CHUNK_BATCH_FINISHED; + } +} diff --git a/src/main/java/net/minestom/server/network/packet/server/play/ChunkBatchStartPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/ChunkBatchStartPacket.java new file mode 100644 index 000000000..ebb84d701 --- /dev/null +++ b/src/main/java/net/minestom/server/network/packet/server/play/ChunkBatchStartPacket.java @@ -0,0 +1,23 @@ +package net.minestom.server.network.packet.server.play; + +import net.minestom.server.network.ConnectionState; +import net.minestom.server.network.NetworkBuffer; +import net.minestom.server.network.packet.server.ServerPacket; +import net.minestom.server.network.packet.server.ServerPacketIdentifier; +import org.jetbrains.annotations.NotNull; + +public record ChunkBatchStartPacket() implements ServerPacket { + + public ChunkBatchStartPacket(@NotNull NetworkBuffer buffer) { + this(); + } + + @Override + public void write(@NotNull NetworkBuffer writer) { + } + + @Override + public int getId(@NotNull ConnectionState state) { + return ServerPacketIdentifier.CHUNK_BATCH_START; + } +} diff --git a/src/main/java/net/minestom/server/network/packet/server/play/JoinGamePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/JoinGamePacket.java index c225f295e..7449e2730 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/JoinGamePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/JoinGamePacket.java @@ -14,52 +14,62 @@ import java.util.List; import static net.minestom.server.network.NetworkBuffer.*; -public record JoinGamePacket(int entityId, boolean isHardcore, GameMode gameMode, GameMode previousGameMode, - List worlds, NBTCompound dimensionCodec, String dimensionType, String world, - long hashedSeed, int maxPlayers, int viewDistance, int simulationDistance, - boolean reducedDebugInfo, boolean enableRespawnScreen, boolean isDebug, boolean isFlat, - DeathLocation deathLocation, int portalCooldown) implements ServerPacket { +public record JoinGamePacket( + int entityId, boolean isHardcore, List worlds, int maxPlayers, + int viewDistance, int simulationDistance, boolean reducedDebugInfo, boolean enableRespawnScreen, + String dimensionType, String world, long hashedSeed, GameMode gameMode, GameMode previousGameMode, + boolean isDebug, boolean isFlat, DeathLocation deathLocation, int portalCooldown +) implements ServerPacket { public JoinGamePacket { worlds = List.copyOf(worlds); } public JoinGamePacket(@NotNull NetworkBuffer reader) { - this(reader.read(INT), reader.read(BOOLEAN), GameMode.fromId(reader.read(BYTE)), getNullableGameMode(reader.read(BYTE)), - reader.readCollection(STRING), (NBTCompound) reader.read(NBT), reader.read(STRING), reader.read(STRING), - reader.read(LONG), reader.read(VAR_INT), reader.read(VAR_INT), reader.read(VAR_INT), - reader.read(BOOLEAN), reader.read(BOOLEAN), reader.read(BOOLEAN), reader.read(BOOLEAN), - reader.read(DEATH_LOCATION), reader.read(VAR_INT)); + this( + reader.read(INT), + reader.read(BOOLEAN), + reader.readCollection(STRING), + reader.read(VAR_INT), + reader.read(VAR_INT), + reader.read(VAR_INT), + reader.read(BOOLEAN), + reader.read(BOOLEAN), + + reader.read(STRING), + reader.read(STRING), + reader.read(LONG), + GameMode.fromId(reader.read(BYTE)), + getNullableGameMode(reader.read(BYTE)), + reader.read(BOOLEAN), + reader.read(BOOLEAN), + reader.read(DEATH_LOCATION), + reader.read(VAR_INT) + ); } @Override public void write(@NotNull NetworkBuffer writer) { writer.write(INT, entityId); writer.write(BOOLEAN, isHardcore); + writer.writeCollection(STRING, worlds); + writer.write(VAR_INT, maxPlayers); + writer.write(VAR_INT, viewDistance); + writer.write(VAR_INT, simulationDistance); + writer.write(BOOLEAN, reducedDebugInfo); + writer.write(BOOLEAN, enableRespawnScreen); + + writer.write(STRING, dimensionType); + writer.write(STRING, world); + writer.write(LONG, hashedSeed); writer.write(BYTE, gameMode.id()); if (previousGameMode != null) { writer.write(BYTE, previousGameMode.id()); } else { writer.write(BYTE, (byte) -1); } - - writer.writeCollection(STRING, worlds); - writer.write(NBT, dimensionCodec); - - writer.write(STRING, dimensionType); - writer.write(STRING, world); - writer.write(LONG, hashedSeed); - writer.write(VAR_INT, maxPlayers); - writer.write(VAR_INT, viewDistance); - writer.write(VAR_INT, simulationDistance); - writer.write(BOOLEAN, reducedDebugInfo); - writer.write(BOOLEAN, enableRespawnScreen); - //debug writer.write(BOOLEAN, isDebug); - //is flat writer.write(BOOLEAN, isFlat); - writer.write(DEATH_LOCATION, deathLocation); - writer.write(VAR_INT, portalCooldown); } diff --git a/src/main/java/net/minestom/server/network/player/PlayerSocketConnection.java b/src/main/java/net/minestom/server/network/player/PlayerSocketConnection.java index f90ba14dc..9009f8a2e 100644 --- a/src/main/java/net/minestom/server/network/player/PlayerSocketConnection.java +++ b/src/main/java/net/minestom/server/network/player/PlayerSocketConnection.java @@ -106,7 +106,6 @@ public class PlayerSocketConnection extends PlayerConnection { return; // Prevent packet corruption ClientPacket packet = null; try { - System.out.println("PROCESS " + getConnectionState() + " " + Integer.toHexString(id)); packet = packetProcessor.process(this, id, payload); } catch (Exception e) { // Error while reading the packet @@ -349,10 +348,14 @@ public class PlayerSocketConnection extends PlayerConnection { writeServerPacketSync(serverPacket, compressed); } else if (packet instanceof FramedPacket framedPacket) { var buffer = framedPacket.body(); + System.out.println("SEND " + getConnectionState() + " " + "UNKNOWN FRAMED"); writeBufferSync(buffer, 0, buffer.limit()); } else if (packet instanceof CachedPacket cachedPacket) { var buffer = cachedPacket.body(getConnectionState()); - if (buffer != null) writeBufferSync(buffer, buffer.position(), buffer.remaining()); + if (buffer != null) { + System.out.println("SEND " + getConnectionState() + " " + cachedPacket.packet(getConnectionState()).getClass().getSimpleName()); + writeBufferSync(buffer, buffer.position(), buffer.remaining()); + } else writeServerPacketSync(cachedPacket.packet(getConnectionState()), compressed); } else if (packet instanceof LazyPacket lazyPacket) { writeServerPacketSync(lazyPacket.packet(), compressed); @@ -362,7 +365,6 @@ public class PlayerSocketConnection extends PlayerConnection { } private void writeServerPacketSync(ServerPacket serverPacket, boolean compressed) { - System.out.println("SEND PACKET " + serverPacket.getClass()); final Player player = getPlayer(); if (player != null) { if (MinestomAdventure.AUTOMATIC_COMPONENT_TRANSLATION && serverPacket instanceof ComponentHoldingServerPacket) { @@ -372,6 +374,7 @@ public class PlayerSocketConnection extends PlayerConnection { } try (var hold = ObjectPool.PACKET_POOL.hold()) { var buffer = PacketUtils.createFramedPacket(getConnectionState(), hold.get(), serverPacket, compressed); + System.out.println("SEND " + getConnectionState() + " " + serverPacket.getClass().getSimpleName() + " " + buffer.limit()); writeBufferSync(buffer, 0, buffer.limit()); } }