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 <cpw+github@weeksfamily.ca>
This commit is contained in:
cpw 2019-11-03 12:33:03 -05:00
parent fab4ce894a
commit 1e1644f6d4
No known key found for this signature in database
GPG key ID: 8EB3DF749553B1B7
8 changed files with 37 additions and 15 deletions

View file

@ -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'

View file

@ -74,6 +74,7 @@ public class ModDiscoverer {
public ModDiscoverer(Map<String, ?> 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);

View file

@ -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<IModFile> 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<String, ?> arguments) {
}
}

View file

@ -42,6 +42,7 @@
<TimeBasedTriggeringPolicy/>
<OnStartupTriggeringPolicy/>
</Policies>
<DefaultRolloverStrategy max="99" fileIndex="min"/>
</RollingRandomAccessFile>
<RollingRandomAccessFile name="DebugFile" fileName="logs/debug.log" filePattern="logs/debug-%i.log.gz">
<PatternLayout pattern="[%d{ddMMMyyyy HH:mm:ss.SSS}] [%t/%level] [%logger/%markerSimpleName]: %minecraftFormatting{%msg}{strip}%n%xEx"/>

View file

@ -209,7 +209,7 @@ public class ModList
modFiles.stream().map(ModFileInfo::getFile).forEach(fileConsumer);
}
private <T> Stream<T> applyForEachModFile(Function<ModFile, T> function) {
public <T> Stream<T> applyForEachModFile(Function<ModFile, T> function) {
return modFiles.stream().map(ModFileInfo::getFile).map(function);
}

View file

@ -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<MessageHandler<?>> indicies = new Short2ObjectArrayMap<>();
private final Object2ObjectArrayMap<Class<?>, MessageHandler<?>> types = new Object2ObjectArrayMap<>();
private final NetworkInstance networkInstance;
public IndexedMessageCodec() {
this(null);
}
public IndexedMessageCodec(final NetworkInstance instance) {
this.networkInstance = instance;
}
@SuppressWarnings("unchecked")
public <MSG> MessageHandler<MSG> findMessageType(final MSG msgToReply) {
@ -127,7 +137,7 @@ public class IndexedMessageCodec
@SuppressWarnings("unchecked")
MessageHandler<MSG> messageHandler = (MessageHandler<MSG>)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<NetworkEvent.Context> 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);

View file

@ -51,7 +51,7 @@ public class SimpleChannel
private SimpleChannel(NetworkInstance instance, Optional<Consumer<NetworkEvent.ChannelRegistrationChangeEvent>> 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);

View file

@ -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;
}