Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Finish Modern forwarding v2
Dieser Commit ist enthalten in:
Ursprung
3501969960
Commit
64bfa285fe
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package com.velocitypowered.proxy.connection.backend;
|
package com.velocitypowered.proxy.connection.backend;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
import com.velocitypowered.api.event.player.ServerLoginPluginMessageEvent;
|
import com.velocitypowered.api.event.player.ServerLoginPluginMessageEvent;
|
||||||
import com.velocitypowered.api.network.ProtocolVersion;
|
import com.velocitypowered.api.network.ProtocolVersion;
|
||||||
import com.velocitypowered.api.proxy.crypto.IdentifiedKey;
|
import com.velocitypowered.api.proxy.crypto.IdentifiedKey;
|
||||||
@ -79,9 +80,19 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
VelocityConfiguration configuration = server.getConfiguration();
|
VelocityConfiguration configuration = server.getConfiguration();
|
||||||
if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
|
if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
|
||||||
&& packet.getChannel().equals(VelocityConstants.VELOCITY_IP_FORWARDING_CHANNEL)) {
|
&& packet.getChannel().equals(VelocityConstants.VELOCITY_IP_FORWARDING_CHANNEL)) {
|
||||||
|
|
||||||
|
int proposedForwardingVersion = VelocityConstants.MODERN_FORWARDING_DEFAULT;
|
||||||
|
// Check version
|
||||||
|
if (packet.content().readableBytes() == 1) {
|
||||||
|
int requested = packet.content().readByte();
|
||||||
|
Preconditions.checkArgument(requested >= VelocityConstants.MODERN_FORWARDING_DEFAULT,
|
||||||
|
"Invalid modern forwarding version");
|
||||||
|
proposedForwardingVersion = Math.min(requested, VelocityConstants.MODERN_FORWARDING_WITH_KEY);
|
||||||
|
}
|
||||||
ByteBuf forwardingData = createForwardingData(configuration.getForwardingSecret(),
|
ByteBuf forwardingData = createForwardingData(configuration.getForwardingSecret(),
|
||||||
serverConn.getPlayerRemoteAddressAsString(),
|
serverConn.getPlayerRemoteAddressAsString(), serverConn.getPlayer().getGameProfile(),
|
||||||
serverConn.getPlayer().getGameProfile(), mc.getProtocolVersion(), serverConn.getPlayer().getIdentifiedKey());
|
serverConn.getPlayer().getIdentifiedKey(), proposedForwardingVersion);
|
||||||
|
|
||||||
LoginPluginResponse response = new LoginPluginResponse(packet.getId(), true, forwardingData);
|
LoginPluginResponse response = new LoginPluginResponse(packet.getId(), true, forwardingData);
|
||||||
mc.write(response);
|
mc.write(response);
|
||||||
informationForwarded = true;
|
informationForwarded = true;
|
||||||
@ -166,20 +177,22 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static ByteBuf createForwardingData(byte[] hmacSecret, String address,
|
private static ByteBuf createForwardingData(byte[] hmacSecret, String address,
|
||||||
GameProfile profile, ProtocolVersion version,
|
GameProfile profile, @Nullable IdentifiedKey playerKey,
|
||||||
@Nullable IdentifiedKey playerKey) {
|
int requestedVersion) {
|
||||||
ByteBuf forwarded = Unpooled.buffer(2048);
|
ByteBuf forwarded = Unpooled.buffer(2048);
|
||||||
try {
|
try {
|
||||||
int forwardingVersion = version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0 && playerKey != null
|
int actualVersion = requestedVersion >= VelocityConstants.MODERN_FORWARDING_WITH_KEY
|
||||||
? VelocityConstants.MODERN_FORWARDING_DEFAULT : VelocityConstants.MODERN_FORWARDING_DEFAULT;
|
? (playerKey != null ? requestedVersion : VelocityConstants.MODERN_FORWARDING_DEFAULT) : requestedVersion;
|
||||||
|
|
||||||
ProtocolUtils.writeVarInt(forwarded, forwardingVersion);
|
ProtocolUtils.writeVarInt(forwarded, actualVersion);
|
||||||
ProtocolUtils.writeString(forwarded, address);
|
ProtocolUtils.writeString(forwarded, address);
|
||||||
ProtocolUtils.writeUuid(forwarded, profile.getId());
|
ProtocolUtils.writeUuid(forwarded, profile.getId());
|
||||||
ProtocolUtils.writeString(forwarded, profile.getName());
|
ProtocolUtils.writeString(forwarded, profile.getName());
|
||||||
ProtocolUtils.writeProperties(forwarded, profile.getProperties());
|
ProtocolUtils.writeProperties(forwarded, profile.getProperties());
|
||||||
|
|
||||||
if (forwardingVersion >= VelocityConstants.MODERN_FORWARDING_WITH_KEY) {
|
// This serves as additional redundancy. The key normally is stored in the
|
||||||
|
// login start to the server, but some setups require this.
|
||||||
|
if (actualVersion >= VelocityConstants.MODERN_FORWARDING_WITH_KEY) {
|
||||||
ProtocolUtils.writePlayerKey(forwarded, playerKey);
|
ProtocolUtils.writePlayerKey(forwarded, playerKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren