use of org.spongepowered.common.accessor.network.protocol.handshake.ClientIntentionPacketAccessor in project SpongeCommon by SpongePowered.
the class ServerHandshakePacketListenerImplMixin_IpForward method bungee$patchHandshake.
@Inject(method = "handleIntention", at = @At("HEAD"), cancellable = true)
private void bungee$patchHandshake(final ClientIntentionPacket packet, final CallbackInfo ci) {
if (SpongeConfigs.getCommon().get().ipForwarding.mode == IpForwardingCategory.Mode.LEGACY && packet.getIntention() == ConnectionProtocol.LOGIN) {
final String ip = ((ClientIntentionPacketAccessor) packet).accessor$hostName();
// ignore any extra data
final String[] split = ip.split("\00\\|", 2)[0].split("\00");
if (split.length == 3 || split.length == 4) {
((ClientIntentionPacketAccessor) packet).accessor$hostName(split[0]);
((ConnectionAccessor) this.connection).accessor$address(new InetSocketAddress(split[1], ((InetSocketAddress) this.connection.getRemoteAddress()).getPort()));
((ConnectionBridge_IpForward) this.connection).bungeeBridge$setSpoofedUUID(UUIDTypeAdapter.fromString(split[2]));
if (split.length == 4) {
((ConnectionBridge_IpForward) this.connection).bungeeBridge$setSpoofedProfile(ServerHandshakePacketListenerImplMixin_IpForward.ipForward$GSON.fromJson(split[3], Property[].class));
}
} else {
this.connection.setProtocol(ConnectionProtocol.LOGIN);
final Component error = new TextComponent("If you wish to use IP forwarding, please enable it in your BungeeCord config as well!").withStyle(ChatFormatting.RED);
this.connection.send(new ClientboundLoginDisconnectPacket(error));
this.connection.disconnect(error);
}
}
}
use of org.spongepowered.common.accessor.network.protocol.handshake.ClientIntentionPacketAccessor in project SpongeCommon by SpongePowered.
the class ServerHandshakePacketListenerImplMixin method impl$updateVersionAndHost.
@Inject(method = "handleIntention", at = @At("HEAD"))
private void impl$updateVersionAndHost(final ClientIntentionPacket packetIn, final CallbackInfo ci) {
final ConnectionBridge info = (ConnectionBridge) this.connection;
info.bridge$setVersion(packetIn.getProtocolVersion());
info.bridge$setVirtualHost(NetworkUtil.cleanVirtualHost(((ClientIntentionPacketAccessor) packetIn).accessor$hostName()), ((ClientIntentionPacketAccessor) packetIn).accessor$port());
}
Aggregations