fix: do not send login disconnect packet before switching to login state

This commit is contained in:
mworzala 2023-12-28 07:58:33 -05:00 committed by Matt Worzala
parent 8859af87ba
commit 6d5b1ea77e
1 changed files with 74 additions and 75 deletions

View File

@ -39,8 +39,21 @@ public final class HandshakeListener {
public static void listener(@NotNull ClientHandshakePacket packet, @NotNull PlayerConnection connection) {
String address = packet.serverAddress();
switch (packet.intent()) {
case 1 -> {
connection.setClientState(ConnectionState.STATUS);
connection.setServerState(ConnectionState.STATUS);
}
case 2 -> {
connection.setClientState(ConnectionState.LOGIN);
connection.setServerState(ConnectionState.LOGIN);
if (packet.protocolVersion() != MinecraftServer.PROTOCOL_VERSION) {
// Incorrect client version
disconnect(connection, INVALID_VERSION_TEXT);
}
// Bungee support (IP forwarding)
if (BungeeCordProxy.isEnabled() && connection instanceof PlayerSocketConnection socketConnection && packet.intent() == 2) {
if (BungeeCordProxy.isEnabled() && connection instanceof PlayerSocketConnection socketConnection) {
final String[] split = address.split("\00");
if (split.length == 3 || split.length == 4) {
@ -104,30 +117,16 @@ public final class HandshakeListener {
return;
}
}
if (connection instanceof PlayerSocketConnection) {
// Give to the connection the server info that the client used
((PlayerSocketConnection) connection).refreshServerInformation(address, packet.serverPort(), packet.protocolVersion());
}
switch (packet.intent()) {
case 1 -> {
connection.setClientState(ConnectionState.STATUS);
connection.setServerState(ConnectionState.STATUS);
}
case 2 -> {
if (packet.protocolVersion() == MinecraftServer.PROTOCOL_VERSION) {
connection.setClientState(ConnectionState.LOGIN);
connection.setServerState(ConnectionState.LOGIN);
} else {
// Incorrect client version
disconnect(connection, INVALID_VERSION_TEXT);
}
}
default -> {
// Unexpected error
}
}
if (connection instanceof PlayerSocketConnection) {
// Give to the connection the server info that the client used
((PlayerSocketConnection) connection).refreshServerInformation(address, packet.serverPort(), packet.protocolVersion());
}
}
private static void disconnect(@NotNull PlayerConnection connection, @NotNull Component reason) {