Search in sources :

Example 1 with TextComponent

use of net.minecraft.network.chat.TextComponent 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 TextComponent

use of net.minecraft.network.chat.TextComponent 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 TextComponent

use of net.minecraft.network.chat.TextComponent in project MinecraftForge by MinecraftForge.

the class DimensionsCommand method register.

static ArgumentBuilder<CommandSourceStack, ?> register() {
    return Commands.literal("dimensions").requires(// permission
    cs -> cs.hasPermission(0)).executes(ctx -> {
        ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.dimensions.list"), true);
        final Registry<DimensionType> reg = ctx.getSource().registryAccess().registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY);
        Map<ResourceLocation, List<ResourceLocation>> types = new HashMap<>();
        for (ServerLevel dim : ctx.getSource().getServer().getAllLevels()) {
            types.computeIfAbsent(reg.getKey(dim.dimensionType()), k -> new ArrayList<>()).add(dim.dimension().location());
        }
        types.keySet().stream().sorted().forEach(key -> {
            ctx.getSource().sendSuccess(new TextComponent(key + ": " + types.get(key).stream().map(ResourceLocation::toString).sorted().collect(Collectors.joining(", "))), false);
        });
        return 0;
    });
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) CommandSourceStack(net.minecraft.commands.CommandSourceStack) Commands(net.minecraft.commands.Commands) HashMap(java.util.HashMap) DimensionType(net.minecraft.world.level.dimension.DimensionType) ServerLevel(net.minecraft.server.level.ServerLevel) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Registry(net.minecraft.core.Registry) TextComponent(net.minecraft.network.chat.TextComponent) List(java.util.List) Map(java.util.Map) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) ArgumentBuilder(com.mojang.brigadier.builder.ArgumentBuilder) TextComponent(net.minecraft.network.chat.TextComponent) DimensionType(net.minecraft.world.level.dimension.DimensionType) ServerLevel(net.minecraft.server.level.ServerLevel) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) HashMap(java.util.HashMap) ResourceLocation(net.minecraft.resources.ResourceLocation) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with TextComponent

use of net.minecraft.network.chat.TextComponent in project MinecraftForge by MinecraftForge.

the class HandshakeHandler method handleServerModListOnClient.

void handleServerModListOnClient(HandshakeMessages.S2CModList serverModList, Supplier<NetworkEvent.Context> c) {
    LOGGER.debug(FMLHSMARKER, "Logging into server with mod list [{}]", String.join(", ", serverModList.getModList()));
    boolean accepted = NetworkRegistry.validateClientChannels(serverModList.getChannels());
    c.get().setPacketHandled(true);
    if (!accepted) {
        LOGGER.error(FMLHSMARKER, "Terminating connection with server, mismatched mod list");
        c.get().getNetworkManager().disconnect(new TextComponent("Connection closed - mismatched mod channel list"));
        return;
    }
    NetworkConstants.handshakeChannel.reply(new HandshakeMessages.C2SModListReply(), c.get());
    LOGGER.debug(FMLHSMARKER, "Accepted server connection");
    // Set the modded marker on the channel so we know we got packets
    c.get().getNetworkManager().channel().attr(NetworkConstants.FML_NETVERSION).set(NetworkConstants.NETVERSION);
    c.get().getNetworkManager().channel().attr(NetworkConstants.FML_CONNECTION_DATA).set(new ConnectionData(serverModList.getModList(), serverModList.getChannels()));
    this.registriesToReceive = new HashSet<>(serverModList.getRegistries());
    this.registrySnapshots = Maps.newHashMap();
    LOGGER.debug(REGISTRIES, "Expecting {} registries: {}", () -> this.registriesToReceive.size(), () -> this.registriesToReceive);
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent)

Example 5 with TextComponent

use of net.minecraft.network.chat.TextComponent in project MinecraftForge by MinecraftForge.

the class HandshakeHandler method handleClientModListOnServer.

void handleClientModListOnServer(HandshakeMessages.C2SModListReply clientModList, Supplier<NetworkEvent.Context> c) {
    LOGGER.debug(FMLHSMARKER, "Received client connection with modlist [{}]", String.join(", ", clientModList.getModList()));
    boolean accepted = NetworkRegistry.validateServerChannels(clientModList.getChannels());
    c.get().getNetworkManager().channel().attr(NetworkConstants.FML_CONNECTION_DATA).set(new ConnectionData(clientModList.getModList(), clientModList.getChannels()));
    c.get().setPacketHandled(true);
    if (!accepted) {
        LOGGER.error(FMLHSMARKER, "Terminating connection with client, mismatched mod list");
        c.get().getNetworkManager().disconnect(new TextComponent("Connection closed - mismatched mod channel list"));
        return;
    }
    LOGGER.debug(FMLHSMARKER, "Accepted client connection mod list");
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent)

Aggregations

TextComponent (net.minecraft.network.chat.TextComponent)19 Component (net.minecraft.network.chat.Component)4 List (java.util.List)3 Minecraft (net.minecraft.client.Minecraft)3 CommandSourceStack (net.minecraft.commands.CommandSourceStack)3 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)3 ServerPlayer (net.minecraft.server.level.ServerPlayer)3 AbstractContainerMenu (net.minecraft.world.inventory.AbstractContainerMenu)3 Commands (net.minecraft.commands.Commands)2 ClientboundOpenScreenPacket (net.minecraft.network.protocol.game.ClientboundOpenScreenPacket)2 ClientboundLoginDisconnectPacket (net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 Player (net.minecraft.world.entity.player.Player)2 ForgeI18n (net.minecraftforge.common.ForgeI18n)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2 Strings (com.google.common.base.Strings)1 Maps (com.google.common.collect.Maps)1 Multimap (com.google.common.collect.Multimap)1 PoseStack (com.mojang.blaze3d.vertex.PoseStack)1 ArgumentBuilder (com.mojang.brigadier.builder.ArgumentBuilder)1