From b04fca8e7fbee264d89fb9c9d40b419a44bd64e8 Mon Sep 17 00:00:00 2001 From: mworzala Date: Sat, 18 Nov 2023 16:37:03 +0200 Subject: [PATCH] chore: remove some unnecessary logging --- demo/src/main/java/net/minestom/demo/Main.java | 5 +++-- .../listener/manager/PacketListenerManager.java | 1 - .../listener/preplay/ConfigurationListener.java | 1 - .../minestom/server/network/PacketProcessor.java | 4 ---- .../network/packet/server/ServerPacket.java | 8 +++++++- .../packet/server/play/UnloadChunkPacket.java | 15 +++++++++++++-- .../network/player/PlayerSocketConnection.java | 15 +++++---------- 7 files changed, 28 insertions(+), 21 deletions(-) diff --git a/demo/src/main/java/net/minestom/demo/Main.java b/demo/src/main/java/net/minestom/demo/Main.java index 5256dc7cc..2e89c5b2c 100644 --- a/demo/src/main/java/net/minestom/demo/Main.java +++ b/demo/src/main/java/net/minestom/demo/Main.java @@ -14,6 +14,7 @@ import net.minestom.server.event.server.ServerListPingEvent; import net.minestom.server.extras.lan.OpenToLAN; import net.minestom.server.extras.lan.OpenToLANConfig; import net.minestom.server.extras.optifine.OptifineSupport; +import net.minestom.server.extras.velocity.VelocityProxy; import net.minestom.server.instance.block.BlockManager; import net.minestom.server.ping.ResponseData; import net.minestom.server.utils.identity.NamedAndIdentified; @@ -107,10 +108,10 @@ public class Main { OptifineSupport.enable(); - //VelocityProxy.enable("rBeJJ79W4MVU"); + VelocityProxy.enable("abc"); //BungeeCordProxy.enable(); - //MojangAuth.init(); + //MojangAuth.init();c // useful for testing - we don't need to worry about event calls so just set this to a long time OpenToLAN.open(new OpenToLANConfig().eventCallDelay(Duration.of(1, TimeUnit.DAY))); diff --git a/src/main/java/net/minestom/server/listener/manager/PacketListenerManager.java b/src/main/java/net/minestom/server/listener/manager/PacketListenerManager.java index daeb8dc44..09ad097f3 100644 --- a/src/main/java/net/minestom/server/listener/manager/PacketListenerManager.java +++ b/src/main/java/net/minestom/server/listener/manager/PacketListenerManager.java @@ -132,7 +132,6 @@ public final class PacketListenerManager { // If the packet intends to switch state, do it now. var nextState = packet.nextState(); if (nextState != null && state != nextState) { - System.out.println("CHANGE CLIENT STATE TO " + nextState); connection.setClientState(nextState); } } diff --git a/src/main/java/net/minestom/server/listener/preplay/ConfigurationListener.java b/src/main/java/net/minestom/server/listener/preplay/ConfigurationListener.java index 99ace6b5c..1e44afb6c 100644 --- a/src/main/java/net/minestom/server/listener/preplay/ConfigurationListener.java +++ b/src/main/java/net/minestom/server/listener/preplay/ConfigurationListener.java @@ -3,7 +3,6 @@ package net.minestom.server.listener.preplay; import net.minestom.server.MinecraftServer; import net.minestom.server.entity.Player; import net.minestom.server.network.ConnectionManager; -import net.minestom.server.network.ConnectionState; import net.minestom.server.network.packet.client.configuration.ClientFinishConfigurationPacket; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/minestom/server/network/PacketProcessor.java b/src/main/java/net/minestom/server/network/PacketProcessor.java index a02c6a067..f928faff6 100644 --- a/src/main/java/net/minestom/server/network/PacketProcessor.java +++ b/src/main/java/net/minestom/server/network/PacketProcessor.java @@ -54,10 +54,6 @@ public class PacketProcessor { public ClientPacket process(@NotNull PlayerConnection connection, int packetId, ByteBuffer body) { final ClientPacket packet = create(connection.getClientState(), packetId, body); - var packetClass = packet.getClass(); - if (packetClass != ClientPlayerPositionPacket.class && packetClass != ClientPlayerPositionAndRotationPacket.class && packetClass != ClientPlayerRotationPacket.class) - System.out.println("PROCESS " + connection.getClientState() + " " + packet.getClass().getSimpleName()); - final ConnectionState state = connection.getClientState(); switch (state) { case HANDSHAKE, STATUS, LOGIN, CONFIGURATION -> packetListenerManager.processClientPacket(connection.getClientState(), packet, connection); diff --git a/src/main/java/net/minestom/server/network/packet/server/ServerPacket.java b/src/main/java/net/minestom/server/network/packet/server/ServerPacket.java index 6068c9e3c..36527f26e 100644 --- a/src/main/java/net/minestom/server/network/packet/server/ServerPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/ServerPacket.java @@ -22,7 +22,13 @@ public non-sealed interface ServerPacket extends NetworkBuffer.Writer, SendableP */ int getId(@NotNull ConnectionState state); - // If not null, the server will switch state immediately after sending this packet + /** + * If not null, the server will switch state immediately after sending this packet + * + *

WARNING: A cached or framed packet will currently never go through writeServerPacketSync, + * so a state change inside one of them will never actually be triggered. Currently, cached + * packets are never used for packets that change state, so this is not a problem.

+ */ default @Nullable ConnectionState nextState() { return null; } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/UnloadChunkPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/UnloadChunkPacket.java index 8b3e98fe1..cac386661 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/UnloadChunkPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/UnloadChunkPacket.java @@ -10,17 +10,28 @@ import static net.minestom.server.network.NetworkBuffer.INT; public record UnloadChunkPacket(int chunkX, int chunkZ) implements ServerPacket { public UnloadChunkPacket(@NotNull NetworkBuffer reader) { - this(reader.read(INT), reader.read(INT)); + this(read(reader)); + } + + private UnloadChunkPacket(@NotNull UnloadChunkPacket other) { + this(other.chunkX(), other.chunkZ()); } @Override public void write(@NotNull NetworkBuffer writer) { - writer.write(INT, chunkX); + // Client reads this as a single long in big endian, so we have to write it backwards writer.write(INT, chunkZ); + writer.write(INT, chunkX); } @Override public int getId(@NotNull ConnectionState state) { return ServerPacketIdentifier.UNLOAD_CHUNK; } + + private static UnloadChunkPacket read(@NotNull NetworkBuffer reader) { + int z = reader.read(INT); + int x = reader.read(INT); + return new UnloadChunkPacket(x, z); + } } 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 5fc5a1318..94b95e265 100644 --- a/src/main/java/net/minestom/server/network/player/PlayerSocketConnection.java +++ b/src/main/java/net/minestom/server/network/player/PlayerSocketConnection.java @@ -347,21 +347,17 @@ public class PlayerSocketConnection extends PlayerConnection { if (event.isCancelled()) return; } // Write packet + // WARNING: A cached or framed packet will currently never go through writeServerPacketSync, + // so a state change inside one of them will never actually be triggered. Currently, cached + // packets are never used for packets that change state, so this is not a problem. if (packet instanceof ServerPacket serverPacket) { writeServerPacketSync(serverPacket, compressed); } else if (packet instanceof FramedPacket framedPacket) { var buffer = framedPacket.body(); - System.out.println("SEND " + getServerState() + " " + "UNKNOWN FRAMED"); writeBufferSync(buffer, 0, buffer.limit()); } else if (packet instanceof CachedPacket cachedPacket) { var buffer = cachedPacket.body(getServerState()); - if (buffer != null) { - var packetClass = cachedPacket.packet(getServerState()).getClass(); - if (packetClass != TimeUpdatePacket.class && packetClass != UpdateLightPacket.class && packetClass != ChunkDataPacket.class) { - System.out.println("SEND " + getServerState() + " " + cachedPacket.packet(getServerState()).getClass().getSimpleName()); - } - writeBufferSync(buffer, buffer.position(), buffer.remaining()); - } + if (buffer != null) writeBufferSync(buffer, buffer.position(), buffer.remaining()); else writeServerPacketSync(cachedPacket.packet(getServerState()), compressed); } else if (packet instanceof LazyPacket lazyPacket) { writeServerPacketSync(lazyPacket.packet(), compressed); @@ -381,12 +377,11 @@ public class PlayerSocketConnection extends PlayerConnection { try (var hold = ObjectPool.PACKET_POOL.hold()) { var state = getServerState(); var buffer = PacketUtils.createFramedPacket(state, hold.get(), serverPacket, compressed); - System.out.println("SEND " + getServerState() + " cls=" + serverPacket.getClass().getSimpleName() + " id=" + serverPacket.getId(getServerState())); writeBufferSync(buffer, 0, buffer.limit()); + // If this packet has a state change, apply it. var nextState = serverPacket.nextState(); if (nextState != null && state != nextState) { - System.out.println("CHANGE SERVER STATE TO " + nextState); setServerState(nextState); } }