Re-add autocrafting calculation timeout setting

This commit is contained in:
raoulvdberge
2019-10-29 13:06:57 +01:00
parent d5997f8542
commit 9c0428a807
5 changed files with 25 additions and 47 deletions

View File

@@ -71,9 +71,6 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
public final class RS {
public static final String ID = "refinedstorage";
public static RS INSTANCE;
public RSOldConfig config = new RSOldConfig();
public static final NetworkHandler NETWORK_HANDLER = new NetworkHandler();
public static final ItemGroup MAIN_GROUP = new MainItemGroup();
public static final ServerConfig SERVER_CONFIG = new ServerConfig();

View File

@@ -1,17 +0,0 @@
package com.raoulvdberge.refinedstorage;
public class RSOldConfig {
//region Autocrafting
public int calculationTimeoutMs;
//endregion
//region Categories
private static final String AUTOCRAFTING = "autocrafting";
//endregion
/*private void loadConfig() {
//region Autocrafting
calculationTimeoutMs = config.getInt("calculationTimeoutMs", AUTOCRAFTING, 5000, 5000, Integer.MAX_VALUE, "The autocrafting calculation timeout in milliseconds, tasks taking longer than this to calculate (NOT execute) are cancelled to avoid server strain");
//endregion
}*/
}

View File

@@ -1,6 +1,7 @@
package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task;
import com.google.common.collect.Maps;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.api.autocrafting.*;
import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElementList;
@@ -373,10 +374,9 @@ public class CraftingTask implements ICraftingTask {
ICraftingPattern pattern,
boolean root) {
/* TODO
if (System.currentTimeMillis() - calculationStarted > RS.INSTANCE.config.calculationTimeoutMs) {
if (System.currentTimeMillis() - calculationStarted > RS.SERVER_CONFIG.getAutocrafting().getCalculationTimeoutMs()) {
return new CraftingTaskError(CraftingTaskErrorType.TOO_COMPLEX);
}*/
}
if (!patternsUsed.add(pattern)) {
return new CraftingTaskError(CraftingTaskErrorType.RECURSIVE, pattern);

View File

@@ -35,6 +35,7 @@ public class ServerConfig {
private CrafterManager crafterManager;
private CraftingMonitor craftingMonitor;
private WirelessCraftingMonitor wirelessCraftingMonitor;
private Autocrafting autocrafting;
public ServerConfig() {
upgrades = new Upgrades();
@@ -66,6 +67,7 @@ public class ServerConfig {
crafterManager = new CrafterManager();
craftingMonitor = new CraftingMonitor();
wirelessCraftingMonitor = new WirelessCraftingMonitor();
autocrafting = new Autocrafting();
spec = builder.build();
}
@@ -190,6 +192,10 @@ public class ServerConfig {
return wirelessCraftingMonitor;
}
public Autocrafting getAutocrafting() {
return autocrafting;
}
public class Controller {
private final ForgeConfigSpec.BooleanValue useEnergy;
private final ForgeConfigSpec.IntValue capacity;
@@ -905,4 +911,20 @@ public class ServerConfig {
return cancelAllUsage.get();
}
}
public class Autocrafting {
private final ForgeConfigSpec.IntValue calculationTimeoutMs;
public Autocrafting() {
builder.push("autocrafting");
calculationTimeoutMs = builder.comment("The autocrafting calculation timeout in milliseconds, crafting tasks taking longer than this to calculate are cancelled to avoid server strain").defineInRange("calculationTimeoutMs", 5000, 5000, Integer.MAX_VALUE);
builder.pop();
}
public int getCalculationTimeoutMs() {
return calculationTimeoutMs.get();
}
}
}

View File

@@ -1,24 +0,0 @@
public static MessageXXX decode(PacketBuffer buf) {
return new MessageXXX(
buf.readInt(),
buf.readInt(),
buf.readBoolean(),
buf.readString(),
buf.readInt()
);
}
public static void encode(MessageXXX message, PacketBuffer buf) {
buf.writeInt(message.compare);
buf.writeInt(message.mode);
buf.writeBoolean(message.modFilter);
buf.writeString(message.name);
buf.writeInt(message.type);
}
public static void handle(MessageXXX message, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
// XXX
});
ctx.get().setPacketHandled(true);
}