From 1e1644f6d432cde79f3fc8cd3c76e5adf6d97fd9 Mon Sep 17 00:00:00 2001 From: cpw Date: Sun, 3 Nov 2019 12:33:03 -0500 Subject: [PATCH] A few tweaks to things. Make the mods command a bit better, make the IndexedMessageCodec actually log which network channel it got back packets on. Also, improve the custom directorymodlocator with actual custom names, finally, allow up to 99 log rollovers, up from 7 default (this means a repeatedly crashing server is less likely to roll out the log of the first crash). Signed-off-by: cpw --- build.gradle | 2 +- .../fml/loading/moddiscovery/ModDiscoverer.java | 1 + .../loading/moddiscovery/ModsFolderLocator.java | 15 +++++++++------ src/fmllauncher/resources/log4j2.xml | 1 + .../java/net/minecraftforge/fml/ModList.java | 2 +- .../fml/network/simple/IndexedMessageCodec.java | 16 +++++++++++++--- .../fml/network/simple/SimpleChannel.java | 2 +- .../server/command/CommandModList.java | 13 ++++++++++--- 8 files changed, 37 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index aad6837f5..175f18b37 100644 --- a/build.gradle +++ b/build.gradle @@ -409,7 +409,7 @@ project(':forge') { installer 'cpw.mods:grossjava9hacks:1.1.+' installer 'net.minecraftforge:accesstransformers:1.0.+:shadowed' installer 'net.minecraftforge:eventbus:1.0.+:service' - installer 'net.minecraftforge:forgespi:1.4.+' + installer 'net.minecraftforge:forgespi:1.5.+' installer 'net.minecraftforge:coremods:1.0.+' installer 'net.minecraftforge:unsafe:0.2.+' installer 'com.electronwill.night-config:core:3.6.0' diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModDiscoverer.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModDiscoverer.java index 2011c6185..55ef0fef6 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModDiscoverer.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModDiscoverer.java @@ -74,6 +74,7 @@ public class ModDiscoverer { public ModDiscoverer(Map arguments) { Launcher.INSTANCE.environment().computePropertyIfAbsent(Environment.Keys.MODFOLDERFACTORY.get(), v->ModsFolderLocator::new); + Launcher.INSTANCE.environment().computePropertyIfAbsent(Environment.Keys.MODDIRECTORYFACTORY.get(), v->ModsFolderLocator::new); Launcher.INSTANCE.environment().computePropertyIfAbsent(Environment.Keys.PROGRESSMESSAGE.get(), v->StartupMessageManager.locatorConsumer().orElseGet(()->s->{})); locatorClassLoader = new LocatorClassLoader(); Launcher.INSTANCE.environment().computePropertyIfAbsent(FMLEnvironment.Keys.LOCATORCLASSLOADER.get(), v->locatorClassLoader); diff --git a/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModsFolderLocator.java b/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModsFolderLocator.java index d2f37ac6a..1e3257e2e 100644 --- a/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModsFolderLocator.java +++ b/src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModsFolderLocator.java @@ -19,9 +19,9 @@ package net.minecraftforge.fml.loading.moddiscovery; +import net.minecraftforge.fml.loading.FMLPaths; import net.minecraftforge.fml.loading.ModDirTransformerDiscoverer; import net.minecraftforge.fml.loading.StringUtils; -import net.minecraftforge.fml.loading.FMLPaths; import net.minecraftforge.forgespi.locating.IModFile; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -43,16 +43,20 @@ public class ModsFolderLocator extends AbstractJarFileLocator { private static final String SUFFIX = ".jar"; private static final Logger LOGGER = LogManager.getLogger(); private final Path modFolder; + private final String customName; public ModsFolderLocator() { this(FMLPaths.MODSDIR.get()); } ModsFolderLocator(Path modFolder) { - super(); - this.modFolder = modFolder; + this(modFolder, "mods folder"); } + ModsFolderLocator(Path modFolder, String name) { + this.modFolder = modFolder; + this.customName = name; + } @Override public List scanMods() { LOGGER.debug(SCAN,"Scanning mods dir {} for mods", this.modFolder); @@ -68,16 +72,15 @@ public class ModsFolderLocator extends AbstractJarFileLocator { @Override public String name() { - return "mods folder"; + return customName; } @Override public String toString() { - return "{ModJarsFolder locator at "+this.modFolder+"}"; + return "{"+customName+" locator at "+this.modFolder+"}"; } @Override public void initArguments(final Map arguments) { - } } diff --git a/src/fmllauncher/resources/log4j2.xml b/src/fmllauncher/resources/log4j2.xml index 85ade7641..2f417be96 100644 --- a/src/fmllauncher/resources/log4j2.xml +++ b/src/fmllauncher/resources/log4j2.xml @@ -42,6 +42,7 @@ + diff --git a/src/main/java/net/minecraftforge/fml/ModList.java b/src/main/java/net/minecraftforge/fml/ModList.java index 83d350bb7..2b27506e0 100644 --- a/src/main/java/net/minecraftforge/fml/ModList.java +++ b/src/main/java/net/minecraftforge/fml/ModList.java @@ -209,7 +209,7 @@ public class ModList modFiles.stream().map(ModFileInfo::getFile).forEach(fileConsumer); } - private Stream applyForEachModFile(Function function) { + public Stream applyForEachModFile(Function function) { return modFiles.stream().map(ModFileInfo::getFile).map(function); } diff --git a/src/main/java/net/minecraftforge/fml/network/simple/IndexedMessageCodec.java b/src/main/java/net/minecraftforge/fml/network/simple/IndexedMessageCodec.java index ea8ceb81f..ab1619d73 100644 --- a/src/main/java/net/minecraftforge/fml/network/simple/IndexedMessageCodec.java +++ b/src/main/java/net/minecraftforge/fml/network/simple/IndexedMessageCodec.java @@ -23,11 +23,13 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; import it.unimi.dsi.fastutil.shorts.Short2ObjectArrayMap; import net.minecraft.network.PacketBuffer; import net.minecraftforge.fml.network.NetworkEvent; +import net.minecraftforge.fml.network.NetworkInstance; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.MarkerManager; +import java.util.Objects; import java.util.Optional; import java.util.function.BiConsumer; import java.util.function.Function; @@ -39,6 +41,14 @@ public class IndexedMessageCodec private static final Marker SIMPLENET = MarkerManager.getMarker("SIMPLENET"); private final Short2ObjectArrayMap> indicies = new Short2ObjectArrayMap<>(); private final Object2ObjectArrayMap, MessageHandler> types = new Object2ObjectArrayMap<>(); + private final NetworkInstance networkInstance; + + public IndexedMessageCodec() { + this(null); + } + public IndexedMessageCodec(final NetworkInstance instance) { + this.networkInstance = instance; + } @SuppressWarnings("unchecked") public MessageHandler findMessageType(final MSG msgToReply) { @@ -127,7 +137,7 @@ public class IndexedMessageCodec @SuppressWarnings("unchecked") MessageHandler messageHandler = (MessageHandler)types.get(message.getClass()); if (messageHandler == null) { - LOGGER.error(SIMPLENET, "Received invalid message {}", message.getClass().getName()); + LOGGER.error(SIMPLENET, "Received invalid message {} on channel {}", message.getClass().getName(), Optional.ofNullable(networkInstance).map(NetworkInstance::getChannelName).map(Objects::toString).orElse("MISSING CHANNEL")); throw new IllegalArgumentException("Invalid message "+message.getClass().getName()); } return tryEncode(target, message, messageHandler); @@ -135,13 +145,13 @@ public class IndexedMessageCodec void consume(PacketBuffer payload, int payloadIndex, Supplier context) { if (payload == null) { - LOGGER.error(SIMPLENET, "Received empty payload"); + LOGGER.error(SIMPLENET, "Received empty payload on channel {}", Optional.ofNullable(networkInstance).map(NetworkInstance::getChannelName).map(Objects::toString).orElse("MISSING CHANNEL")); return; } short discriminator = payload.readUnsignedByte(); final MessageHandler messageHandler = indicies.get(discriminator); if (messageHandler == null) { - LOGGER.error(SIMPLENET, "Received invalid discriminator byte {}", discriminator); + LOGGER.error(SIMPLENET, "Received invalid discriminator byte {} on channel {}", discriminator, Optional.ofNullable(networkInstance).map(NetworkInstance::getChannelName).map(Objects::toString).orElse("MISSING CHANNEL")); return; } tryDecode(payload, context, payloadIndex, messageHandler); diff --git a/src/main/java/net/minecraftforge/fml/network/simple/SimpleChannel.java b/src/main/java/net/minecraftforge/fml/network/simple/SimpleChannel.java index 060839880..1f5148708 100644 --- a/src/main/java/net/minecraftforge/fml/network/simple/SimpleChannel.java +++ b/src/main/java/net/minecraftforge/fml/network/simple/SimpleChannel.java @@ -51,7 +51,7 @@ public class SimpleChannel private SimpleChannel(NetworkInstance instance, Optional> registryChangeNotify) { this.instance = instance; - this.indexedCodec = new IndexedMessageCodec(); + this.indexedCodec = new IndexedMessageCodec(instance); this.loginPackets = new ArrayList<>(); instance.addListener(this::networkEventListener); instance.addGatherListener(this::networkLoginGather); diff --git a/src/main/java/net/minecraftforge/server/command/CommandModList.java b/src/main/java/net/minecraftforge/server/command/CommandModList.java index d9bfe5600..7d4bd7b33 100644 --- a/src/main/java/net/minecraftforge/server/command/CommandModList.java +++ b/src/main/java/net/minecraftforge/server/command/CommandModList.java @@ -24,6 +24,7 @@ import net.minecraft.command.CommandSource; import net.minecraft.command.Commands; import net.minecraft.util.text.TranslationTextComponent; import net.minecraftforge.fml.ModList; +import net.minecraftforge.fml.loading.moddiscovery.ModFileInfo; import net.minecraftforge.fml.loading.moddiscovery.ModInfo; import java.util.stream.Collectors; @@ -35,9 +36,15 @@ public class CommandModList { .requires(cs->cs.hasPermissionLevel(0)) //permission .executes(ctx -> { ctx.getSource().sendFeedback(new TranslationTextComponent("commands.forge.mods.list", - ModList.get().applyForEachModContainer( - mc->String.format("%s:%s(%s)", mc.getModId(), mc.getModInfo().getVersion().toString(), mc.getCurrentState())). - collect(Collectors.joining(","))), + ModList.get().applyForEachModFile(modFile -> + // locator - filename : firstmod (version) - numberofmods\n + String.format("%s %s : %s (%s) - %d", + modFile.getLocator().name().replace(' ', '_'), + modFile.getFileName(), + modFile.getModInfos().get(0).getModId(), + modFile.getModInfos().get(0).getVersion(), + modFile.getModInfos().size())). + collect(Collectors.joining("\n• ","• ", ""))), true); return 0; }