diff --git a/build.gradle b/build.gradle index aeeed41f0..73f572fb6 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ sourceSets { srcDir 'src/autogenerated/java' } } - generation { + generators { java { srcDir 'src/generators/java' } diff --git a/src/main/java/net/minestom/server/MinecraftServer.java b/src/main/java/net/minestom/server/MinecraftServer.java index 6935810b2..061836253 100644 --- a/src/main/java/net/minestom/server/MinecraftServer.java +++ b/src/main/java/net/minestom/server/MinecraftServer.java @@ -142,7 +142,7 @@ public class MinecraftServer { // Registry try { - ResourceGatherer.ensureResourcesArePresent("1.15.2", null); // TODO: provide a way to give a path override, probably via launch arguments? + ResourceGatherer.ensureResourcesArePresent("1.16.1", null); // TODO: provide a way to give a path override, probably via launch arguments? } catch (IOException e) { LOGGER.error("An error happened during resource gathering. Minestom will attempt to load anyway, but things may not work, and crashes can happen.", e); } diff --git a/src/main/java/net/minestom/server/network/packet/client/handshake/HandshakePacket.java b/src/main/java/net/minestom/server/network/packet/client/handshake/HandshakePacket.java index b04a9722d..efe9a6a68 100644 --- a/src/main/java/net/minestom/server/network/packet/client/handshake/HandshakePacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/handshake/HandshakePacket.java @@ -1,9 +1,13 @@ package net.minestom.server.network.packet.client.handshake; +import net.minestom.server.MinecraftServer; +import net.minestom.server.chat.ChatColor; +import net.minestom.server.chat.ColoredText; import net.minestom.server.network.ConnectionManager; import net.minestom.server.network.ConnectionState; import net.minestom.server.network.packet.PacketReader; import net.minestom.server.network.packet.client.ClientPreplayPacket; +import net.minestom.server.network.packet.server.login.LoginDisconnect; import net.minestom.server.network.player.PlayerConnection; public class HandshakePacket implements ClientPreplayPacket { @@ -29,6 +33,10 @@ public class HandshakePacket implements ClientPreplayPacket { break; case 2: connection.setConnectionState(ConnectionState.LOGIN); + if (protocolVersion != MinecraftServer.PROTOCOL_VERSION) { + connection.sendPacket(new LoginDisconnect(ColoredText.of(ChatColor.RED, "Invalid Version").toString())); + connection.disconnect(); + } break; default: // Unexpected error diff --git a/src/main/java/net/minestom/server/network/packet/client/login/LoginStartPacket.java b/src/main/java/net/minestom/server/network/packet/client/login/LoginStartPacket.java index ffa5651b0..b60b05717 100644 --- a/src/main/java/net/minestom/server/network/packet/client/login/LoginStartPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/login/LoginStartPacket.java @@ -28,6 +28,7 @@ public class LoginStartPacket implements ClientPreplayPacket { //toLowerCase b/c there is a hack to change caps in your name if (pl.getUsername().toLowerCase().equals(username.toLowerCase())) { connection.sendPacket(new LoginDisconnect(ColoredText.of(ChatColor.RED, "You are already on this server").toString())); + connection.disconnect(); return; } } diff --git a/src/main/java/net/minestom/server/network/player/NettyPlayerConnection.java b/src/main/java/net/minestom/server/network/player/NettyPlayerConnection.java index ef7d81906..0e9d2465e 100644 --- a/src/main/java/net/minestom/server/network/player/NettyPlayerConnection.java +++ b/src/main/java/net/minestom/server/network/player/NettyPlayerConnection.java @@ -2,12 +2,10 @@ package net.minestom.server.network.player; import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; -import io.netty.channel.ChannelHandlerContext; import lombok.Getter; import net.minestom.server.extras.mojangAuth.Decrypter; import net.minestom.server.extras.mojangAuth.Encrypter; import net.minestom.server.extras.mojangAuth.MojangCrypt; -import io.netty.channel.ChannelPipeline; import io.netty.channel.socket.SocketChannel; import net.minestom.server.network.netty.codec.PacketCompressor; import net.minestom.server.network.packet.server.ServerPacket; @@ -25,6 +23,8 @@ public class NettyPlayerConnection extends PlayerConnection { private final SocketChannel channel; @Getter private boolean encrypted = false; + @Getter + private boolean compressed = false; public NettyPlayerConnection(SocketChannel channel) { super(); @@ -39,6 +39,7 @@ public class NettyPlayerConnection extends PlayerConnection { @Override public void enableCompression(int threshold) { + this.compressed = true; sendPacket(new SetCompressionPacket(threshold)); channel.pipeline().addAfter("framer", "compressor", new PacketCompressor(threshold)); } @@ -46,7 +47,7 @@ public class NettyPlayerConnection extends PlayerConnection { @Override public void sendPacket(ByteBuf buffer, boolean copy) { //System.out.println(getConnectionState() + " out"); - if (encrypted && copy) { + if ((encrypted || compressed) && copy) { buffer = buffer.copy(); buffer.retain(); channel.writeAndFlush(buffer); @@ -58,7 +59,7 @@ public class NettyPlayerConnection extends PlayerConnection { @Override public void writePacket(ByteBuf buffer, boolean copy) { - if (encrypted && copy) { + if ((encrypted || compressed) && copy) { buffer = buffer.copy(); buffer.retain(); channel.write(buffer); diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml index 15ff6dede..f8c195373 100644 --- a/src/main/resources/log4j2.xml +++ b/src/main/resources/log4j2.xml @@ -8,7 +8,7 @@ - + \ No newline at end of file