mirror of
https://github.com/PaperMC/Velocity.git
synced 2026-02-17 14:37:43 +01:00
Backport IPv6 modern forwarding fix to Velocity 1.0.x
This commit is contained in:
@@ -21,6 +21,7 @@ import com.velocitypowered.proxy.protocol.packet.SetCompression;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -62,7 +63,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
response.setSuccess(true);
|
||||
response.setId(packet.getId());
|
||||
response.setData(createForwardingData(configuration.getForwardingSecret(),
|
||||
serverConn.getPlayer().getRemoteAddress().getHostString(),
|
||||
cleanRemoteAddress(serverConn.getPlayer().getRemoteAddress()),
|
||||
serverConn.getPlayer().getGameProfile()));
|
||||
mc.write(response);
|
||||
informationForwarded = true;
|
||||
@@ -123,6 +124,16 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
.completeExceptionally(new IOException("Unexpectedly disconnected from remote server"));
|
||||
}
|
||||
|
||||
private static String cleanRemoteAddress(InetSocketAddress address) {
|
||||
String addressString = address.getAddress().getHostAddress();
|
||||
int ipv6ScopeIdx = addressString.indexOf('%');
|
||||
if (ipv6ScopeIdx == -1) {
|
||||
return addressString;
|
||||
} else {
|
||||
return addressString.substring(0, ipv6ScopeIdx);
|
||||
}
|
||||
}
|
||||
|
||||
private static ByteBuf createForwardingData(byte[] hmacSecret, String address,
|
||||
GameProfile profile) {
|
||||
ByteBuf dataToForward = Unpooled.buffer();
|
||||
|
||||
Reference in New Issue
Block a user