Update the configuration system to be more easily extensible and better documented, save input capture state between UI close/reopen, add multiple client-side configurable input capture modes, implement default state setting for capture input mode. Fix edge case terminal bug. Implement ICMP as a native library.

This commit is contained in:
JacksonAbney
2025-04-20 16:22:44 -08:00
parent 7a2db0fb45
commit b6ca653ba3
79 changed files with 934 additions and 429 deletions

1
.gitignore vendored
View File

@@ -30,6 +30,7 @@ logs
# Files from Forge MDK
forge*changelog.txt
/src/generated/
/src/main/resources/natives/
#vscode
.vscode

View File

@@ -1,3 +1,5 @@
import org.apache.commons.io.IOUtils
plugins {
id "idea"
id "maven-publish"
@@ -15,7 +17,7 @@ allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile).tap {
configureEach {
options.compilerArgs << "-Xmaxerrs" << "1000"
options.compilerArgs << "-Xmaxerrs" << "1000" << "-h" << ("${layout.buildDirectory.get().toString().replace("\\", "/")}/c" as String)
}
}
}
@@ -137,6 +139,36 @@ dependencies {
System.setProperty("line.separator", "\n")
def nativeLibsDir = file("src/main/resources/natives")
tasks.register("downloadNativeLibs") {
group = "build setup"
doLast {
def repo = "North-Western-Development/oc2r-native-networking"
def baseUrl = "https://github.com/${repo}/releases/latest/download/"
def targets = [
"macos/liboc2rnet-x86_64.dylib",
"macos/liboc2rnet-arm64.dylib",
"windows/oc2rnet-x86_64.dll",
"windows/oc2rnet-arm64.dll",
"linux/liboc2rnet-linux-x86_64.so",
"linux/liboc2rnet-linux-arm64.so"
]
targets.each { path ->
def file = new File(nativeLibsDir, path)
file.parentFile.mkdirs()
def fileName = path.tokenize('/')[-1]
def url = new URL("${baseUrl}${fileName}")
println "Downloading ${url} → ${file}"
file.withOutputStream { out ->
url.openStream().withCloseable { IOUtils.copy(it, out) }
}
}
}
}
tasks.register('packageScripts', Zip) {
archiveFileName = "scripts.zip"
destinationDirectory = file("${layout.buildDirectory.get()}/resources/main/data/oc2r/file_systems")
@@ -152,6 +184,7 @@ tasks.register('copyLicensesToResources', Copy) {
processResources.dependsOn(packageScripts)
processResources.dependsOn(copyLicensesToResources)
processResources.dependsOn(downloadNativeLibs)
tasks.named('jarJar'){
}

View File

@@ -14,6 +14,7 @@ import li.cil.oc2.client.renderer.entity.RobotRenderer;
import li.cil.oc2.client.renderer.entity.model.RobotModel;
import li.cil.oc2.common.block.Blocks;
import li.cil.oc2.common.blockentity.BlockEntities;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.container.Containers;
import li.cil.oc2.common.entity.Entities;
import net.minecraft.client.gui.screens.MenuScreens;
@@ -26,9 +27,12 @@ import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import org.jetbrains.annotations.Nullable;
@SuppressWarnings("unused")
public final class ClientSetup {
@Nullable private static Boolean captureInputState = null;
@SubscribeEvent
public static void handleSetupEvent(final FMLClientSetupEvent event) {
BusInterfaceNameRenderer.initialize();
@@ -58,6 +62,7 @@ public final class ClientSetup {
@SubscribeEvent
public static void handleModelRegistryEvent(final RegisterGeometryLoaders event) {
if (Blocks.BUS_CABLE.getId() == null) throw new RuntimeException("Null bus cable ID");
event.register(Blocks.BUS_CABLE.getId().toString().replace("oc2r:", ""), new BusCableModelLoader());
}
@@ -84,4 +89,16 @@ public final class ClientSetup {
public static void handleRegisterLayerDefinitionsEvent(final EntityRenderersEvent.RegisterLayerDefinitions event) {
event.registerLayerDefinition(RobotModel.ROBOT_MODEL_LAYER, RobotModel::createRobotLayer);
}
public static boolean getCaptureInputState() {
if (captureInputState == null) {
captureInputState = Config.captureInputDefaultState;
}
return captureInputState;
}
public static void setCaptureInputState(final boolean value) {
captureInputState = value;
}
}

View File

@@ -30,7 +30,6 @@ public abstract class AbstractMachineTerminalScreen<T extends AbstractMachineTer
private static final int CONTROLS_TOP = 8;
private static final int ENERGY_TOP = CONTROLS_TOP + Sprites.SIDEBAR_3.height + 4;
private boolean mouseClicked;
private final MachineTerminalWidget terminalWidget;
@@ -170,12 +169,13 @@ public abstract class AbstractMachineTerminalScreen<T extends AbstractMachineTer
@Override
public void onPress() {
super.onPress();
terminalWidget.isInputCaptureEnabled = !terminalWidget.isInputCaptureEnabled;
getMenu().toggleCaptureInputState();
}
@Override
public boolean isToggled() {
return terminalWidget.isInputCaptureEnabled;
return getMenu().getCaptureInputState();
}
}).withTooltip(
Component.translatable(Constants.TERMINAL_CAPTURE_INPUT_CAPTION),

View File

@@ -4,7 +4,7 @@ package li.cil.oc2.client.gui;
import com.mojang.blaze3d.platform.InputConstants;
import li.cil.oc2.client.gui.widget.ToggleImageButton;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.Constants;
import li.cil.oc2.common.container.AbstractMonitorContainer;
import li.cil.oc2.common.util.TooltipUtils;
@@ -129,12 +129,13 @@ public abstract class AbstractMonitorDisplayScreen<T extends AbstractMonitorCont
@Override
public void onPress() {
super.onPress();
monitorDisplayWidget.isInputCaptureEnabled = !monitorDisplayWidget.isInputCaptureEnabled;
getMenu().toggleCaptureInputState();
}
@Override
public boolean isToggled() {
return monitorDisplayWidget.isInputCaptureEnabled;
return getMenu().getCaptureInputState();
}
}).withTooltip(
Component.translatable(Constants.TERMINAL_CAPTURE_INPUT_CAPTION),

View File

@@ -26,8 +26,6 @@ import java.nio.charset.StandardCharsets;
@OnlyIn(Dist.CLIENT)
public final class MachineTerminalWidget {
public boolean isInputCaptureEnabled;
private static final int TERMINAL_WIDTH = Terminal.WIDTH * Terminal.CHAR_WIDTH / 2;
private static final int TERMINAL_HEIGHT = Terminal.HEIGHT * Terminal.CHAR_HEIGHT / 2;
@@ -302,7 +300,7 @@ public final class MachineTerminalWidget {
}
private boolean shouldCaptureInput() {
return isMouseOverTerminal && isInputCaptureEnabled &&
return isMouseOverTerminal && container.getCaptureInputState() &&
container.getVirtualMachine().isRunning();
}

View File

@@ -24,8 +24,6 @@ import javax.annotation.Nullable;
@OnlyIn(Dist.CLIENT)
public final class MonitorDisplayWidget {
public boolean isInputCaptureEnabled;
private static final int TERMINAL_WIDTH = Terminal.WIDTH * Terminal.CHAR_WIDTH / 2;
private static final int TERMINAL_HEIGHT = Terminal.HEIGHT * Terminal.CHAR_HEIGHT / 2;
@@ -144,7 +142,7 @@ public final class MonitorDisplayWidget {
}
private boolean shouldCaptureInput() {
return isMouseOverTerminal && isInputCaptureEnabled;
return isMouseOverTerminal && container.getCaptureInputState();
}
private boolean isMouseOverTerminal(final int mouseX, final int mouseY) {

View File

@@ -1,95 +0,0 @@
/* SPDX-License-Identifier: MIT */
package li.cil.oc2.common;
import li.cil.oc2.common.ConfigManager.Path;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Tiers;
import net.minecraftforge.common.TierSortingRegistry;
import java.util.UUID;
@SuppressWarnings("FieldMayBeFinal")
public final class Config {
//TODO: Implement configuration of CPU MHzs
@Path("vm") public static long maxAllocatedMemory = 512 * Constants.MEGABYTE;
@Path("vm") public static int diskSizeFactor = 2 * Constants.MEGABYTE;
@Path("energy.blocks") public static double busCableEnergyPerTick = 0.1;
@Path("energy.blocks") public static double busInterfaceEnergyPerTick = 0.5;
@Path("energy.blocks") public static int computerEnergyPerTick = 10;
@Path("energy.blocks") public static int computerEnergyStorage = 2000;
@Path("energy.blocks") public static int chargerEnergyPerTick = 2500;
@Path("energy.blocks") public static int chargerEnergyStorage = 10000;
@Path("energy.blocks") public static int projectorEnergyPerTick = 20;
@Path("energy.blocks") public static int projectorEnergyStorage = 2000;
@Path("energy.blocks") public static int monitorEnergyPerTick = 15;
@Path("energy.blocks") public static int monitorEnergyStorage = 2000;
@Path("energy.blocks") public static int cardCageEnergyPerTick = 20;
@Path("energy.blocks") public static int cardCageEnergyStorage = 2000;
@Path("energy.blocks") public static int gatewayEnergyPerPacket = 20;
@Path("energy.blocks") public static int gatewayEnergyStorage = 2000;
@Path("energy.entities") public static int robotEnergyPerTick = 5;
@Path("energy.entities") public static int robotEnergyStorage = 750000;
@Path("energy.items") public static double memoryEnergyPerMegabytePerTick = 0.5;
@Path("energy.items") public static double hardDriveEnergyPerMegabytePerTick = 1;
@Path("energy.items") public static double cpuEnergyPerMegahertzPerTick = 0.1;
@Path("energy.items") public static int redstoneInterfaceCardEnergyPerTick = 1;
@Path("energy.items") public static int networkInterfaceEnergyPerTick = 1;
@Path("energy.items") public static int fileImportExportCardEnergyPerTick = 1;
@Path("energy.items") public static int soundCardEnergyPerTick = 1;
@Path("energy.items") public static int blockOperationsModuleEnergyPerTick = 2;
@Path("energy.items") public static int inventoryOperationsModuleEnergyPerTick = 1;
@Path("energy.items") public static int networkTunnelEnergyPerTick = 2;
@Path("gameplay") public static ResourceLocation blockOperationsModuleToolTier = TierSortingRegistry.getName(Tiers.DIAMOND);
@Path("gameplay") public static long soundCardCoolDownSeconds = 2;
@Path("admin") public static UUID fakePlayerUUID = UUID.fromString("e39dd9a7-514f-4a2d-aa5e-b6030621416d");
@Path("admin.network") public static int projectorAverageMaxBytesPerSecond = 160 * 1024;
@Path("admin.virtual_network") public static int ethernetFrameTimeToLive = 12;
@Path("admin.virtual_network") public static int hubEthernetFramesPerTick = 32;
@Path("vxlan") public static boolean enable = false;
@Path("vxlan") public static String remoteHost = "::1";
@Path("vxlan") public static int remotePort = 4789;
@Path("vxlan") public static String bindHost = "::1";
@Path("vxlan") public static int bindPort = 4789;
@Path("internet-card") public static boolean internetCardEnabled = false;
@Path("internet-card") public static int defaultSessionLifetimeMs = 60 * 1000;
@Path("internet-card") public static int defaultSessionsNumberPerCardLimit = 10;
@Path("internet-card") public static int defaultSessionsNumberLimit = 100;
@Path("internet-card") public static int defaultEchoRequestTimeoutMs = 1000;
@Path("internet-card") public static String deniedHosts =
"127.0.0.0/8, 10.0.0.0/8, 100.64.0.0/10, 172.16.0.0/12, 192.168.0.0/16, 224.0.0.0/4";
@Path("internet-card") public static String allowedHosts = "";
@Path("internet-card") public static String defaultNameServer = "1.1.1.1";
@Path("internet-card") public static boolean useSynchronisedNAT = false;
@Path("internet-card") public static int streamBufferSize = 2000;
@Path("internet-card") public static int tcpRetransmissionTimeoutMs = 2 * 1000;
public static boolean computersUseEnergy() {
return computerEnergyPerTick > 0 && computerEnergyStorage > 0;
}
public static boolean projectorsUseEnergy() {
return projectorEnergyStorage > 0 && projectorEnergyPerTick > 0;
}
public static boolean cardCagesUseEnergy() {
return cardCageEnergyStorage > 0 && cardCageEnergyPerTick > 0;
}
public static boolean robotsUseEnergy() {
return robotEnergyPerTick > 0 && robotEnergyStorage > 0;
}
public static boolean monitorsUseEnergy() {
return computerEnergyPerTick > 0 && computerEnergyStorage > 0;
}
public static boolean gatewayUseEnergy() {
return gatewayEnergyPerPacket > 0 && gatewayEnergyStorage > 0;
}
}

View File

@@ -3,251 +3,25 @@
package li.cil.oc2.common;
import li.cil.oc2.api.API;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.ForgeConfigSpec;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.config.client.ClientSpec;
import li.cil.oc2.common.config.common.CommonSpec;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.IConfigSpec;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.config.ModConfigEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.annotation.Nullable;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.function.Function;
import java.util.function.Supplier;
@SuppressWarnings("unused")
@Mod.EventBusSubscriber(modid = API.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public final class ConfigManager {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Type {
ModConfig.Type value() default ModConfig.Type.COMMON;
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Path {
String value() default "";
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Min {
double value() default 0;
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Max {
double value() default Double.POSITIVE_INFINITY;
}
///////////////////////////////////////////////////////////////////
private static final Logger LOGGER = LogManager.getLogger();
///////////////////////////////////////////////////////////////////
private static final Map<Class<?>, ConfigFieldParser> PARSERS = new HashMap<>();
private static final Map<IConfigSpec<ForgeConfigSpec>, ConfigDefinition> CONFIGS = new HashMap<>();
static {
PARSERS.put(int.class, ConfigManager::parseIntField);
PARSERS.put(short.class, ConfigManager::parseShortField);
PARSERS.put(long.class, ConfigManager::parseLongField);
PARSERS.put(double.class, ConfigManager::parseDoubleField);
PARSERS.put(String.class, ConfigManager::parseStringField);
PARSERS.put(UUID.class, ConfigManager::parseUUIDField);
PARSERS.put(ResourceLocation.class, ConfigManager::parseResourceLocationField);
PARSERS.put(boolean.class, ConfigManager::parseBooleanField);
}
///////////////////////////////////////////////////////////////////
public static <T> void add(final Supplier<T> factory) {
final ArrayList<ConfigFieldPair<?>> values = new ArrayList<>();
final Pair<?, ForgeConfigSpec> config = new ForgeConfigSpec.Builder().configure(builder -> {
final T instance = factory.get();
fillSpec(instance, builder, values);
return instance;
});
CONFIGS.put(config.getValue(), new ConfigDefinition(config.getKey(), values));
}
public static void initialize(FMLJavaModLoadingContext context) {
CONFIGS.forEach((spec, config) -> {
final Type typeAnnotation = config.instance.getClass().getAnnotation(Type.class);
final ModConfig.Type configType = typeAnnotation != null ? typeAnnotation.value() : ModConfig.Type.COMMON;
context.registerConfig(configType, spec);
});
}
///////////////////////////////////////////////////////////////////
@SubscribeEvent
public static void handleModConfigEvent(final ModConfigEvent event) {
final ConfigDefinition config = CONFIGS.get(event.getConfig().getSpec());
if (config != null) {
config.apply();
final ModConfig.Type config = event.getConfig().getType();
if (config == ModConfig.Type.CLIENT) {
ClientSpec.loadValues();
}
}
///////////////////////////////////////////////////////////////////
private static <T> void fillSpec(final T instance, final ForgeConfigSpec.Builder builder, final ArrayList<ConfigFieldPair<?>> values) {
for (final Field field : instance.getClass().getFields()) {
parseField(instance, builder, values, field);
}
}
private static <T> void parseField(final T instance, final ForgeConfigSpec.Builder builder, final ArrayList<ConfigFieldPair<?>> values, final Field field) {
final ConfigFieldParser parser = PARSERS.get(field.getType());
if (parser != null) {
final Path pathAnnotation = field.getAnnotation(Path.class);
final String path = getPath(pathAnnotation.value(), field);
try {
values.add(parser.apply(instance, field, path, builder));
} catch (final IllegalAccessException e) {
LOGGER.error("Failed accessing field [{}.{}], ignoring.", field.getDeclaringClass().getName(), field.getName());
}
}
}
private static ConfigFieldPair<?> parseIntField(final Object instance, final Field field, final String path, final ForgeConfigSpec.Builder builder) throws IllegalAccessException {
final int defaultValue = field.getInt(instance);
final int minValue = (int) Math.max(getMin(field), Integer.MIN_VALUE);
final int maxValue = (int) Math.min(getMax(field), Integer.MAX_VALUE);
final ForgeConfigSpec.IntValue configValue = builder.defineInRange(path, defaultValue, minValue, maxValue);
return new ConfigFieldPair<>(field, configValue);
}
private static ConfigFieldPair<?> parseShortField(final Object instance, final Field field, final String path, final ForgeConfigSpec.Builder builder) throws IllegalAccessException {
final short defaultValue = field.getShort(instance);
final short minValue = (short) Math.max(getMin(field), Short.MIN_VALUE);
final short maxValue = (short) Math.min(getMax(field), Short.MAX_VALUE);
final ForgeConfigSpec.IntValue configValue = builder.defineInRange(path, defaultValue, minValue, maxValue);
return new ConfigFieldPair<>(field, configValue);
}
private static ConfigFieldPair<?> parseLongField(final Object instance, final Field field, final String path, final ForgeConfigSpec.Builder builder) throws IllegalAccessException {
final long defaultValue = field.getLong(instance);
final long minValue = (long) Math.max(getMin(field), Long.MIN_VALUE);
final long maxValue = (long) Math.min(getMax(field), Long.MAX_VALUE);
final ForgeConfigSpec.LongValue configValue = builder.defineInRange(path, defaultValue, minValue, maxValue);
return new ConfigFieldPair<>(field, configValue);
}
private static ConfigFieldPair<?> parseDoubleField(final Object instance, final Field field, final String path, final ForgeConfigSpec.Builder builder) throws IllegalAccessException {
final double defaultValue = field.getDouble(instance);
final double minValue = getMin(field);
final double maxValue = getMax(field);
final ForgeConfigSpec.DoubleValue configValue = builder.defineInRange(path, defaultValue, minValue, maxValue);
return new ConfigFieldPair<>(field, configValue);
}
private static ConfigFieldPair<?> parseStringField(final Object instance, final Field field, final String path, final ForgeConfigSpec.Builder builder) throws IllegalAccessException {
final String defaultValue = (String) field.get(instance);
final ForgeConfigSpec.ConfigValue<String> configValue = builder.define(path, defaultValue);
return new ConfigFieldPair<>(field, configValue);
}
private static ConfigFieldPair<?> parseUUIDField(final Object instance, final Field field, final String path, final ForgeConfigSpec.Builder builder) throws IllegalAccessException {
final UUID defaultValue = (UUID) field.get(instance);
final ForgeConfigSpec.ConfigValue<String> configValue = builder.define(path, defaultValue.toString());
return new ConfigFieldPair<>(field, configValue, UUID::fromString);
}
private static ConfigFieldPair<?> parseBooleanField(final Object instance, final Field field, final String path, final ForgeConfigSpec.Builder builder) throws IllegalAccessException {
final boolean defaultValue = (boolean) field.get(instance);
final ForgeConfigSpec.ConfigValue<Boolean> configValue = builder.define(path, defaultValue);
return new ConfigFieldPair<>(field, configValue);
}
private static ConfigFieldPair<?> parseResourceLocationField(final Object instance, final Field field, final String path, final ForgeConfigSpec.Builder builder) throws IllegalAccessException {
final ResourceLocation defaultValue = (ResourceLocation) field.get(instance);
final ForgeConfigSpec.ConfigValue<String> configValue = builder.define(path, defaultValue.toString());
return new ConfigFieldPair<>(field, configValue, ResourceLocation::parse);
}
private static String getPath(@Nullable final String prefix, final Field field) {
return (prefix != null ? prefix + "." : "") + field.getName();
}
private static double getMin(final Field field) {
final Min minAnnotation = field.getAnnotation(Min.class);
return minAnnotation != null ? minAnnotation.value() : 0;
}
private static double getMax(final Field field) {
final Max maxAnnotation = field.getAnnotation(Max.class);
return maxAnnotation != null ? maxAnnotation.value() : Double.POSITIVE_INFINITY;
}
///////////////////////////////////////////////////////////////////
@FunctionalInterface
private interface ConfigFieldParser {
ConfigFieldPair<?> apply(final Object instance, final Field field, final String path, final ForgeConfigSpec.Builder builder) throws IllegalAccessException;
}
private record ConfigDefinition(Object instance, ArrayList<ConfigFieldPair<?>> values) {
public void apply() {
for (final ConfigFieldPair<?> pair : values) {
pair.apply(instance);
}
}
}
private static final class ConfigFieldPair<T> {
public final Field field;
public final ForgeConfigSpec.ConfigValue<T> value;
private final Function<T, Object> converter;
public ConfigFieldPair(final Field field, final ForgeConfigSpec.ConfigValue<T> value, final Function<T, Object> converter) {
this.field = field;
this.value = value;
this.converter = converter;
}
public ConfigFieldPair(final Field field, final ForgeConfigSpec.ConfigValue<T> value) {
this(field, value, x -> x);
}
public void apply(final Object instance) {
try {
field.set(instance, converter.apply(value.get()));
} catch (final IllegalAccessException ignored) {
}
else {
CommonSpec.loadValues();
System.out.println(Config.captureInputMode);
}
}
}

View File

@@ -13,6 +13,8 @@ import li.cil.oc2.common.bus.device.DeviceTypes;
import li.cil.oc2.common.bus.device.data.BlockDeviceDataRegistry;
import li.cil.oc2.common.bus.device.data.FirmwareRegistry;
import li.cil.oc2.common.bus.device.provider.ProviderRegistry;
import li.cil.oc2.common.config.client.ClientSpec;
import li.cil.oc2.common.config.common.CommonSpec;
import li.cil.oc2.common.container.Containers;
import li.cil.oc2.common.entity.Entities;
import li.cil.oc2.common.item.ItemGroup;
@@ -28,8 +30,16 @@ import li.cil.sedna.Sedna;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
@Mod(API.MOD_ID)
public final class Main {
public Main(FMLJavaModLoadingContext context) {
@@ -39,8 +49,8 @@ public final class Main {
DeviceTreeProviders.initialize();
Serializers.initialize();
ConfigManager.add(Config::new);
ConfigManager.initialize(context);
context.registerConfig(ModConfig.Type.COMMON, CommonSpec.CONFIG_SPEC);
context.registerConfig(ModConfig.Type.CLIENT, ClientSpec.CLIENT_CONFIG_SPEC);
RegistryUtils.begin();
@@ -68,5 +78,58 @@ public final class Main {
context.getModEventBus().register(ClientSetup.class));
ItemGroup.TAB_REGISTER.register(context.getModEventBus());
NativeLoader.loadLibrary();
}
public static class NativeLoader {
public static void loadLibrary() {
String os = System.getProperty("os.name").toLowerCase();
String arch = System.getProperty("os.arch").toLowerCase();
String platform;
String libName;
String fileNameArch = getArchString(arch);
if (os.contains("mac")) {
platform = "macos";
libName = "liboc2rnet-" + fileNameArch + ".dylib";
} else if (os.contains("win")) {
platform = "windows";
libName = "oc2rnet-"+ fileNameArch + ".dll";
} else if (os.contains("nux") || os.contains("nix")) {
platform = "linux";
libName = "liboc2rnet-linux-" + fileNameArch + ".so";
} else {
throw new UnsupportedOperationException("Unsupported OS: " + os);
}
String resourcePath = "/natives/" + platform + "/" + libName;
try {
Path tempFile = extractToTemp(resourcePath);
System.load(tempFile.toAbsolutePath().toString());
} catch (IOException e) {
throw new RuntimeException("Failed to load native library: " + resourcePath, e);
}
}
private static String getArchString(String arch) {
if (arch.equals("amd64")) {
return "x86_64";
} else if (arch.equals("aarch64")) {
return "arm64";
} else {
throw new UnsupportedOperationException("Unsupported architecture: " + arch);
}
}
private static Path extractToTemp(String resourcePath) throws IOException {
try (InputStream in = NativeLoader.class.getResourceAsStream(resourcePath)) {
if (in == null) throw new FileNotFoundException("Resource not found: " + resourcePath);
Path local = Path.of(System.getProperty("user.dir"), System.mapLibraryName("oc2rnet"));
Files.copy(in, local, StandardCopyOption.REPLACE_EXISTING);
return local;
}
}
}
}

View File

@@ -4,7 +4,7 @@ package li.cil.oc2.common.block;
import li.cil.oc2.api.bus.device.DeviceTypes;
import li.cil.oc2.api.capabilities.RedstoneEmitter;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.blockentity.BlockEntities;
import li.cil.oc2.common.blockentity.ComputerBlockEntity;
import li.cil.oc2.common.blockentity.TickableBlockEntity;

View File

@@ -2,7 +2,7 @@
package li.cil.oc2.common.block;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.blockentity.BlockEntities;
import li.cil.oc2.common.blockentity.MonitorBlockEntity;
import li.cil.oc2.common.blockentity.TickableBlockEntity;

View File

@@ -2,7 +2,7 @@
package li.cil.oc2.common.block;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.blockentity.BlockEntities;
import li.cil.oc2.common.blockentity.TickableBlockEntity;
import li.cil.oc2.common.util.VoxelShapeUtils;

View File

@@ -2,7 +2,7 @@
package li.cil.oc2.common.block;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.blockentity.BlockEntities;
import li.cil.oc2.common.blockentity.TickableBlockEntity;
import li.cil.oc2.common.util.VoxelShapeUtils;

View File

@@ -5,7 +5,7 @@ package li.cil.oc2.common.blockentity;
import li.cil.oc2.api.bus.DeviceBus;
import li.cil.oc2.api.bus.DeviceBusElement;
import li.cil.oc2.client.model.BusCableBakedModel;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.Constants;
import li.cil.oc2.common.block.BusCableBlock;
import li.cil.oc2.common.bus.AbstractBlockDeviceBusElement;

View File

@@ -4,7 +4,7 @@ package li.cil.oc2.common.blockentity;
import li.cil.oc2.api.bus.device.object.Callback;
import li.cil.oc2.api.bus.device.object.NamedDevice;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.Constants;
import li.cil.oc2.common.capabilities.Capabilities;
import li.cil.oc2.common.energy.FixedEnergyStorage;

View File

@@ -8,7 +8,7 @@ import li.cil.oc2.api.bus.device.DeviceTypes;
import li.cil.oc2.api.bus.device.provider.ItemDeviceQuery;
import li.cil.oc2.api.capabilities.TerminalUserProvider;
import li.cil.oc2.client.audio.LoopingSoundManager;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.block.ComputerBlock;
import li.cil.oc2.common.bus.AbstractBlockDeviceBusElement;
import li.cil.oc2.common.bus.BlockDeviceBusController;
@@ -18,6 +18,7 @@ import li.cil.oc2.common.capabilities.Capabilities;
import li.cil.oc2.common.container.ComputerInventoryContainer;
import li.cil.oc2.common.container.ComputerTerminalContainer;
import li.cil.oc2.common.energy.FixedEnergyStorage;
import li.cil.oc2.common.ext.ICaptureInputStateStorage;
import li.cil.oc2.common.network.Network;
import li.cil.oc2.common.network.message.ComputerBootErrorMessage;
import li.cil.oc2.common.network.message.ComputerBusStateMessage;
@@ -50,7 +51,7 @@ import java.util.*;
import static li.cil.oc2.common.Constants.BLOCK_ENTITY_TAG_NAME_IN_ITEM;
import static li.cil.oc2.common.Constants.ITEMS_TAG_NAME;
public final class ComputerBlockEntity extends ModBlockEntity implements TerminalUserProvider, TickableBlockEntity {
public final class ComputerBlockEntity extends ModBlockEntity implements TerminalUserProvider, TickableBlockEntity, ICaptureInputStateStorage {
private static final String BUS_ELEMENT_TAG_NAME = "busElement";
private static final String DEVICES_TAG_NAME = "devices";
private static final String TERMINAL_TAG_NAME = "terminal";
@@ -79,6 +80,7 @@ public final class ComputerBlockEntity extends ModBlockEntity implements Termina
private final FixedEnergyStorage energy = new FixedEnergyStorage(Config.computerEnergyStorage);
private final ComputerVirtualMachine virtualMachine = new ComputerVirtualMachine(new BlockDeviceBusController(busElement, Config.computerEnergyPerTick, this), deviceItems::getDeviceAddressBase);
private final Set<Player> terminalUsers = Collections.newSetFromMap(new WeakHashMap<>());
private boolean captureInputState;
///////////////////////////////////////////////////////////////////
@@ -101,6 +103,16 @@ public final class ComputerBlockEntity extends ModBlockEntity implements Termina
return deviceItems;
}
@Override
public boolean getCaptureInputState() {
return captureInputState;
}
@Override
public void setCaptureInputState(boolean value) {
this.captureInputState = value;
}
public void start() {
if (level != null && !level.isClientSide()) {
virtualMachine.start();

View File

@@ -6,7 +6,7 @@ import java.util.Deque;
import javax.annotation.Nullable;
import li.cil.oc2.api.capabilities.NetworkInterface;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.Constants;
import li.cil.oc2.common.capabilities.Capabilities;
import li.cil.oc2.common.energy.FixedEnergyStorage;

View File

@@ -3,7 +3,7 @@
package li.cil.oc2.common.blockentity;
import li.cil.oc2.client.renderer.MonitorGUIRenderer;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.block.MonitorBlock;
import li.cil.oc2.common.bus.device.DeviceGroup;
import li.cil.oc2.common.bus.device.vm.block.KeyboardDevice;
@@ -11,6 +11,7 @@ import li.cil.oc2.common.bus.device.vm.block.MonitorDevice;
import li.cil.oc2.common.capabilities.Capabilities;
import li.cil.oc2.common.container.MonitorDisplayContainer;
import li.cil.oc2.common.energy.FixedEnergyStorage;
import li.cil.oc2.common.ext.ICaptureInputStateStorage;
import li.cil.oc2.common.network.MonitorLoadBalancer;
import li.cil.oc2.common.network.Network;
import li.cil.oc2.common.network.message.*;
@@ -43,7 +44,7 @@ import java.util.zip.Inflater;
import static li.cil.oc2.common.bus.device.vm.block.MonitorDevice.HEIGHT;
import static li.cil.oc2.common.bus.device.vm.block.MonitorDevice.WIDTH;
public final class MonitorBlockEntity extends ModBlockEntity implements TickableBlockEntity {
public final class MonitorBlockEntity extends ModBlockEntity implements TickableBlockEntity, ICaptureInputStateStorage {
@FunctionalInterface
public interface FrameConsumer {
void processFrame(final Picture picture);
@@ -88,6 +89,8 @@ public final class MonitorBlockEntity extends ModBlockEntity implements Tickable
private final H264Encoder encoder = new H264Encoder(new CQPRateControl(12));
private final ByteBuffer encoderBuffer = ByteBuffer.allocateDirect(WIDTH * HEIGHT * SimpleFramebufferDevice.STRIDE);
private boolean captureInputState;
///////////////////////////////////////////////////////////////////
public void setRequiresKeyframe() {
@@ -110,6 +113,16 @@ public final class MonitorBlockEntity extends ModBlockEntity implements Tickable
keyboardDevice.sendKeyEvent(keycode, isDown);
}
@Override
public boolean getCaptureInputState() {
return captureInputState;
}
@Override
public void setCaptureInputState(boolean value) {
this.captureInputState = value;
}
@Nullable
private ByteBuffer encodeFrame() {
final boolean hasChanges = monitorDevice.applyChanges(picture);

View File

@@ -4,7 +4,7 @@ package li.cil.oc2.common.blockentity;
import li.cil.oc2.api.capabilities.NetworkInterface;
import li.cil.oc2.client.renderer.NetworkCableRenderer;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.block.NetworkConnectorBlock;
import li.cil.oc2.common.capabilities.Capabilities;
import li.cil.oc2.common.item.Items;

View File

@@ -3,7 +3,7 @@
package li.cil.oc2.common.blockentity;
import li.cil.oc2.api.capabilities.NetworkInterface;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.Constants;
import li.cil.oc2.common.capabilities.Capabilities;
import li.cil.oc2.common.util.LazyOptionalUtils;

View File

@@ -2,7 +2,7 @@
package li.cil.oc2.common.blockentity;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.block.PciCardCageBlock;
import li.cil.oc2.common.bus.device.vm.block.PciCardCageDevice;
import li.cil.oc2.common.capabilities.Capabilities;

View File

@@ -2,7 +2,7 @@
package li.cil.oc2.common.blockentity;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.block.ProjectorBlock;
import li.cil.oc2.common.bus.device.vm.block.ProjectorDevice;
import li.cil.oc2.common.capabilities.Capabilities;

View File

@@ -1,7 +1,7 @@
package li.cil.oc2.common.blockentity;
import li.cil.oc2.api.capabilities.NetworkInterface;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.Constants;
import li.cil.oc2.common.capabilities.Capabilities;
import li.cil.oc2.common.util.LazyOptionalUtils;
@@ -50,6 +50,7 @@ public final class VxlanBlockEntity extends ModBlockEntity implements NetworkInt
}
@Override
@Nullable
public byte[] readEthernetFrame() {
return null;
}

View File

@@ -25,7 +25,7 @@ public final class FirmwareRegistry {
///////////////////////////////////////////////////////////////////
public static final RegistryObject<Firmware> BUILDROOT = INITIALIZER.register("buildroot", BuildrootFirmware::new);
public static final RegistryObject<Firmware> MINUX = INITIALIZER.register("minux", MinuxFirmware::new);
///////////////////////////////////////////////////////////////////

View File

@@ -10,12 +10,11 @@ import net.minecraft.network.chat.Component;
import java.io.IOException;
public final class BuildrootFirmware implements Firmware {
public final class MinuxFirmware implements Firmware {
@Override
public boolean run(final MemoryMap memory, final long startAddress) {
try {
MemoryMaps.store(memory, startAddress, Buildroot.getFirmware());
//MemoryMaps.store(memory, startAddress + 0x200000, BuildrootFirmware.class.getClassLoader().getResourceAsStream("generated/ociivrkernel.bin"));
MemoryMaps.store(memory, startAddress + 0x200000, Buildroot.getLinuxImage());
return true;
} catch (final IOException e) {
@@ -25,6 +24,6 @@ public final class BuildrootFirmware implements Firmware {
@Override
public Component getDisplayName() {
return Component.literal("Sedna Linux");
return Component.literal("Minux");
}
}

View File

@@ -4,7 +4,7 @@ package li.cil.oc2.common.bus.device.provider.item;
import li.cil.oc2.api.bus.device.ItemDevice;
import li.cil.oc2.api.bus.device.provider.ItemDeviceQuery;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.bus.device.provider.util.AbstractItemDeviceProvider;
import li.cil.oc2.common.bus.device.rpc.item.BlockOperationsModuleDevice;
import li.cil.oc2.common.capabilities.Capabilities;

View File

@@ -2,7 +2,7 @@ package li.cil.oc2.common.bus.device.provider.item;
import li.cil.oc2.api.bus.device.ItemDevice;
import li.cil.oc2.api.bus.device.provider.ItemDeviceQuery;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.bus.device.provider.util.AbstractItemDeviceProvider;
import li.cil.oc2.common.bus.device.rpc.item.CPUItemDevice;
import li.cil.oc2.common.item.CPUItem;

View File

@@ -5,7 +5,7 @@ package li.cil.oc2.common.bus.device.provider.item;
import li.cil.oc2.api.bus.device.ItemDevice;
import li.cil.oc2.api.bus.device.provider.ItemDeviceQuery;
import li.cil.oc2.api.capabilities.TerminalUserProvider;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.bus.device.provider.util.AbstractItemDeviceProvider;
import li.cil.oc2.common.bus.device.rpc.item.FileImportExportCardItemDevice;
import li.cil.oc2.common.capabilities.Capabilities;

View File

@@ -4,7 +4,7 @@ package li.cil.oc2.common.bus.device.provider.item;
import li.cil.oc2.api.bus.device.ItemDevice;
import li.cil.oc2.api.bus.device.provider.ItemDeviceQuery;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.Constants;
import li.cil.oc2.common.bus.device.provider.util.AbstractItemDeviceProvider;
import li.cil.oc2.common.bus.device.vm.item.HardDriveDevice;

View File

@@ -5,7 +5,7 @@ package li.cil.oc2.common.bus.device.provider.item;
import li.cil.oc2.api.bus.device.ItemDevice;
import li.cil.oc2.api.bus.device.data.BlockDeviceData;
import li.cil.oc2.api.bus.device.provider.ItemDeviceQuery;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.Constants;
import li.cil.oc2.common.bus.device.provider.util.AbstractItemDeviceProvider;
import li.cil.oc2.common.bus.device.vm.item.HardDriveDeviceWithInitialData;

View File

@@ -2,7 +2,7 @@ package li.cil.oc2.common.bus.device.provider.item;
import li.cil.oc2.api.bus.device.ItemDevice;
import li.cil.oc2.api.bus.device.provider.ItemDeviceQuery;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.bus.device.vm.item.InternetCardDevice;
import li.cil.oc2.common.bus.device.provider.util.AbstractItemDeviceProvider;
import li.cil.oc2.common.item.Items;

View File

@@ -4,7 +4,7 @@ package li.cil.oc2.common.bus.device.provider.item;
import li.cil.oc2.api.bus.device.ItemDevice;
import li.cil.oc2.api.bus.device.provider.ItemDeviceQuery;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.bus.device.provider.util.AbstractItemDeviceProvider;
import li.cil.oc2.common.bus.device.rpc.item.InventoryOperationsModuleDevice;
import li.cil.oc2.common.capabilities.Capabilities;

View File

@@ -4,7 +4,7 @@ package li.cil.oc2.common.bus.device.provider.item;
import li.cil.oc2.api.bus.device.ItemDevice;
import li.cil.oc2.api.bus.device.provider.ItemDeviceQuery;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.Constants;
import li.cil.oc2.common.bus.device.provider.util.AbstractItemDeviceProvider;
import li.cil.oc2.common.bus.device.vm.item.MemoryDevice;

View File

@@ -4,7 +4,7 @@ package li.cil.oc2.common.bus.device.provider.item;
import li.cil.oc2.api.bus.device.ItemDevice;
import li.cil.oc2.api.bus.device.provider.ItemDeviceQuery;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.bus.device.provider.util.AbstractItemDeviceProvider;
import li.cil.oc2.common.bus.device.vm.item.NetworkInterfaceCardDevice;
import li.cil.oc2.common.item.Items;

View File

@@ -4,7 +4,7 @@ package li.cil.oc2.common.bus.device.provider.item;
import li.cil.oc2.api.bus.device.ItemDevice;
import li.cil.oc2.api.bus.device.provider.ItemDeviceQuery;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.bus.device.provider.util.AbstractItemDeviceProvider;
import li.cil.oc2.common.bus.device.vm.item.NetworkTunnelDevice;
import li.cil.oc2.common.item.Items;

View File

@@ -4,7 +4,7 @@ package li.cil.oc2.common.bus.device.provider.item;
import li.cil.oc2.api.bus.device.ItemDevice;
import li.cil.oc2.api.bus.device.provider.ItemDeviceQuery;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.bus.device.provider.util.AbstractItemDeviceProvider;
import li.cil.oc2.common.bus.device.vm.item.NetworkTunnelDevice;
import li.cil.oc2.common.item.Items;

View File

@@ -4,7 +4,7 @@ package li.cil.oc2.common.bus.device.provider.item;
import li.cil.oc2.api.bus.device.ItemDevice;
import li.cil.oc2.api.bus.device.provider.ItemDeviceQuery;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.bus.device.provider.util.AbstractItemDeviceProvider;
import li.cil.oc2.common.bus.device.rpc.item.RedstoneInterfaceCardItemDevice;
import li.cil.oc2.common.item.Items;

View File

@@ -4,7 +4,7 @@ package li.cil.oc2.common.bus.device.provider.item;
import li.cil.oc2.api.bus.device.ItemDevice;
import li.cil.oc2.api.bus.device.provider.ItemDeviceQuery;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.bus.device.provider.util.AbstractItemDeviceProvider;
import li.cil.oc2.common.bus.device.rpc.item.SoundCardItemDevice;
import li.cil.oc2.common.item.Items;

View File

@@ -6,7 +6,7 @@ import li.cil.oc2.api.bus.device.object.Callback;
import li.cil.oc2.api.bus.device.object.Parameter;
import li.cil.oc2.api.capabilities.Robot;
import li.cil.oc2.api.util.RobotOperationSide;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.util.FakePlayerUtils;
import li.cil.oc2.common.util.TickUtils;
import net.minecraft.core.BlockPos;

View File

@@ -4,7 +4,7 @@ package li.cil.oc2.common.bus.device.rpc.item;
import li.cil.oc2.api.bus.device.object.Callback;
import li.cil.oc2.api.bus.device.object.Parameter;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.util.BlockLocation;
import li.cil.oc2.common.util.TickUtils;
import net.minecraft.resources.ResourceLocation;

View File

@@ -0,0 +1,101 @@
/* SPDX-License-Identifier: MIT */
package li.cil.oc2.common.config;
import li.cil.oc2.common.Constants;
import li.cil.oc2.common.config.client.GUISpec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Tiers;
import net.minecraftforge.common.TierSortingRegistry;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
@SuppressWarnings("FieldMayBeFinal")
public final class Config {
//TODO: Implement configuration of CPU MHzs
public static long maxAllocatedMemory = 512 * Constants.MEGABYTE;
public static int diskSizeFactor = 2 * Constants.MEGABYTE;
public static double busCableEnergyPerTick = 0.1;
public static double busInterfaceEnergyPerTick = 0.5;
public static int computerEnergyPerTick = 10;
public static int computerEnergyStorage = 2000;
public static int chargerEnergyPerTick = 2500;
public static int chargerEnergyStorage = 10000;
public static int projectorEnergyPerTick = 20;
public static int projectorEnergyStorage = 2000;
public static int monitorEnergyPerTick = 15;
public static int monitorEnergyStorage = 2000;
public static int cardCageEnergyPerTick = 20;
public static int cardCageEnergyStorage = 2000;
public static int gatewayEnergyPerPacket = 20;
public static int gatewayEnergyStorage = 2000;
public static int robotEnergyPerTick = 5;
public static int robotEnergyStorage = 750000;
public static double memoryEnergyPerMegabytePerTick = 0.5;
public static double hardDriveEnergyPerMegabytePerTick = 1;
public static double cpuEnergyPerMegahertzPerTick = 0.1;
public static int redstoneInterfaceCardEnergyPerTick = 1;
public static int networkInterfaceEnergyPerTick = 1;
public static int fileImportExportCardEnergyPerTick = 1;
public static int soundCardEnergyPerTick = 1;
public static int blockOperationsModuleEnergyPerTick = 2;
public static int inventoryOperationsModuleEnergyPerTick = 1;
public static int networkTunnelEnergyPerTick = 2;
public static ResourceLocation blockOperationsModuleToolTier = TierSortingRegistry.getName(Tiers.DIAMOND);
public static long soundCardCoolDownSeconds = 2;
public static UUID fakePlayerUUID = UUID.fromString("e39dd9a7-514f-4a2d-aa5e-b6030621416d");
public static int projectorAverageMaxBytesPerSecond = 160 * 1024;
public static int ethernetFrameTimeToLive = 12;
public static int hubEthernetFramesPerTick = 32;
public static boolean enable = false;
public static String remoteHost = "::1";
public static int remotePort = 4789;
public static String bindHost = "::1";
public static int bindPort = 4789;
public static boolean internetCardEnabled = false;
public static int defaultSessionLifetimeMs = 60 * 1000;
public static int defaultSessionsNumberPerCardLimit = 10;
public static int defaultSessionsNumberLimit = 100;
public static int defaultEchoRequestTimeoutMs = 1000;
public static List<String> deniedHosts =
Arrays.asList("127.0.0.0/8", "10.0.0.0/8", "100.64.0.0/10", "172.16.0.0/12", "192.168.0.0/16", "224.0.0.0/4");
public static List<String> allowedHosts = List.of();
public static String defaultNameServer = "1.1.1.1";
public static boolean useSynchronisedNAT = false;
public static int streamBufferSize = 2000;
public static int tcpRetransmissionTimeoutMs = 2 * 1000;
public static GUISpec.CaptureInputMode captureInputMode = GUISpec.CaptureInputMode.PER_BLOCK;
public static boolean captureInputDefaultState = false;
public static boolean computersUseEnergy() {
return computerEnergyPerTick > 0 && computerEnergyStorage > 0;
}
public static boolean projectorsUseEnergy() {
return projectorEnergyStorage > 0 && projectorEnergyPerTick > 0;
}
public static boolean cardCagesUseEnergy() {
return cardCageEnergyStorage > 0 && cardCageEnergyPerTick > 0;
}
public static boolean robotsUseEnergy() {
return robotEnergyPerTick > 0 && robotEnergyStorage > 0;
}
public static boolean monitorsUseEnergy() {
return computerEnergyPerTick > 0 && computerEnergyStorage > 0;
}
public static boolean gatewayUseEnergy() {
return gatewayEnergyPerPacket > 0 && gatewayEnergyStorage > 0;
}
}

View File

@@ -0,0 +1,24 @@
package li.cil.oc2.common.config.client;
import net.minecraftforge.common.ForgeConfigSpec;
public class ClientSpec {
public static final ForgeConfigSpec CLIENT_CONFIG_SPEC;
private static final GUISpec guiSpec;
static {
final ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
// GUI CONFIGURATION //
builder.push("gui");
guiSpec = new GUISpec(builder);
builder.pop();
CLIENT_CONFIG_SPEC = builder.build();
}
public static void loadValues() {
// GUI CONFIGURATION //
guiSpec.loadValues();
}
}

View File

@@ -0,0 +1,34 @@
package li.cil.oc2.common.config.client;
import li.cil.oc2.common.config.Config;
import net.minecraftforge.common.ForgeConfigSpec;
public class GUISpec {
public final ForgeConfigSpec.EnumValue<CaptureInputMode> captureInputMode;
public final ForgeConfigSpec.BooleanValue captureInputDefaultState;
GUISpec(ForgeConfigSpec.Builder builder) {
captureInputMode = builder.comment(
"The option below changes the behavior of the capture input feature:",
"PER_BLOCK - The capture input value is saved between UI opens on a per computer/monitor/robot basis",
"SHARED_BETWEEN_TYPE - The capture input value is saved between UI opens and is shared between all",
"blocks of the same type, e.g. enabling the setting on one monitor will enable it for all monitors but not for a computer",
"GLOBAL_CAPTURE - The capture input value is saved between UI opens and is shared between all devices that have the option"
).defineEnum("captureInputMode", CaptureInputMode.PER_BLOCK);
captureInputDefaultState = builder.comment(
"Defines whether input capture should be enabled by default in a session"
).define("captureInputDefaultState", false);
}
public enum CaptureInputMode {
PER_BLOCK,
SHARED_BETWEEN_TYPE,
GLOBAL_CAPTURE
}
public void loadValues() {
Config.captureInputMode = captureInputMode.get();
Config.captureInputDefaultState = captureInputDefaultState.get();
}
}

View File

@@ -0,0 +1,45 @@
package li.cil.oc2.common.config.common;
import li.cil.oc2.common.config.Config;
import net.minecraftforge.common.ForgeConfigSpec;
import java.util.UUID;
public class AdminSpec {
// ROOT //
public final ForgeConfigSpec.ConfigValue<String> fakePlayerUUID;
// NETWORK //
public final ForgeConfigSpec.IntValue projectorAverageMaxBytesPerSecond;
// VIRTUAL NETWORK //
public final ForgeConfigSpec.IntValue ethernetFrameTimeToLive;
public final ForgeConfigSpec.IntValue hubEthernetFrameTimeToLive;
AdminSpec(ForgeConfigSpec.Builder builder) {
fakePlayerUUID = builder.comment("The UUID that the mod will use for it's fake player")
.define("fakePlayerUUID", "e39dd9a7-514f-4a2d-aa5e-b6030621416d");
builder.push("network");
projectorAverageMaxBytesPerSecond = builder.comment("The maximum number of bytes a projector will send per second on average")
.defineInRange("projectorAverageMaxBytesPerSecond", 160*1024, 0, Integer.MAX_VALUE);
builder.pop();
builder.push("virtual_network");
ethernetFrameTimeToLive = builder.comment("The time to live of an ethernet frame sent over the virtual network")
.defineInRange("ethernetFrameTimeToLive", 12, 0, Integer.MAX_VALUE);
hubEthernetFrameTimeToLive = builder.comment("The time to live of an ethernet frame sent over the virtual network to a hub")
.defineInRange("hubEthernetFrameTimeToLive", 32, 0, Integer.MAX_VALUE);
builder.pop();
}
public void loadValues() {
Config.fakePlayerUUID = UUID.fromString(fakePlayerUUID.get());
Config.projectorAverageMaxBytesPerSecond = projectorAverageMaxBytesPerSecond.get();
Config.ethernetFrameTimeToLive = ethernetFrameTimeToLive.get();
Config.hubEthernetFramesPerTick = ethernetFrameTimeToLive.get();
}
}

View File

@@ -0,0 +1,64 @@
package li.cil.oc2.common.config.common;
import net.minecraftforge.common.ForgeConfigSpec;
public class CommonSpec {
public static final ForgeConfigSpec CONFIG_SPEC;
private static final VMSpec vmSpec;
private static final EnergySpec energySpec;
private static final GameplaySpec gameplaySpec;
private static final AdminSpec adminSpec;
private static final VXLANSpec vxlanSpec;
private static final InternetCardSpec internetCardSpec;
static {
final ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
// VM CONFIGURATION //
builder.push("vm");
vmSpec = new VMSpec(builder);
builder.pop();
// ENERGY CONFIGURATION //
builder.push("energy");
energySpec = new EnergySpec(builder);
builder.pop();
// GAMEPLAY CONFIGURATION //
builder.push("gameplay");
gameplaySpec = new GameplaySpec(builder);
builder.pop();
// ADMIN CONFIGURATION //
builder.push("admin");
adminSpec = new AdminSpec(builder);
builder.pop();
// VXLAN CONFIGURATION //
builder.push("vxlan");
vxlanSpec = new VXLANSpec(builder);
builder.pop();
// INTERNET CARD CONFIGURATION //
builder.push("internet_card");
internetCardSpec = new InternetCardSpec(builder);
builder.pop();
CONFIG_SPEC = builder.build();
}
public static void loadValues() {
// VM CONFIGURATION //
vmSpec.loadValues();
// ENERGY CONFIGURATION //
energySpec.loadValues();
// GAMEPLAY CONFIGURATION //
gameplaySpec.loadValues();
// ADMIN CONFIGURATION //
adminSpec.loadValues();
// VXLAN CONFIGURATION //
vxlanSpec.loadValues();
// INTERNET CARD CONFIGURATION //
internetCardSpec.loadValues();
}
}

View File

@@ -0,0 +1,159 @@
package li.cil.oc2.common.config.common;
import li.cil.oc2.common.config.Config;
import net.minecraftforge.common.ForgeConfigSpec;
public class EnergySpec {
// BLOCKS //
public final ForgeConfigSpec.DoubleValue busCableEnergyPerTick;
public final ForgeConfigSpec.DoubleValue busInterfaceEnergyPerTick;
public final ForgeConfigSpec.IntValue computerEnergyPerTick;
public final ForgeConfigSpec.IntValue computerEnergyStorage;
public final ForgeConfigSpec.IntValue chargerEnergyPerTick;
public final ForgeConfigSpec.IntValue chargerEnergyStorage;
public final ForgeConfigSpec.IntValue projectorEnergyPerTick;
public final ForgeConfigSpec.IntValue projectorEnergyStorage;
public final ForgeConfigSpec.IntValue monitorEnergyPerTick;
public final ForgeConfigSpec.IntValue monitorEnergyStorage;
public final ForgeConfigSpec.IntValue cardCageEnergyPerTick;
public final ForgeConfigSpec.IntValue cardCageEnergyStorage;
public final ForgeConfigSpec.IntValue gatewayEnergyPerPacket;
public final ForgeConfigSpec.IntValue gatewayEnergyStorage;
// ENTITIES //
public final ForgeConfigSpec.IntValue robotEnergyPerTick;
public final ForgeConfigSpec.IntValue robotEnergyStorage;
// ITEMS //
public final ForgeConfigSpec.DoubleValue memoryEnergyPerMegabytePerTick;
public final ForgeConfigSpec.DoubleValue hardDriveEnergyPerMegabytePerTick;
public final ForgeConfigSpec.DoubleValue cpuEnergyPerMegahertzPerTick;
public final ForgeConfigSpec.IntValue redstoneInterfaceCardEnergyPerTick;
public final ForgeConfigSpec.IntValue networkInterfaceEnergyPerTick;
public final ForgeConfigSpec.IntValue fileImportExportCardEnergyPerTick;
public final ForgeConfigSpec.IntValue soundCardEnergyPerTick;
public final ForgeConfigSpec.IntValue blockOperationsModuleEnergyPerTick;
public final ForgeConfigSpec.IntValue inventoryOperationsModuleEnergyPerTick;
public final ForgeConfigSpec.IntValue networkTunnelEnergyPerTick;
EnergySpec(ForgeConfigSpec.Builder builder) {
builder.push("blocks");
busCableEnergyPerTick = builder.comment("The amount of energy consumed per tick by a bus cable")
.defineInRange("busCableEnergyPerTick", 0.05, 0, Double.MAX_VALUE);
busInterfaceEnergyPerTick = builder.comment("The amount of energy consumed per tick by a bus interface")
.defineInRange("busInterfaceEnergyPerTick", 0.05, 0, Double.MAX_VALUE);
computerEnergyPerTick = builder.comment("The amount of energy consumed per tick by a computer")
.defineInRange("computerEnergyPerTick", 10, 0, Integer.MAX_VALUE);
computerEnergyStorage = builder.comment("The amount of energy stored in a computer")
.defineInRange("computerEnergyStorage", 2000, 0, Integer.MAX_VALUE);
chargerEnergyPerTick = builder.comment("The amount of energy consumed per tick by a charger")
.defineInRange("chargerEnergyPerTick", 2500, 0, Integer.MAX_VALUE);
chargerEnergyStorage = builder.comment("The amount of energy stored in a charger")
.defineInRange("chargerEnergyStorage", 10000, 0, Integer.MAX_VALUE);
projectorEnergyPerTick = builder.comment("The amount of energy consumed per tick by a projector")
.defineInRange("projectorEnergyPerTick", 20, 0, Integer.MAX_VALUE);
projectorEnergyStorage = builder.comment("The amount of energy stored in a projector")
.defineInRange("projectorEnergyStorage", 2000, 0, Integer.MAX_VALUE);
monitorEnergyPerTick = builder.comment("The amount of energy consumed per tick by a monitor")
.defineInRange("monitorEnergyPerTick", 15, 0, Integer.MAX_VALUE);
monitorEnergyStorage = builder.comment("The amount of energy stored in a monitor")
.defineInRange("monitorEnergyStorage", 2000, 0, Integer.MAX_VALUE);
cardCageEnergyPerTick = builder.comment("The amount of energy consumed per tick by a card cage")
.defineInRange("cardCageEnergyPerTick", 20, 0, Integer.MAX_VALUE);
cardCageEnergyStorage = builder.comment("The amount of energy stored in a card cage")
.defineInRange("cardCageEnergyStorage", 2000, 0, Integer.MAX_VALUE);
gatewayEnergyPerPacket = builder.comment("The amount of energy consumed per packet by a gateway")
.defineInRange("gatewayEnergyPerPacket", 20, 0, Integer.MAX_VALUE);
gatewayEnergyStorage = builder.comment("The amount of energy stored in a gateway")
.defineInRange("gatewayEnergyStorage", 2000, 0, Integer.MAX_VALUE);
builder.pop();
builder.push("entities");
robotEnergyPerTick = builder.comment("The amount of energy consumed per tick by a robot")
.defineInRange("gatewayEnergyStorage", 5, 0, Integer.MAX_VALUE);
robotEnergyStorage = builder.comment("The amount of energy stored in a robot")
.defineInRange("robotEnergyStorage", 750000, 0, Integer.MAX_VALUE);
builder.pop();
builder.push("items");
memoryEnergyPerMegabytePerTick = builder.comment("The amount of energy consumed per megabyte per tick for memory modules")
.defineInRange("memoryEnergyPerMegabytePerTick", 0.05, 0, Double.MAX_VALUE);
hardDriveEnergyPerMegabytePerTick = builder.comment("The amount of energy consumed per megabyte per tick for hard drive modules")
.defineInRange("hardDriveEnergyPerMegabytePerTick", 1.0, 0, Double.MAX_VALUE);
cpuEnergyPerMegahertzPerTick = builder.comment("The amount of energy consumed per megahertz per tick for CPU modules")
.defineInRange("cpuEnergyPerMegahertzPerTick", 0.1, 0, Double.MAX_VALUE);
redstoneInterfaceCardEnergyPerTick = builder.comment("The amount of energy consumed per tick for redstone interface cards")
.defineInRange("redstoneInterfaceCardEnergyPerTick", 1, 0, Integer.MAX_VALUE);
networkInterfaceEnergyPerTick = builder.comment("The amount of energy consumed per tick for network interface cards")
.defineInRange("redstoneInterfaceCardEnergyPerTick", 1, 0, Integer.MAX_VALUE);
fileImportExportCardEnergyPerTick = builder.comment("The amount of energy consumed per tick for file import/export cards")
.defineInRange("fileImportExportCardEnergyPerTick", 1, 0, Integer.MAX_VALUE);
soundCardEnergyPerTick = builder.comment("The amount of energy consumed per tick for sound cards")
.defineInRange("soundCardEnergyPerTick", 1, 0, Integer.MAX_VALUE);
blockOperationsModuleEnergyPerTick = builder.comment("The amount of energy consumed per tick for block operations modules")
.defineInRange("blockOperationsModuleEnergyPerTick", 2, 0, Integer.MAX_VALUE);
inventoryOperationsModuleEnergyPerTick = builder.comment("The amount of energy consumed per tick for inventory operations modules")
.defineInRange("inventoryOperationsModuleEnergyPerTick", 1, 0, Integer.MAX_VALUE);
networkTunnelEnergyPerTick = builder.comment("The amount of energy consumed per tick for network tunnels")
.defineInRange("networkTunnelEnergyPerTick", 2, 0, Integer.MAX_VALUE);
builder.pop();
}
public void loadValues() {
// BLOCKS //
Config.busCableEnergyPerTick = busCableEnergyPerTick.get();
Config.busInterfaceEnergyPerTick = busInterfaceEnergyPerTick.get();
Config.computerEnergyPerTick = computerEnergyPerTick.get();
Config.computerEnergyStorage = computerEnergyStorage.get();
Config.chargerEnergyPerTick = chargerEnergyPerTick.get();
Config.chargerEnergyStorage = chargerEnergyStorage.get();
Config.projectorEnergyPerTick = projectorEnergyPerTick.get();
Config.projectorEnergyStorage = projectorEnergyStorage.get();
Config.monitorEnergyPerTick = monitorEnergyPerTick.get();
Config.monitorEnergyStorage = monitorEnergyStorage.get();
Config.cardCageEnergyPerTick = cardCageEnergyPerTick.get();
Config.cardCageEnergyStorage = cardCageEnergyStorage.get();
Config.gatewayEnergyPerPacket = gatewayEnergyPerPacket.get();
Config.gatewayEnergyStorage = gatewayEnergyStorage.get();
// ENTITIES //
Config.robotEnergyPerTick = robotEnergyPerTick.get();
Config.robotEnergyStorage = robotEnergyStorage.get();
// ITEMS //
Config.memoryEnergyPerMegabytePerTick = memoryEnergyPerMegabytePerTick.get();
Config.hardDriveEnergyPerMegabytePerTick = hardDriveEnergyPerMegabytePerTick.get();
Config.cpuEnergyPerMegahertzPerTick = cpuEnergyPerMegahertzPerTick.get();
Config.redstoneInterfaceCardEnergyPerTick = redstoneInterfaceCardEnergyPerTick.get();
Config.networkInterfaceEnergyPerTick = networkInterfaceEnergyPerTick.get();
Config.fileImportExportCardEnergyPerTick = fileImportExportCardEnergyPerTick.get();
Config.soundCardEnergyPerTick = soundCardEnergyPerTick.get();
Config.blockOperationsModuleEnergyPerTick = blockOperationsModuleEnergyPerTick.get();
Config.inventoryOperationsModuleEnergyPerTick = inventoryOperationsModuleEnergyPerTick.get();
}
}

View File

@@ -0,0 +1,26 @@
package li.cil.oc2.common.config.common;
import li.cil.oc2.common.config.Config;
import net.minecraft.world.item.Tiers;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.TierSortingRegistry;
public class GameplaySpec {
public final ForgeConfigSpec.EnumValue<Tiers> blockOperationsModuleToolTier;
public final ForgeConfigSpec.LongValue soundCardCoolDownSeconds;
GameplaySpec(ForgeConfigSpec.Builder builder) {
blockOperationsModuleToolTier = builder.comment(
"The mining tool equivalent of the block operations module"
).defineEnum("blockOperationsModuleToolTier", Tiers.DIAMOND);
soundCardCoolDownSeconds = builder.comment(
"The number of seconds between sound card uses, to prevent spam/abuse"
).defineInRange("soundCardCoolDownSeconds", 2, 1, Long.MAX_VALUE);
}
public void loadValues() {
Config.blockOperationsModuleToolTier = TierSortingRegistry.getName(blockOperationsModuleToolTier.get());
Config.soundCardCoolDownSeconds = soundCardCoolDownSeconds.get();
}
}

View File

@@ -0,0 +1,75 @@
package li.cil.oc2.common.config.common;
import li.cil.oc2.common.config.Config;
import net.minecraftforge.common.ForgeConfigSpec;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class InternetCardSpec {
public final ForgeConfigSpec.BooleanValue internetCardEnabled;
public final ForgeConfigSpec.IntValue defaultSessionLifetimeMs;
public final ForgeConfigSpec.IntValue defaultSessionsNumberPerCardLimit;
public final ForgeConfigSpec.IntValue defaultSessionsNumberLimit;
public final ForgeConfigSpec.IntValue defaultEchoRequestTimeoutMs;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> deniedHosts;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> allowedHosts;
public final ForgeConfigSpec.ConfigValue<String> defaultNameServer;
public final ForgeConfigSpec.BooleanValue useSynchronisedNAT;
public final ForgeConfigSpec.IntValue streamBufferSize;
public final ForgeConfigSpec.IntValue tcpRetransmissionTimeoutMs;
InternetCardSpec(ForgeConfigSpec.Builder builder) {
internetCardEnabled = builder.comment("Whether to enable to internet card, VXLAN must also be enabled")
.define("internetCardEnabled", false);
defaultSessionLifetimeMs = builder.comment("Default lifetime of sessions in milliseconds")
.defineInRange("defaultSessionLifetimeMs", 60*1000, 0, Integer.MAX_VALUE);
defaultSessionsNumberPerCardLimit = builder.comment("Number of sessions (connections) allowed per internet card")
.defineInRange("defaultSessionsNumberPerCardLimit", 10, 0, Integer.MAX_VALUE);
defaultSessionsNumberLimit = builder.comment("Number of sessions (connections) allowed in total across all cards")
.defineInRange("defaultSessionsNumberLimit", 100, 0, Integer.MAX_VALUE);
defaultEchoRequestTimeoutMs = builder.comment("Number of milliseconds before a timeout should be assumed on ICMP/Echo (ping) packets")
.defineInRange("defaultEchoRequestTimeoutMs", 1000, 1, Integer.MAX_VALUE);
deniedHosts = builder.comment("A list of hosts (IPs) that VMs are not allowed to access",
"By default all local network address are disallowed, we recommend leaving it this way",
"Only denied hosts or allowed hosts may have a value, or an error will occur"
).defineListAllowEmpty("deniedHosts", Arrays.asList("127.0.0.0/8", "10.0.0.0/8", "100.64.0.0/10", "172.16.0.0/12", "192.168.0.0/16", "224.0.0.0/4"), obj -> obj instanceof String && !((String) obj).trim().isEmpty());
allowedHosts = builder.comment("A list of hosts (IPs) that VMs are allowed to access",
"Only denied hosts or allowed hosts may have a value, or an error will occur"
).defineListAllowEmpty("deniedHosts", List.of(), obj -> obj instanceof String && !((String) obj).trim().isEmpty());
defaultNameServer = builder.comment("The default nameserver to be used")
.define("defaultNameServer", "1.1.1.1");
useSynchronisedNAT = builder.define("useSynchronisedNAT", false);
streamBufferSize = builder.defineInRange("streamBufferSize", 2000, 1, Integer.MAX_VALUE);
tcpRetransmissionTimeoutMs = builder.defineInRange("tcpRetransmissionTimeoutMs", 2000, 1, Integer.MAX_VALUE);
}
public void loadValues() {
Config.internetCardEnabled = internetCardEnabled.get();
Config.defaultSessionLifetimeMs = defaultSessionLifetimeMs.get();
Config.defaultSessionsNumberPerCardLimit = defaultSessionsNumberPerCardLimit.get();
Config.defaultSessionsNumberLimit = defaultSessionsNumberLimit.get();
Config.defaultEchoRequestTimeoutMs = defaultEchoRequestTimeoutMs.get();
Config.deniedHosts = deniedHosts.get().stream()
.map(String::valueOf)
.collect(Collectors.toList());
Config.allowedHosts = allowedHosts.get().stream()
.map(String::valueOf)
.collect(Collectors.toList());
Config.defaultNameServer = defaultNameServer.get();
Config.useSynchronisedNAT = useSynchronisedNAT.get();
Config.streamBufferSize = streamBufferSize.get();
Config.tcpRetransmissionTimeoutMs = tcpRetransmissionTimeoutMs.get();
}
}

View File

@@ -0,0 +1,30 @@
package li.cil.oc2.common.config.common;
import li.cil.oc2.common.Constants;
import li.cil.oc2.common.config.Config;
import net.minecraftforge.common.ForgeConfigSpec;
public class VMSpec {
public final ForgeConfigSpec.LongValue maxAllocatedMemory;
public final ForgeConfigSpec.IntValue diskSizeFactor;
VMSpec(ForgeConfigSpec.Builder builder) {
maxAllocatedMemory = builder.comment(
"Maximum memory that can be allocated across all virtual machines (computers/robots) at any one time (in bytes)"
).defineInRange("maxAllocatedMemory", 512 * Constants.MEGABYTE, 0, Long.MAX_VALUE);
diskSizeFactor = builder.comment(
"Determines the size factor of drives, where SF is the size factor set below the sizes are as follows (this settings is in bytes):",
"Small Disk: SF",
"Medium Disk: 2 * SF",
"Large Disk: 4 * SF",
"Extra Large Disk: 16 * SF",
"With the default factor this is equivalent to (in the same order) 2MB, 4MB, 8MB, 32MB."
).defineInRange("diskSizeFactor", 2 * Constants.MEGABYTE, 0, Integer.MAX_VALUE);
}
public void loadValues() {
Config.maxAllocatedMemory = maxAllocatedMemory.get();
Config.diskSizeFactor = diskSizeFactor.get();
}
}

View File

@@ -0,0 +1,38 @@
package li.cil.oc2.common.config.common;
import li.cil.oc2.common.config.Config;
import net.minecraftforge.common.ForgeConfigSpec;
public class VXLANSpec {
public final ForgeConfigSpec.BooleanValue enable;
public final ForgeConfigSpec.ConfigValue<String> remoteHost;
public final ForgeConfigSpec.IntValue remotePort;
public final ForgeConfigSpec.ConfigValue<String> bindHost;
public final ForgeConfigSpec.IntValue bindPort;
VXLANSpec(ForgeConfigSpec.Builder builder) {
enable = builder.comment(
"Whether to enable VXLAN support, must be on for the internet card to work"
).define("enable", true);
remoteHost = builder.comment("The remote host that the VXLAN protocol is running on")
.define("remoteHost", "::1");
remotePort = builder.comment("The remote port that the VXLAN protocol is exposed on")
.defineInRange("remotePort", 4789, 1, 65535);
bindHost = builder.comment("The address to bind VXLAN to")
.define("bindHost", "::1");
bindPort = builder.comment("The port to bind VXLAN to")
.defineInRange("bindPort", 4789, 1, 65535);
}
public void loadValues() {
Config.enable = enable.get();
Config.remoteHost = remoteHost.get();
Config.remotePort = remotePort.get();
Config.bindHost = bindHost.get();
Config.bindPort = bindPort.get();
}
}

View File

@@ -2,9 +2,11 @@
package li.cil.oc2.common.container;
import li.cil.oc2.client.ClientSetup;
import li.cil.oc2.common.block.Blocks;
import li.cil.oc2.common.blockentity.ComputerBlockEntity;
import li.cil.oc2.common.bus.CommonDeviceBusController;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.network.Network;
import li.cil.oc2.common.network.message.ComputerPowerMessage;
import li.cil.oc2.common.network.message.ComputerTerminalInputMessage;
@@ -22,6 +24,7 @@ import java.nio.ByteBuffer;
public abstract class AbstractComputerContainer extends AbstractMachineTerminalContainer {
private final ComputerBlockEntity computer;
private static boolean captureInputState = Config.captureInputDefaultState;
///////////////////////////////////////////////////////////////////
@@ -59,6 +62,24 @@ public abstract class AbstractComputerContainer extends AbstractMachineTerminalC
return computer.getTerminal();
}
@Override
public boolean getCaptureInputState() {
return switch (Config.captureInputMode) {
case PER_BLOCK -> computer.getCaptureInputState();
case SHARED_BETWEEN_TYPE -> captureInputState;
case GLOBAL_CAPTURE -> ClientSetup.getCaptureInputState();
};
}
@Override
public void setCaptureInputState(final boolean state) {
switch (Config.captureInputMode) {
case PER_BLOCK -> computer.setCaptureInputState(state);
case SHARED_BETWEEN_TYPE -> captureInputState = state;
case GLOBAL_CAPTURE -> ClientSetup.setCaptureInputState(state);
}
}
@Override
public void sendTerminalInputToServer(final ByteBuffer input) {
Network.sendToServer(new ComputerTerminalInputMessage(computer, input));

View File

@@ -18,5 +18,13 @@ public abstract class AbstractMachineTerminalContainer extends AbstractMachineCo
public abstract Terminal getTerminal();
public abstract boolean getCaptureInputState();
public abstract void setCaptureInputState(boolean state);
public void toggleCaptureInputState() {
setCaptureInputState(!getCaptureInputState());
}
public abstract void sendTerminalInputToServer(final ByteBuffer input);
}

View File

@@ -2,9 +2,11 @@
package li.cil.oc2.common.container;
import li.cil.oc2.client.ClientSetup;
import li.cil.oc2.common.block.Blocks;
import li.cil.oc2.common.blockentity.MonitorBlockEntity;
import li.cil.oc2.common.bus.CommonDeviceBusController;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.network.Network;
import li.cil.oc2.common.network.message.*;
import li.cil.oc2.common.vm.VirtualMachine;
@@ -18,6 +20,7 @@ import javax.annotation.Nullable;
public abstract class AbstractMonitorContainer extends AbstractMachineContainer {
private final MonitorBlockEntity monitor;
private static boolean captureInputState = Config.captureInputDefaultState;
///////////////////////////////////////////////////////////////////
@@ -43,6 +46,24 @@ public abstract class AbstractMonitorContainer extends AbstractMachineContainer
public boolean isMounted() { return monitor.isMounted(); }
public boolean getCaptureInputState() {
return switch (Config.captureInputMode) {
case PER_BLOCK -> monitor.getCaptureInputState();
case SHARED_BETWEEN_TYPE -> captureInputState;
case GLOBAL_CAPTURE -> ClientSetup.getCaptureInputState();
};
}
public void setCaptureInputState(final boolean state) {
switch (Config.captureInputMode) {
case PER_BLOCK -> monitor.setCaptureInputState(state);
case SHARED_BETWEEN_TYPE -> captureInputState = state;
case GLOBAL_CAPTURE -> ClientSetup.setCaptureInputState(state);
}
}
public void toggleCaptureInputState() { setCaptureInputState(!getCaptureInputState()); }
@Override
public void sendPowerStateToServer(final boolean value) {
Network.sendToServer(new MonitorPowerMessage(monitor, value));

View File

@@ -2,7 +2,9 @@
package li.cil.oc2.common.container;
import li.cil.oc2.client.ClientSetup;
import li.cil.oc2.common.bus.CommonDeviceBusController;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.energy.FixedEnergyStorage;
import li.cil.oc2.common.entity.Robot;
import li.cil.oc2.common.network.Network;
@@ -19,6 +21,7 @@ import java.nio.ByteBuffer;
public abstract class AbstractRobotContainer extends AbstractMachineTerminalContainer {
private final Robot robot;
private static boolean captureInputState = Config.captureInputDefaultState;
///////////////////////////////////////////////////////////////////
@@ -60,6 +63,24 @@ public abstract class AbstractRobotContainer extends AbstractMachineTerminalCont
return robot.getTerminal();
}
@Override
public boolean getCaptureInputState() {
return switch (Config.captureInputMode) {
case PER_BLOCK -> robot.getCaptureInputState();
case SHARED_BETWEEN_TYPE -> captureInputState;
case GLOBAL_CAPTURE -> ClientSetup.getCaptureInputState();
};
}
@Override
public void setCaptureInputState(final boolean state) {
switch (Config.captureInputMode) {
case PER_BLOCK -> robot.setCaptureInputState(state);
case SHARED_BETWEEN_TYPE -> captureInputState = state;
case GLOBAL_CAPTURE -> ClientSetup.setCaptureInputState(state);
}
}
@Override
public void sendTerminalInputToServer(final ByteBuffer input) {
Network.sendToServer(new RobotTerminalInputMessage(robot, input));

View File

@@ -10,7 +10,7 @@ import li.cil.oc2.api.bus.device.object.ObjectDevice;
import li.cil.oc2.api.bus.device.object.Parameter;
import li.cil.oc2.api.bus.device.provider.ItemDeviceQuery;
import li.cil.oc2.api.capabilities.TerminalUserProvider;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.bus.AbstractDeviceBusElement;
import li.cil.oc2.common.bus.CommonDeviceBusController;
import li.cil.oc2.common.bus.device.util.Devices;
@@ -20,6 +20,7 @@ import li.cil.oc2.common.container.RobotInventoryContainer;
import li.cil.oc2.common.container.RobotTerminalContainer;
import li.cil.oc2.common.energy.FixedEnergyStorage;
import li.cil.oc2.common.entity.robot.*;
import li.cil.oc2.common.ext.ICaptureInputStateStorage;
import li.cil.oc2.common.integration.Wrenches;
import li.cil.oc2.common.item.Items;
import li.cil.oc2.common.network.Network;
@@ -86,7 +87,7 @@ import java.util.function.Consumer;
import static java.util.Collections.singleton;
import static li.cil.oc2.common.Constants.*;
public final class Robot extends Entity implements li.cil.oc2.api.capabilities.Robot, TerminalUserProvider {
public final class Robot extends Entity implements li.cil.oc2.api.capabilities.Robot, TerminalUserProvider, ICaptureInputStateStorage {
public static final EntityDataAccessor<BlockPos> TARGET_POSITION = SynchedEntityData.defineId(Robot.class, EntityDataSerializers.BLOCK_POS);
public static final EntityDataAccessor<Direction> TARGET_DIRECTION = SynchedEntityData.defineId(Robot.class, EntityDataSerializers.DIRECTION);
public static final EntityDataAccessor<Byte> SELECTED_SLOT = SynchedEntityData.defineId(Robot.class, EntityDataSerializers.BYTE);
@@ -126,6 +127,8 @@ public final class Robot extends Entity implements li.cil.oc2.api.capabilities.R
private final Set<Player> terminalUsers = Collections.newSetFromMap(new WeakHashMap<>());
private long lastPistonMovement;
public boolean captureInputState;
///////////////////////////////////////////////////////////////////
public Robot(final EntityType<?> type, final Level world) {
@@ -172,6 +175,16 @@ public final class Robot extends Entity implements li.cil.oc2.api.capabilities.R
getEntityData().set(SELECTED_SLOT, (byte) Mth.clamp(value, 0, INVENTORY_SIZE - 1));
}
@Override
public boolean getCaptureInputState() {
return captureInputState;
}
@Override
public void setCaptureInputState(boolean value) {
this.captureInputState = value;
}
@Nonnull
@Override
public <T> LazyOptional<T> getCapability(final Capability<T> capability, @Nullable final Direction side) {

View File

@@ -0,0 +1,7 @@
package li.cil.oc2.common.ext;
public interface ICaptureInputStateStorage {
boolean getCaptureInputState();
void setCaptureInputState(boolean value);
}

View File

@@ -6,7 +6,7 @@ import li.cil.oc2.api.inet.session.DatagramSession;
import li.cil.oc2.api.inet.session.EchoSession;
import li.cil.oc2.api.inet.session.Session;
import li.cil.oc2.api.inet.session.StreamSession;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable;
@@ -131,15 +131,24 @@ public final class DefaultSessionLayer implements SessionLayer {
});
}
public native byte[] sendICMP(byte[] ip, byte[] data, int size, int timeout);
@Override
public void sendSession(final Session session, @Nullable final ByteBuffer data) {
if (session instanceof final EchoSession echoSession) {
if (data == null) {
return; // session closed due expiration
}
final EchoResponse response = new EchoResponse(data, echoSession);
final InetAddress address = session.getDestination().getAddress();
executor.execute(() -> {
byte[] payload = new byte[data.remaining()];
int size = data.remaining();
data.get(payload);
byte[] responseData = sendICMP(address.getAddress(), payload, size, Config.defaultEchoRequestTimeoutMs);
if (responseData != null) {
final EchoResponse response = new EchoResponse(ByteBuffer.wrap(responseData), echoSession);
echoResponse.set(response);
}
/*executor.execute(() -> {
try {
if (address.isReachable(null, echoSession.getTtl(), Config.defaultEchoRequestTimeoutMs)) {
echoResponse.set(response);
@@ -147,7 +156,7 @@ public final class DefaultSessionLayer implements SessionLayer {
} catch (IOException e) {
LOGGER.error("Failed to get echo response", e);
}
});
});*/
} else if (session instanceof DatagramSession datagramSession) {
try {
switch (session.getState()) {

View File

@@ -7,7 +7,7 @@ import li.cil.oc2.api.inet.session.DatagramSession;
import li.cil.oc2.api.inet.session.EchoSession;
import li.cil.oc2.api.inet.session.Session;
import li.cil.oc2.api.inet.session.StreamSession;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import org.apache.logging.log4j.LogManager;

View File

@@ -9,6 +9,7 @@ import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
@@ -237,9 +238,9 @@ public final class InetUtils {
return -1 << (32 - prefix);
}
private static void configureIpSpace(final Ipv4Space ipSpace, final String hosts) {
private static void configureIpSpace(final Ipv4Space ipSpace, final List<String> hosts) {
int i = 1;
for (final String hostString : hosts.split(",")) {
for (final String hostString : hosts) {
final String rangeString = hostString.trim();
if (rangeString.isEmpty()) {
continue;
@@ -253,9 +254,9 @@ public final class InetUtils {
}
}
public static Ipv4Space computeIpSpace(final String deniedHosts, final String allowedHosts) {
final boolean deniedHostsIsEmpty = deniedHosts.trim().isEmpty();
final boolean allowedHostsIsEmpty = allowedHosts.trim().isEmpty();
public static Ipv4Space computeIpSpace(final List<String> deniedHosts, final List<String> allowedHosts) {
final boolean deniedHostsIsEmpty = deniedHosts.isEmpty();
final boolean allowedHostsIsEmpty = allowedHosts.isEmpty();
if (deniedHostsIsEmpty && allowedHostsIsEmpty) {
return new Ipv4Space(Ipv4Space.Modes.DENYLIST);
} else if (allowedHostsIsEmpty) {

View File

@@ -4,7 +4,7 @@ import li.cil.oc2.api.inet.LayerParameters;
import li.cil.oc2.api.inet.InternetManager;
import li.cil.oc2.api.inet.provider.InternetProvider;
import li.cil.oc2.api.inet.layer.LinkLocalLayer;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import net.minecraft.nbt.Tag;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;

View File

@@ -1,7 +1,7 @@
package li.cil.oc2.common.inet;
import li.cil.oc2.api.inet.session.StreamSession;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

View File

@@ -23,7 +23,6 @@ public class TcpHeader {
public boolean read(final ByteBuffer data) {
if (data.remaining() < MIN_HEADER_SIZE_NO_PORTS) {
System.out.println("A");
return false;
}
final int position = data.position();
@@ -31,7 +30,6 @@ public class TcpHeader {
acknowledgmentNumber = data.getInt();
final int dataOffset = position + ((data.get() >>> 2) & 0x3C) - 4;
if (dataOffset > data.limit()) {
System.out.println("C dataOffset=" + dataOffset + ", data.limit()=" + data.limit());
return false;
}
final int flags = Byte.toUnsignedInt(data.get());
@@ -62,7 +60,6 @@ public class TcpHeader {
if (type == OPTION_MAX_SEGMENT_SIZE) {
if (size != 4) {
data.position(position);
System.out.println("B");
return false;
}
maxSegmentSize = Short.toUnsignedInt(data.getShort());

View File

@@ -2,7 +2,7 @@
package li.cil.oc2.common.item;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.block.BusCableBlock;
import li.cil.oc2.common.util.LevelUtils;
import li.cil.oc2.common.util.TooltipUtils;

View File

@@ -2,7 +2,7 @@
package li.cil.oc2.common.item;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.block.Blocks;
import li.cil.oc2.common.block.BusCableBlock;
import li.cil.oc2.common.block.BusCableBlock.ConnectionType;

View File

@@ -4,7 +4,7 @@ package li.cil.oc2.common.item;
import li.cil.oc2.api.API;
import li.cil.oc2.common.Constants;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.block.Blocks;
import li.cil.oc2.common.bus.device.data.FirmwareRegistry;
import net.minecraft.world.item.DyeColor;
@@ -81,7 +81,7 @@ public final class Items {
public static final RegistryObject<FlashMemoryItem> FLASH_MEMORY = register("flash_memory", () ->
new FlashMemoryItem(12 * Constants.MEGABYTE));
public static final RegistryObject<FlashMemoryWithExternalDataItem> FLASH_MEMORY_CUSTOM = register("flash_memory_custom", () ->
new FlashMemoryWithExternalDataItem(FirmwareRegistry.BUILDROOT.getId()));
new FlashMemoryWithExternalDataItem(FirmwareRegistry.MINUX.getId()));
public static final RegistryObject<FloppyItem> FLOPPY = register("floppy", () ->
new FloppyItem(512 * Constants.KILOBYTE));

View File

@@ -5,7 +5,7 @@ package li.cil.oc2.common.item;
import li.cil.oc2.api.API;
import li.cil.oc2.api.bus.device.DeviceTypes;
import li.cil.oc2.client.renderer.entity.RobotWithoutLevelRenderer;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.energy.EnergyStorageItemStack;
import li.cil.oc2.common.entity.Entities;
import li.cil.oc2.common.entity.Robot;

View File

@@ -3,7 +3,7 @@
package li.cil.oc2.common.network;
import li.cil.oc2.api.API;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.blockentity.MonitorBlockEntity;
import li.cil.oc2.common.network.message.MonitorFramebufferMessage;
import net.minecraft.core.BlockPos;

View File

@@ -3,7 +3,7 @@
package li.cil.oc2.common.network;
import li.cil.oc2.api.API;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.blockentity.ProjectorBlockEntity;
import li.cil.oc2.common.network.message.ProjectorFramebufferMessage;
import net.minecraft.core.BlockPos;

View File

@@ -4,7 +4,7 @@ package li.cil.oc2.common.util;
import com.mojang.authlib.GameProfile;
import li.cil.oc2.api.API;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;

View File

@@ -6,7 +6,7 @@ import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import li.cil.oc2.api.bus.device.DeviceType;
import li.cil.oc2.api.bus.device.provider.ItemDeviceQuery;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import li.cil.oc2.common.Constants;
import li.cil.oc2.common.block.EnergyConsumingBlock;
import li.cil.oc2.common.bus.device.util.Devices;

View File

@@ -3,7 +3,7 @@
package li.cil.oc2.common.vm;
import li.cil.oc2.api.API;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import net.minecraftforge.event.server.ServerStoppedEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

View File

@@ -643,20 +643,20 @@ public class Terminal {
case SIXTEEN_COLOR_BRIGHT -> c = sixteenColorBright;
default -> c = Terminal.DEFAULT_BACKGROUND_COLOR;
}
final int shiftUpOrDown = count > 0 ? srcIndex : (dstIndex + charCount);
if (currentPrivateModeState.isAltBufferEnabled()) {
System.arraycopy(altBuffer, srcIndex, altBuffer, dstIndex, charCount);
System.arraycopy(altColors, srcIndex, altColors, dstIndex, charCount);
System.arraycopy(altColorsBackground, srcIndex, altColorsBackground, dstIndex, charCount);
System.arraycopy(altStyles, srcIndex, altStyles, dstIndex, charCount);
final int clearIndex = count > 0 ? srcIndex : (dstIndex + charCount);
// TODO Copy color and style from last line.
// TODO Copy color and style from last line.
final int clearCount = Math.abs(count * WIDTH);
Arrays.fill(altBuffer, clearIndex, clearIndex + clearCount, ' ');
// TODO Copy color and style from last line.
// TODO Copy color and style from last line.
Arrays.fill(altColors, clearIndex, clearIndex + clearCount, DEFAULT_COLORS.Copy());
Arrays.fill(altColorsBackground, clearIndex, clearIndex + clearCount, c.Copy());
Arrays.fill(altStyles, clearIndex, clearIndex + clearCount, DEFAULT_STYLE);
Arrays.fill(altBuffer, shiftUpOrDown, shiftUpOrDown + clearCount, ' ');
Arrays.fill(altColors, shiftUpOrDown, shiftUpOrDown + clearCount, DEFAULT_COLORS.Copy());
Arrays.fill(altColorsBackground, shiftUpOrDown, shiftUpOrDown + clearCount, c.Copy());
Arrays.fill(altStyles, shiftUpOrDown, shiftUpOrDown + clearCount, DEFAULT_STYLE);
int dirtyLinesMask = 0;
final int dirtyStart = Math.min(firstLine, firstLine + count);
@@ -672,14 +672,13 @@ public class Terminal {
System.arraycopy(colorsBackground, srcIndex, colorsBackground, dstIndex, charCount);
System.arraycopy(styles, srcIndex, styles, dstIndex, charCount);
final int clearIndex = count > 0 ? srcIndex : (dstIndex + charCount);
// TODO Copy color and style from last line.
// TODO Copy color and style from last line.
final int clearCount = Math.abs(count * WIDTH);
Arrays.fill(buffer, clearIndex, clearIndex + clearCount, ' ');
// TODO Copy color and style from last line.
// TODO Copy color and style from last line.
Arrays.fill(colors, clearIndex, clearIndex + clearCount, DEFAULT_COLORS.Copy());
Arrays.fill(colorsBackground, clearIndex, clearIndex + clearCount, c.Copy());
Arrays.fill(styles, clearIndex, clearIndex + clearCount, DEFAULT_STYLE);
Arrays.fill(buffer, shiftUpOrDown, shiftUpOrDown + clearCount, ' ');
Arrays.fill(colors, shiftUpOrDown, shiftUpOrDown + clearCount, DEFAULT_COLORS.Copy());
Arrays.fill(colorsBackground, shiftUpOrDown, shiftUpOrDown + clearCount, c.Copy());
Arrays.fill(styles, shiftUpOrDown, shiftUpOrDown + clearCount, DEFAULT_STYLE);
int dirtyLinesMask = 0;
final int dirtyStart = Math.min(firstLine, firstLine + count);
@@ -1046,7 +1045,7 @@ public class Terminal {
case TWO_FIFTY_SIX_COLOR -> COLORS_256[!invertBackground ? color.R : color.G];
case TRUE_COLOR -> color.ToInt();
case SIXTEEN_COLOR_BRIGHT -> BRIGHT_COLORS[!invertBackground ? color.R : color.G];
case DEFAULT_BACKGROUND -> throw new IllegalStateException("Unexpected value for foreground: " + color.Mode);
case DEFAULT_BACKGROUND -> 0x000000;
};
final int character = (useAltBuffer) ? terminal.altBuffer[index] : terminal.buffer[index];

View File

@@ -101,11 +101,9 @@ public class CH1 extends CSISequenceHandler { // Combined Handler 1 (DECSTBM & X
private void handleDECSTBM(int[] args, int argCount) {
final int first, last;
if (argCount == 2) {
System.out.println("Top: " + args[0] + ", Bottom: " + args[1]);
first = args[0] - 1;
last = args[1] - 1;
} else {
System.out.println("Full screen");
first = 0;
last = Terminal.HEIGHT - 1;
}

View File

@@ -56,7 +56,6 @@ public class CH11 extends CSISequenceHandler { // Combined Handler 10 (ICH and S
Arrays.fill(terminal.buffer, endIndex, endIndex + chars, ' ');
Arrays.fill(terminal.colors, endIndex, endIndex + chars, Terminal.DEFAULT_COLORS.Copy());
Arrays.fill(terminal.colorsBackground, endIndex, endIndex + chars, c.Copy());
Arrays.fill(terminal.styles, endIndex, endIndex + chars, Terminal.DEFAULT_STYLE);
}

View File

@@ -92,7 +92,6 @@ public class FontAtlas {
}
private void resizeAtlas() {
System.out.println("resizing atlas at " + atlasWidth + "x" + atlasHeight);
int newWidth = atlasWidth * 2;
int newHeight = atlasHeight * 2;

View File

@@ -1,7 +1,7 @@
package li.cil.oc2.common.vxlan;
import li.cil.oc2.api.capabilities.NetworkInterface;
import li.cil.oc2.common.Config;
import li.cil.oc2.common.config.Config;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

View File

@@ -2,6 +2,8 @@ package li.cil.oc2.common.inet;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
public class Ipv4SpaceTest {
@@ -30,7 +32,7 @@ public class Ipv4SpaceTest {
@Test
public void computeIpSpaceTest() throws AddressParseException {
final Ipv4Space space = InetUtils.computeIpSpace("127.0.0.0/8, 10.0.0.0/8, 100.64.0.0/10, 172.16.0.0/12, 192.168.0.0/16, 224.0.0.0/4", " ");
final Ipv4Space space = InetUtils.computeIpSpace(List.of("127.0.0.0/8", "10.0.0.0/8", "100.64.0.0/10", "172.16.0.0/12", "192.168.0.0/16", "224.0.0.0/4"), List.of());
assertEquals("[172.16.0.0-172.31.255.255, 192.168.0.0-192.168.255.255, 224.0.0.0-239.255.255.255, 10.0.0.0-10.255.255.255, 100.64.0.0-100.127.255.255, 127.0.0.0-127.255.255.255]", space.toString());
assertFalse(space.isAllowed(InetUtils.parseIpv4Address("192.168.1.1")));
assertTrue(space.isAllowed(InetUtils.parseIpv4Address("1.1.1.1")));

View File

@@ -105,7 +105,6 @@ public class IntegerSpaceTest {
assertTrue(space.put(23, 26));
assertEquals("[23-27, 29-39]", space.toString());
} catch (final AssertionError e) {
System.out.println("Space state: " + space);
throw e;
}
}