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;
}
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);
}
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;
});
}
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);
}
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");
}
Aggregations