Search in sources :

Example 1 with SPacketDisconnect

use of net.minecraft.network.login.server.SPacketDisconnect in project SpongeCommon by SpongePowered.

the class MixinNetHandlerLoginServer method closeConnection.

private void closeConnection(ITextComponent reason) {
    try {
        LOGGER.info("Disconnecting " + this.getConnectionInfo() + ": " + reason.getUnformattedText());
        this.networkManager.sendPacket(new SPacketDisconnect(reason));
        this.networkManager.closeChannel(reason);
    } catch (Exception exception) {
        LOGGER.error("Error whilst disconnecting player", exception);
    }
}
Also used : SPacketDisconnect(net.minecraft.network.login.server.SPacketDisconnect)

Example 2 with SPacketDisconnect

use of net.minecraft.network.login.server.SPacketDisconnect 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 3 with SPacketDisconnect

use of net.minecraft.network.login.server.SPacketDisconnect in project MinecraftForge by MinecraftForge.

the class FMLCommonHandler method handleServerHandshake.

/**
     * Process initial Handshake packet, kicks players from the server if they are connecting while we are starting up.
     * Also verifies the client has the FML marker.
     *
     * @param packet Handshake Packet
     * @param manager Network connection
     * @return True to allow connection, otherwise False.
     */
public boolean handleServerHandshake(C00Handshake packet, NetworkManager manager) {
    if (!shouldAllowPlayerLogins()) {
        TextComponentString text = new TextComponentString("Server is still starting! Please wait before reconnecting.");
        FMLLog.info("Disconnecting Player: " + text.getUnformattedText());
        manager.sendPacket(new SPacketDisconnect(text));
        manager.closeChannel(text);
        return false;
    }
    if (packet.getRequestedState() == EnumConnectionState.LOGIN && (!NetworkRegistry.INSTANCE.isVanillaAccepted(Side.CLIENT) && !packet.hasFMLMarker())) {
        manager.setConnectionState(EnumConnectionState.LOGIN);
        TextComponentString text = new TextComponentString("This server requires FML/Forge to be installed. Contact your server admin for more details.");
        FMLLog.info("Disconnecting Player: " + text.getUnformattedText());
        manager.sendPacket(new SPacketDisconnect(text));
        manager.closeChannel(text);
        return false;
    }
    manager.channel().attr(NetworkRegistry.FML_MARKER).set(packet.hasFMLMarker());
    return true;
}
Also used : SPacketDisconnect(net.minecraft.network.login.server.SPacketDisconnect) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

SPacketDisconnect (net.minecraft.network.login.server.SPacketDisconnect)3 TextComponentString (net.minecraft.util.text.TextComponentString)2 InetSocketAddress (java.net.InetSocketAddress)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 IMixinNetworkManager (org.spongepowered.common.interfaces.IMixinNetworkManager)1