Search in sources :

Example 1 with ClientboundLoginDisconnectPacket

use of net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket in project MinecraftForge by MinecraftForge.

the class ServerLifecycleHooks method handleServerLogin.

public static boolean handleServerLogin(final ClientIntentionPacket packet, final Connection manager) {
    if (!allowLogins.get()) {
        TextComponent text = new TextComponent("Server is still starting! Please wait before reconnecting.");
        LOGGER.info(SERVERHOOKS, "Disconnecting Player (server is still starting): {}", text.getContents());
        manager.send(new ClientboundLoginDisconnectPacket(text));
        manager.disconnect(text);
        return false;
    }
    if (packet.getIntention() == ConnectionProtocol.LOGIN) {
        final ConnectionType connectionType = ConnectionType.forVersionFlag(packet.getFMLVersion());
        final int versionNumber = connectionType.getFMLVersionNumber(packet.getFMLVersion());
        if (connectionType == ConnectionType.MODDED && versionNumber != NetworkConstants.FMLNETVERSION) {
            rejectConnection(manager, connectionType, "This modded server is not impl compatible with your modded client. Please verify your Forge version closely matches the server. Got net version " + versionNumber + " this server is net version " + NetworkConstants.FMLNETVERSION);
            return false;
        }
        if (connectionType == ConnectionType.VANILLA && !NetworkRegistry.acceptsVanillaClientConnections()) {
            rejectConnection(manager, connectionType, "This server has mods that require Forge to be installed on the client. Contact your server admin for more details.");
            return false;
        }
    }
    if (packet.getIntention() == ConnectionProtocol.STATUS)
        return true;
    NetworkHooks.registerServerLoginChannel(manager, packet);
    return true;
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) ClientboundLoginDisconnectPacket(net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket) ConnectionType(net.minecraftforge.network.ConnectionType)

Example 2 with ClientboundLoginDisconnectPacket

use of net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket in project MinecraftForge by MinecraftForge.

the class ServerLifecycleHooks method rejectConnection.

private static void rejectConnection(final Connection manager, ConnectionType type, String message) {
    manager.setProtocol(ConnectionProtocol.LOGIN);
    LOGGER.info(SERVERHOOKS, "Disconnecting {} connection attempt: {}", type, message);
    TextComponent text = new TextComponent(message);
    manager.send(new ClientboundLoginDisconnectPacket(text));
    manager.disconnect(text);
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) ClientboundLoginDisconnectPacket(net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket)

Example 3 with ClientboundLoginDisconnectPacket

use of net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket 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)

Aggregations

TextComponent (net.minecraft.network.chat.TextComponent)3 ClientboundLoginDisconnectPacket (net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket)3 InetSocketAddress (java.net.InetSocketAddress)1 Component (net.minecraft.network.chat.Component)1 ConnectionType (net.minecraftforge.network.ConnectionType)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 ConnectionAccessor (org.spongepowered.common.accessor.network.ConnectionAccessor)1 ClientIntentionPacketAccessor (org.spongepowered.common.accessor.network.protocol.handshake.ClientIntentionPacketAccessor)1 ConnectionBridge_IpForward (org.spongepowered.common.bridge.network.ConnectionBridge_IpForward)1