Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
feat: Add extra vHost data in ConnectionHandshakeEvent
Dieser Commit ist enthalten in:
Ursprung
6100e675af
Commit
3bb304b7e4
@ -20,10 +20,19 @@ public final class ConnectionHandshakeEvent {
|
|||||||
|
|
||||||
private final InboundConnection connection;
|
private final InboundConnection connection;
|
||||||
private final HandshakeIntent intent;
|
private final HandshakeIntent intent;
|
||||||
|
private final String extraDataInHandshake;
|
||||||
|
|
||||||
public ConnectionHandshakeEvent(InboundConnection connection, HandshakeIntent intent) {
|
/**
|
||||||
|
* Creates a new event.
|
||||||
|
*
|
||||||
|
* @param connection the inbound connection
|
||||||
|
* @param intent the intent of the handshake
|
||||||
|
* @param extraDataInHandshake the extra data in the handshake
|
||||||
|
*/
|
||||||
|
public ConnectionHandshakeEvent(InboundConnection connection, HandshakeIntent intent, String extraDataInHandshake) {
|
||||||
this.connection = Preconditions.checkNotNull(connection, "connection");
|
this.connection = Preconditions.checkNotNull(connection, "connection");
|
||||||
this.intent = Preconditions.checkNotNull(intent, "intent");
|
this.intent = Preconditions.checkNotNull(intent, "intent");
|
||||||
|
this.extraDataInHandshake = Preconditions.checkNotNull(extraDataInHandshake, "extraDataInHandshake");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,12 +40,13 @@ public final class ConnectionHandshakeEvent {
|
|||||||
* that have not yet updated their integration tests.
|
* that have not yet updated their integration tests.
|
||||||
*
|
*
|
||||||
* @param connection the inbound connection
|
* @param connection the inbound connection
|
||||||
* @deprecated use {@link #ConnectionHandshakeEvent(InboundConnection, HandshakeIntent)}
|
* @deprecated use {@link #ConnectionHandshakeEvent(InboundConnection, HandshakeIntent, String)}
|
||||||
*/
|
*/
|
||||||
@Deprecated(forRemoval = true)
|
@Deprecated(forRemoval = true)
|
||||||
public ConnectionHandshakeEvent(InboundConnection connection) {
|
public ConnectionHandshakeEvent(InboundConnection connection) {
|
||||||
this.connection = Preconditions.checkNotNull(connection, "connection");
|
this.connection = Preconditions.checkNotNull(connection, "connection");
|
||||||
this.intent = HandshakeIntent.LOGIN;
|
this.intent = HandshakeIntent.LOGIN;
|
||||||
|
this.extraDataInHandshake = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public InboundConnection getConnection() {
|
public InboundConnection getConnection() {
|
||||||
@ -47,6 +57,10 @@ public final class ConnectionHandshakeEvent {
|
|||||||
return this.intent;
|
return this.intent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getExtraDataInHandshake() {
|
||||||
|
return this.extraDataInHandshake;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ConnectionHandshakeEvent{"
|
return "ConnectionHandshakeEvent{"
|
||||||
|
@ -105,7 +105,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
|
|||||||
switch (nextState) {
|
switch (nextState) {
|
||||||
case STATUS -> connection.setActiveSessionHandler(StateRegistry.STATUS,
|
case STATUS -> connection.setActiveSessionHandler(StateRegistry.STATUS,
|
||||||
new StatusSessionHandler(server, ic));
|
new StatusSessionHandler(server, ic));
|
||||||
case LOGIN -> this.handleLogin(handshake, ic);
|
case LOGIN -> this.handleLogin(handshake, ic, getExtraVhostData(handshake.getServerAddress()));
|
||||||
default ->
|
default ->
|
||||||
// If you get this, it's a bug in Velocity.
|
// If you get this, it's a bug in Velocity.
|
||||||
throw new AssertionError("getStateForProtocol provided invalid state!");
|
throw new AssertionError("getStateForProtocol provided invalid state!");
|
||||||
@ -123,7 +123,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleLogin(HandshakePacket handshake, InitialInboundConnection ic) {
|
private void handleLogin(HandshakePacket handshake, InitialInboundConnection ic, String extraData) {
|
||||||
if (!handshake.getProtocolVersion().isSupported()) {
|
if (!handshake.getProtocolVersion().isSupported()) {
|
||||||
// Bump connection into correct protocol state so that we can send the disconnect packet.
|
// Bump connection into correct protocol state so that we can send the disconnect packet.
|
||||||
connection.setState(StateRegistry.LOGIN);
|
connection.setState(StateRegistry.LOGIN);
|
||||||
@ -157,7 +157,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
|
|||||||
|
|
||||||
final LoginInboundConnection lic = new LoginInboundConnection(ic);
|
final LoginInboundConnection lic = new LoginInboundConnection(ic);
|
||||||
server.getEventManager().fireAndForget(
|
server.getEventManager().fireAndForget(
|
||||||
new ConnectionHandshakeEvent(lic, handshake.getIntent()));
|
new ConnectionHandshakeEvent(lic, handshake.getIntent(), extraData));
|
||||||
connection.setActiveSessionHandler(StateRegistry.LOGIN,
|
connection.setActiveSessionHandler(StateRegistry.LOGIN,
|
||||||
new InitialLoginSessionHandler(server, connection, lic));
|
new InitialLoginSessionHandler(server, connection, lic));
|
||||||
}
|
}
|
||||||
@ -206,6 +206,23 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
|
|||||||
return cleaned;
|
return cleaned;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts the extra data from the specified hostname.
|
||||||
|
*
|
||||||
|
* @param hostname the host name to extract the extra data from
|
||||||
|
* @return the extra data
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
static String getExtraVhostData(String hostname) {
|
||||||
|
// Add extra data support
|
||||||
|
String data = "";
|
||||||
|
if (hostname.contains("\0")) {
|
||||||
|
String[] split = hostname.split("\0", 2);
|
||||||
|
data = "\0" + split[1];
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleGeneric(MinecraftPacket packet) {
|
public void handleGeneric(MinecraftPacket packet) {
|
||||||
// Unknown packet received. Better to close the connection.
|
// Unknown packet received. Better to close the connection.
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren