kick for invalid version, use disconnect after kick packet, change logging level back to info, fix problem with compression on and encryption off.

This commit is contained in:
Eoghanmc22 2020-06-29 18:07:40 -04:00
parent a7c376a410
commit 3e740cf874
6 changed files with 17 additions and 7 deletions

View File

@ -22,7 +22,7 @@ sourceSets {
srcDir 'src/autogenerated/java'
}
}
generation {
generators {
java {
srcDir 'src/generators/java'
}

View File

@ -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);
}

View File

@ -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

View File

@ -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;
}
}

View File

@ -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);

View File

@ -8,7 +8,7 @@
<Loggers>
<Root level="trace">
<AppenderRef ref="STDOUT" level="debug"/>
<AppenderRef ref="STDOUT" level="info"/>
</Root>
</Loggers>
</Configuration>