13
0
geforkt von Mirrors/Velocity

Properly block connecting to Velocity with legacy forwarding.

I also took the opportunity to improve the disconnect handling for
Disconnect messages from the server.
Dieser Commit ist enthalten in:
Andrew Steinborn 2018-08-26 18:18:02 -04:00
Ursprung 44c4221e19
Commit 1e178cfe2a
3 geänderte Dateien mit 23 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -208,7 +208,11 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
} else { } else {
logger.error("{}: disconnected while connecting to {}: {}", this, info.getName(), plainTextReason); logger.error("{}: disconnected while connecting to {}: {}", this, info.getName(), plainTextReason);
} }
handleConnectionException(info, disconnectReason); handleConnectionException(info, TextComponent.builder()
.content("Unable to connect to " + info.getName() + ": ")
.color(TextColor.RED)
.append(disconnectReason)
.build());
} }
public void handleConnectionException(ServerInfo info, Component disconnectReason) { public void handleConnectionException(ServerInfo info, Component disconnectReason) {

Datei anzeigen

@ -55,18 +55,27 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
case StateRegistry.LOGIN_ID: case StateRegistry.LOGIN_ID:
connection.setState(StateRegistry.LOGIN); connection.setState(StateRegistry.LOGIN);
connection.setProtocolVersion(handshake.getProtocolVersion()); connection.setProtocolVersion(handshake.getProtocolVersion());
if (!ProtocolConstants.isSupported(handshake.getProtocolVersion())) { if (!ProtocolConstants.isSupported(handshake.getProtocolVersion())) {
connection.closeWith(Disconnect.create(TranslatableComponent.of("multiplayer.disconnect.outdated_client"))); connection.closeWith(Disconnect.create(TranslatableComponent.of("multiplayer.disconnect.outdated_client")));
return; return;
} else {
InetAddress address = ((InetSocketAddress) connection.getChannel().remoteAddress()).getAddress();
if (!VelocityServer.getServer().getIpAttemptLimiter().attempt(address)) {
connection.closeWith(Disconnect.create(TextComponent.of("You are logging in too fast, try again later.")));
return;
}
VelocityServer.getServer().getEventManager().fireAndForget(new ConnectionHandshakeEvent(ic));
connection.setSessionHandler(new LoginSessionHandler(connection, ic));
} }
InetAddress address = ((InetSocketAddress) connection.getChannel().remoteAddress()).getAddress();
if (!VelocityServer.getServer().getIpAttemptLimiter().attempt(address)) {
connection.closeWith(Disconnect.create(TextComponent.of("You are logging in too fast, try again later.")));
return;
}
// Make sure legacy forwarding is not in use on this connection. Make sure that we do _not_ reject Forge,
// although Velocity does not yet support Forge.
if (handshake.getServerAddress().contains("\0") && !handshake.getServerAddress().endsWith("\0FML\0")) {
connection.closeWith(Disconnect.create(TextComponent.of("Running Velocity behind Velocity is unsupported.")));
return;
}
VelocityServer.getServer().getEventManager().fireAndForget(new ConnectionHandshakeEvent(ic));
connection.setSessionHandler(new LoginSessionHandler(connection, ic));
break; break;
default: default:
throw new IllegalArgumentException("Invalid state " + handshake.getNextStatus()); throw new IllegalArgumentException("Invalid state " + handshake.getNextStatus());

Datei anzeigen

@ -56,7 +56,7 @@ public class Handshake implements MinecraftPacket {
@Override @Override
public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) { public void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
this.protocolVersion = ProtocolUtils.readVarInt(buf); this.protocolVersion = ProtocolUtils.readVarInt(buf);
this.serverAddress = ProtocolUtils.readString(buf, 255); this.serverAddress = ProtocolUtils.readString(buf);
this.port = buf.readUnsignedShort(); this.port = buf.readUnsignedShort();
this.nextStatus = ProtocolUtils.readVarInt(buf); this.nextStatus = ProtocolUtils.readVarInt(buf);
} }