mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-31 21:48:08 +01:00
Add missing break and fix various things with the netty improvements made by WhileInside, add the disconnect during login packet currently only used for preventing multiple people with the same username from logging in when Mojang auth is enabled.
This commit is contained in:
parent
1f56bc10fc
commit
f04e8036fc
@ -716,6 +716,7 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
break;
|
||||
case SET_ACTION_BAR:
|
||||
titlePacket.actionBarText = text.toString();
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Invalid TitlePacket.Action type!");
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class NettyServer {
|
||||
channel = EpollServerSocketChannel.class;
|
||||
} else {
|
||||
boss = new NioEventLoopGroup(2);
|
||||
worker = new EpollEventLoopGroup();
|
||||
worker = new NioEventLoopGroup();
|
||||
|
||||
channel = NioServerSocketChannel.class;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@ -131,10 +132,10 @@ public class LegacyPingHandler extends ChannelInboundHandlerAdapter {
|
||||
private String formatResponse(int playerProtocol) {
|
||||
// todo server motd, online and slots
|
||||
final String motd = "Minestom";
|
||||
final String version = "1.15.2";
|
||||
final int online = 0;
|
||||
final int max = 1;
|
||||
final int protocol = 578; // 1.15.2
|
||||
final String version = "1.16.1";
|
||||
final int online = MinecraftServer.getConnectionManager().getOnlinePlayers().size();
|
||||
final int max = 0;
|
||||
final int protocol = MinecraftServer.PROTOCOL_VERSION; // 1.15.2
|
||||
|
||||
if (playerProtocol == -2) {
|
||||
return String.format(
|
||||
|
@ -39,6 +39,11 @@ public class EncryptionResponsePacket implements ClientPreplayPacket {
|
||||
String string3 = new BigInteger(MojangCrypt.digestData("", MinecraftServer.getKeyPair().getPublic(), getSecretKey())).toString(16);
|
||||
GameProfile gameProfile = MinecraftServer.getSessionService().hasJoinedServer(new GameProfile(null, connection.getLoginUsername()), string3);
|
||||
((NettyPlayerConnection) connection).setEncryptionKey(getSecretKey());
|
||||
int threshold = MinecraftServer.COMPRESSION_THRESHOLD;
|
||||
|
||||
if (threshold > 0) {
|
||||
connection.enableCompression(threshold);
|
||||
}
|
||||
LoginSuccessPacket loginSuccessPacket = new LoginSuccessPacket(gameProfile.getId(), gameProfile.getName());
|
||||
connection.sendPacket(loginSuccessPacket);
|
||||
MinecraftServer.getLOGGER().info("UUID of player {} is {}", connection.getLoginUsername(), gameProfile.getId());
|
||||
|
@ -1,5 +1,8 @@
|
||||
package net.minestom.server.network.packet.client.login;
|
||||
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.chat.ColoredText;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.extras.MojangAuth;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
@ -7,6 +10,7 @@ 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.EncryptionRequestPacket;
|
||||
import net.minestom.server.network.packet.server.login.LoginDisconnect;
|
||||
import net.minestom.server.network.packet.server.login.LoginSuccessPacket;
|
||||
import net.minestom.server.network.packet.server.login.SetCompressionPacket;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
@ -15,35 +19,42 @@ import java.util.UUID;
|
||||
|
||||
public class LoginStartPacket implements ClientPreplayPacket {
|
||||
|
||||
public String username;
|
||||
public String username;
|
||||
|
||||
@Override
|
||||
public void process(PlayerConnection connection, ConnectionManager connectionManager) {
|
||||
if (MojangAuth.isUsingMojangAuth()) {
|
||||
connection.setConnectionState(ConnectionState.LOGIN);
|
||||
@Override
|
||||
public void process(PlayerConnection connection, ConnectionManager connectionManager) {
|
||||
if (MojangAuth.isUsingMojangAuth()) {
|
||||
for (final Player pl : MinecraftServer.getConnectionManager().getOnlinePlayers()) {
|
||||
//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()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
connection.setConnectionState(ConnectionState.LOGIN);
|
||||
connection.setLoginUsername(username);
|
||||
EncryptionRequestPacket encryptionRequestPacket = new EncryptionRequestPacket(connection);
|
||||
connection.sendPacket(encryptionRequestPacket);
|
||||
} else {
|
||||
UUID playerUuid = connectionManager.getPlayerConnectionUuid(connection, username);
|
||||
|
||||
connection.setLoginUsername(username);
|
||||
EncryptionRequestPacket encryptionRequestPacket = new EncryptionRequestPacket(connection);
|
||||
connection.sendPacket(encryptionRequestPacket);
|
||||
} else {
|
||||
UUID playerUuid = connectionManager.getPlayerConnectionUuid(connection, username);
|
||||
int threshold = MinecraftServer.COMPRESSION_THRESHOLD;
|
||||
|
||||
int threshold = MinecraftServer.COMPRESSION_THRESHOLD;
|
||||
if (threshold > 0) {
|
||||
connection.enableCompression(threshold);
|
||||
}
|
||||
|
||||
if (threshold > 0) {
|
||||
connection.enableCompression(threshold);
|
||||
}
|
||||
LoginSuccessPacket successPacket = new LoginSuccessPacket(playerUuid, username);
|
||||
connection.sendPacket(successPacket);
|
||||
|
||||
LoginSuccessPacket successPacket = new LoginSuccessPacket(playerUuid, username);
|
||||
connection.sendPacket(successPacket);
|
||||
connection.setConnectionState(ConnectionState.PLAY);
|
||||
connectionManager.createPlayer(playerUuid, username, connection);
|
||||
}
|
||||
}
|
||||
|
||||
connection.setConnectionState(ConnectionState.PLAY);
|
||||
connectionManager.createPlayer(playerUuid, username, connection);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void read(PacketReader reader) {
|
||||
this.username = reader.readSizedString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(PacketReader reader) {
|
||||
this.username = reader.readSizedString();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
package net.minestom.server.network.packet.server.login;
|
||||
|
||||
import net.minestom.server.network.packet.PacketWriter;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
|
||||
public class LoginDisconnect implements ServerPacket {
|
||||
private String kickMessage;
|
||||
|
||||
public LoginDisconnect(String kickMessage) {
|
||||
this.kickMessage = kickMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketWriter writer) {
|
||||
writer.writeSizedString(kickMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
}
|
@ -33,40 +33,37 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
|
||||
public void setEncryptionKey(SecretKey secretKey) {
|
||||
this.encrypted = true;
|
||||
getChannel().pipeline().addBefore("decoder", "decrypt", new Decrypter(MojangCrypt.getCipher(2, secretKey)));
|
||||
getChannel().pipeline().addBefore("encoder", "encrypt", new Encrypter(MojangCrypt.getCipher(1, secretKey)));
|
||||
getChannel().pipeline().addBefore("framer", "decrypt", new Decrypter(MojangCrypt.getCipher(2, secretKey)));
|
||||
getChannel().pipeline().addBefore("framer", "encrypt", new Encrypter(MojangCrypt.getCipher(1, secretKey)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableCompression(int threshold) {
|
||||
sendPacket(new SetCompressionPacket(threshold));
|
||||
|
||||
channel.pipeline().addAfter("framer", "compressor", new PacketCompressor(threshold));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(ByteBuf buffer, boolean copy) {
|
||||
//System.out.println(getConnectionState() + " out");
|
||||
if (encrypted) {
|
||||
if (encrypted && copy) {
|
||||
buffer = buffer.copy();
|
||||
buffer.retain();
|
||||
channel.writeAndFlush(buffer);
|
||||
buffer.release();
|
||||
} else {
|
||||
buffer.retain();
|
||||
getChannel().writeAndFlush(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writePacket(ByteBuf buffer, boolean copy) {
|
||||
if (encrypted) {
|
||||
if (encrypted && copy) {
|
||||
buffer = buffer.copy();
|
||||
buffer.retain();
|
||||
channel.write(buffer);
|
||||
buffer.release();
|
||||
} else {
|
||||
buffer.retain();
|
||||
getChannel().write(buffer);
|
||||
}
|
||||
}
|
||||
@ -74,7 +71,6 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
@Override
|
||||
public void sendPacket(ServerPacket serverPacket) {
|
||||
//System.out.println(serverPacket.getClass().getName() + " out");
|
||||
//TODO check wat this does
|
||||
channel.writeAndFlush(serverPacket);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user