Search in sources :

Example 1 with ConnectionBridge_IpForward

use of org.spongepowered.common.bridge.network.ConnectionBridge_IpForward 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 2 with ConnectionBridge_IpForward

use of org.spongepowered.common.bridge.network.ConnectionBridge_IpForward in project SpongeCommon by SpongePowered.

the class ServerLoginPacketListenerImplMixin_IpForward method bungee$initUuid.

// Bungee
@Inject(method = "handleHello", at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerLoginPacketListenerImpl;gameProfile:Lcom/mojang/authlib/GameProfile;", opcode = Opcodes.PUTFIELD, ordinal = 0, shift = At.Shift.AFTER))
private void bungee$initUuid(final CallbackInfo ci) {
    if (!this.server.usesAuthentication() && SpongeConfigs.getCommon().get().ipForwarding.mode == IpForwardingCategory.Mode.LEGACY) {
        final UUID uuid;
        if (((ConnectionBridge_IpForward) this.connection).bungeeBridge$getSpoofedUUID() != null) {
            uuid = ((ConnectionBridge_IpForward) this.connection).bungeeBridge$getSpoofedUUID();
        } else {
            uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + this.gameProfile.getName()).getBytes(Charsets.UTF_8));
        }
        this.gameProfile = new GameProfile(uuid, this.gameProfile.getName());
        if (((ConnectionBridge_IpForward) this.connection).bungeeBridge$getSpoofedProfile() != null) {
            for (final Property property : ((ConnectionBridge_IpForward) this.connection).bungeeBridge$getSpoofedProfile()) {
                this.gameProfile.getProperties().put(property.getName(), property);
            }
        }
    }
}
Also used : GameProfile(com.mojang.authlib.GameProfile) UUID(java.util.UUID) Property(com.mojang.authlib.properties.Property) ConnectionBridge_IpForward(org.spongepowered.common.bridge.network.ConnectionBridge_IpForward) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

Inject (org.spongepowered.asm.mixin.injection.Inject)2 ConnectionBridge_IpForward (org.spongepowered.common.bridge.network.ConnectionBridge_IpForward)2 GameProfile (com.mojang.authlib.GameProfile)1 Property (com.mojang.authlib.properties.Property)1 InetSocketAddress (java.net.InetSocketAddress)1 UUID (java.util.UUID)1 Component (net.minecraft.network.chat.Component)1 TextComponent (net.minecraft.network.chat.TextComponent)1 ClientboundLoginDisconnectPacket (net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket)1 ConnectionAccessor (org.spongepowered.common.accessor.network.ConnectionAccessor)1 ClientIntentionPacketAccessor (org.spongepowered.common.accessor.network.protocol.handshake.ClientIntentionPacketAccessor)1