Search in sources :

Example 1 with ConnectionAccessor

use of org.spongepowered.common.accessor.network.ConnectionAccessor in project SpongeCommon by SpongePowered.

the class VelocityForwardingInfo method sendQuery.

public static void sendQuery(final ServerLoginPacketListenerImpl mcConn) {
    final EngineConnection conn = (EngineConnection) mcConn;
    VelocityChannel.CHANNEL.sendTo(conn, cbuf -> {
    }).whenComplete((response, error) -> {
        if (error != null) {
            if (error instanceof NoResponseException) {
                conn.close(Component.text("This server requires you to connect with Velocity."));
            }
            return;
        }
        if (!VelocityForwardingInfo.checkIntegrity(response)) {
            conn.close(Component.text("Unable to verify player details. Is your forwarding secret correct?"));
            return;
        }
        final ConnectionAccessor connectionAccessor = (ConnectionAccessor) mcConn.getConnection();
        connectionAccessor.accessor$address(new InetSocketAddress(VelocityForwardingInfo.readAddress(response), ((InetSocketAddress) mcConn.getConnection().getRemoteAddress()).getPort()));
        ((ServerLoginPacketListenerImplAccessor) mcConn).accessor$gameProfile(VelocityForwardingInfo.createProfile(response));
    }).exceptionally(err -> {
        if (!(err instanceof NoResponseException)) {
            // Handled above
            VelocityForwardingInfo.LOGGER.error("Failed to process velocity forwarding info", err);
            conn.close(Component.text("Invalid forwarding information received!"));
        }
        return null;
    });
}
Also used : MessageDigest(java.security.MessageDigest) GameProfile(com.mojang.authlib.GameProfile) SecretKeySpec(javax.crypto.spec.SecretKeySpec) FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) InetAddress(java.net.InetAddress) RawDataChannel(org.spongepowered.api.network.channel.raw.RawDataChannel) ByteBuf(io.netty.buffer.ByteBuf) Component(net.kyori.adventure.text.Component) Property(com.mojang.authlib.properties.Property) ResourceKey(org.spongepowered.api.ResourceKey) ServerLoginPacketListenerImpl(net.minecraft.server.network.ServerLoginPacketListenerImpl) EngineConnection(org.spongepowered.api.network.EngineConnection) NoResponseException(org.spongepowered.api.network.channel.NoResponseException) ServerLoginPacketListenerImplAccessor(org.spongepowered.common.accessor.server.network.ServerLoginPacketListenerImplAccessor) Sponge(org.spongepowered.api.Sponge) Mac(javax.crypto.Mac) InetSocketAddress(java.net.InetSocketAddress) StandardCharsets(java.nio.charset.StandardCharsets) ChannelBuf(org.spongepowered.api.network.channel.ChannelBuf) Logger(org.apache.logging.log4j.Logger) ChannelExceptionHandler(org.spongepowered.api.network.channel.ChannelExceptionHandler) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SpongeConfigs(org.spongepowered.common.applaunch.config.core.SpongeConfigs) ConnectionAccessor(org.spongepowered.common.accessor.network.ConnectionAccessor) InvalidKeyException(java.security.InvalidKeyException) InetAddresses(com.google.common.net.InetAddresses) LogManager(org.apache.logging.log4j.LogManager) RawHandshakeDataChannel(org.spongepowered.api.network.channel.raw.handshake.RawHandshakeDataChannel) InetSocketAddress(java.net.InetSocketAddress) EngineConnection(org.spongepowered.api.network.EngineConnection) ConnectionAccessor(org.spongepowered.common.accessor.network.ConnectionAccessor) NoResponseException(org.spongepowered.api.network.channel.NoResponseException)

Example 2 with ConnectionAccessor

use of org.spongepowered.common.accessor.network.ConnectionAccessor 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);
        }
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) ClientboundLoginDisconnectPacket(net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket) ClientIntentionPacketAccessor(org.spongepowered.common.accessor.network.protocol.handshake.ClientIntentionPacketAccessor) InetSocketAddress(java.net.InetSocketAddress) ConnectionAccessor(org.spongepowered.common.accessor.network.ConnectionAccessor) Component(net.minecraft.network.chat.Component) TextComponent(net.minecraft.network.chat.TextComponent) ConnectionBridge_IpForward(org.spongepowered.common.bridge.network.ConnectionBridge_IpForward) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with ConnectionAccessor

use of org.spongepowered.common.accessor.network.ConnectionAccessor in project SpongeCommon by SpongePowered.

the class ServerPlayerMixin method bridge$setLanguage.

@Override
public void bridge$setLanguage(final Locale language) {
    // Update locale on Channel, used for sending localized messages
    if (this.connection != null) {
        final Channel channel = ((ConnectionAccessor) this.connection.connection).accessor$channel();
        channel.attr(SpongeAdventure.CHANNEL_LOCALE).set(language);
        SpongeAdventure.forEachBossBar(bar -> {
            if (bar.getPlayers().contains(this)) {
                this.connection.send(new ClientboundBossEventPacket(ClientboundBossEventPacket.Operation.UPDATE_NAME, bar));
            }
        });
    }
    this.impl$language = language;
}
Also used : Channel(io.netty.channel.Channel) ClientboundBossEventPacket(net.minecraft.network.protocol.game.ClientboundBossEventPacket) ConnectionAccessor(org.spongepowered.common.accessor.network.ConnectionAccessor)

Aggregations

ConnectionAccessor (org.spongepowered.common.accessor.network.ConnectionAccessor)3 InetSocketAddress (java.net.InetSocketAddress)2 InetAddresses (com.google.common.net.InetAddresses)1 GameProfile (com.mojang.authlib.GameProfile)1 Property (com.mojang.authlib.properties.Property)1 ByteBuf (io.netty.buffer.ByteBuf)1 Channel (io.netty.channel.Channel)1 InetAddress (java.net.InetAddress)1 StandardCharsets (java.nio.charset.StandardCharsets)1 InvalidKeyException (java.security.InvalidKeyException)1 MessageDigest (java.security.MessageDigest)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Mac (javax.crypto.Mac)1 SecretKeySpec (javax.crypto.spec.SecretKeySpec)1 Component (net.kyori.adventure.text.Component)1 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)1 Component (net.minecraft.network.chat.Component)1 TextComponent (net.minecraft.network.chat.TextComponent)1 ClientboundBossEventPacket (net.minecraft.network.protocol.game.ClientboundBossEventPacket)1 ClientboundLoginDisconnectPacket (net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket)1