Search in sources :

Example 1 with IMixinNetworkManager

use of org.spongepowered.common.interfaces.IMixinNetworkManager in project SpongeCommon by SpongePowered.

the class MixinNetHandlerHandshakeTCP method onProcessHandshakeStart.

@Inject(method = "processHandshake", at = @At(value = "HEAD"), cancellable = true)
public void onProcessHandshakeStart(C00Handshake packetIn, CallbackInfo ci) {
    if (SpongeImpl.getGlobalConfig().getConfig().getBungeeCord().getIpForwarding() && packetIn.getRequestedState().equals(EnumConnectionState.LOGIN)) {
        // ignore any extra data
        String[] split = packetIn.ip.split("\00\\|", 2)[0].split("\00");
        if (split.length == 3 || split.length == 4) {
            packetIn.ip = split[0];
            ((IMixinNetworkManager) this.networkManager).setRemoteAddress(new InetSocketAddress(split[1], ((InetSocketAddress) this.networkManager.getRemoteAddress()).getPort()));
            ((IMixinNetworkManager) this.networkManager).setSpoofedUUID(UUIDTypeAdapter.fromString(split[2]));
            if (split.length == 4) {
                ((IMixinNetworkManager) this.networkManager).setSpoofedProfile(gson.fromJson(split[3], Property[].class));
            }
        } else {
            TextComponentString chatcomponenttext = new TextComponentString("If you wish to use IP forwarding, please enable it in your BungeeCord config as well!");
            this.networkManager.sendPacket(new SPacketDisconnect(chatcomponenttext));
            this.networkManager.closeChannel(chatcomponenttext);
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) TextComponentString(net.minecraft.util.text.TextComponentString) IMixinNetworkManager(org.spongepowered.common.interfaces.IMixinNetworkManager) SPacketDisconnect(net.minecraft.network.login.server.SPacketDisconnect) TextComponentString(net.minecraft.util.text.TextComponentString) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with IMixinNetworkManager

use of org.spongepowered.common.interfaces.IMixinNetworkManager in project SpongeCommon by SpongePowered.

the class MixinNetHandlerHandshakeTCP method onProcessHandshake.

@Inject(method = "processHandshake", at = @At("HEAD"))
public void onProcessHandshake(C00Handshake packetIn, CallbackInfo ci) {
    IMixinNetworkManager info = (IMixinNetworkManager) this.networkManager;
    info.setVersion(packetIn.getProtocolVersion());
    info.setVirtualHost(NetworkUtil.cleanVirtualHost(packetIn.ip), packetIn.port);
}
Also used : IMixinNetworkManager(org.spongepowered.common.interfaces.IMixinNetworkManager) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with IMixinNetworkManager

use of org.spongepowered.common.interfaces.IMixinNetworkManager in project SpongeCommon by SpongePowered.

the class MixinNetHandlerLoginServer method initUuid.

@Inject(method = "processLoginStart", at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/NetHandlerLoginServer;" + "loginGameProfile:Lcom/mojang/authlib/GameProfile;", opcode = Opcodes.PUTFIELD, ordinal = 0, shift = At.Shift.AFTER))
public void initUuid(CallbackInfo ci) {
    if (!this.server.isServerInOnlineMode()) {
        UUID uuid;
        if (((IMixinNetworkManager) this.networkManager).getSpoofedUUID() != null) {
            uuid = ((IMixinNetworkManager) this.networkManager).getSpoofedUUID();
        } else {
            uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + this.loginGameProfile.getName()).getBytes(Charsets.UTF_8));
        }
        this.loginGameProfile = new GameProfile(uuid, this.loginGameProfile.getName());
        if (((IMixinNetworkManager) this.networkManager).getSpoofedProfile() != null) {
            for (Property property : ((IMixinNetworkManager) this.networkManager).getSpoofedProfile()) {
                this.loginGameProfile.getProperties().put(property.getName(), property);
            }
        }
    }
}
Also used : GameProfile(com.mojang.authlib.GameProfile) UUID(java.util.UUID) Property(com.mojang.authlib.properties.Property) IMixinNetworkManager(org.spongepowered.common.interfaces.IMixinNetworkManager) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

Inject (org.spongepowered.asm.mixin.injection.Inject)3 IMixinNetworkManager (org.spongepowered.common.interfaces.IMixinNetworkManager)3 GameProfile (com.mojang.authlib.GameProfile)1 Property (com.mojang.authlib.properties.Property)1 InetSocketAddress (java.net.InetSocketAddress)1 UUID (java.util.UUID)1 SPacketDisconnect (net.minecraft.network.login.server.SPacketDisconnect)1 TextComponentString (net.minecraft.util.text.TextComponentString)1