mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-06 16:37:38 +01:00
parent
2f85ce0231
commit
183159c85d
@ -27,6 +27,8 @@ public class Main {
|
|||||||
System.setProperty("minestom.use-new-chunk-sending", "true");
|
System.setProperty("minestom.use-new-chunk-sending", "true");
|
||||||
System.setProperty("minestom.experiment.pose-updates", "true");
|
System.setProperty("minestom.experiment.pose-updates", "true");
|
||||||
|
|
||||||
|
MinecraftServer.setCompressionThreshold(0);
|
||||||
|
|
||||||
MinecraftServer minecraftServer = MinecraftServer.init();
|
MinecraftServer minecraftServer = MinecraftServer.init();
|
||||||
|
|
||||||
BlockManager blockManager = MinecraftServer.getBlockManager();
|
BlockManager blockManager = MinecraftServer.getBlockManager();
|
||||||
|
@ -181,6 +181,6 @@ public class PlayerInit {
|
|||||||
.append(Component.text("ACQ TIME: " + MathUtils.round(tickMonitor.getAcquisitionTime(), 2) + "ms"));
|
.append(Component.text("ACQ TIME: " + MathUtils.round(tickMonitor.getAcquisitionTime(), 2) + "ms"));
|
||||||
final Component footer = benchmarkManager.getCpuMonitoringMessage();
|
final Component footer = benchmarkManager.getCpuMonitoringMessage();
|
||||||
Audiences.players().sendPlayerListHeaderAndFooter(header, footer);
|
Audiences.players().sendPlayerListHeaderAndFooter(header, footer);
|
||||||
}).repeat(10, TimeUnit.SERVER_TICK).schedule();
|
}).repeat(10, TimeUnit.SERVER_TICK);//.schedule();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -238,7 +238,7 @@ public final class MinecraftServer {
|
|||||||
* @throws IllegalStateException if this is called after the server started
|
* @throws IllegalStateException if this is called after the server started
|
||||||
*/
|
*/
|
||||||
public static void setCompressionThreshold(int compressionThreshold) {
|
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;
|
MinecraftServer.compressionThreshold = compressionThreshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,39 +263,11 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
public CompletableFuture<Void> UNSAFE_init(@NotNull Instance spawnInstance) {
|
public CompletableFuture<Void> UNSAFE_init(@NotNull Instance spawnInstance) {
|
||||||
this.dimensionType = spawnInstance.getDimensionType();
|
this.dimensionType = spawnInstance.getDimensionType();
|
||||||
|
|
||||||
var registry = new HashMap<String, NBT>();
|
final JoinGamePacket joinGamePacket = new JoinGamePacket(
|
||||||
registry.put("minecraft:chat_type", Messenger.chatRegistry());
|
getEntityId(), false, List.of(), 0,
|
||||||
registry.put("minecraft:dimension_type", MinecraftServer.getDimensionTypeManager().toNBT());
|
MinecraftServer.getChunkViewDistance(), MinecraftServer.getChunkViewDistance(),
|
||||||
registry.put("minecraft:worldgen/biome", MinecraftServer.getBiomeManager().toNBT());
|
false, true, dimensionType.toString(), spawnInstance.getDimensionName(),
|
||||||
|
0, gameMode, null, false, levelFlat, deathLocation, portalCooldown);
|
||||||
var damageTypeData = Registry.load(Registry.Resource.DAMAGE_TYPES);
|
|
||||||
var damageTypes = new ArrayList<NBT>();
|
|
||||||
int i = 0;
|
|
||||||
for (var entry : damageTypeData.entrySet()) {
|
|
||||||
var elem = new HashMap<String, NBT>();
|
|
||||||
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);
|
|
||||||
sendPacket(joinGamePacket);
|
sendPacket(joinGamePacket);
|
||||||
|
|
||||||
// Server brand name
|
// Server brand name
|
||||||
@ -364,9 +336,6 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
}
|
}
|
||||||
// Recipes end
|
// Recipes end
|
||||||
|
|
||||||
// Tags
|
|
||||||
sendPacket(TagsPacket.DEFAULT_TAGS);
|
|
||||||
|
|
||||||
// Some client updates
|
// Some client updates
|
||||||
sendPacket(getPropertiesPacket()); // Send default properties
|
sendPacket(getPropertiesPacket()); // Send default properties
|
||||||
triggerStatus((byte) (24 + permissionLevel)); // Set permission level
|
triggerStatus((byte) (24 + permissionLevel)); // Set permission level
|
||||||
|
@ -10,6 +10,7 @@ import net.minestom.server.extras.MojangAuth;
|
|||||||
import net.minestom.server.extras.bungee.BungeeCordProxy;
|
import net.minestom.server.extras.bungee.BungeeCordProxy;
|
||||||
import net.minestom.server.extras.mojangAuth.MojangCrypt;
|
import net.minestom.server.extras.mojangAuth.MojangCrypt;
|
||||||
import net.minestom.server.extras.velocity.VelocityProxy;
|
import net.minestom.server.extras.velocity.VelocityProxy;
|
||||||
|
import net.minestom.server.message.Messenger;
|
||||||
import net.minestom.server.network.ConnectionManager;
|
import net.minestom.server.network.ConnectionManager;
|
||||||
import net.minestom.server.network.ConnectionState;
|
import net.minestom.server.network.ConnectionState;
|
||||||
import net.minestom.server.network.NetworkBuffer;
|
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.ClientLoginAcknowledgedPacket;
|
||||||
import net.minestom.server.network.packet.client.login.ClientLoginPluginResponsePacket;
|
import net.minestom.server.network.packet.client.login.ClientLoginPluginResponsePacket;
|
||||||
import net.minestom.server.network.packet.client.login.ClientLoginStartPacket;
|
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.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.EncryptionRequestPacket;
|
||||||
import net.minestom.server.network.packet.server.login.LoginDisconnectPacket;
|
import net.minestom.server.network.packet.server.login.LoginDisconnectPacket;
|
||||||
import net.minestom.server.network.packet.server.login.LoginPluginRequestPacket;
|
import net.minestom.server.network.packet.server.login.LoginPluginRequestPacket;
|
||||||
import net.minestom.server.network.player.GameProfile;
|
import net.minestom.server.network.player.GameProfile;
|
||||||
import net.minestom.server.network.player.PlayerConnection;
|
import net.minestom.server.network.player.PlayerConnection;
|
||||||
import net.minestom.server.network.player.PlayerSocketConnection;
|
import net.minestom.server.network.player.PlayerSocketConnection;
|
||||||
|
import net.minestom.server.registry.Registry;
|
||||||
import net.minestom.server.utils.async.AsyncUtils;
|
import net.minestom.server.utils.async.AsyncUtils;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jglrxavpok.hephaistos.nbt.NBT;
|
||||||
|
import org.jglrxavpok.hephaistos.nbt.NBTType;
|
||||||
|
|
||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
@ -35,10 +41,8 @@ import java.net.http.HttpRequest;
|
|||||||
import java.net.http.HttpResponse;
|
import java.net.http.HttpResponse;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
import java.util.concurrent.ForkJoinPool;
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
import static net.minestom.server.network.NetworkBuffer.STRING;
|
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) {
|
public static void loginAckListener(@NotNull ClientLoginAcknowledgedPacket packet, @NotNull PlayerConnection connection) {
|
||||||
connection.setConnectionState(ConnectionState.CONFIGURATION);
|
connection.setConnectionState(ConnectionState.CONFIGURATION);
|
||||||
|
|
||||||
connection.sendPacket(new FinishConfigurationPacket());
|
CONNECTION_MANAGER.registerPlayer(connection.getPlayer());
|
||||||
|
|
||||||
|
// Registry data
|
||||||
|
var registry = new HashMap<String, NBT>();
|
||||||
|
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<NBT>();
|
||||||
|
int i = 0;
|
||||||
|
for (var entry : damageTypeData.entrySet()) {
|
||||||
|
var elem = new HashMap<String, NBT>();
|
||||||
|
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());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -240,7 +240,8 @@ final class NetworkBufferTypes {
|
|||||||
// Kotlin - https://discord.com/channels/706185253441634317/706186227493109860/1163703658341478462
|
// Kotlin - https://discord.com/channels/706185253441634317/706186227493109860/1163703658341478462
|
||||||
buffer.write(BYTE, (byte) NBTType.TAG_End.getOrdinal());
|
buffer.write(BYTE, (byte) NBTType.TAG_End.getOrdinal());
|
||||||
} else {
|
} else {
|
||||||
nbtWriter.writeNamed("", value);
|
buffer.write(BYTE, (byte) NBTType.TAG_Compound.getOrdinal());
|
||||||
|
nbtWriter.writeRaw(value);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -51,6 +51,7 @@ public class PacketProcessor {
|
|||||||
|
|
||||||
public ClientPacket process(@NotNull PlayerConnection connection, int packetId, ByteBuffer body) {
|
public ClientPacket process(@NotNull PlayerConnection connection, int packetId, ByteBuffer body) {
|
||||||
final ClientPacket packet = create(connection.getConnectionState(), packetId, body);
|
final ClientPacket packet = create(connection.getConnectionState(), packetId, body);
|
||||||
|
System.out.println("PROCESS " + connection.getConnectionState() + " " + packet.getClass().getSimpleName());
|
||||||
|
|
||||||
final ConnectionState state = connection.getConnectionState();
|
final ConnectionState state = connection.getConnectionState();
|
||||||
switch (state) {
|
switch (state) {
|
||||||
|
@ -8,6 +8,7 @@ import net.minestom.server.network.packet.server.ServerPacket;
|
|||||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||||
import net.minestom.server.resourcepack.ResourcePack;
|
import net.minestom.server.resourcepack.ResourcePack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -15,8 +16,12 @@ import java.util.function.UnaryOperator;
|
|||||||
|
|
||||||
import static net.minestom.server.network.NetworkBuffer.*;
|
import static net.minestom.server.network.NetworkBuffer.*;
|
||||||
|
|
||||||
public record ResourcePackSendPacket(String url, String hash, boolean forced,
|
public record ResourcePackSendPacket(
|
||||||
Component prompt) implements ComponentHoldingServerPacket {
|
@NotNull String url,
|
||||||
|
@NotNull String hash,
|
||||||
|
boolean forced,
|
||||||
|
@Nullable Component prompt
|
||||||
|
) implements ComponentHoldingServerPacket {
|
||||||
public ResourcePackSendPacket(@NotNull NetworkBuffer reader) {
|
public ResourcePackSendPacket(@NotNull NetworkBuffer reader) {
|
||||||
this(reader.read(STRING), reader.read(STRING), reader.read(BOOLEAN),
|
this(reader.read(STRING), reader.read(STRING), reader.read(BOOLEAN),
|
||||||
reader.read(BOOLEAN) ? reader.read(COMPONENT) : null);
|
reader.read(BOOLEAN) ? reader.read(COMPONENT) : null);
|
||||||
|
@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.configuration;
|
|||||||
import net.minestom.server.network.ConnectionState;
|
import net.minestom.server.network.ConnectionState;
|
||||||
import net.minestom.server.network.NetworkBuffer;
|
import net.minestom.server.network.NetworkBuffer;
|
||||||
import net.minestom.server.network.packet.server.ServerPacket;
|
import net.minestom.server.network.packet.server.ServerPacket;
|
||||||
|
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public record FinishConfigurationPacket() implements ServerPacket {
|
public record FinishConfigurationPacket() implements ServerPacket {
|
||||||
@ -17,6 +18,6 @@ public record FinishConfigurationPacket() implements ServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getId(@NotNull ConnectionState state) {
|
public int getId(@NotNull ConnectionState state) {
|
||||||
return 2;
|
return ServerPacketIdentifier.CONFIGURATION_FINISH_CONFIGURATION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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<NamespaceID> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -37,6 +37,7 @@ public record ChangeGameStatePacket(@NotNull Reason reason, float value) impleme
|
|||||||
THUNDER_LEVEL_CHANGE,
|
THUNDER_LEVEL_CHANGE,
|
||||||
PLAY_PUFFERFISH_STING_SOUND,
|
PLAY_PUFFERFISH_STING_SOUND,
|
||||||
PLAYER_ELDER_GUARDIAN_MOB_APPEARANCE,
|
PLAYER_ELDER_GUARDIAN_MOB_APPEARANCE,
|
||||||
ENABLE_RESPAWN_SCREEN
|
ENABLE_RESPAWN_SCREEN,
|
||||||
|
LIMITED_CRAFTING
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -14,52 +14,62 @@ import java.util.List;
|
|||||||
|
|
||||||
import static net.minestom.server.network.NetworkBuffer.*;
|
import static net.minestom.server.network.NetworkBuffer.*;
|
||||||
|
|
||||||
public record JoinGamePacket(int entityId, boolean isHardcore, GameMode gameMode, GameMode previousGameMode,
|
public record JoinGamePacket(
|
||||||
List<String> worlds, NBTCompound dimensionCodec, String dimensionType, String world,
|
int entityId, boolean isHardcore, List<String> worlds, int maxPlayers,
|
||||||
long hashedSeed, int maxPlayers, int viewDistance, int simulationDistance,
|
int viewDistance, int simulationDistance, boolean reducedDebugInfo, boolean enableRespawnScreen,
|
||||||
boolean reducedDebugInfo, boolean enableRespawnScreen, boolean isDebug, boolean isFlat,
|
String dimensionType, String world, long hashedSeed, GameMode gameMode, GameMode previousGameMode,
|
||||||
DeathLocation deathLocation, int portalCooldown) implements ServerPacket {
|
boolean isDebug, boolean isFlat, DeathLocation deathLocation, int portalCooldown
|
||||||
|
) implements ServerPacket {
|
||||||
public JoinGamePacket {
|
public JoinGamePacket {
|
||||||
worlds = List.copyOf(worlds);
|
worlds = List.copyOf(worlds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JoinGamePacket(@NotNull NetworkBuffer reader) {
|
public JoinGamePacket(@NotNull NetworkBuffer reader) {
|
||||||
this(reader.read(INT), reader.read(BOOLEAN), GameMode.fromId(reader.read(BYTE)), getNullableGameMode(reader.read(BYTE)),
|
this(
|
||||||
reader.readCollection(STRING), (NBTCompound) reader.read(NBT), reader.read(STRING), reader.read(STRING),
|
reader.read(INT),
|
||||||
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(BOOLEAN),
|
reader.readCollection(STRING),
|
||||||
reader.read(DEATH_LOCATION), reader.read(VAR_INT));
|
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
|
@Override
|
||||||
public void write(@NotNull NetworkBuffer writer) {
|
public void write(@NotNull NetworkBuffer writer) {
|
||||||
writer.write(INT, entityId);
|
writer.write(INT, entityId);
|
||||||
writer.write(BOOLEAN, isHardcore);
|
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());
|
writer.write(BYTE, gameMode.id());
|
||||||
if (previousGameMode != null) {
|
if (previousGameMode != null) {
|
||||||
writer.write(BYTE, previousGameMode.id());
|
writer.write(BYTE, previousGameMode.id());
|
||||||
} else {
|
} else {
|
||||||
writer.write(BYTE, (byte) -1);
|
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);
|
writer.write(BOOLEAN, isDebug);
|
||||||
//is flat
|
|
||||||
writer.write(BOOLEAN, isFlat);
|
writer.write(BOOLEAN, isFlat);
|
||||||
|
|
||||||
writer.write(DEATH_LOCATION, deathLocation);
|
writer.write(DEATH_LOCATION, deathLocation);
|
||||||
|
|
||||||
writer.write(VAR_INT, portalCooldown);
|
writer.write(VAR_INT, portalCooldown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,6 @@ public class PlayerSocketConnection extends PlayerConnection {
|
|||||||
return; // Prevent packet corruption
|
return; // Prevent packet corruption
|
||||||
ClientPacket packet = null;
|
ClientPacket packet = null;
|
||||||
try {
|
try {
|
||||||
System.out.println("PROCESS " + getConnectionState() + " " + Integer.toHexString(id));
|
|
||||||
packet = packetProcessor.process(this, id, payload);
|
packet = packetProcessor.process(this, id, payload);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Error while reading the packet
|
// Error while reading the packet
|
||||||
@ -349,10 +348,14 @@ public class PlayerSocketConnection extends PlayerConnection {
|
|||||||
writeServerPacketSync(serverPacket, compressed);
|
writeServerPacketSync(serverPacket, compressed);
|
||||||
} else if (packet instanceof FramedPacket framedPacket) {
|
} else if (packet instanceof FramedPacket framedPacket) {
|
||||||
var buffer = framedPacket.body();
|
var buffer = framedPacket.body();
|
||||||
|
System.out.println("SEND " + getConnectionState() + " " + "UNKNOWN FRAMED");
|
||||||
writeBufferSync(buffer, 0, buffer.limit());
|
writeBufferSync(buffer, 0, buffer.limit());
|
||||||
} else if (packet instanceof CachedPacket cachedPacket) {
|
} else if (packet instanceof CachedPacket cachedPacket) {
|
||||||
var buffer = cachedPacket.body(getConnectionState());
|
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 writeServerPacketSync(cachedPacket.packet(getConnectionState()), compressed);
|
||||||
} else if (packet instanceof LazyPacket lazyPacket) {
|
} else if (packet instanceof LazyPacket lazyPacket) {
|
||||||
writeServerPacketSync(lazyPacket.packet(), compressed);
|
writeServerPacketSync(lazyPacket.packet(), compressed);
|
||||||
@ -362,7 +365,6 @@ public class PlayerSocketConnection extends PlayerConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void writeServerPacketSync(ServerPacket serverPacket, boolean compressed) {
|
private void writeServerPacketSync(ServerPacket serverPacket, boolean compressed) {
|
||||||
System.out.println("SEND PACKET " + serverPacket.getClass());
|
|
||||||
final Player player = getPlayer();
|
final Player player = getPlayer();
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
if (MinestomAdventure.AUTOMATIC_COMPONENT_TRANSLATION && serverPacket instanceof ComponentHoldingServerPacket) {
|
if (MinestomAdventure.AUTOMATIC_COMPONENT_TRANSLATION && serverPacket instanceof ComponentHoldingServerPacket) {
|
||||||
@ -372,6 +374,7 @@ public class PlayerSocketConnection extends PlayerConnection {
|
|||||||
}
|
}
|
||||||
try (var hold = ObjectPool.PACKET_POOL.hold()) {
|
try (var hold = ObjectPool.PACKET_POOL.hold()) {
|
||||||
var buffer = PacketUtils.createFramedPacket(getConnectionState(), hold.get(), serverPacket, compressed);
|
var buffer = PacketUtils.createFramedPacket(getConnectionState(), hold.get(), serverPacket, compressed);
|
||||||
|
System.out.println("SEND " + getConnectionState() + " " + serverPacket.getClass().getSimpleName() + " " + buffer.limit());
|
||||||
writeBufferSync(buffer, 0, buffer.limit());
|
writeBufferSync(buffer, 0, buffer.limit());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user